Skip to content

Commit bb9b18f

Browse files
tgrafjessegross
authored andcommitted
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>
1 parent 663efa3 commit bb9b18f

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎include/net/genetlink.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct genl_family {
7373
* @attrs: netlink attributes
7474
* @_net: network namespace
7575
* @user_ptr: user pointers
76+
* @dst_sk: destination socket
7677
*/
7778
struct genl_info {
7879
u32 snd_seq;
@@ -85,6 +86,7 @@ struct genl_info {
8586
struct net * _net;
8687
#endif
8788
void * user_ptr[2];
89+
struct sock * dst_sk;
8890
};
8991

9092
static inline struct net *genl_info_net(struct genl_info *info)
@@ -177,6 +179,8 @@ void genl_notify(struct genl_family *family,
177179
struct sk_buff *skb, struct net *net, u32 portid,
178180
u32 group, struct nlmsghdr *nlh, gfp_t flags);
179181

182+
struct sk_buff *genlmsg_new_unicast(size_t payload, struct genl_info *info,
183+
gfp_t flags);
180184
void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
181185
struct genl_family *family, int flags, u8 cmd);
182186

‎net/netlink/genetlink.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,26 @@ int genl_unregister_family(struct genl_family *family)
453453
}
454454
EXPORT_SYMBOL(genl_unregister_family);
455455

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+
456476
/**
457477
* genlmsg_put - Add generic netlink header to netlink message
458478
* @skb: socket buffer holding the message
@@ -593,6 +613,7 @@ static int genl_family_rcv_msg(struct genl_family *family,
593613
info.genlhdr = nlmsg_data(nlh);
594614
info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN;
595615
info.attrs = attrbuf;
616+
info.dst_sk = skb->sk;
596617
genl_info_net_set(&info, net);
597618
memset(&info.user_ptr, 0, sizeof(info.user_ptr));
598619

0 commit comments

Comments
 (0)