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