Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

genl: Add genlmsg_new_unicast() for unicast message allocation

Allocates a new sk_buff large enough to cover the specified payload
plus required Netlink headers. Will check receiving socket for
memory mapped i/o capability and use it if enabled. Will fall back
to non-mapped skb if message size exceeds the frame size of the ring.

Signed-of-by: Thomas Graf <tgraf@suug.ch>
Reviewed-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Jesse Gross <jesse@nicira.com>

authored by

Thomas Graf and committed by
Jesse Gross
bb9b18fb 663efa36

+25
+4
include/net/genetlink.h
··· 73 73 * @attrs: netlink attributes 74 74 * @_net: network namespace 75 75 * @user_ptr: user pointers 76 + * @dst_sk: destination socket 76 77 */ 77 78 struct genl_info { 78 79 u32 snd_seq; ··· 86 85 struct net * _net; 87 86 #endif 88 87 void * user_ptr[2]; 88 + struct sock * dst_sk; 89 89 }; 90 90 91 91 static inline struct net *genl_info_net(struct genl_info *info) ··· 179 177 struct sk_buff *skb, struct net *net, u32 portid, 180 178 u32 group, struct nlmsghdr *nlh, gfp_t flags); 181 179 180 + struct sk_buff *genlmsg_new_unicast(size_t payload, struct genl_info *info, 181 + gfp_t flags); 182 182 void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, 183 183 struct genl_family *family, int flags, u8 cmd); 184 184
+21
net/netlink/genetlink.c
··· 454 454 EXPORT_SYMBOL(genl_unregister_family); 455 455 456 456 /** 457 + * genlmsg_new_unicast - Allocate generic netlink message for unicast 458 + * @payload: size of the message payload 459 + * @info: information on destination 460 + * @flags: the type of memory to allocate 461 + * 462 + * Allocates a new sk_buff large enough to cover the specified payload 463 + * plus required Netlink headers. Will check receiving socket for 464 + * memory mapped i/o capability and use it if enabled. Will fall back 465 + * to non-mapped skb if message size exceeds the frame size of the ring. 466 + */ 467 + struct sk_buff *genlmsg_new_unicast(size_t payload, struct genl_info *info, 468 + gfp_t flags) 469 + { 470 + size_t len = nlmsg_total_size(genlmsg_total_size(payload)); 471 + 472 + return netlink_alloc_skb(info->dst_sk, len, info->snd_portid, flags); 473 + } 474 + EXPORT_SYMBOL_GPL(genlmsg_new_unicast); 475 + 476 + /** 457 477 * genlmsg_put - Add generic netlink header to netlink message 458 478 * @skb: socket buffer holding the message 459 479 * @portid: netlink portid the message is addressed to ··· 613 593 info.genlhdr = nlmsg_data(nlh); 614 594 info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN; 615 595 info.attrs = attrbuf; 596 + info.dst_sk = skb->sk; 616 597 genl_info_net_set(&info, net); 617 598 memset(&info.user_ptr, 0, sizeof(info.user_ptr)); 618 599