57a47316dc2264c6e3f4e17a1929d4b776ab4712
[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
5 #include <linux/netlink.h>
6 #include_next <net/genetlink.h>
7
8 #include <linux/version.h>
9 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
10
11 #include <linux/genetlink.h>
12
13 /*----------------------------------------------------------------------------
14  * In 2.6.23, registering of multicast groups was added.  Our compatability 
15  * layer just supports registering a single group, since that's all we
16  * need.
17  */
18
19 /**
20  * struct genl_multicast_group - generic netlink multicast group
21  * @name: name of the multicast group, names are per-family
22  * @id: multicast group ID, assigned by the core, to use with
23  *        genlmsg_multicast().
24  * @list: list entry for linking
25  * @family: pointer to family, need not be set before registering
26  */
27 struct genl_multicast_group
28 {
29         struct genl_family  *family;    /* private */
30         struct list_head        list;      /* private */
31         char name[GENL_NAMSIZ];
32         u32     id;
33 };
34
35 int genl_register_mc_group(struct genl_family *family,
36                 struct genl_multicast_group *grp);
37 #endif /* linux kernel < 2.6.23 */
38
39
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
41 /**
42  * genlmsg_msg_size - length of genetlink message not including padding
43  * @payload: length of message payload
44  */
45 static inline int genlmsg_msg_size(int payload)
46 {
47         return GENL_HDRLEN + payload;
48 }
49
50 /**
51  * genlmsg_total_size - length of genetlink message including padding
52  * @payload: length of message payload
53  */
54 static inline int genlmsg_total_size(int payload)
55 {
56         return NLMSG_ALIGN(genlmsg_msg_size(payload));
57 }
58
59 #define genlmsg_multicast(s, p, g, f) \
60                 genlmsg_multicast_flags((s), (p), (g), (f))
61
62 static inline int genlmsg_multicast_flags(struct sk_buff *skb, u32 pid, 
63                 unsigned int group, gfp_t flags)
64 {
65         int err;
66
67         NETLINK_CB(skb).dst_group = group;
68
69         err = netlink_broadcast(genl_sock, skb, pid, group, flags);
70         if (err > 0)
71                 err = 0;
72
73         return err;
74 }
75 #endif /* linux kernel < 2.6.19 */
76
77
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
79
80 #define genlmsg_put(skb, p, seq, fam, flg, c) \
81         genlmsg_put((skb), (p), (seq), (fam)->id, (fam)->hdrsize, \
82                         (flg), (c), (fam)->version)
83
84 /**
85  * genlmsg_put_reply - Add generic netlink header to a reply message
86  * @skb: socket buffer holding the message
87  * @info: receiver info
88  * @family: generic netlink family
89  * @flags: netlink message flags
90  * @cmd: generic netlink command
91  *
92  * Returns pointer to user specific header
93  */
94 static inline void *genlmsg_put_reply(struct sk_buff *skb,
95                         struct genl_info *info, struct genl_family *family,
96                         int flags, u8 cmd)
97 {
98         return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
99                                 flags, cmd);
100 }
101
102 /**
103  * genlmsg_reply - reply to a request
104  * @skb: netlink message to be sent back
105  * @info: receiver information
106  */
107 static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
108 {
109         return genlmsg_unicast(skb, info->snd_pid);
110 }
111
112 /**
113  * genlmsg_new - Allocate a new generic netlink message
114  * @payload: size of the message payload
115  * @flags: the type of memory to allocate.
116  */
117 static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
118 {
119         return nlmsg_new(genlmsg_total_size(payload), flags);
120 }
121 #endif /* linux kernel < 2.6.20 */
122
123 #endif /* genetlink.h */