mctp: Implement extended addressing
Jeremy Kerr
maintainerPATCH v4 1/1 mctp: Implement extended addressing
This change allows an extended address struct - struct sockaddr_mctp_ext
- to be passed to sendmsg/recvmsg. This allows userspace to specify output ifindex and physical address information (for sendmsg) or receive the input ifindex/physaddr for incoming messages (for recvmsg). This is typically used by userspace for MCTP address discovery and assignment operations.
The extended addressing facility is conditional on a new sockopt:MCTP_OPT_ADDR_EXT; userspace must explicitly enable addressing before the kernel will consume/populate the extended address data.
Includes a fix for an uninitialised var:
---
v4:
- move SOL_MCTP to linux/sockets.h
v3:
- avoid uninitialised rc if we hit the !rt->dev WARN.
v2:
- non-RFC
- learn to spell "typically"
RFC: this patch adds a bit of an new ABI, in that the struct sockaddr for MCTP has been extended, with extra addressing data being available for applications after setting a sockopt.
Using something like IP_PKTINFO might be suitable instead, but that requires sendmsg/recvmsg, and control message setup, whereas this is a a simpler interface, and also allows extended addressing info in sendto/recvfrom too. Comments most welcome!
--- include/linux/socket.h | 1 + include/net/mctp.h | 16 +++++-- include/uapi/linux/mctp.h | 10 ++++ net/mctp/af_mctp.c | 86 ++++++++++++++++++++++++++++++---- net/mctp/route.c | 98 +++++++++++++++++++++++++++++---------- 5 files changed, 171 insertions(+), 40 deletions(-)
include/linux/socket.h +1 -0
@@ -365,6 +365,7 @@ struct ucred {#define SOL_TLS 282#define SOL_XDP 283#define SOL_MPTCP 284 +#define SOL_MCTP 285/* IPX options */ #define IPX_TYPE 1
include/net/mctp.h +11 -5
@@ -58,6 +58,9 @@ struct mctp_sock {mctp_eid_t bind_addr;__u8 bind_type; +/* sendmsg()/recvmsg() uses struct sockaddr_mctp_ext */ +bool addr_ext; +/* list of mctp_sk_key, for incoming tag lookup. updates protected * by sk->net->keys_lock */
@@ -152,10 +155,16 @@ struct mctp_sk_key {struct mctp_skb_cb {unsigned int magic; -unsigned int net; +int net; +int ifindex;/* extended/direct addressing if set */ +unsigned char halen;mctp_eid_t src; +unsigned char haddr[]; }; +#define MCTP_SKB_CB_HADDR_MAXLEN (sizeof((((struct sk_buff *)(NULL))->cb)) \ + - offsetof(struct mctp_skb_cb, haddr)) +/* skb control-block accessors with a little extra debugging for initial * development. *
@@ -189,8 +198,7 @@ static inline struct mctp_skb_cb *mctp_cb(struct sk_buff *skb)* * Updates to the route table are performed under rtnl; all reads under RCU, * so routes cannot be referenced over a RCU grace period. Specifically: A -* caller cannot block between mctp_route_lookup and passing the route to -* mctp_do_route. +* caller cannot block between mctp_route_lookup and mctp_route_release() */ struct mctp_route {mctp_eid_t min, max;
@@ -210,8 +218,6 @@ struct mctp_route {struct mctp_route *mctp_route_lookup (struct net *net,unsigned int dnet,mctp_eid_t daddr); -int mctp_do_route (struct mctp_route *rt,struct sk_buff *skb); -int mctp_local_output (struct sock *sk,struct mctp_route *rt,struct sk_buff *skb,mctp_eid_t daddr,u8 req_tag);
include/uapi/linux/mctp.h +10 -0
@@ -10,6 +10,7 @@#define __UAPI_MCTP_H#include <linux/types.h> +#include <linux/netdevice.h> typedef __u8 mctp_eid_t ;
@@ -25,6 +26,13 @@ struct sockaddr_mctp {__u8 smctp_tag; }; +struct sockaddr_mctp_ext { +struct sockaddr_mctp smctp_base; +int smctp_ifindex; +unsigned char smctp_halen; +unsigned char smctp_haddr[MAX_ADDR_LEN ]; +}; +#define MCTP_NET_ANY 0x0#define MCTP_ADDR_NULL 0x00
@@ -33,4 +41,6 @@ struct sockaddr_mctp {#define MCTP_TAG_MASK 0x07#define MCTP_TAG_OWNER 0x08 +#define MCTP_OPT_ADDR_EXT 1 +#endif /* __UAPI_MCTP_H */
net/mctp/af_mctp.c +76 -10
136 lines not on this page · raw message
net/mctp/route.c +73 -25
178 lines not on this page · raw message
Signature · 1 line
2.30.2