Commit | Line | Data |
---|---|---|
09748a22 MS |
1 | /* Copyright (C) 2016 B.A.T.M.A.N. contributors: |
2 | * | |
3 | * Matthias Schiffer | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of version 2 of the GNU General Public | |
7 | * License as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | #include "netlink.h" | |
19 | #include "main.h" | |
20 | ||
f32ed4b5 | 21 | #include <linux/atomic.h> |
5da0aef5 MS |
22 | #include <linux/errno.h> |
23 | #include <linux/fs.h> | |
09748a22 | 24 | #include <linux/genetlink.h> |
5da0aef5 | 25 | #include <linux/if_ether.h> |
09748a22 | 26 | #include <linux/init.h> |
5da0aef5 MS |
27 | #include <linux/netdevice.h> |
28 | #include <linux/netlink.h> | |
09748a22 | 29 | #include <linux/printk.h> |
b60620cf MS |
30 | #include <linux/rculist.h> |
31 | #include <linux/rcupdate.h> | |
32 | #include <linux/skbuff.h> | |
5da0aef5 | 33 | #include <linux/stddef.h> |
33a3bb4a | 34 | #include <linux/types.h> |
09748a22 | 35 | #include <net/genetlink.h> |
5da0aef5 | 36 | #include <net/netlink.h> |
b60620cf | 37 | #include <net/sock.h> |
09748a22 MS |
38 | #include <uapi/linux/batman_adv.h> |
39 | ||
07a3061e | 40 | #include "bat_algo.h" |
04f3f5bf | 41 | #include "bridge_loop_avoidance.h" |
d7129daf | 42 | #include "gateway_client.h" |
5da0aef5 | 43 | #include "hard-interface.h" |
85cf8c85 | 44 | #include "originator.h" |
5da0aef5 | 45 | #include "soft-interface.h" |
33a3bb4a | 46 | #include "tp_meter.h" |
d34f0550 | 47 | #include "translation-table.h" |
5da0aef5 | 48 | |
07a3061e | 49 | struct genl_family batadv_netlink_family = { |
09748a22 MS |
50 | .id = GENL_ID_GENERATE, |
51 | .hdrsize = 0, | |
52 | .name = BATADV_NL_NAME, | |
53 | .version = 1, | |
54 | .maxattr = BATADV_ATTR_MAX, | |
55 | }; | |
56 | ||
33a3bb4a AQ |
57 | /* multicast groups */ |
58 | enum batadv_netlink_multicast_groups { | |
59 | BATADV_NL_MCGRP_TPMETER, | |
60 | }; | |
61 | ||
62 | static struct genl_multicast_group batadv_netlink_mcgrps[] = { | |
63 | [BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER }, | |
64 | }; | |
65 | ||
5da0aef5 MS |
66 | static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { |
67 | [BATADV_ATTR_VERSION] = { .type = NLA_STRING }, | |
68 | [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING }, | |
69 | [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, | |
70 | [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING }, | |
71 | [BATADV_ATTR_MESH_ADDRESS] = { .len = ETH_ALEN }, | |
72 | [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, | |
73 | [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING }, | |
74 | [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN }, | |
33a3bb4a AQ |
75 | [BATADV_ATTR_ORIG_ADDRESS] = { .len = ETH_ALEN }, |
76 | [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 }, | |
77 | [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 }, | |
78 | [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 }, | |
79 | [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 }, | |
b60620cf | 80 | [BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG }, |
d34f0550 MS |
81 | [BATADV_ATTR_TT_ADDRESS] = { .len = ETH_ALEN }, |
82 | [BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 }, | |
83 | [BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 }, | |
84 | [BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 }, | |
85 | [BATADV_ATTR_TT_VID] = { .type = NLA_U16 }, | |
86 | [BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 }, | |
87 | [BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG }, | |
88 | [BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 }, | |
024f99cb MS |
89 | [BATADV_ATTR_NEIGH_ADDRESS] = { .len = ETH_ALEN }, |
90 | [BATADV_ATTR_TQ] = { .type = NLA_U8 }, | |
f02a478f | 91 | [BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 }, |
d7129daf SE |
92 | [BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 }, |
93 | [BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 }, | |
94 | [BATADV_ATTR_ROUTER] = { .len = ETH_ALEN }, | |
04f3f5bf AL |
95 | [BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG }, |
96 | [BATADV_ATTR_BLA_ADDRESS] = { .len = ETH_ALEN }, | |
97 | [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 }, | |
98 | [BATADV_ATTR_BLA_BACKBONE] = { .len = ETH_ALEN }, | |
99 | [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 }, | |
5da0aef5 MS |
100 | }; |
101 | ||
b60620cf MS |
102 | /** |
103 | * batadv_netlink_get_ifindex - Extract an interface index from a message | |
104 | * @nlh: Message header | |
105 | * @attrtype: Attribute which holds an interface index | |
106 | * | |
107 | * Return: interface index, or 0. | |
108 | */ | |
d34f0550 | 109 | int |
b60620cf MS |
110 | batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype) |
111 | { | |
112 | struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype); | |
113 | ||
114 | return attr ? nla_get_u32(attr) : 0; | |
115 | } | |
116 | ||
5da0aef5 MS |
117 | /** |
118 | * batadv_netlink_mesh_info_put - fill in generic information about mesh | |
119 | * interface | |
120 | * @msg: netlink message to be sent back | |
121 | * @soft_iface: interface for which the data should be taken | |
122 | * | |
123 | * Return: 0 on success, < 0 on error | |
124 | */ | |
125 | static int | |
126 | batadv_netlink_mesh_info_put(struct sk_buff *msg, struct net_device *soft_iface) | |
127 | { | |
128 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); | |
129 | struct batadv_hard_iface *primary_if = NULL; | |
130 | struct net_device *hard_iface; | |
131 | int ret = -ENOBUFS; | |
132 | ||
133 | if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) || | |
134 | nla_put_string(msg, BATADV_ATTR_ALGO_NAME, | |
29824a55 | 135 | bat_priv->algo_ops->name) || |
5da0aef5 MS |
136 | nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) || |
137 | nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) || | |
138 | nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN, | |
f32ed4b5 SE |
139 | soft_iface->dev_addr) || |
140 | nla_put_u8(msg, BATADV_ATTR_TT_TTVN, | |
141 | (u8)atomic_read(&bat_priv->tt.vn))) | |
5da0aef5 MS |
142 | goto out; |
143 | ||
144 | primary_if = batadv_primary_if_get_selected(bat_priv); | |
145 | if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) { | |
146 | hard_iface = primary_if->net_dev; | |
147 | ||
148 | if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, | |
149 | hard_iface->ifindex) || | |
150 | nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, | |
151 | hard_iface->name) || | |
152 | nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, | |
153 | hard_iface->dev_addr)) | |
154 | goto out; | |
155 | } | |
156 | ||
157 | ret = 0; | |
158 | ||
159 | out: | |
160 | if (primary_if) | |
161 | batadv_hardif_put(primary_if); | |
162 | ||
163 | return ret; | |
164 | } | |
165 | ||
166 | /** | |
167 | * batadv_netlink_get_mesh_info - handle incoming BATADV_CMD_GET_MESH_INFO | |
168 | * netlink request | |
169 | * @skb: received netlink message | |
170 | * @info: receiver information | |
171 | * | |
172 | * Return: 0 on success, < 0 on error | |
173 | */ | |
174 | static int | |
175 | batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) | |
176 | { | |
177 | struct net *net = genl_info_net(info); | |
178 | struct net_device *soft_iface; | |
179 | struct sk_buff *msg = NULL; | |
180 | void *msg_head; | |
181 | int ifindex; | |
182 | int ret; | |
183 | ||
184 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) | |
185 | return -EINVAL; | |
186 | ||
187 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); | |
188 | if (!ifindex) | |
189 | return -EINVAL; | |
190 | ||
191 | soft_iface = dev_get_by_index(net, ifindex); | |
192 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { | |
193 | ret = -ENODEV; | |
194 | goto out; | |
195 | } | |
196 | ||
197 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
198 | if (!msg) { | |
199 | ret = -ENOMEM; | |
200 | goto out; | |
201 | } | |
202 | ||
203 | msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq, | |
204 | &batadv_netlink_family, 0, | |
205 | BATADV_CMD_GET_MESH_INFO); | |
206 | if (!msg_head) { | |
207 | ret = -ENOBUFS; | |
208 | goto out; | |
209 | } | |
210 | ||
211 | ret = batadv_netlink_mesh_info_put(msg, soft_iface); | |
212 | ||
213 | out: | |
214 | if (soft_iface) | |
215 | dev_put(soft_iface); | |
216 | ||
217 | if (ret) { | |
218 | if (msg) | |
219 | nlmsg_free(msg); | |
220 | return ret; | |
221 | } | |
222 | ||
223 | genlmsg_end(msg, msg_head); | |
224 | return genlmsg_reply(msg, info); | |
225 | } | |
226 | ||
33a3bb4a AQ |
227 | /** |
228 | * batadv_netlink_tp_meter_put - Fill information of started tp_meter session | |
229 | * @msg: netlink message to be sent back | |
230 | * @cookie: tp meter session cookie | |
231 | * | |
232 | * Return: 0 on success, < 0 on error | |
233 | */ | |
234 | static int | |
235 | batadv_netlink_tp_meter_put(struct sk_buff *msg, u32 cookie) | |
236 | { | |
237 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie)) | |
238 | return -ENOBUFS; | |
239 | ||
240 | return 0; | |
241 | } | |
242 | ||
243 | /** | |
244 | * batadv_netlink_tpmeter_notify - send tp_meter result via netlink to client | |
245 | * @bat_priv: the bat priv with all the soft interface information | |
246 | * @dst: destination of tp_meter session | |
247 | * @result: reason for tp meter session stop | |
248 | * @test_time: total time ot the tp_meter session | |
249 | * @total_bytes: bytes acked to the receiver | |
250 | * @cookie: cookie of tp_meter session | |
251 | * | |
252 | * Return: 0 on success, < 0 on error | |
253 | */ | |
254 | int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst, | |
255 | u8 result, u32 test_time, u64 total_bytes, | |
256 | u32 cookie) | |
257 | { | |
258 | struct sk_buff *msg; | |
259 | void *hdr; | |
260 | int ret; | |
261 | ||
262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
263 | if (!msg) | |
264 | return -ENOMEM; | |
265 | ||
266 | hdr = genlmsg_put(msg, 0, 0, &batadv_netlink_family, 0, | |
267 | BATADV_CMD_TP_METER); | |
268 | if (!hdr) { | |
269 | ret = -ENOBUFS; | |
270 | goto err_genlmsg; | |
271 | } | |
272 | ||
273 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie)) | |
274 | goto nla_put_failure; | |
275 | ||
276 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, test_time)) | |
277 | goto nla_put_failure; | |
278 | ||
279 | if (nla_put_u64_64bit(msg, BATADV_ATTR_TPMETER_BYTES, total_bytes, | |
280 | BATADV_ATTR_PAD)) | |
281 | goto nla_put_failure; | |
282 | ||
283 | if (nla_put_u8(msg, BATADV_ATTR_TPMETER_RESULT, result)) | |
284 | goto nla_put_failure; | |
285 | ||
286 | if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst)) | |
287 | goto nla_put_failure; | |
288 | ||
289 | genlmsg_end(msg, hdr); | |
290 | ||
291 | genlmsg_multicast_netns(&batadv_netlink_family, | |
292 | dev_net(bat_priv->soft_iface), msg, 0, | |
293 | BATADV_NL_MCGRP_TPMETER, GFP_KERNEL); | |
294 | ||
295 | return 0; | |
296 | ||
297 | nla_put_failure: | |
298 | genlmsg_cancel(msg, hdr); | |
299 | ret = -EMSGSIZE; | |
300 | ||
301 | err_genlmsg: | |
302 | nlmsg_free(msg); | |
303 | return ret; | |
304 | } | |
305 | ||
306 | /** | |
307 | * batadv_netlink_tp_meter_start - Start a new tp_meter session | |
308 | * @skb: received netlink message | |
309 | * @info: receiver information | |
310 | * | |
311 | * Return: 0 on success, < 0 on error | |
312 | */ | |
313 | static int | |
314 | batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info) | |
315 | { | |
316 | struct net *net = genl_info_net(info); | |
317 | struct net_device *soft_iface; | |
318 | struct batadv_priv *bat_priv; | |
319 | struct sk_buff *msg = NULL; | |
320 | u32 test_length; | |
321 | void *msg_head; | |
322 | int ifindex; | |
323 | u32 cookie; | |
324 | u8 *dst; | |
325 | int ret; | |
326 | ||
327 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) | |
328 | return -EINVAL; | |
329 | ||
330 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) | |
331 | return -EINVAL; | |
332 | ||
333 | if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]) | |
334 | return -EINVAL; | |
335 | ||
336 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); | |
337 | if (!ifindex) | |
338 | return -EINVAL; | |
339 | ||
340 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); | |
341 | ||
342 | test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]); | |
343 | ||
344 | soft_iface = dev_get_by_index(net, ifindex); | |
345 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { | |
346 | ret = -ENODEV; | |
347 | goto out; | |
348 | } | |
349 | ||
350 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
351 | if (!msg) { | |
352 | ret = -ENOMEM; | |
353 | goto out; | |
354 | } | |
355 | ||
356 | msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq, | |
357 | &batadv_netlink_family, 0, | |
358 | BATADV_CMD_TP_METER); | |
359 | if (!msg_head) { | |
360 | ret = -ENOBUFS; | |
361 | goto out; | |
362 | } | |
363 | ||
364 | bat_priv = netdev_priv(soft_iface); | |
365 | batadv_tp_start(bat_priv, dst, test_length, &cookie); | |
366 | ||
367 | ret = batadv_netlink_tp_meter_put(msg, cookie); | |
368 | ||
369 | out: | |
370 | if (soft_iface) | |
371 | dev_put(soft_iface); | |
372 | ||
373 | if (ret) { | |
374 | if (msg) | |
375 | nlmsg_free(msg); | |
376 | return ret; | |
377 | } | |
378 | ||
379 | genlmsg_end(msg, msg_head); | |
380 | return genlmsg_reply(msg, info); | |
381 | } | |
382 | ||
383 | /** | |
384 | * batadv_netlink_tp_meter_start - Cancel a running tp_meter session | |
385 | * @skb: received netlink message | |
386 | * @info: receiver information | |
387 | * | |
388 | * Return: 0 on success, < 0 on error | |
389 | */ | |
390 | static int | |
391 | batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info) | |
392 | { | |
393 | struct net *net = genl_info_net(info); | |
394 | struct net_device *soft_iface; | |
395 | struct batadv_priv *bat_priv; | |
396 | int ifindex; | |
397 | u8 *dst; | |
398 | int ret = 0; | |
399 | ||
400 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) | |
401 | return -EINVAL; | |
402 | ||
403 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) | |
404 | return -EINVAL; | |
405 | ||
406 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); | |
407 | if (!ifindex) | |
408 | return -EINVAL; | |
409 | ||
410 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); | |
411 | ||
412 | soft_iface = dev_get_by_index(net, ifindex); | |
413 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { | |
414 | ret = -ENODEV; | |
415 | goto out; | |
416 | } | |
417 | ||
418 | bat_priv = netdev_priv(soft_iface); | |
419 | batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL); | |
420 | ||
421 | out: | |
422 | if (soft_iface) | |
423 | dev_put(soft_iface); | |
424 | ||
425 | return ret; | |
426 | } | |
427 | ||
b60620cf MS |
428 | /** |
429 | * batadv_netlink_dump_hardif_entry - Dump one hard interface into a message | |
430 | * @msg: Netlink message to dump into | |
431 | * @portid: Port making netlink request | |
432 | * @seq: Sequence number of netlink message | |
433 | * @hard_iface: Hard interface to dump | |
434 | * | |
435 | * Return: error code, or 0 on success | |
436 | */ | |
437 | static int | |
438 | batadv_netlink_dump_hardif_entry(struct sk_buff *msg, u32 portid, u32 seq, | |
439 | struct batadv_hard_iface *hard_iface) | |
440 | { | |
441 | struct net_device *net_dev = hard_iface->net_dev; | |
442 | void *hdr; | |
443 | ||
444 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, | |
445 | BATADV_CMD_GET_HARDIFS); | |
446 | if (!hdr) | |
447 | return -EMSGSIZE; | |
448 | ||
449 | if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, | |
450 | net_dev->ifindex) || | |
451 | nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, | |
452 | net_dev->name) || | |
453 | nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, | |
454 | net_dev->dev_addr)) | |
455 | goto nla_put_failure; | |
456 | ||
457 | if (hard_iface->if_status == BATADV_IF_ACTIVE) { | |
458 | if (nla_put_flag(msg, BATADV_ATTR_ACTIVE)) | |
459 | goto nla_put_failure; | |
460 | } | |
461 | ||
462 | genlmsg_end(msg, hdr); | |
463 | return 0; | |
464 | ||
465 | nla_put_failure: | |
466 | genlmsg_cancel(msg, hdr); | |
467 | return -EMSGSIZE; | |
468 | } | |
469 | ||
470 | /** | |
471 | * batadv_netlink_dump_hardifs - Dump all hard interface into a messages | |
472 | * @msg: Netlink message to dump into | |
473 | * @cb: Parameters from query | |
474 | * | |
475 | * Return: error code, or length of reply message on success | |
476 | */ | |
477 | static int | |
478 | batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb) | |
479 | { | |
480 | struct net *net = sock_net(cb->skb->sk); | |
481 | struct net_device *soft_iface; | |
482 | struct batadv_hard_iface *hard_iface; | |
483 | int ifindex; | |
484 | int portid = NETLINK_CB(cb->skb).portid; | |
485 | int seq = cb->nlh->nlmsg_seq; | |
486 | int skip = cb->args[0]; | |
487 | int i = 0; | |
488 | ||
489 | ifindex = batadv_netlink_get_ifindex(cb->nlh, | |
490 | BATADV_ATTR_MESH_IFINDEX); | |
491 | if (!ifindex) | |
492 | return -EINVAL; | |
493 | ||
494 | soft_iface = dev_get_by_index(net, ifindex); | |
495 | if (!soft_iface) | |
496 | return -ENODEV; | |
497 | ||
498 | if (!batadv_softif_is_valid(soft_iface)) { | |
499 | dev_put(soft_iface); | |
500 | return -ENODEV; | |
501 | } | |
502 | ||
503 | rcu_read_lock(); | |
504 | ||
505 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { | |
506 | if (hard_iface->soft_iface != soft_iface) | |
507 | continue; | |
508 | ||
509 | if (i++ < skip) | |
510 | continue; | |
511 | ||
512 | if (batadv_netlink_dump_hardif_entry(msg, portid, seq, | |
513 | hard_iface)) { | |
514 | i--; | |
515 | break; | |
516 | } | |
517 | } | |
518 | ||
519 | rcu_read_unlock(); | |
520 | ||
521 | dev_put(soft_iface); | |
522 | ||
523 | cb->args[0] = i; | |
524 | ||
525 | return msg->len; | |
526 | } | |
527 | ||
09748a22 | 528 | static struct genl_ops batadv_netlink_ops[] = { |
5da0aef5 MS |
529 | { |
530 | .cmd = BATADV_CMD_GET_MESH_INFO, | |
531 | .flags = GENL_ADMIN_PERM, | |
532 | .policy = batadv_netlink_policy, | |
533 | .doit = batadv_netlink_get_mesh_info, | |
534 | }, | |
33a3bb4a AQ |
535 | { |
536 | .cmd = BATADV_CMD_TP_METER, | |
537 | .flags = GENL_ADMIN_PERM, | |
538 | .policy = batadv_netlink_policy, | |
539 | .doit = batadv_netlink_tp_meter_start, | |
540 | }, | |
541 | { | |
542 | .cmd = BATADV_CMD_TP_METER_CANCEL, | |
543 | .flags = GENL_ADMIN_PERM, | |
544 | .policy = batadv_netlink_policy, | |
545 | .doit = batadv_netlink_tp_meter_cancel, | |
546 | }, | |
07a3061e MS |
547 | { |
548 | .cmd = BATADV_CMD_GET_ROUTING_ALGOS, | |
549 | .flags = GENL_ADMIN_PERM, | |
550 | .policy = batadv_netlink_policy, | |
551 | .dumpit = batadv_algo_dump, | |
552 | }, | |
b60620cf MS |
553 | { |
554 | .cmd = BATADV_CMD_GET_HARDIFS, | |
555 | .flags = GENL_ADMIN_PERM, | |
556 | .policy = batadv_netlink_policy, | |
557 | .dumpit = batadv_netlink_dump_hardifs, | |
558 | }, | |
d34f0550 MS |
559 | { |
560 | .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, | |
561 | .flags = GENL_ADMIN_PERM, | |
562 | .policy = batadv_netlink_policy, | |
563 | .dumpit = batadv_tt_local_dump, | |
564 | }, | |
565 | { | |
566 | .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, | |
567 | .flags = GENL_ADMIN_PERM, | |
568 | .policy = batadv_netlink_policy, | |
569 | .dumpit = batadv_tt_global_dump, | |
570 | }, | |
85cf8c85 MS |
571 | { |
572 | .cmd = BATADV_CMD_GET_ORIGINATORS, | |
573 | .flags = GENL_ADMIN_PERM, | |
574 | .policy = batadv_netlink_policy, | |
575 | .dumpit = batadv_orig_dump, | |
576 | }, | |
577 | { | |
578 | .cmd = BATADV_CMD_GET_NEIGHBORS, | |
579 | .flags = GENL_ADMIN_PERM, | |
580 | .policy = batadv_netlink_policy, | |
581 | .dumpit = batadv_hardif_neigh_dump, | |
582 | }, | |
d7129daf SE |
583 | { |
584 | .cmd = BATADV_CMD_GET_GATEWAYS, | |
585 | .flags = GENL_ADMIN_PERM, | |
586 | .policy = batadv_netlink_policy, | |
587 | .dumpit = batadv_gw_dump, | |
588 | }, | |
04f3f5bf AL |
589 | { |
590 | .cmd = BATADV_CMD_GET_BLA_CLAIM, | |
591 | .flags = GENL_ADMIN_PERM, | |
592 | .policy = batadv_netlink_policy, | |
593 | .dumpit = batadv_bla_claim_dump, | |
594 | }, | |
09748a22 MS |
595 | }; |
596 | ||
597 | /** | |
598 | * batadv_netlink_register - register batadv genl netlink family | |
599 | */ | |
600 | void __init batadv_netlink_register(void) | |
601 | { | |
602 | int ret; | |
603 | ||
33a3bb4a AQ |
604 | ret = genl_register_family_with_ops_groups(&batadv_netlink_family, |
605 | batadv_netlink_ops, | |
606 | batadv_netlink_mcgrps); | |
09748a22 MS |
607 | if (ret) |
608 | pr_warn("unable to register netlink family"); | |
609 | } | |
610 | ||
611 | /** | |
612 | * batadv_netlink_unregister - unregister batadv genl netlink family | |
613 | */ | |
614 | void batadv_netlink_unregister(void) | |
615 | { | |
616 | genl_unregister_family(&batadv_netlink_family); | |
617 | } |