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 #include <net/net_namespace.h>
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
56 #include <linux/genetlink.h>
59 * struct genl_multicast_group - generic netlink multicast group
60 * @name: name of the multicast group, names are per-family
61 * @id: multicast group ID, assigned by the core, to use with
62 * genlmsg_multicast().
63 * @list: list entry for linking
64 * @family: pointer to family, need not be set before registering
66 struct genl_multicast_group {
67 struct genl_family *family; /* private */
68 struct list_head list; /* private */
69 char name[GENL_NAMSIZ];
73 int genl_register_mc_group(struct genl_family *family,
74 struct genl_multicast_group *grp);
75 #endif /* linux kernel < 2.6.23 */
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
80 * genlmsg_msg_size - length of genetlink message not including padding
81 * @payload: length of message payload
83 static inline int genlmsg_msg_size(int payload)
85 return GENL_HDRLEN + payload;
89 * genlmsg_total_size - length of genetlink message including padding
90 * @payload: length of message payload
92 static inline int genlmsg_total_size(int payload)
94 return NLMSG_ALIGN(genlmsg_msg_size(payload));
97 #define genlmsg_multicast(s, p, g, f) \
98 genlmsg_multicast_flags((s), (p), (g), (f))
100 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 portid,
101 unsigned int group, gfp_t flags)
105 NETLINK_CB(skb).dst_group = group;
107 err = netlink_broadcast(genl_sock, skb, portid, group, flags);
113 #endif /* linux kernel < 2.6.19 */
115 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
116 #define genlmsg_multicast_netns(net, skb, portid, grp, flags) \
117 genlmsg_multicast(skb, portid, grp, flags)
120 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
122 #define genlmsg_put(skb, p, seq, fam, flg, c) \
123 genlmsg_put((skb), (p), (seq), (fam)->id, (fam)->hdrsize, \
124 (flg), (c), (fam)->version)
127 * genlmsg_put_reply - Add generic netlink header to a reply message
128 * @skb: socket buffer holding the message
129 * @info: receiver info
130 * @family: generic netlink family
131 * @flags: netlink message flags
132 * @cmd: generic netlink command
134 * Returns pointer to user specific header
136 static inline void *genlmsg_put_reply(struct sk_buff *skb,
137 struct genl_info *info, struct genl_family *family,
140 return genlmsg_put(skb, info->snd_portid, info->snd_seq, family,
145 * genlmsg_reply - reply to a request
146 * @skb: netlink message to be sent back
147 * @info: receiver information
149 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
151 return genlmsg_unicast(skb, info->snd_portid);
155 * genlmsg_new - Allocate a new generic netlink message
156 * @payload: size of the message payload
157 * @flags: the type of memory to allocate.
159 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
161 return nlmsg_new(genlmsg_total_size(payload), flags);
163 #endif /* linux kernel < 2.6.20 */
165 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
166 int genl_register_family_with_ops(struct genl_family *family,
167 struct genl_ops *ops, size_t n_ops);
170 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
171 #define genl_notify(skb, net, portid, group, nlh, flags) \
172 genl_notify(skb, portid, group, nlh, flags)
174 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 portid,
175 u32 group, struct nlmsghdr *nlh, gfp_t flags);
177 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && \
178 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
179 static inline struct net *genl_info_net(struct genl_info *info)
185 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
186 #define genlmsg_unicast(ignore_net, skb, portid) genlmsg_unicast(skb, portid)
188 #endif /* genetlink.h */