1#ifndef __NET_GENERIC_NETLINK_H
2#define __NET_GENERIC_NETLINK_H
3
4#include <linux/genetlink.h>
5#include <net/netlink.h>
6
7
8
9
10
11
12
13
14
15struct genl_multicast_group
16{
17 struct genl_family *family;
18 struct list_head list;
19 char name[GENL_NAMSIZ];
20 u32 id;
21};
22
23
24
25
26
27
28
29
30
31
32
33
34
35struct genl_family
36{
37 unsigned int id;
38 unsigned int hdrsize;
39 char name[GENL_NAMSIZ];
40 unsigned int version;
41 unsigned int maxattr;
42 struct nlattr ** attrbuf;
43 struct list_head ops_list;
44 struct list_head family_list;
45 struct list_head mcast_groups;
46};
47
48
49
50
51
52
53
54
55
56
57struct genl_info
58{
59 u32 snd_seq;
60 u32 snd_pid;
61 struct nlmsghdr * nlhdr;
62 struct genlmsghdr * genlhdr;
63 void * userhdr;
64 struct nlattr ** attrs;
65};
66
67
68
69
70
71
72
73
74
75
76
77struct genl_ops
78{
79 u8 cmd;
80 unsigned int flags;
81 const struct nla_policy *policy;
82 int (*doit)(struct sk_buff *skb,
83 struct genl_info *info);
84 int (*dumpit)(struct sk_buff *skb,
85 struct netlink_callback *cb);
86 int (*done)(struct netlink_callback *cb);
87 struct list_head ops_list;
88};
89
90extern int genl_register_family(struct genl_family *family);
91extern int genl_unregister_family(struct genl_family *family);
92extern int genl_register_ops(struct genl_family *, struct genl_ops *ops);
93extern int genl_unregister_ops(struct genl_family *, struct genl_ops *ops);
94extern int genl_register_mc_group(struct genl_family *family,
95 struct genl_multicast_group *grp);
96extern void genl_unregister_mc_group(struct genl_family *family,
97 struct genl_multicast_group *grp);
98
99extern struct sock *genl_sock;
100
101
102
103
104
105
106
107
108
109
110
111
112static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq,
113 struct genl_family *family, int flags, u8 cmd)
114{
115 struct nlmsghdr *nlh;
116 struct genlmsghdr *hdr;
117
118 nlh = nlmsg_put(skb, pid, seq, family->id, GENL_HDRLEN +
119 family->hdrsize, flags);
120 if (nlh == NULL)
121 return NULL;
122
123 hdr = nlmsg_data(nlh);
124 hdr->cmd = cmd;
125 hdr->version = family->version;
126 hdr->reserved = 0;
127
128 return (char *) hdr + GENL_HDRLEN;
129}
130
131
132
133
134
135
136
137
138
139
140
141static inline void *genlmsg_put_reply(struct sk_buff *skb,
142 struct genl_info *info,
143 struct genl_family *family,
144 int flags, u8 cmd)
145{
146 return genlmsg_put(skb, info->snd_pid, info->snd_seq, family,
147 flags, cmd);
148}
149
150
151
152
153
154
155static inline int genlmsg_end(struct sk_buff *skb, void *hdr)
156{
157 return nlmsg_end(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN);
158}
159
160
161
162
163
164
165static inline int genlmsg_cancel(struct sk_buff *skb, void *hdr)
166{
167 return nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN);
168}
169
170
171
172
173
174
175
176
177static inline int genlmsg_multicast(struct sk_buff *skb, u32 pid,
178 unsigned int group, gfp_t flags)
179{
180 return nlmsg_multicast(genl_sock, skb, pid, group, flags);
181}
182
183
184
185
186
187
188static inline int genlmsg_unicast(struct sk_buff *skb, u32 pid)
189{
190 return nlmsg_unicast(genl_sock, skb, pid);
191}
192
193
194
195
196
197
198static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
199{
200 return genlmsg_unicast(skb, info->snd_pid);
201}
202
203
204
205
206
207static inline void *genlmsg_data(const struct genlmsghdr *gnlh)
208{
209 return ((unsigned char *) gnlh + GENL_HDRLEN);
210}
211
212
213
214
215
216static inline int genlmsg_len(const struct genlmsghdr *gnlh)
217{
218 struct nlmsghdr *nlh = (struct nlmsghdr *)((unsigned char *)gnlh -
219 NLMSG_HDRLEN);
220 return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN);
221}
222
223
224
225
226
227static inline int genlmsg_msg_size(int payload)
228{
229 return GENL_HDRLEN + payload;
230}
231
232
233
234
235
236static inline int genlmsg_total_size(int payload)
237{
238 return NLMSG_ALIGN(genlmsg_msg_size(payload));
239}
240
241
242
243
244
245
246static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
247{
248 return nlmsg_new(genlmsg_total_size(payload), flags);
249}
250
251
252#endif
253