Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* Copyright (C) 2016-2020  B.A.T.M.A.N. contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Matthias Schiffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include "netlink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <uapi/linux/batadv_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <uapi/linux/batman_adv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include "bat_algo.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include "bridge_loop_avoidance.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include "distributed-arp-table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include "gateway_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include "gateway_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include "hard-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include "multicast.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include "network-coding.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include "originator.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include "soft-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include "tp_meter.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include "translation-table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) struct genl_family batadv_netlink_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) /* multicast groups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) enum batadv_netlink_multicast_groups {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	BATADV_NL_MCGRP_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	BATADV_NL_MCGRP_TPMETER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  * enum batadv_genl_ops_flags - flags for genl_ops's internal_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) enum batadv_genl_ops_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	 * @BATADV_FLAG_NEED_MESH: request requires valid soft interface in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	 *  attribute BATADV_ATTR_MESH_IFINDEX and expects a pointer to it to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	 *  saved in info->user_ptr[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	BATADV_FLAG_NEED_MESH = BIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	 * @BATADV_FLAG_NEED_HARDIF: request requires valid hard interface in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	 *  attribute BATADV_ATTR_HARD_IFINDEX and expects a pointer to it to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	 *  saved in info->user_ptr[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	BATADV_FLAG_NEED_HARDIF = BIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	 * @BATADV_FLAG_NEED_VLAN: request requires valid vlan in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	 *  attribute BATADV_ATTR_VLANID and expects a pointer to it to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	 *  saved in info->user_ptr[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	BATADV_FLAG_NEED_VLAN = BIT(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static const struct genl_multicast_group batadv_netlink_mcgrps[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	[BATADV_NL_MCGRP_CONFIG] = { .name = BATADV_NL_MCAST_GROUP_CONFIG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	[BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	[BATADV_ATTR_VERSION]			= { .type = NLA_STRING },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	[BATADV_ATTR_ALGO_NAME]			= { .type = NLA_STRING },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	[BATADV_ATTR_MESH_IFINDEX]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	[BATADV_ATTR_MESH_IFNAME]		= { .type = NLA_STRING },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	[BATADV_ATTR_MESH_ADDRESS]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	[BATADV_ATTR_HARD_IFINDEX]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	[BATADV_ATTR_HARD_IFNAME]		= { .type = NLA_STRING },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	[BATADV_ATTR_HARD_ADDRESS]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	[BATADV_ATTR_ORIG_ADDRESS]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	[BATADV_ATTR_TPMETER_RESULT]		= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	[BATADV_ATTR_TPMETER_TEST_TIME]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	[BATADV_ATTR_TPMETER_BYTES]		= { .type = NLA_U64 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	[BATADV_ATTR_TPMETER_COOKIE]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	[BATADV_ATTR_ACTIVE]			= { .type = NLA_FLAG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	[BATADV_ATTR_TT_ADDRESS]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	[BATADV_ATTR_TT_TTVN]			= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	[BATADV_ATTR_TT_LAST_TTVN]		= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	[BATADV_ATTR_TT_CRC32]			= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	[BATADV_ATTR_TT_VID]			= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	[BATADV_ATTR_TT_FLAGS]			= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	[BATADV_ATTR_FLAG_BEST]			= { .type = NLA_FLAG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	[BATADV_ATTR_LAST_SEEN_MSECS]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	[BATADV_ATTR_NEIGH_ADDRESS]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	[BATADV_ATTR_TQ]			= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	[BATADV_ATTR_THROUGHPUT]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	[BATADV_ATTR_BANDWIDTH_UP]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	[BATADV_ATTR_BANDWIDTH_DOWN]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	[BATADV_ATTR_ROUTER]			= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	[BATADV_ATTR_BLA_OWN]			= { .type = NLA_FLAG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	[BATADV_ATTR_BLA_ADDRESS]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	[BATADV_ATTR_BLA_VID]			= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	[BATADV_ATTR_BLA_BACKBONE]		= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	[BATADV_ATTR_BLA_CRC]			= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	[BATADV_ATTR_DAT_CACHE_IP4ADDRESS]	= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	[BATADV_ATTR_DAT_CACHE_HWADDRESS]	= { .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	[BATADV_ATTR_DAT_CACHE_VID]		= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	[BATADV_ATTR_MCAST_FLAGS]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	[BATADV_ATTR_MCAST_FLAGS_PRIV]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	[BATADV_ATTR_VLANID]			= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	[BATADV_ATTR_AP_ISOLATION_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	[BATADV_ATTR_ISOLATION_MARK]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	[BATADV_ATTR_ISOLATION_MASK]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	[BATADV_ATTR_BONDING_ENABLED]		= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	[BATADV_ATTR_FRAGMENTATION_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	[BATADV_ATTR_GW_BANDWIDTH_DOWN]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	[BATADV_ATTR_GW_BANDWIDTH_UP]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	[BATADV_ATTR_GW_MODE]			= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	[BATADV_ATTR_GW_SEL_CLASS]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	[BATADV_ATTR_HOP_PENALTY]		= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	[BATADV_ATTR_LOG_LEVEL]			= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	[BATADV_ATTR_MULTICAST_FANOUT]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	[BATADV_ATTR_NETWORK_CODING_ENABLED]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	[BATADV_ATTR_ORIG_INTERVAL]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	[BATADV_ATTR_ELP_INTERVAL]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	[BATADV_ATTR_THROUGHPUT_OVERRIDE]	= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)  * batadv_netlink_get_ifindex() - Extract an interface index from a message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)  * @nlh: Message header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)  * @attrtype: Attribute which holds an interface index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  * Return: interface index, or 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return (attr && nla_len(attr) == sizeof(u32)) ? nla_get_u32(attr) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  * batadv_netlink_mesh_fill_ap_isolation() - Add ap_isolation softif attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  * @msg: Netlink message to dump into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) static int batadv_netlink_mesh_fill_ap_isolation(struct sk_buff *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 						 struct batadv_priv *bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	u8 ap_isolation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	ap_isolation = atomic_read(&vlan->ap_isolation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	return nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 			  !!ap_isolation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  * batadv_option_set_ap_isolation() - Set ap_isolation from genl msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  * @attr: parsed BATADV_ATTR_AP_ISOLATION_ENABLED attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) static int batadv_netlink_set_mesh_ap_isolation(struct nlattr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 						struct batadv_priv *bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)  * batadv_netlink_mesh_fill() - Fill message with mesh attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  * @msg: Netlink message to dump into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  * @cmd: type of message to generate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  * @portid: Port making netlink request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  * @seq: sequence number for message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  * @flags: Additional flags for message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) static int batadv_netlink_mesh_fill(struct sk_buff *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 				    struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 				    enum batadv_nl_commands cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 				    u32 portid, u32 seq, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct net_device *soft_iface = bat_priv->soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct batadv_hard_iface *primary_if = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	struct net_device *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	    nla_put_string(msg, BATADV_ATTR_ALGO_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 			   bat_priv->algo_ops->name) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	    nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	    nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	    nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		    soft_iface->dev_addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	    nla_put_u8(msg, BATADV_ATTR_TT_TTVN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		       (u8)atomic_read(&bat_priv->tt.vn)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) #ifdef CONFIG_BATMAN_ADV_BLA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	if (nla_put_u16(msg, BATADV_ATTR_BLA_CRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 			ntohs(bat_priv->bla.claim_dest.group)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (batadv_mcast_mesh_info_put(msg, bat_priv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		hard_iface = primary_if->net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 				hard_iface->ifindex) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		    nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 				   hard_iface->name) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		    nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			    hard_iface->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	if (nla_put_u8(msg, BATADV_ATTR_AGGREGATED_OGMS_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		       !!atomic_read(&bat_priv->aggregated_ogms)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	if (batadv_netlink_mesh_fill_ap_isolation(msg, bat_priv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MARK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 			bat_priv->isolation_mark))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			bat_priv->isolation_mark_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	if (nla_put_u8(msg, BATADV_ATTR_BONDING_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		       !!atomic_read(&bat_priv->bonding)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) #ifdef CONFIG_BATMAN_ADV_BLA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	if (nla_put_u8(msg, BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		       !!atomic_read(&bat_priv->bridge_loop_avoidance)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) #endif /* CONFIG_BATMAN_ADV_BLA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) #ifdef CONFIG_BATMAN_ADV_DAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	if (nla_put_u8(msg, BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		       !!atomic_read(&bat_priv->distributed_arp_table)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) #endif /* CONFIG_BATMAN_ADV_DAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	if (nla_put_u8(msg, BATADV_ATTR_FRAGMENTATION_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		       !!atomic_read(&bat_priv->fragmentation)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			atomic_read(&bat_priv->gw.bandwidth_down)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			atomic_read(&bat_priv->gw.bandwidth_up)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	if (nla_put_u8(msg, BATADV_ATTR_GW_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		       atomic_read(&bat_priv->gw.mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	if (bat_priv->algo_ops->gw.get_best_gw_node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	    bat_priv->algo_ops->gw.is_eligible) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		/* GW selection class is not available if the routing algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		 * in use does not implement the GW API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		if (nla_put_u32(msg, BATADV_ATTR_GW_SEL_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 				atomic_read(&bat_priv->gw.sel_class)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		       atomic_read(&bat_priv->hop_penalty)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) #ifdef CONFIG_BATMAN_ADV_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	if (nla_put_u32(msg, BATADV_ATTR_LOG_LEVEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			atomic_read(&bat_priv->log_level)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) #endif /* CONFIG_BATMAN_ADV_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) #ifdef CONFIG_BATMAN_ADV_MCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	if (nla_put_u8(msg, BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		       !atomic_read(&bat_priv->multicast_mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	if (nla_put_u32(msg, BATADV_ATTR_MULTICAST_FANOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			atomic_read(&bat_priv->multicast_fanout)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) #endif /* CONFIG_BATMAN_ADV_MCAST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) #ifdef CONFIG_BATMAN_ADV_NC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	if (nla_put_u8(msg, BATADV_ATTR_NETWORK_CODING_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		       !!atomic_read(&bat_priv->network_coding)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) #endif /* CONFIG_BATMAN_ADV_NC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	if (nla_put_u32(msg, BATADV_ATTR_ORIG_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 			atomic_read(&bat_priv->orig_interval)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	if (primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	genlmsg_end(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	genlmsg_cancel(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)  * batadv_netlink_notify_mesh() - send softif attributes to listener
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) int batadv_netlink_notify_mesh(struct batadv_priv *bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_SET_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 				       0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	genlmsg_multicast_netns(&batadv_netlink_family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 				dev_net(bat_priv->soft_iface), msg, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 				BATADV_NL_MCGRP_CONFIG, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  * batadv_netlink_get_mesh() - Get softif attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) static int batadv_netlink_get_mesh(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_GET_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 				       info->snd_portid, info->snd_seq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	ret = genlmsg_reply(msg, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434)  * batadv_netlink_set_mesh() - Set softif attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	if (info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		attr = info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		atomic_set(&bat_priv->aggregated_ogms, !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		batadv_netlink_set_mesh_ap_isolation(attr, bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	if (info->attrs[BATADV_ATTR_ISOLATION_MARK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		attr = info->attrs[BATADV_ATTR_ISOLATION_MARK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		bat_priv->isolation_mark = nla_get_u32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	if (info->attrs[BATADV_ATTR_ISOLATION_MASK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		attr = info->attrs[BATADV_ATTR_ISOLATION_MASK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		bat_priv->isolation_mark_mask = nla_get_u32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if (info->attrs[BATADV_ATTR_BONDING_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		attr = info->attrs[BATADV_ATTR_BONDING_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		atomic_set(&bat_priv->bonding, !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) #ifdef CONFIG_BATMAN_ADV_BLA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		attr = info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		atomic_set(&bat_priv->bridge_loop_avoidance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			   !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		batadv_bla_status_update(bat_priv->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) #endif /* CONFIG_BATMAN_ADV_BLA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) #ifdef CONFIG_BATMAN_ADV_DAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	if (info->attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		attr = info->attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		atomic_set(&bat_priv->distributed_arp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			   !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		batadv_dat_status_update(bat_priv->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) #endif /* CONFIG_BATMAN_ADV_DAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (info->attrs[BATADV_ATTR_FRAGMENTATION_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		attr = info->attrs[BATADV_ATTR_FRAGMENTATION_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		atomic_set(&bat_priv->fragmentation, !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		batadv_update_min_mtu(bat_priv->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		atomic_set(&bat_priv->gw.bandwidth_down, nla_get_u32(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		batadv_gw_tvlv_container_update(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		atomic_set(&bat_priv->gw.bandwidth_up, nla_get_u32(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		batadv_gw_tvlv_container_update(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	if (info->attrs[BATADV_ATTR_GW_MODE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		u8 gw_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		attr = info->attrs[BATADV_ATTR_GW_MODE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		gw_mode = nla_get_u8(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		if (gw_mode <= BATADV_GW_MODE_SERVER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			/* Invoking batadv_gw_reselect() is not enough to really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 			 * de-select the current GW. It will only instruct the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			 * gateway client code to perform a re-election the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			 * time that this is needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			 * When gw client mode is being switched off the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			 * GW must be de-selected explicitly otherwise no GW_ADD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			 * uevent is thrown on client mode re-activation. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			 * is operation is performed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 			 * batadv_gw_check_client_stop().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			batadv_gw_reselect(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			/* always call batadv_gw_check_client_stop() before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			 * changing the gateway state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 			batadv_gw_check_client_stop(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			atomic_set(&bat_priv->gw.mode, gw_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			batadv_gw_tvlv_container_update(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	if (info->attrs[BATADV_ATTR_GW_SEL_CLASS] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	    bat_priv->algo_ops->gw.get_best_gw_node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	    bat_priv->algo_ops->gw.is_eligible) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		/* setting the GW selection class is allowed only if the routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		 * algorithm in use implements the GW API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		u32 sel_class_max = 0xffffffffu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		u32 sel_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		attr = info->attrs[BATADV_ATTR_GW_SEL_CLASS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		sel_class = nla_get_u32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		if (!bat_priv->algo_ops->gw.store_sel_class)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 			sel_class_max = BATADV_TQ_MAX_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		if (sel_class >= 1 && sel_class <= sel_class_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			atomic_set(&bat_priv->gw.sel_class, sel_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 			batadv_gw_reselect(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	if (info->attrs[BATADV_ATTR_HOP_PENALTY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		attr = info->attrs[BATADV_ATTR_HOP_PENALTY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		atomic_set(&bat_priv->hop_penalty, nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) #ifdef CONFIG_BATMAN_ADV_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	if (info->attrs[BATADV_ATTR_LOG_LEVEL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		attr = info->attrs[BATADV_ATTR_LOG_LEVEL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		atomic_set(&bat_priv->log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			   nla_get_u32(attr) & BATADV_DBG_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) #endif /* CONFIG_BATMAN_ADV_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) #ifdef CONFIG_BATMAN_ADV_MCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	if (info->attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		attr = info->attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		atomic_set(&bat_priv->multicast_mode, !nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	if (info->attrs[BATADV_ATTR_MULTICAST_FANOUT]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		attr = info->attrs[BATADV_ATTR_MULTICAST_FANOUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		atomic_set(&bat_priv->multicast_fanout, nla_get_u32(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) #endif /* CONFIG_BATMAN_ADV_MCAST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) #ifdef CONFIG_BATMAN_ADV_NC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	if (info->attrs[BATADV_ATTR_NETWORK_CODING_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		attr = info->attrs[BATADV_ATTR_NETWORK_CODING_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		atomic_set(&bat_priv->network_coding, !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		batadv_nc_status_update(bat_priv->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) #endif /* CONFIG_BATMAN_ADV_NC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	if (info->attrs[BATADV_ATTR_ORIG_INTERVAL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		u32 orig_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		attr = info->attrs[BATADV_ATTR_ORIG_INTERVAL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		orig_interval = nla_get_u32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		orig_interval = min_t(u32, orig_interval, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		orig_interval = max_t(u32, orig_interval, 2 * BATADV_JITTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		atomic_set(&bat_priv->orig_interval, orig_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	batadv_netlink_notify_mesh(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)  * batadv_netlink_tp_meter_put() - Fill information of started tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  * @msg: netlink message to be sent back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)  * @cookie: tp meter session cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)  *  Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) batadv_netlink_tp_meter_put(struct sk_buff *msg, u32 cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639)  * batadv_netlink_tpmeter_notify() - send tp_meter result via netlink to client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641)  * @dst: destination of tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)  * @result: reason for tp meter session stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)  * @test_time: total time of the tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644)  * @total_bytes: bytes acked to the receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)  * @cookie: cookie of tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)  * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 				  u8 result, u32 test_time, u64 total_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 				  u32 cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	hdr = genlmsg_put(msg, 0, 0, &batadv_netlink_family, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			  BATADV_CMD_TP_METER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	if (!hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		goto err_genlmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	if (nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, test_time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	if (nla_put_u64_64bit(msg, BATADV_ATTR_TPMETER_BYTES, total_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			      BATADV_ATTR_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (nla_put_u8(msg, BATADV_ATTR_TPMETER_RESULT, result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	genlmsg_end(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	genlmsg_multicast_netns(&batadv_netlink_family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 				dev_net(bat_priv->soft_iface), msg, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 				BATADV_NL_MCGRP_TPMETER, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	genlmsg_cancel(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	ret = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) err_genlmsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702)  * batadv_netlink_tp_meter_start() - Start a new tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)  * @skb: received netlink message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	struct sk_buff *msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	u32 test_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	void *msg_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	u32 cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	u8 *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 			       &batadv_netlink_family, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 			       BATADV_CMD_TP_METER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (!msg_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	batadv_tp_start(bat_priv, dst, test_length, &cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	ret = batadv_netlink_tp_meter_put(msg, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		if (msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 			nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	genlmsg_end(msg, msg_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	return genlmsg_reply(msg, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759)  * batadv_netlink_tp_meter_start() - Cancel a running tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760)  * @skb: received netlink message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763)  * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	u8 *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783)  * batadv_netlink_hardif_fill() - Fill message with hardif attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784)  * @msg: Netlink message to dump into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786)  * @hard_iface: hard interface which was modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)  * @cmd: type of message to generate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788)  * @portid: Port making netlink request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789)  * @seq: sequence number for message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790)  * @flags: Additional flags for message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791)  * @cb: Control block containing additional options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) static int batadv_netlink_hardif_fill(struct sk_buff *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 				      struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 				      struct batadv_hard_iface *hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 				      enum batadv_nl_commands cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 				      u32 portid, u32 seq, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 				      struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	struct net_device *net_dev = hard_iface->net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	if (cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		genl_dump_check_consistent(cb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			bat_priv->soft_iface->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			net_dev->ifindex) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	    nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			   net_dev->name) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	    nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		    net_dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	if (hard_iface->if_status == BATADV_IF_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		if (nla_put_flag(msg, BATADV_ATTR_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		       atomic_read(&hard_iface->hop_penalty)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) #ifdef CONFIG_BATMAN_ADV_BATMAN_V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	if (nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			atomic_read(&hard_iface->bat_v.elp_interval)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			atomic_read(&hard_iface->bat_v.throughput_override)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) #endif /* CONFIG_BATMAN_ADV_BATMAN_V */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	genlmsg_end(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	genlmsg_cancel(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852)  * batadv_netlink_notify_hardif() - send hardif attributes to listener
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854)  * @hard_iface: hard interface which was modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856)  * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) int batadv_netlink_notify_hardif(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 				 struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 					 BATADV_CMD_SET_HARDIF, 0, 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	genlmsg_multicast_netns(&batadv_netlink_family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 				dev_net(bat_priv->soft_iface), msg, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 				BATADV_NL_MCGRP_CONFIG, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)  * batadv_netlink_get_hardif() - Get hardif attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) static int batadv_netlink_get_hardif(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 				     struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	struct batadv_hard_iface *hard_iface = info->user_ptr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 					 BATADV_CMD_GET_HARDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 					 info->snd_portid, info->snd_seq, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 					 NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	ret = genlmsg_reply(msg, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)  * batadv_netlink_set_hardif() - Set hardif attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) static int batadv_netlink_set_hardif(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 				     struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	struct batadv_hard_iface *hard_iface = info->user_ptr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (info->attrs[BATADV_ATTR_HOP_PENALTY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		attr = info->attrs[BATADV_ATTR_HOP_PENALTY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		atomic_set(&hard_iface->hop_penalty, nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) #ifdef CONFIG_BATMAN_ADV_BATMAN_V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (info->attrs[BATADV_ATTR_ELP_INTERVAL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		attr = info->attrs[BATADV_ATTR_ELP_INTERVAL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		atomic_set(&hard_iface->bat_v.elp_interval, nla_get_u32(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		attr = info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		atomic_set(&hard_iface->bat_v.throughput_override,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			   nla_get_u32(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) #endif /* CONFIG_BATMAN_ADV_BATMAN_V */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	batadv_netlink_notify_hardif(bat_priv, hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)  * batadv_netlink_dump_hardif() - Dump all hard interface into a messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958)  * @msg: Netlink message to dump into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959)  * @cb: Parameters from query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961)  * Return: error code, or length of reply message on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	struct net *net = sock_net(cb->skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	struct net_device *soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	int portid = NETLINK_CB(cb->skb).portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	int skip = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	ifindex = batadv_netlink_get_ifindex(cb->nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 					     BATADV_ATTR_MESH_IFINDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	if (!ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	soft_iface = dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	if (!soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	if (!batadv_softif_is_valid(soft_iface)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		dev_put(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	cb->seq = batadv_hardif_generation << 1 | 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	list_for_each_entry(hard_iface, &batadv_hardif_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		if (hard_iface->soft_iface != soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		if (i++ < skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		if (batadv_netlink_hardif_fill(msg, bat_priv, hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 					       BATADV_CMD_GET_HARDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 					       portid, cb->nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 					       NLM_F_MULTI, cb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 			i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	dev_put(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	cb->args[0] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	return msg->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)  * batadv_netlink_vlan_fill() - Fill message with vlan attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)  * @msg: Netlink message to dump into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)  * @vlan: vlan which was modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)  * @cmd: type of message to generate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)  * @portid: Port making netlink request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)  * @seq: sequence number for message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)  * @flags: Additional flags for message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) static int batadv_netlink_vlan_fill(struct sk_buff *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 				    struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 				    struct batadv_softif_vlan *vlan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 				    enum batadv_nl_commands cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 				    u32 portid, u32 seq, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			bat_priv->soft_iface->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	if (nla_put_u32(msg, BATADV_ATTR_VLANID, vlan->vid & VLAN_VID_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	if (nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		       !!atomic_read(&vlan->ap_isolation)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	genlmsg_end(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	genlmsg_cancel(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)  * batadv_netlink_notify_vlan() - send vlan attributes to listener
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)  * @vlan: vlan which was modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)  * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) int batadv_netlink_notify_vlan(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			       struct batadv_softif_vlan *vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 				       BATADV_CMD_SET_VLAN, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	genlmsg_multicast_netns(&batadv_netlink_family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 				dev_net(bat_priv->soft_iface), msg, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 				BATADV_NL_MCGRP_CONFIG, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)  * batadv_netlink_get_vlan() - Get vlan attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) static int batadv_netlink_get_vlan(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	struct batadv_softif_vlan *vlan = info->user_ptr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan, BATADV_CMD_GET_VLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 				       info->snd_portid, info->snd_seq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	ret = genlmsg_reply(msg, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * batadv_netlink_set_vlan() - Get vlan attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static int batadv_netlink_set_vlan(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	struct batadv_softif_vlan *vlan = info->user_ptr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	struct batadv_priv *bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	batadv_netlink_notify_vlan(bat_priv, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)  * batadv_get_softif_from_info() - Retrieve soft interface from genl attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)  * @net: the applicable net namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * Return: Pointer to soft interface (with increased refcnt) on success, error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  *  pointer on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) static struct net_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) batadv_get_softif_from_info(struct net *net, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	struct net_device *soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (!info->attrs[BATADV_ATTR_MESH_IFINDEX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	soft_iface = dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (!soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	if (!batadv_softif_is_valid(soft_iface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		goto err_put_softif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	return soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) err_put_softif:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	dev_put(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)  * batadv_get_hardif_from_info() - Retrieve hardif from genl attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)  * @net: the applicable net namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)  * Return: Pointer to hard interface (with increased refcnt) on success, error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)  *  pointer on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static struct batadv_hard_iface *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) batadv_get_hardif_from_info(struct batadv_priv *bat_priv, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			    struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	struct net_device *hard_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	unsigned int hardif_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	if (!info->attrs[BATADV_ATTR_HARD_IFINDEX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	hardif_index = nla_get_u32(info->attrs[BATADV_ATTR_HARD_IFINDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	hard_dev = dev_get_by_index(net, hardif_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	if (!hard_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	hard_iface = batadv_hardif_get_by_netdev(hard_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	if (!hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		goto err_put_harddev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	if (hard_iface->soft_iface != bat_priv->soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		goto err_put_hardif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	/* hard_dev is referenced by hard_iface and not needed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	dev_put(hard_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	return hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) err_put_hardif:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	batadv_hardif_put(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) err_put_harddev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	dev_put(hard_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)  * batadv_get_vlan_from_info() - Retrieve vlan from genl attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)  * @net: the applicable net namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)  * Return: Pointer to vlan on success (with increased refcnt), error pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)  *  on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static struct batadv_softif_vlan *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) batadv_get_vlan_from_info(struct batadv_priv *bat_priv, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 			  struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	u16 vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	if (!info->attrs[BATADV_ATTR_VLANID])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	vid = nla_get_u16(info->attrs[BATADV_ATTR_VLANID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	return vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)  * batadv_pre_doit() - Prepare batman-adv genl doit request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)  * @ops: requested netlink operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) static int batadv_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 			   struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	struct batadv_priv *bat_priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	struct net_device *soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	u8 user_ptr1_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	u8 mesh_dep_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	user_ptr1_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	if (WARN_ON(hweight8(ops->internal_flags & user_ptr1_flags) > 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	mesh_dep_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (WARN_ON((ops->internal_flags & mesh_dep_flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		    (~ops->internal_flags & BATADV_FLAG_NEED_MESH)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	if (ops->internal_flags & BATADV_FLAG_NEED_MESH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		soft_iface = batadv_get_softif_from_info(net, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		if (IS_ERR(soft_iface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 			return PTR_ERR(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		info->user_ptr[0] = bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		hard_iface = batadv_get_hardif_from_info(bat_priv, net, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		if (IS_ERR(hard_iface)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			ret = PTR_ERR(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 			goto err_put_softif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		info->user_ptr[1] = hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	if (ops->internal_flags & BATADV_FLAG_NEED_VLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		vlan = batadv_get_vlan_from_info(bat_priv, net, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		if (IS_ERR(vlan)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 			ret = PTR_ERR(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 			goto err_put_softif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		info->user_ptr[1] = vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) err_put_softif:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	if (bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		dev_put(bat_priv->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)  * batadv_post_doit() - End batman-adv genl doit request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)  * @ops: requested netlink operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)  * @skb: Netlink message with request data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)  * @info: receiver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) static void batadv_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 			     struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	    info->user_ptr[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		hard_iface = info->user_ptr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		batadv_hardif_put(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	if (ops->internal_flags & BATADV_FLAG_NEED_VLAN && info->user_ptr[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		vlan = info->user_ptr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	if (ops->internal_flags & BATADV_FLAG_NEED_MESH && info->user_ptr[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		bat_priv = info->user_ptr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		dev_put(bat_priv->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) static const struct genl_small_ops batadv_netlink_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		.cmd = BATADV_CMD_GET_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		/* can be retrieved by unprivileged users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		.doit = batadv_netlink_get_mesh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		.internal_flags = BATADV_FLAG_NEED_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		.cmd = BATADV_CMD_TP_METER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		.doit = batadv_netlink_tp_meter_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		.internal_flags = BATADV_FLAG_NEED_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		.cmd = BATADV_CMD_TP_METER_CANCEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		.doit = batadv_netlink_tp_meter_cancel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		.internal_flags = BATADV_FLAG_NEED_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		.cmd = BATADV_CMD_GET_ROUTING_ALGOS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 		.dumpit = batadv_algo_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		.cmd = BATADV_CMD_GET_HARDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		/* can be retrieved by unprivileged users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		.dumpit = batadv_netlink_dump_hardif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		.doit = batadv_netlink_get_hardif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		.internal_flags = BATADV_FLAG_NEED_MESH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 				  BATADV_FLAG_NEED_HARDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		.cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		.dumpit = batadv_tt_local_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		.cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		.dumpit = batadv_tt_global_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		.cmd = BATADV_CMD_GET_ORIGINATORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		.dumpit = batadv_orig_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		.cmd = BATADV_CMD_GET_NEIGHBORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		.dumpit = batadv_hardif_neigh_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		.cmd = BATADV_CMD_GET_GATEWAYS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		.dumpit = batadv_gw_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		.cmd = BATADV_CMD_GET_BLA_CLAIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		.dumpit = batadv_bla_claim_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		.cmd = BATADV_CMD_GET_BLA_BACKBONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		.dumpit = batadv_bla_backbone_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 		.cmd = BATADV_CMD_GET_DAT_CACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 		.dumpit = batadv_dat_cache_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 		.cmd = BATADV_CMD_GET_MCAST_FLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		.dumpit = batadv_mcast_flags_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		.cmd = BATADV_CMD_SET_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		.doit = batadv_netlink_set_mesh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		.internal_flags = BATADV_FLAG_NEED_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		.cmd = BATADV_CMD_SET_HARDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		.doit = batadv_netlink_set_hardif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		.internal_flags = BATADV_FLAG_NEED_MESH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 				  BATADV_FLAG_NEED_HARDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		.cmd = BATADV_CMD_GET_VLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		/* can be retrieved by unprivileged users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		.doit = batadv_netlink_get_vlan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 		.internal_flags = BATADV_FLAG_NEED_MESH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 				  BATADV_FLAG_NEED_VLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 		.cmd = BATADV_CMD_SET_VLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		.flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		.doit = batadv_netlink_set_vlan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		.internal_flags = BATADV_FLAG_NEED_MESH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 				  BATADV_FLAG_NEED_VLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) struct genl_family batadv_netlink_family __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	.hdrsize = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	.name = BATADV_NL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	.version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	.maxattr = BATADV_ATTR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	.policy = batadv_netlink_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	.netnsok = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	.pre_doit = batadv_pre_doit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	.post_doit = batadv_post_doit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	.module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	.small_ops = batadv_netlink_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	.n_small_ops = ARRAY_SIZE(batadv_netlink_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	.mcgrps = batadv_netlink_mcgrps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	.n_mcgrps = ARRAY_SIZE(batadv_netlink_mcgrps),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)  * batadv_netlink_register() - register batadv genl netlink family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) void __init batadv_netlink_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	ret = genl_register_family(&batadv_netlink_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		pr_warn("unable to register netlink family");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)  * batadv_netlink_unregister() - unregister batadv genl netlink family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) void batadv_netlink_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	genl_unregister_family(&batadv_netlink_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }