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 */
105 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
107 #define genlmsg_put(skb, p, seq, fam, flg, c) \
108 genlmsg_put((skb), (p), (seq), (fam)->id, (fam)->hdrsize, \
109 (flg), (c), (fam)->version)
112 * genlmsg_put_reply - Add generic netlink header to a reply message
113 * @skb: socket buffer holding the message
114 * @info: receiver info
115 * @family: generic netlink family
116 * @flags: netlink message flags
117 * @cmd: generic netlink command
119 * Returns pointer to user specific header
121 static inline void *genlmsg_put_reply(struct sk_buff *skb,
122 struct genl_info *info, struct genl_family *family,
125 return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
130 * genlmsg_reply - reply to a request
131 * @skb: netlink message to be sent back
132 * @info: receiver information
134 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
136 return genlmsg_unicast(skb, info->snd_pid);
140 * genlmsg_new - Allocate a new generic netlink message
141 * @payload: size of the message payload
142 * @flags: the type of memory to allocate.
144 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
146 return nlmsg_new(genlmsg_total_size(payload), flags);
148 #endif /* linux kernel < 2.6.20 */
150 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
151 int genl_register_family_with_ops(struct genl_family *family,
152 struct genl_ops *ops, size_t n_ops);
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
156 #define genl_notify(skb, net, pid, group, nlh, flags) \
157 genl_notify(skb, pid, group, nlh, flags)
159 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 pid,
160 u32 group, struct nlmsghdr *nlh, gfp_t flags);
162 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && \
163 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
164 static inline struct net *genl_info_net(struct genl_info *info)
170 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
171 #define genlmsg_unicast(ignore_net, skb, pid) genlmsg_unicast(skb, pid)
173 #endif /* genetlink.h */