datapath: Convert ODP_DP_* commands to use AF_NETLINK socket layer.
[sliver-openvswitch.git] / datapath / linux-2.6 / compat-2.6 / 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
7 /* Very special super-nasty workaround here:
8  *
9  * Before 2.6.19, nlmsg_multicast() lacked a 'flags' parameter.  We work
10  * around that in our <net/netlink.h> replacement, so that nlmsg_multicast
11  * is a macro that expands to rpl_nlmsg_multicast, which in turn has the
12  * 'flags' parameter.
13  *
14  * However, also before 2.6.19, <net/genetlink.h> contains an inline definition
15  * of genlmsg_multicast() that, of course, calls it without the 'flags'
16  * parameter.  This causes a build failure.
17  *
18  * This works around the problem by temporarily renaming both nlmsg_multicast
19  * and genlmsg_multicast with a "busted_" prefix.  (Nothing actually defines
20  * busted_nlmsg_multicast(), so if anything actually tries to call it, then
21  * we'll get a link error.)
22  */
23 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
24 #undef nlmsg_multicast
25 #define nlmsg_multicast busted_nlmsg_multicast
26 #define genlmsg_multicast busted_genlmsg_multicast
27 extern int busted_nlmsg_multicast(struct sock *sk, struct sk_buff *skb,
28                                   u32 pid, unsigned int group);
29 #endif  /* linux kernel < v2.6.19 */
30
31 #include_next <net/genetlink.h>
32
33 /* Drop the "busted_" prefix described above. */
34 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
35 #undef nlmsg_multicast
36 #undef genlmsg_multicast
37 #define nlmsg_multicast rpl_nlmsg_multicast
38 #endif  /* linux kernel < v2.6.19 */
39
40 #include <net/net_namespace.h>
41
42 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
43
44 #include <linux/genetlink.h>
45
46 /**
47  * struct genl_multicast_group - generic netlink multicast group
48  * @name: name of the multicast group, names are per-family
49  * @id: multicast group ID, assigned by the core, to use with
50  *        genlmsg_multicast().
51  * @list: list entry for linking
52  * @family: pointer to family, need not be set before registering
53  */
54 struct genl_multicast_group
55 {
56         struct genl_family  *family;    /* private */
57         struct list_head        list;      /* private */
58         char name[GENL_NAMSIZ];
59         u32     id;
60 };
61
62 int genl_register_mc_group(struct genl_family *family,
63                 struct genl_multicast_group *grp);
64 #endif /* linux kernel < 2.6.23 */
65
66
67 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
68 /**
69  * genlmsg_msg_size - length of genetlink message not including padding
70  * @payload: length of message payload
71  */
72 static inline int genlmsg_msg_size(int payload)
73 {
74         return GENL_HDRLEN + payload;
75 }
76
77 /**
78  * genlmsg_total_size - length of genetlink message including padding
79  * @payload: length of message payload
80  */
81 static inline int genlmsg_total_size(int payload)
82 {
83         return NLMSG_ALIGN(genlmsg_msg_size(payload));
84 }
85
86 #define genlmsg_multicast(s, p, g, f) \
87                 genlmsg_multicast_flags((s), (p), (g), (f))
88
89 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 pid,
90                 unsigned int group, gfp_t flags)
91 {
92         int err;
93
94         NETLINK_CB(skb).dst_group = group;
95
96         err = netlink_broadcast(genl_sock, skb, pid, group, flags);
97         if (err > 0)
98                 err = 0;
99
100         return err;
101 }
102 #endif /* linux kernel < 2.6.19 */
103
104
105 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
106
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)
110
111 /**
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
118  *
119  * Returns pointer to user specific header
120  */
121 static inline void *genlmsg_put_reply(struct sk_buff *skb,
122                         struct genl_info *info, struct genl_family *family,
123                         int flags, u8 cmd)
124 {
125         return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
126                                 flags, cmd);
127 }
128
129 /**
130  * genlmsg_reply - reply to a request
131  * @skb: netlink message to be sent back
132  * @info: receiver information
133  */
134 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
135 {
136         return genlmsg_unicast(skb, info->snd_pid);
137 }
138
139 /**
140  * genlmsg_new - Allocate a new generic netlink message
141  * @payload: size of the message payload
142  * @flags: the type of memory to allocate.
143  */
144 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
145 {
146         return nlmsg_new(genlmsg_total_size(payload), flags);
147 }
148 #endif /* linux kernel < 2.6.20 */
149
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);
153 #endif
154
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
156 #define genl_notify(skb, net, pid, group, nlh, flags) \
157         genl_notify(skb, pid, group, nlh, flags)
158 #endif
159 extern void genl_notify(struct sk_buff *skb, struct net *net, u32 pid,
160                         u32 group, struct nlmsghdr *nlh, gfp_t flags);
161
162 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19) && \
163     LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
164 static inline struct net *genl_info_net(struct genl_info *info)
165 {
166         return &init_net;
167 }
168 #endif
169
170 #endif /* genetlink.h */