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