1 #ifndef __NET_GENERIC_NETLINK_WRAPPER_H
2 #define __NET_GENERIC_NETLINK_WRAPPER_H 1
4 #include <linux/version.h>
5 #include <linux/netlink.h>
6 #include <net/net_namespace.h>
9 * 15e473046cb6e5d18a4d0057e61d76315230382b renames pid to portid
10 * the affected structures are
11 * netlink_skb_parms::pid -> portid
12 * genl_info::snd_pid -> snd_portid
14 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)
15 #define snd_portid snd_pid
19 /* Very special super-nasty workaround here:
21 * Before 2.6.19, nlmsg_multicast() lacked a 'flags' parameter. We work
22 * around that in our <net/netlink.h> replacement, so that nlmsg_multicast
23 * is a macro that expands to rpl_nlmsg_multicast, which in turn has the
26 * However, also before 2.6.19, <net/genetlink.h> contains an inline definition
27 * of genlmsg_multicast() that, of course, calls it without the 'flags'
28 * parameter. This causes a build failure.
30 * This works around the problem by temporarily renaming both nlmsg_multicast
31 * and genlmsg_multicast with a "busted_" prefix. (Nothing actually defines
32 * busted_nlmsg_multicast(), so if anything actually tries to call it, then
33 * we'll get a link error.)
35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
36 #undef nlmsg_multicast
37 #define nlmsg_multicast busted_nlmsg_multicast
38 #define genlmsg_multicast busted_genlmsg_multicast
39 extern int busted_nlmsg_multicast(struct sock *sk, struct sk_buff *skb,
40 u32 portid, unsigned int group);
41 #endif /* linux kernel < v2.6.19 */
43 #include_next <net/genetlink.h>
45 /* Drop the "busted_" prefix described above. */
46 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
47 #undef nlmsg_multicast
48 #undef genlmsg_multicast
49 #define nlmsg_multicast rpl_nlmsg_multicast
50 #endif /* linux kernel < v2.6.19 */
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
54 #include <linux/genetlink.h>
57 * struct genl_multicast_group - generic netlink multicast group
58 * @name: name of the multicast group, names are per-family
59 * @id: multicast group ID, assigned by the core, to use with
60 * genlmsg_multicast().
61 * @list: list entry for linking
62 * @family: pointer to family, need not be set before registering
64 struct genl_multicast_group {
65 struct genl_family *family; /* private */
66 struct list_head list; /* private */
67 char name[GENL_NAMSIZ];
71 int genl_register_mc_group(struct genl_family *family,
72 struct genl_multicast_group *grp);
73 #endif /* linux kernel < 2.6.23 */
76 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
78 * genlmsg_msg_size - length of genetlink message not including padding
79 * @payload: length of message payload
81 static inline int genlmsg_msg_size(int payload)
83 return GENL_HDRLEN + payload;
87 * genlmsg_total_size - length of genetlink message including padding
88 * @payload: length of message payload
90 static inline int genlmsg_total_size(int payload)
92 return NLMSG_ALIGN(genlmsg_msg_size(payload));
95 #define genlmsg_multicast(s, p, g, f) \
96 genlmsg_multicast_flags((s), (p), (g), (f))
98 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 portid,
99 unsigned int group, gfp_t flags)
103 NETLINK_CB(skb).dst_group = group;
105 err = netlink_broadcast(genl_sock, skb, portid, group, flags);
111 #endif /* linux kernel < 2.6.19 */
113 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
115 #define genlmsg_put(skb, p, seq, fam, flg, c) \
116 genlmsg_put((skb), (p), (seq), (fam)->id, (fam)->hdrsize, \
117 (flg), (c), (fam)->version)
120 * genlmsg_put_reply - Add generic netlink header to a reply message
121 * @skb: socket buffer holding the message
122 * @info: receiver info
123 * @family: generic netlink family
124 * @flags: netlink message flags
125 * @cmd: generic netlink command
127 * Returns pointer to user specific header
129 static inline void *genlmsg_put_reply(struct sk_buff *skb,
130 struct genl_info *info, struct genl_family *family,
133 return genlmsg_put(skb, info->snd_portid, info->snd_seq, family,
138 * genlmsg_reply - reply to a request
139 * @skb: netlink message to be sent back
140 * @info: receiver information
142 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
144 return genlmsg_unicast(skb, info->snd_portid);
148 * genlmsg_new - Allocate a new generic netlink message
149 * @payload: size of the message payload
150 * @flags: the type of memory to allocate.
152 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
154 return nlmsg_new(genlmsg_total_size(payload), flags);
156 #endif /* linux kernel < 2.6.20 */
158 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
159 int genl_register_family_with_ops(struct genl_family *family,
160 struct genl_ops *ops, size_t n_ops);
163 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
164 #define genl_notify(skb, net, portid, group, nlh, flags) \
165 genl_notify(skb, portid, group, nlh, flags)
167 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 portid,
168 u32 group, struct nlmsghdr *nlh, gfp_t flags);
170 #endif /* genetlink.h */