1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) B.A.T.M.A.N. contributors:
10 #include <linux/atomic.h>
11 #include <linux/bitops.h>
12 #include <linux/bug.h>
13 #include <linux/byteorder/generic.h>
14 #include <linux/cache.h>
15 #include <linux/err.h>
16 #include <linux/errno.h>
17 #include <linux/export.h>
18 #include <linux/genetlink.h>
19 #include <linux/gfp.h>
20 #include <linux/if_ether.h>
21 #include <linux/if_vlan.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/limits.h>
25 #include <linux/list.h>
26 #include <linux/minmax.h>
27 #include <linux/netdevice.h>
28 #include <linux/netlink.h>
29 #include <linux/printk.h>
30 #include <linux/rtnetlink.h>
31 #include <linux/skbuff.h>
32 #include <linux/stddef.h>
33 #include <linux/types.h>
34 #include <net/genetlink.h>
35 #include <net/net_namespace.h>
36 #include <net/netlink.h>
38 #include <uapi/linux/batadv_packet.h>
39 #include <uapi/linux/batman_adv.h>
42 #include "bridge_loop_avoidance.h"
43 #include "distributed-arp-table.h"
44 #include "gateway_client.h"
45 #include "gateway_common.h"
46 #include "hard-interface.h"
48 #include "multicast.h"
49 #include "network-coding.h"
50 #include "originator.h"
51 #include "soft-interface.h"
53 #include "translation-table.h"
55 struct genl_family batadv_netlink_family;
57 /* multicast groups */
58 enum batadv_netlink_multicast_groups {
59 BATADV_NL_MCGRP_CONFIG,
60 BATADV_NL_MCGRP_TPMETER,
64 * enum batadv_genl_ops_flags - flags for genl_ops's internal_flags
66 enum batadv_genl_ops_flags {
68 * @BATADV_FLAG_NEED_MESH: request requires valid soft interface in
69 * attribute BATADV_ATTR_MESH_IFINDEX and expects a pointer to it to be
70 * saved in info->user_ptr[0]
72 BATADV_FLAG_NEED_MESH = BIT(0),
75 * @BATADV_FLAG_NEED_HARDIF: request requires valid hard interface in
76 * attribute BATADV_ATTR_HARD_IFINDEX and expects a pointer to it to be
77 * saved in info->user_ptr[1]
79 BATADV_FLAG_NEED_HARDIF = BIT(1),
82 * @BATADV_FLAG_NEED_VLAN: request requires valid vlan in
83 * attribute BATADV_ATTR_VLANID and expects a pointer to it to be
84 * saved in info->user_ptr[1]
86 BATADV_FLAG_NEED_VLAN = BIT(2),
89 static const struct genl_multicast_group batadv_netlink_mcgrps[] = {
90 [BATADV_NL_MCGRP_CONFIG] = { .name = BATADV_NL_MCAST_GROUP_CONFIG },
91 [BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER },
94 static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
95 [BATADV_ATTR_VERSION] = { .type = NLA_STRING },
96 [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING },
97 [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 },
98 [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING },
99 [BATADV_ATTR_MESH_ADDRESS] = { .len = ETH_ALEN },
100 [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 },
101 [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING },
102 [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN },
103 [BATADV_ATTR_ORIG_ADDRESS] = { .len = ETH_ALEN },
104 [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
105 [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
106 [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
107 [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 },
108 [BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
109 [BATADV_ATTR_TT_ADDRESS] = { .len = ETH_ALEN },
110 [BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
111 [BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
112 [BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
113 [BATADV_ATTR_TT_VID] = { .type = NLA_U16 },
114 [BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 },
115 [BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
116 [BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
117 [BATADV_ATTR_NEIGH_ADDRESS] = { .len = ETH_ALEN },
118 [BATADV_ATTR_TQ] = { .type = NLA_U8 },
119 [BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
120 [BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
121 [BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
122 [BATADV_ATTR_ROUTER] = { .len = ETH_ALEN },
123 [BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG },
124 [BATADV_ATTR_BLA_ADDRESS] = { .len = ETH_ALEN },
125 [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 },
126 [BATADV_ATTR_BLA_BACKBONE] = { .len = ETH_ALEN },
127 [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 },
128 [BATADV_ATTR_DAT_CACHE_IP4ADDRESS] = { .type = NLA_U32 },
129 [BATADV_ATTR_DAT_CACHE_HWADDRESS] = { .len = ETH_ALEN },
130 [BATADV_ATTR_DAT_CACHE_VID] = { .type = NLA_U16 },
131 [BATADV_ATTR_MCAST_FLAGS] = { .type = NLA_U32 },
132 [BATADV_ATTR_MCAST_FLAGS_PRIV] = { .type = NLA_U32 },
133 [BATADV_ATTR_VLANID] = { .type = NLA_U16 },
134 [BATADV_ATTR_AGGREGATED_OGMS_ENABLED] = { .type = NLA_U8 },
135 [BATADV_ATTR_AP_ISOLATION_ENABLED] = { .type = NLA_U8 },
136 [BATADV_ATTR_ISOLATION_MARK] = { .type = NLA_U32 },
137 [BATADV_ATTR_ISOLATION_MASK] = { .type = NLA_U32 },
138 [BATADV_ATTR_BONDING_ENABLED] = { .type = NLA_U8 },
139 [BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED] = { .type = NLA_U8 },
140 [BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED] = { .type = NLA_U8 },
141 [BATADV_ATTR_FRAGMENTATION_ENABLED] = { .type = NLA_U8 },
142 [BATADV_ATTR_GW_BANDWIDTH_DOWN] = { .type = NLA_U32 },
143 [BATADV_ATTR_GW_BANDWIDTH_UP] = { .type = NLA_U32 },
144 [BATADV_ATTR_GW_MODE] = { .type = NLA_U8 },
145 [BATADV_ATTR_GW_SEL_CLASS] = { .type = NLA_U32 },
146 [BATADV_ATTR_HOP_PENALTY] = { .type = NLA_U8 },
147 [BATADV_ATTR_LOG_LEVEL] = { .type = NLA_U32 },
148 [BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED] = { .type = NLA_U8 },
149 [BATADV_ATTR_MULTICAST_FANOUT] = { .type = NLA_U32 },
150 [BATADV_ATTR_NETWORK_CODING_ENABLED] = { .type = NLA_U8 },
151 [BATADV_ATTR_ORIG_INTERVAL] = { .type = NLA_U32 },
152 [BATADV_ATTR_ELP_INTERVAL] = { .type = NLA_U32 },
153 [BATADV_ATTR_THROUGHPUT_OVERRIDE] = { .type = NLA_U32 },
157 * batadv_netlink_get_ifindex() - Extract an interface index from a message
158 * @nlh: Message header
159 * @attrtype: Attribute which holds an interface index
161 * Return: interface index, or 0.
164 batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype)
166 struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype);
168 return (attr && nla_len(attr) == sizeof(u32)) ? nla_get_u32(attr) : 0;
172 * batadv_netlink_mesh_fill_ap_isolation() - Add ap_isolation softif attribute
173 * @msg: Netlink message to dump into
174 * @bat_priv: the bat priv with all the soft interface information
176 * Return: 0 on success or negative error number in case of failure
178 static int batadv_netlink_mesh_fill_ap_isolation(struct sk_buff *msg,
179 struct batadv_priv *bat_priv)
181 struct batadv_softif_vlan *vlan;
184 vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
188 ap_isolation = atomic_read(&vlan->ap_isolation);
189 batadv_softif_vlan_put(vlan);
191 return nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED,
196 * batadv_netlink_set_mesh_ap_isolation() - Set ap_isolation from genl msg
197 * @attr: parsed BATADV_ATTR_AP_ISOLATION_ENABLED attribute
198 * @bat_priv: the bat priv with all the soft interface information
200 * Return: 0 on success or negative error number in case of failure
202 static int batadv_netlink_set_mesh_ap_isolation(struct nlattr *attr,
203 struct batadv_priv *bat_priv)
205 struct batadv_softif_vlan *vlan;
207 vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
211 atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr));
212 batadv_softif_vlan_put(vlan);
218 * batadv_netlink_mesh_fill() - Fill message with mesh attributes
219 * @msg: Netlink message to dump into
220 * @bat_priv: the bat priv with all the soft interface information
221 * @cmd: type of message to generate
222 * @portid: Port making netlink request
223 * @seq: sequence number for message
224 * @flags: Additional flags for message
226 * Return: 0 on success or negative error number in case of failure
228 static int batadv_netlink_mesh_fill(struct sk_buff *msg,
229 struct batadv_priv *bat_priv,
230 enum batadv_nl_commands cmd,
231 u32 portid, u32 seq, int flags)
233 struct net_device *soft_iface = bat_priv->soft_iface;
234 struct batadv_hard_iface *primary_if = NULL;
235 struct net_device *hard_iface;
238 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd);
242 if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) ||
243 nla_put_string(msg, BATADV_ATTR_ALGO_NAME,
244 bat_priv->algo_ops->name) ||
245 nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) ||
246 nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) ||
247 nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN,
248 soft_iface->dev_addr) ||
249 nla_put_u8(msg, BATADV_ATTR_TT_TTVN,
250 (u8)atomic_read(&bat_priv->tt.vn)))
251 goto nla_put_failure;
253 #ifdef CONFIG_BATMAN_ADV_BLA
254 if (nla_put_u16(msg, BATADV_ATTR_BLA_CRC,
255 ntohs(bat_priv->bla.claim_dest.group)))
256 goto nla_put_failure;
259 if (batadv_mcast_mesh_info_put(msg, bat_priv))
260 goto nla_put_failure;
262 primary_if = batadv_primary_if_get_selected(bat_priv);
263 if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) {
264 hard_iface = primary_if->net_dev;
266 if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
267 hard_iface->ifindex) ||
268 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
270 nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN,
271 hard_iface->dev_addr))
272 goto nla_put_failure;
275 if (nla_put_u8(msg, BATADV_ATTR_AGGREGATED_OGMS_ENABLED,
276 !!atomic_read(&bat_priv->aggregated_ogms)))
277 goto nla_put_failure;
279 if (batadv_netlink_mesh_fill_ap_isolation(msg, bat_priv))
280 goto nla_put_failure;
282 if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MARK,
283 bat_priv->isolation_mark))
284 goto nla_put_failure;
286 if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MASK,
287 bat_priv->isolation_mark_mask))
288 goto nla_put_failure;
290 if (nla_put_u8(msg, BATADV_ATTR_BONDING_ENABLED,
291 !!atomic_read(&bat_priv->bonding)))
292 goto nla_put_failure;
294 #ifdef CONFIG_BATMAN_ADV_BLA
295 if (nla_put_u8(msg, BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED,
296 !!atomic_read(&bat_priv->bridge_loop_avoidance)))
297 goto nla_put_failure;
298 #endif /* CONFIG_BATMAN_ADV_BLA */
300 #ifdef CONFIG_BATMAN_ADV_DAT
301 if (nla_put_u8(msg, BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED,
302 !!atomic_read(&bat_priv->distributed_arp_table)))
303 goto nla_put_failure;
304 #endif /* CONFIG_BATMAN_ADV_DAT */
306 if (nla_put_u8(msg, BATADV_ATTR_FRAGMENTATION_ENABLED,
307 !!atomic_read(&bat_priv->fragmentation)))
308 goto nla_put_failure;
310 if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_DOWN,
311 atomic_read(&bat_priv->gw.bandwidth_down)))
312 goto nla_put_failure;
314 if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_UP,
315 atomic_read(&bat_priv->gw.bandwidth_up)))
316 goto nla_put_failure;
318 if (nla_put_u8(msg, BATADV_ATTR_GW_MODE,
319 atomic_read(&bat_priv->gw.mode)))
320 goto nla_put_failure;
322 if (bat_priv->algo_ops->gw.get_best_gw_node &&
323 bat_priv->algo_ops->gw.is_eligible) {
324 /* GW selection class is not available if the routing algorithm
325 * in use does not implement the GW API
327 if (nla_put_u32(msg, BATADV_ATTR_GW_SEL_CLASS,
328 atomic_read(&bat_priv->gw.sel_class)))
329 goto nla_put_failure;
332 if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY,
333 atomic_read(&bat_priv->hop_penalty)))
334 goto nla_put_failure;
336 #ifdef CONFIG_BATMAN_ADV_DEBUG
337 if (nla_put_u32(msg, BATADV_ATTR_LOG_LEVEL,
338 atomic_read(&bat_priv->log_level)))
339 goto nla_put_failure;
340 #endif /* CONFIG_BATMAN_ADV_DEBUG */
342 #ifdef CONFIG_BATMAN_ADV_MCAST
343 if (nla_put_u8(msg, BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED,
344 !atomic_read(&bat_priv->multicast_mode)))
345 goto nla_put_failure;
347 if (nla_put_u32(msg, BATADV_ATTR_MULTICAST_FANOUT,
348 atomic_read(&bat_priv->multicast_fanout)))
349 goto nla_put_failure;
350 #endif /* CONFIG_BATMAN_ADV_MCAST */
352 #ifdef CONFIG_BATMAN_ADV_NC
353 if (nla_put_u8(msg, BATADV_ATTR_NETWORK_CODING_ENABLED,
354 !!atomic_read(&bat_priv->network_coding)))
355 goto nla_put_failure;
356 #endif /* CONFIG_BATMAN_ADV_NC */
358 if (nla_put_u32(msg, BATADV_ATTR_ORIG_INTERVAL,
359 atomic_read(&bat_priv->orig_interval)))
360 goto nla_put_failure;
362 batadv_hardif_put(primary_if);
364 genlmsg_end(msg, hdr);
368 batadv_hardif_put(primary_if);
370 genlmsg_cancel(msg, hdr);
375 * batadv_netlink_notify_mesh() - send softif attributes to listener
376 * @bat_priv: the bat priv with all the soft interface information
378 * Return: 0 on success, < 0 on error
380 static int batadv_netlink_notify_mesh(struct batadv_priv *bat_priv)
385 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
389 ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_SET_MESH,
396 genlmsg_multicast_netns(&batadv_netlink_family,
397 dev_net(bat_priv->soft_iface), msg, 0,
398 BATADV_NL_MCGRP_CONFIG, GFP_KERNEL);
404 * batadv_netlink_get_mesh() - Get softif attributes
405 * @skb: Netlink message with request data
406 * @info: receiver information
408 * Return: 0 on success or negative error number in case of failure
410 static int batadv_netlink_get_mesh(struct sk_buff *skb, struct genl_info *info)
412 struct batadv_priv *bat_priv = info->user_ptr[0];
416 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
420 ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_GET_MESH,
421 info->snd_portid, info->snd_seq, 0);
427 ret = genlmsg_reply(msg, info);
433 * batadv_netlink_set_mesh() - Set softif attributes
434 * @skb: Netlink message with request data
435 * @info: receiver information
437 * Return: 0 on success or negative error number in case of failure
439 static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info)
441 struct batadv_priv *bat_priv = info->user_ptr[0];
444 if (info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]) {
445 attr = info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED];
447 atomic_set(&bat_priv->aggregated_ogms, !!nla_get_u8(attr));
450 if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) {
451 attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED];
453 batadv_netlink_set_mesh_ap_isolation(attr, bat_priv);
456 if (info->attrs[BATADV_ATTR_ISOLATION_MARK]) {
457 attr = info->attrs[BATADV_ATTR_ISOLATION_MARK];
459 bat_priv->isolation_mark = nla_get_u32(attr);
462 if (info->attrs[BATADV_ATTR_ISOLATION_MASK]) {
463 attr = info->attrs[BATADV_ATTR_ISOLATION_MASK];
465 bat_priv->isolation_mark_mask = nla_get_u32(attr);
468 if (info->attrs[BATADV_ATTR_BONDING_ENABLED]) {
469 attr = info->attrs[BATADV_ATTR_BONDING_ENABLED];
471 atomic_set(&bat_priv->bonding, !!nla_get_u8(attr));
474 #ifdef CONFIG_BATMAN_ADV_BLA
475 if (info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]) {
476 attr = info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED];
478 atomic_set(&bat_priv->bridge_loop_avoidance,
480 batadv_bla_status_update(bat_priv->soft_iface);
482 #endif /* CONFIG_BATMAN_ADV_BLA */
484 #ifdef CONFIG_BATMAN_ADV_DAT
485 if (info->attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED]) {
486 attr = info->attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED];
488 atomic_set(&bat_priv->distributed_arp_table,
490 batadv_dat_status_update(bat_priv->soft_iface);
492 #endif /* CONFIG_BATMAN_ADV_DAT */
494 if (info->attrs[BATADV_ATTR_FRAGMENTATION_ENABLED]) {
495 attr = info->attrs[BATADV_ATTR_FRAGMENTATION_ENABLED];
497 atomic_set(&bat_priv->fragmentation, !!nla_get_u8(attr));
500 batadv_update_min_mtu(bat_priv->soft_iface);
504 if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]) {
505 attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN];
507 atomic_set(&bat_priv->gw.bandwidth_down, nla_get_u32(attr));
508 batadv_gw_tvlv_container_update(bat_priv);
511 if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP]) {
512 attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP];
514 atomic_set(&bat_priv->gw.bandwidth_up, nla_get_u32(attr));
515 batadv_gw_tvlv_container_update(bat_priv);
518 if (info->attrs[BATADV_ATTR_GW_MODE]) {
521 attr = info->attrs[BATADV_ATTR_GW_MODE];
522 gw_mode = nla_get_u8(attr);
524 if (gw_mode <= BATADV_GW_MODE_SERVER) {
525 /* Invoking batadv_gw_reselect() is not enough to really
526 * de-select the current GW. It will only instruct the
527 * gateway client code to perform a re-election the next
528 * time that this is needed.
530 * When gw client mode is being switched off the current
531 * GW must be de-selected explicitly otherwise no GW_ADD
532 * uevent is thrown on client mode re-activation. This
533 * is operation is performed in
534 * batadv_gw_check_client_stop().
536 batadv_gw_reselect(bat_priv);
538 /* always call batadv_gw_check_client_stop() before
539 * changing the gateway state
541 batadv_gw_check_client_stop(bat_priv);
542 atomic_set(&bat_priv->gw.mode, gw_mode);
543 batadv_gw_tvlv_container_update(bat_priv);
547 if (info->attrs[BATADV_ATTR_GW_SEL_CLASS] &&
548 bat_priv->algo_ops->gw.get_best_gw_node &&
549 bat_priv->algo_ops->gw.is_eligible) {
550 /* setting the GW selection class is allowed only if the routing
551 * algorithm in use implements the GW API
554 u32 sel_class_max = bat_priv->algo_ops->gw.sel_class_max;
557 attr = info->attrs[BATADV_ATTR_GW_SEL_CLASS];
558 sel_class = nla_get_u32(attr);
560 if (sel_class >= 1 && sel_class <= sel_class_max) {
561 atomic_set(&bat_priv->gw.sel_class, sel_class);
562 batadv_gw_reselect(bat_priv);
566 if (info->attrs[BATADV_ATTR_HOP_PENALTY]) {
567 attr = info->attrs[BATADV_ATTR_HOP_PENALTY];
569 atomic_set(&bat_priv->hop_penalty, nla_get_u8(attr));
572 #ifdef CONFIG_BATMAN_ADV_DEBUG
573 if (info->attrs[BATADV_ATTR_LOG_LEVEL]) {
574 attr = info->attrs[BATADV_ATTR_LOG_LEVEL];
576 atomic_set(&bat_priv->log_level,
577 nla_get_u32(attr) & BATADV_DBG_ALL);
579 #endif /* CONFIG_BATMAN_ADV_DEBUG */
581 #ifdef CONFIG_BATMAN_ADV_MCAST
582 if (info->attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED]) {
583 attr = info->attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED];
585 atomic_set(&bat_priv->multicast_mode, !nla_get_u8(attr));
588 if (info->attrs[BATADV_ATTR_MULTICAST_FANOUT]) {
589 attr = info->attrs[BATADV_ATTR_MULTICAST_FANOUT];
591 atomic_set(&bat_priv->multicast_fanout, nla_get_u32(attr));
593 #endif /* CONFIG_BATMAN_ADV_MCAST */
595 #ifdef CONFIG_BATMAN_ADV_NC
596 if (info->attrs[BATADV_ATTR_NETWORK_CODING_ENABLED]) {
597 attr = info->attrs[BATADV_ATTR_NETWORK_CODING_ENABLED];
599 atomic_set(&bat_priv->network_coding, !!nla_get_u8(attr));
600 batadv_nc_status_update(bat_priv->soft_iface);
602 #endif /* CONFIG_BATMAN_ADV_NC */
604 if (info->attrs[BATADV_ATTR_ORIG_INTERVAL]) {
607 attr = info->attrs[BATADV_ATTR_ORIG_INTERVAL];
608 orig_interval = nla_get_u32(attr);
610 orig_interval = min_t(u32, orig_interval, INT_MAX);
611 orig_interval = max_t(u32, orig_interval, 2 * BATADV_JITTER);
613 atomic_set(&bat_priv->orig_interval, orig_interval);
616 batadv_netlink_notify_mesh(bat_priv);
622 * batadv_netlink_tp_meter_put() - Fill information of started tp_meter session
623 * @msg: netlink message to be sent back
624 * @cookie: tp meter session cookie
626 * Return: 0 on success, < 0 on error
629 batadv_netlink_tp_meter_put(struct sk_buff *msg, u32 cookie)
631 if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie))
638 * batadv_netlink_tpmeter_notify() - send tp_meter result via netlink to client
639 * @bat_priv: the bat priv with all the soft interface information
640 * @dst: destination of tp_meter session
641 * @result: reason for tp meter session stop
642 * @test_time: total time of the tp_meter session
643 * @total_bytes: bytes acked to the receiver
644 * @cookie: cookie of tp_meter session
646 * Return: 0 on success, < 0 on error
648 int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst,
649 u8 result, u32 test_time, u64 total_bytes,
656 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
660 hdr = genlmsg_put(msg, 0, 0, &batadv_netlink_family, 0,
661 BATADV_CMD_TP_METER);
667 if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie))
668 goto nla_put_failure;
670 if (nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, test_time))
671 goto nla_put_failure;
673 if (nla_put_u64_64bit(msg, BATADV_ATTR_TPMETER_BYTES, total_bytes,
675 goto nla_put_failure;
677 if (nla_put_u8(msg, BATADV_ATTR_TPMETER_RESULT, result))
678 goto nla_put_failure;
680 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst))
681 goto nla_put_failure;
683 genlmsg_end(msg, hdr);
685 genlmsg_multicast_netns(&batadv_netlink_family,
686 dev_net(bat_priv->soft_iface), msg, 0,
687 BATADV_NL_MCGRP_TPMETER, GFP_KERNEL);
692 genlmsg_cancel(msg, hdr);
701 * batadv_netlink_tp_meter_start() - Start a new tp_meter session
702 * @skb: received netlink message
703 * @info: receiver information
705 * Return: 0 on success, < 0 on error
708 batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info)
710 struct batadv_priv *bat_priv = info->user_ptr[0];
711 struct sk_buff *msg = NULL;
718 if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
721 if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME])
724 dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]);
726 test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]);
728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
734 msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq,
735 &batadv_netlink_family, 0,
736 BATADV_CMD_TP_METER);
742 batadv_tp_start(bat_priv, dst, test_length, &cookie);
744 ret = batadv_netlink_tp_meter_put(msg, cookie);
753 genlmsg_end(msg, msg_head);
754 return genlmsg_reply(msg, info);
758 * batadv_netlink_tp_meter_cancel() - Cancel a running tp_meter session
759 * @skb: received netlink message
760 * @info: receiver information
762 * Return: 0 on success, < 0 on error
765 batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info)
767 struct batadv_priv *bat_priv = info->user_ptr[0];
771 if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
774 dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]);
776 batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL);
782 * batadv_netlink_hardif_fill() - Fill message with hardif attributes
783 * @msg: Netlink message to dump into
784 * @bat_priv: the bat priv with all the soft interface information
785 * @hard_iface: hard interface which was modified
786 * @cmd: type of message to generate
787 * @portid: Port making netlink request
788 * @seq: sequence number for message
789 * @flags: Additional flags for message
790 * @cb: Control block containing additional options
792 * Return: 0 on success or negative error number in case of failure
794 static int batadv_netlink_hardif_fill(struct sk_buff *msg,
795 struct batadv_priv *bat_priv,
796 struct batadv_hard_iface *hard_iface,
797 enum batadv_nl_commands cmd,
798 u32 portid, u32 seq, int flags,
799 struct netlink_callback *cb)
801 struct net_device *net_dev = hard_iface->net_dev;
804 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd);
809 genl_dump_check_consistent(cb, hdr);
811 if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX,
812 bat_priv->soft_iface->ifindex))
813 goto nla_put_failure;
815 if (nla_put_string(msg, BATADV_ATTR_MESH_IFNAME,
816 bat_priv->soft_iface->name))
817 goto nla_put_failure;
819 if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
821 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
823 nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN,
825 goto nla_put_failure;
827 if (hard_iface->if_status == BATADV_IF_ACTIVE) {
828 if (nla_put_flag(msg, BATADV_ATTR_ACTIVE))
829 goto nla_put_failure;
832 if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY,
833 atomic_read(&hard_iface->hop_penalty)))
834 goto nla_put_failure;
836 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
837 if (nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL,
838 atomic_read(&hard_iface->bat_v.elp_interval)))
839 goto nla_put_failure;
841 if (nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE,
842 atomic_read(&hard_iface->bat_v.throughput_override)))
843 goto nla_put_failure;
844 #endif /* CONFIG_BATMAN_ADV_BATMAN_V */
846 genlmsg_end(msg, hdr);
850 genlmsg_cancel(msg, hdr);
855 * batadv_netlink_notify_hardif() - send hardif attributes to listener
856 * @bat_priv: the bat priv with all the soft interface information
857 * @hard_iface: hard interface which was modified
859 * Return: 0 on success, < 0 on error
861 static int batadv_netlink_notify_hardif(struct batadv_priv *bat_priv,
862 struct batadv_hard_iface *hard_iface)
867 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
871 ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface,
872 BATADV_CMD_SET_HARDIF, 0, 0, 0, NULL);
878 genlmsg_multicast_netns(&batadv_netlink_family,
879 dev_net(bat_priv->soft_iface), msg, 0,
880 BATADV_NL_MCGRP_CONFIG, GFP_KERNEL);
886 * batadv_netlink_get_hardif() - Get hardif attributes
887 * @skb: Netlink message with request data
888 * @info: receiver information
890 * Return: 0 on success or negative error number in case of failure
892 static int batadv_netlink_get_hardif(struct sk_buff *skb,
893 struct genl_info *info)
895 struct batadv_hard_iface *hard_iface = info->user_ptr[1];
896 struct batadv_priv *bat_priv = info->user_ptr[0];
900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
904 ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface,
905 BATADV_CMD_GET_HARDIF,
906 info->snd_portid, info->snd_seq, 0,
913 ret = genlmsg_reply(msg, info);
919 * batadv_netlink_set_hardif() - Set hardif attributes
920 * @skb: Netlink message with request data
921 * @info: receiver information
923 * Return: 0 on success or negative error number in case of failure
925 static int batadv_netlink_set_hardif(struct sk_buff *skb,
926 struct genl_info *info)
928 struct batadv_hard_iface *hard_iface = info->user_ptr[1];
929 struct batadv_priv *bat_priv = info->user_ptr[0];
932 if (info->attrs[BATADV_ATTR_HOP_PENALTY]) {
933 attr = info->attrs[BATADV_ATTR_HOP_PENALTY];
935 atomic_set(&hard_iface->hop_penalty, nla_get_u8(attr));
938 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
940 if (info->attrs[BATADV_ATTR_ELP_INTERVAL]) {
941 attr = info->attrs[BATADV_ATTR_ELP_INTERVAL];
943 atomic_set(&hard_iface->bat_v.elp_interval, nla_get_u32(attr));
946 if (info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]) {
947 attr = info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE];
949 atomic_set(&hard_iface->bat_v.throughput_override,
952 #endif /* CONFIG_BATMAN_ADV_BATMAN_V */
954 batadv_netlink_notify_hardif(bat_priv, hard_iface);
960 * batadv_netlink_dump_hardif() - Dump all hard interface into a messages
961 * @msg: Netlink message to dump into
962 * @cb: Parameters from query
964 * Return: error code, or length of reply message on success
967 batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb)
969 struct net *net = sock_net(cb->skb->sk);
970 struct net_device *soft_iface;
971 struct batadv_hard_iface *hard_iface;
972 struct batadv_priv *bat_priv;
974 int portid = NETLINK_CB(cb->skb).portid;
975 int skip = cb->args[0];
978 ifindex = batadv_netlink_get_ifindex(cb->nlh,
979 BATADV_ATTR_MESH_IFINDEX);
983 soft_iface = dev_get_by_index(net, ifindex);
987 if (!batadv_softif_is_valid(soft_iface)) {
992 bat_priv = netdev_priv(soft_iface);
995 cb->seq = batadv_hardif_generation << 1 | 1;
997 list_for_each_entry(hard_iface, &batadv_hardif_list, list) {
998 if (hard_iface->soft_iface != soft_iface)
1004 if (batadv_netlink_hardif_fill(msg, bat_priv, hard_iface,
1005 BATADV_CMD_GET_HARDIF,
1006 portid, cb->nlh->nlmsg_seq,
1015 dev_put(soft_iface);
1023 * batadv_netlink_vlan_fill() - Fill message with vlan attributes
1024 * @msg: Netlink message to dump into
1025 * @bat_priv: the bat priv with all the soft interface information
1026 * @vlan: vlan which was modified
1027 * @cmd: type of message to generate
1028 * @portid: Port making netlink request
1029 * @seq: sequence number for message
1030 * @flags: Additional flags for message
1032 * Return: 0 on success or negative error number in case of failure
1034 static int batadv_netlink_vlan_fill(struct sk_buff *msg,
1035 struct batadv_priv *bat_priv,
1036 struct batadv_softif_vlan *vlan,
1037 enum batadv_nl_commands cmd,
1038 u32 portid, u32 seq, int flags)
1042 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd);
1046 if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX,
1047 bat_priv->soft_iface->ifindex))
1048 goto nla_put_failure;
1050 if (nla_put_string(msg, BATADV_ATTR_MESH_IFNAME,
1051 bat_priv->soft_iface->name))
1052 goto nla_put_failure;
1054 if (nla_put_u32(msg, BATADV_ATTR_VLANID, vlan->vid & VLAN_VID_MASK))
1055 goto nla_put_failure;
1057 if (nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED,
1058 !!atomic_read(&vlan->ap_isolation)))
1059 goto nla_put_failure;
1061 genlmsg_end(msg, hdr);
1065 genlmsg_cancel(msg, hdr);
1070 * batadv_netlink_notify_vlan() - send vlan attributes to listener
1071 * @bat_priv: the bat priv with all the soft interface information
1072 * @vlan: vlan which was modified
1074 * Return: 0 on success, < 0 on error
1076 static int batadv_netlink_notify_vlan(struct batadv_priv *bat_priv,
1077 struct batadv_softif_vlan *vlan)
1079 struct sk_buff *msg;
1082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1086 ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan,
1087 BATADV_CMD_SET_VLAN, 0, 0, 0);
1093 genlmsg_multicast_netns(&batadv_netlink_family,
1094 dev_net(bat_priv->soft_iface), msg, 0,
1095 BATADV_NL_MCGRP_CONFIG, GFP_KERNEL);
1101 * batadv_netlink_get_vlan() - Get vlan attributes
1102 * @skb: Netlink message with request data
1103 * @info: receiver information
1105 * Return: 0 on success or negative error number in case of failure
1107 static int batadv_netlink_get_vlan(struct sk_buff *skb, struct genl_info *info)
1109 struct batadv_softif_vlan *vlan = info->user_ptr[1];
1110 struct batadv_priv *bat_priv = info->user_ptr[0];
1111 struct sk_buff *msg;
1114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1118 ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan, BATADV_CMD_GET_VLAN,
1119 info->snd_portid, info->snd_seq, 0);
1125 ret = genlmsg_reply(msg, info);
1131 * batadv_netlink_set_vlan() - Get vlan attributes
1132 * @skb: Netlink message with request data
1133 * @info: receiver information
1135 * Return: 0 on success or negative error number in case of failure
1137 static int batadv_netlink_set_vlan(struct sk_buff *skb, struct genl_info *info)
1139 struct batadv_softif_vlan *vlan = info->user_ptr[1];
1140 struct batadv_priv *bat_priv = info->user_ptr[0];
1141 struct nlattr *attr;
1143 if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) {
1144 attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED];
1146 atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr));
1149 batadv_netlink_notify_vlan(bat_priv, vlan);
1155 * batadv_get_softif_from_info() - Retrieve soft interface from genl attributes
1156 * @net: the applicable net namespace
1157 * @info: receiver information
1159 * Return: Pointer to soft interface (with increased refcnt) on success, error
1162 static struct net_device *
1163 batadv_get_softif_from_info(struct net *net, struct genl_info *info)
1165 struct net_device *soft_iface;
1168 if (!info->attrs[BATADV_ATTR_MESH_IFINDEX])
1169 return ERR_PTR(-EINVAL);
1171 ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]);
1173 soft_iface = dev_get_by_index(net, ifindex);
1175 return ERR_PTR(-ENODEV);
1177 if (!batadv_softif_is_valid(soft_iface))
1178 goto err_put_softif;
1183 dev_put(soft_iface);
1185 return ERR_PTR(-EINVAL);
1189 * batadv_get_hardif_from_info() - Retrieve hardif from genl attributes
1190 * @bat_priv: the bat priv with all the soft interface information
1191 * @net: the applicable net namespace
1192 * @info: receiver information
1194 * Return: Pointer to hard interface (with increased refcnt) on success, error
1197 static struct batadv_hard_iface *
1198 batadv_get_hardif_from_info(struct batadv_priv *bat_priv, struct net *net,
1199 struct genl_info *info)
1201 struct batadv_hard_iface *hard_iface;
1202 struct net_device *hard_dev;
1203 unsigned int hardif_index;
1205 if (!info->attrs[BATADV_ATTR_HARD_IFINDEX])
1206 return ERR_PTR(-EINVAL);
1208 hardif_index = nla_get_u32(info->attrs[BATADV_ATTR_HARD_IFINDEX]);
1210 hard_dev = dev_get_by_index(net, hardif_index);
1212 return ERR_PTR(-ENODEV);
1214 hard_iface = batadv_hardif_get_by_netdev(hard_dev);
1216 goto err_put_harddev;
1218 if (hard_iface->soft_iface != bat_priv->soft_iface)
1219 goto err_put_hardif;
1221 /* hard_dev is referenced by hard_iface and not needed here */
1227 batadv_hardif_put(hard_iface);
1231 return ERR_PTR(-EINVAL);
1235 * batadv_get_vlan_from_info() - Retrieve vlan from genl attributes
1236 * @bat_priv: the bat priv with all the soft interface information
1237 * @net: the applicable net namespace
1238 * @info: receiver information
1240 * Return: Pointer to vlan on success (with increased refcnt), error pointer
1243 static struct batadv_softif_vlan *
1244 batadv_get_vlan_from_info(struct batadv_priv *bat_priv, struct net *net,
1245 struct genl_info *info)
1247 struct batadv_softif_vlan *vlan;
1250 if (!info->attrs[BATADV_ATTR_VLANID])
1251 return ERR_PTR(-EINVAL);
1253 vid = nla_get_u16(info->attrs[BATADV_ATTR_VLANID]);
1255 vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG);
1257 return ERR_PTR(-ENOENT);
1263 * batadv_pre_doit() - Prepare batman-adv genl doit request
1264 * @ops: requested netlink operation
1265 * @skb: Netlink message with request data
1266 * @info: receiver information
1268 * Return: 0 on success or negative error number in case of failure
1270 static int batadv_pre_doit(const struct genl_split_ops *ops,
1271 struct sk_buff *skb,
1272 struct genl_info *info)
1274 struct net *net = genl_info_net(info);
1275 struct batadv_hard_iface *hard_iface;
1276 struct batadv_priv *bat_priv = NULL;
1277 struct batadv_softif_vlan *vlan;
1278 struct net_device *soft_iface;
1283 user_ptr1_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN;
1284 if (WARN_ON(hweight8(ops->internal_flags & user_ptr1_flags) > 1))
1287 mesh_dep_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN;
1288 if (WARN_ON((ops->internal_flags & mesh_dep_flags) &&
1289 (~ops->internal_flags & BATADV_FLAG_NEED_MESH)))
1292 if (ops->internal_flags & BATADV_FLAG_NEED_MESH) {
1293 soft_iface = batadv_get_softif_from_info(net, info);
1294 if (IS_ERR(soft_iface))
1295 return PTR_ERR(soft_iface);
1297 bat_priv = netdev_priv(soft_iface);
1298 info->user_ptr[0] = bat_priv;
1301 if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF) {
1302 hard_iface = batadv_get_hardif_from_info(bat_priv, net, info);
1303 if (IS_ERR(hard_iface)) {
1304 ret = PTR_ERR(hard_iface);
1305 goto err_put_softif;
1308 info->user_ptr[1] = hard_iface;
1311 if (ops->internal_flags & BATADV_FLAG_NEED_VLAN) {
1312 vlan = batadv_get_vlan_from_info(bat_priv, net, info);
1314 ret = PTR_ERR(vlan);
1315 goto err_put_softif;
1318 info->user_ptr[1] = vlan;
1325 dev_put(bat_priv->soft_iface);
1331 * batadv_post_doit() - End batman-adv genl doit request
1332 * @ops: requested netlink operation
1333 * @skb: Netlink message with request data
1334 * @info: receiver information
1336 static void batadv_post_doit(const struct genl_split_ops *ops,
1337 struct sk_buff *skb,
1338 struct genl_info *info)
1340 struct batadv_hard_iface *hard_iface;
1341 struct batadv_softif_vlan *vlan;
1342 struct batadv_priv *bat_priv;
1344 if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF &&
1345 info->user_ptr[1]) {
1346 hard_iface = info->user_ptr[1];
1348 batadv_hardif_put(hard_iface);
1351 if (ops->internal_flags & BATADV_FLAG_NEED_VLAN && info->user_ptr[1]) {
1352 vlan = info->user_ptr[1];
1353 batadv_softif_vlan_put(vlan);
1356 if (ops->internal_flags & BATADV_FLAG_NEED_MESH && info->user_ptr[0]) {
1357 bat_priv = info->user_ptr[0];
1358 dev_put(bat_priv->soft_iface);
1362 static const struct genl_small_ops batadv_netlink_ops[] = {
1364 .cmd = BATADV_CMD_GET_MESH,
1365 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1366 /* can be retrieved by unprivileged users */
1367 .doit = batadv_netlink_get_mesh,
1368 .internal_flags = BATADV_FLAG_NEED_MESH,
1371 .cmd = BATADV_CMD_TP_METER,
1372 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1373 .flags = GENL_UNS_ADMIN_PERM,
1374 .doit = batadv_netlink_tp_meter_start,
1375 .internal_flags = BATADV_FLAG_NEED_MESH,
1378 .cmd = BATADV_CMD_TP_METER_CANCEL,
1379 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1380 .flags = GENL_UNS_ADMIN_PERM,
1381 .doit = batadv_netlink_tp_meter_cancel,
1382 .internal_flags = BATADV_FLAG_NEED_MESH,
1385 .cmd = BATADV_CMD_GET_ROUTING_ALGOS,
1386 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1387 .flags = GENL_UNS_ADMIN_PERM,
1388 .dumpit = batadv_algo_dump,
1391 .cmd = BATADV_CMD_GET_HARDIF,
1392 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1393 /* can be retrieved by unprivileged users */
1394 .dumpit = batadv_netlink_dump_hardif,
1395 .doit = batadv_netlink_get_hardif,
1396 .internal_flags = BATADV_FLAG_NEED_MESH |
1397 BATADV_FLAG_NEED_HARDIF,
1400 .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL,
1401 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1402 .flags = GENL_UNS_ADMIN_PERM,
1403 .dumpit = batadv_tt_local_dump,
1406 .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL,
1407 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1408 .flags = GENL_UNS_ADMIN_PERM,
1409 .dumpit = batadv_tt_global_dump,
1412 .cmd = BATADV_CMD_GET_ORIGINATORS,
1413 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1414 .flags = GENL_UNS_ADMIN_PERM,
1415 .dumpit = batadv_orig_dump,
1418 .cmd = BATADV_CMD_GET_NEIGHBORS,
1419 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1420 .flags = GENL_UNS_ADMIN_PERM,
1421 .dumpit = batadv_hardif_neigh_dump,
1424 .cmd = BATADV_CMD_GET_GATEWAYS,
1425 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1426 .flags = GENL_UNS_ADMIN_PERM,
1427 .dumpit = batadv_gw_dump,
1430 .cmd = BATADV_CMD_GET_BLA_CLAIM,
1431 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1432 .flags = GENL_UNS_ADMIN_PERM,
1433 .dumpit = batadv_bla_claim_dump,
1436 .cmd = BATADV_CMD_GET_BLA_BACKBONE,
1437 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1438 .flags = GENL_UNS_ADMIN_PERM,
1439 .dumpit = batadv_bla_backbone_dump,
1442 .cmd = BATADV_CMD_GET_DAT_CACHE,
1443 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1444 .flags = GENL_UNS_ADMIN_PERM,
1445 .dumpit = batadv_dat_cache_dump,
1448 .cmd = BATADV_CMD_GET_MCAST_FLAGS,
1449 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1450 .flags = GENL_UNS_ADMIN_PERM,
1451 .dumpit = batadv_mcast_flags_dump,
1454 .cmd = BATADV_CMD_SET_MESH,
1455 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1456 .flags = GENL_UNS_ADMIN_PERM,
1457 .doit = batadv_netlink_set_mesh,
1458 .internal_flags = BATADV_FLAG_NEED_MESH,
1461 .cmd = BATADV_CMD_SET_HARDIF,
1462 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1463 .flags = GENL_UNS_ADMIN_PERM,
1464 .doit = batadv_netlink_set_hardif,
1465 .internal_flags = BATADV_FLAG_NEED_MESH |
1466 BATADV_FLAG_NEED_HARDIF,
1469 .cmd = BATADV_CMD_GET_VLAN,
1470 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1471 /* can be retrieved by unprivileged users */
1472 .doit = batadv_netlink_get_vlan,
1473 .internal_flags = BATADV_FLAG_NEED_MESH |
1474 BATADV_FLAG_NEED_VLAN,
1477 .cmd = BATADV_CMD_SET_VLAN,
1478 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1479 .flags = GENL_UNS_ADMIN_PERM,
1480 .doit = batadv_netlink_set_vlan,
1481 .internal_flags = BATADV_FLAG_NEED_MESH |
1482 BATADV_FLAG_NEED_VLAN,
1486 struct genl_family batadv_netlink_family __ro_after_init = {
1488 .name = BATADV_NL_NAME,
1490 .maxattr = BATADV_ATTR_MAX,
1491 .policy = batadv_netlink_policy,
1493 .pre_doit = batadv_pre_doit,
1494 .post_doit = batadv_post_doit,
1495 .module = THIS_MODULE,
1496 .small_ops = batadv_netlink_ops,
1497 .n_small_ops = ARRAY_SIZE(batadv_netlink_ops),
1498 .resv_start_op = BATADV_CMD_SET_VLAN + 1,
1499 .mcgrps = batadv_netlink_mcgrps,
1500 .n_mcgrps = ARRAY_SIZE(batadv_netlink_mcgrps),
1504 * batadv_netlink_register() - register batadv genl netlink family
1506 void __init batadv_netlink_register(void)
1510 ret = genl_register_family(&batadv_netlink_family);
1512 pr_warn("unable to register netlink family");
1516 * batadv_netlink_unregister() - unregister batadv genl netlink family
1518 void batadv_netlink_unregister(void)
1520 genl_unregister_family(&batadv_netlink_family);