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