datapath: Rename linux-2.6 and compat-2.6 directories.
[sliver-openvswitch.git] / datapath / linux / compat / include / net / genetlink.h
1 #ifndef __NET_GENERIC_NETLINK_WRAPPER_H
2 #define __NET_GENERIC_NETLINK_WRAPPER_H 1
3
4 #include <linux/version.h>
5 #include <linux/netlink.h>
6 #include <net/net_namespace.h>
7
8 /* Very special super-nasty workaround here:
9  *
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
13  * 'flags' parameter.
14  *
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.
18  *
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.)
23  */
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 */
31
32 #include_next <net/genetlink.h>
33
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 */
40
41 #include <net/net_namespace.h>
42
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
44
45 #include <linux/genetlink.h>
46
47 /**
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
54  */
55 struct genl_multicast_group
56 {
57         struct genl_family  *family;    /* private */
58         struct list_head        list;      /* private */
59         char name[GENL_NAMSIZ];
60         u32     id;
61 };
62
63 int genl_register_mc_group(struct genl_family *family,
64                 struct genl_multicast_group *grp);
65 #endif /* linux kernel < 2.6.23 */
66
67
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
69 /**
70  * genlmsg_msg_size - length of genetlink message not including padding
71  * @payload: length of message payload
72  */
73 static inline int genlmsg_msg_size(int payload)
74 {
75         return GENL_HDRLEN + payload;
76 }
77
78 /**
79  * genlmsg_total_size - length of genetlink message including padding
80  * @payload: length of message payload
81  */
82 static inline int genlmsg_total_size(int payload)
83 {
84         return NLMSG_ALIGN(genlmsg_msg_size(payload));
85 }
86
87 #define genlmsg_multicast(s, p, g, f) \
88                 genlmsg_multicast_flags((s), (p), (g), (f))
89
90 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 pid,
91                 unsigned int group, gfp_t flags)
92 {
93         int err;
94
95         NETLINK_CB(skb).dst_group = group;
96
97         err = netlink_broadcast(genl_sock, skb, pid, group, flags);
98         if (err > 0)
99                 err = 0;
100
101         return err;
102 }
103 #endif /* linux kernel < 2.6.19 */
104
105
106 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
107
108 #define genlmsg_put(skb, p, seq, fam, flg, c) \
109         genlmsg_put((skb), (p), (seq), (fam)->id, (fam)->hdrsize, \
110                         (flg), (c), (fam)->version)
111
112 /**
113  * genlmsg_put_reply - Add generic netlink header to a reply message
114  * @skb: socket buffer holding the message
115  * @info: receiver info
116  * @family: generic netlink family
117  * @flags: netlink message flags
118  * @cmd: generic netlink command
119  *
120  * Returns pointer to user specific header
121  */
122 static inline void *genlmsg_put_reply(struct sk_buff *skb,
123                         struct genl_info *info, struct genl_family *family,
124                         int flags, u8 cmd)
125 {
126         return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
127                                 flags, cmd);
128 }
129
130 /**
131  * genlmsg_reply - reply to a request
132  * @skb: netlink message to be sent back
133  * @info: receiver information
134  */
135 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
136 {
137         return genlmsg_unicast(skb, info->snd_pid);
138 }
139
140 /**
141  * genlmsg_new - Allocate a new generic netlink message
142  * @payload: size of the message payload
143  * @flags: the type of memory to allocate.
144  */
145 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
146 {
147         return nlmsg_new(genlmsg_total_size(payload), flags);
148 }
149 #endif /* linux kernel < 2.6.20 */
150
151 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
152 int genl_register_family_with_ops(struct genl_family *family,
153         struct genl_ops *ops, size_t n_ops);
154 #endif
155
156 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
157 #define genl_notify(skb, net, pid, group, nlh, flags) \
158         genl_notify(skb, pid, group, nlh, flags)
159 #endif
160 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 pid,
161                         u32 group, struct nlmsghdr *nlh, gfp_t flags);
162
163 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && \
164     LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
165 static inline struct net *genl_info_net(struct genl_info *info)
166 {
167         return &init_net;
168 }
169 #endif
170
171 #endif /* genetlink.h */