datapath: linux2.7 s/pid/portid/g
[cascardo/ovs.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 /*
9  * 15e473046cb6e5d18a4d0057e61d76315230382b renames pid to portid
10  * the affected structures are
11  * netlink_skb_parms::pid -> portid
12  * genl_info::snd_pid -> snd_portid
13  */
14 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)
15 #define snd_portid snd_pid
16 #define portid pid
17 #endif
18
19 /* Very special super-nasty workaround here:
20  *
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
24  * 'flags' parameter.
25  *
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.
29  *
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.)
34  */
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 */
42
43 #include_next <net/genetlink.h>
44
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 */
51
52 #include <net/net_namespace.h>
53
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
55
56 #include <linux/genetlink.h>
57
58 /**
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
65  */
66 struct genl_multicast_group {
67         struct genl_family  *family;    /* private */
68         struct list_head        list;      /* private */
69         char name[GENL_NAMSIZ];
70         u32     id;
71 };
72
73 int genl_register_mc_group(struct genl_family *family,
74                 struct genl_multicast_group *grp);
75 #endif /* linux kernel < 2.6.23 */
76
77
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
79 /**
80  * genlmsg_msg_size - length of genetlink message not including padding
81  * @payload: length of message payload
82  */
83 static inline int genlmsg_msg_size(int payload)
84 {
85         return GENL_HDRLEN + payload;
86 }
87
88 /**
89  * genlmsg_total_size - length of genetlink message including padding
90  * @payload: length of message payload
91  */
92 static inline int genlmsg_total_size(int payload)
93 {
94         return NLMSG_ALIGN(genlmsg_msg_size(payload));
95 }
96
97 #define genlmsg_multicast(s, p, g, f) \
98                 genlmsg_multicast_flags((s), (p), (g), (f))
99
100 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 portid,
101                 unsigned int group, gfp_t flags)
102 {
103         int err;
104
105         NETLINK_CB(skb).dst_group = group;
106
107         err = netlink_broadcast(genl_sock, skb, portid, group, flags);
108         if (err > 0)
109                 err = 0;
110
111         return err;
112 }
113 #endif /* linux kernel < 2.6.19 */
114
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)
118 #endif
119
120 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
121
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)
125
126 /**
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
133  *
134  * Returns pointer to user specific header
135  */
136 static inline void *genlmsg_put_reply(struct sk_buff *skb,
137                         struct genl_info *info, struct genl_family *family,
138                         int flags, u8 cmd)
139 {
140         return genlmsg_put(skb, info->snd_portid, info->snd_seq, family,
141                                 flags, cmd);
142 }
143
144 /**
145  * genlmsg_reply - reply to a request
146  * @skb: netlink message to be sent back
147  * @info: receiver information
148  */
149 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
150 {
151         return genlmsg_unicast(skb, info->snd_portid);
152 }
153
154 /**
155  * genlmsg_new - Allocate a new generic netlink message
156  * @payload: size of the message payload
157  * @flags: the type of memory to allocate.
158  */
159 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
160 {
161         return nlmsg_new(genlmsg_total_size(payload), flags);
162 }
163 #endif /* linux kernel < 2.6.20 */
164
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);
168 #endif
169
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)
173 #endif
174 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 portid,
175                         u32 group, struct nlmsghdr *nlh, gfp_t flags);
176
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)
180 {
181         return &init_net;
182 }
183 #endif
184
185 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
186 #define genlmsg_unicast(ignore_net, skb, portid)   genlmsg_unicast(skb, portid)
187 #endif
188 #endif /* genetlink.h */