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>
8 /* Very special super-nasty workaround here:
10 * Before 2.6.19, nlmsg_multicast() lacked a 'flags' parameter. We work
11 * around that in our <net/netlink.h> replacement, so that nlmsg_multicast
12 * is a macro that expands to rpl_nlmsg_multicast, which in turn has the
15 * However, also before 2.6.19, <net/genetlink.h> contains an inline definition
16 * of genlmsg_multicast() that, of course, calls it without the 'flags'
17 * parameter. This causes a build failure.
19 * This works around the problem by temporarily renaming both nlmsg_multicast
20 * and genlmsg_multicast with a "busted_" prefix. (Nothing actually defines
21 * busted_nlmsg_multicast(), so if anything actually tries to call it, then
22 * we'll get a link error.)
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
25 #undef nlmsg_multicast
26 #define nlmsg_multicast busted_nlmsg_multicast
27 #define genlmsg_multicast busted_genlmsg_multicast
28 extern int busted_nlmsg_multicast(struct sock *sk, struct sk_buff *skb,
29 u32 pid, unsigned int group);
30 #endif /* linux kernel < v2.6.19 */
32 #include_next <net/genetlink.h>
34 /* Drop the "busted_" prefix described above. */
35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
36 #undef nlmsg_multicast
37 #undef genlmsg_multicast
38 #define nlmsg_multicast rpl_nlmsg_multicast
39 #endif /* linux kernel < v2.6.19 */
41 #include <net/net_namespace.h>
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
45 #include <linux/genetlink.h>
48 * struct genl_multicast_group - generic netlink multicast group
49 * @name: name of the multicast group, names are per-family
50 * @id: multicast group ID, assigned by the core, to use with
51 * genlmsg_multicast().
52 * @list: list entry for linking
53 * @family: pointer to family, need not be set before registering
55 struct genl_multicast_group {
56 struct genl_family *family; /* private */
57 struct list_head list; /* private */
58 char name[GENL_NAMSIZ];
62 int genl_register_mc_group(struct genl_family *family,
63 struct genl_multicast_group *grp);
64 #endif /* linux kernel < 2.6.23 */
67 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
69 * genlmsg_msg_size - length of genetlink message not including padding
70 * @payload: length of message payload
72 static inline int genlmsg_msg_size(int payload)
74 return GENL_HDRLEN + payload;
78 * genlmsg_total_size - length of genetlink message including padding
79 * @payload: length of message payload
81 static inline int genlmsg_total_size(int payload)
83 return NLMSG_ALIGN(genlmsg_msg_size(payload));
86 #define genlmsg_multicast(s, p, g, f) \
87 genlmsg_multicast_flags((s), (p), (g), (f))
89 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 pid,
90 unsigned int group, gfp_t flags)
94 NETLINK_CB(skb).dst_group = group;
96 err = netlink_broadcast(genl_sock, skb, pid, group, flags);
102 #endif /* linux kernel < 2.6.19 */
104 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
105 #define genlmsg_multicast_netns(net, skb, pid, grp, flags) \
106 genlmsg_multicast(skb, pid, grp, flags)
109 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
111 #define genlmsg_put(skb, p, seq, fam, flg, c) \
112 genlmsg_put((skb), (p), (seq), (fam)->id, (fam)->hdrsize, \
113 (flg), (c), (fam)->version)
116 * genlmsg_put_reply - Add generic netlink header to a reply message
117 * @skb: socket buffer holding the message
118 * @info: receiver info
119 * @family: generic netlink family
120 * @flags: netlink message flags
121 * @cmd: generic netlink command
123 * Returns pointer to user specific header
125 static inline void *genlmsg_put_reply(struct sk_buff *skb,
126 struct genl_info *info, struct genl_family *family,
129 return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
134 * genlmsg_reply - reply to a request
135 * @skb: netlink message to be sent back
136 * @info: receiver information
138 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
140 return genlmsg_unicast(skb, info->snd_pid);
144 * genlmsg_new - Allocate a new generic netlink message
145 * @payload: size of the message payload
146 * @flags: the type of memory to allocate.
148 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
150 return nlmsg_new(genlmsg_total_size(payload), flags);
152 #endif /* linux kernel < 2.6.20 */
154 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
155 int genl_register_family_with_ops(struct genl_family *family,
156 struct genl_ops *ops, size_t n_ops);
159 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
160 #define genl_notify(skb, net, pid, group, nlh, flags) \
161 genl_notify(skb, pid, group, nlh, flags)
163 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 pid,
164 u32 group, struct nlmsghdr *nlh, gfp_t flags);
166 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && \
167 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
168 static inline struct net *genl_info_net(struct genl_info *info)
174 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
175 #define genlmsg_unicast(ignore_net, skb, pid) genlmsg_unicast(skb, pid)
177 #endif /* genetlink.h */