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) 2007-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)  * Marek Lindner, Simon Wunderlich
^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 "soft-interface.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/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/lockdep.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/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <uapi/linux/batadv_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <uapi/linux/batman_adv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include "bat_algo.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include "bridge_loop_avoidance.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include "debugfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include "distributed-arp-table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include "gateway_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include "hard-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include "multicast.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include "network-coding.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include "originator.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include "send.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include "sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include "translation-table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * batadv_skb_head_push() - Increase header size and move (push) head pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  * @skb: packet buffer which should be modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  * @len: number of bytes to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  * Return: 0 on success or negative error number in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	/* TODO: We must check if we can release all references to non-payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	 * data using __skb_header_release in our skbs to allow skb_cow_header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	 * to work optimally. This means that those skbs are not allowed to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	 * or write any data which is before the current position of skb->data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	 * after that call and thus allow other skbs with the same data buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	 * to write freely in that area.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	result = skb_cow_head(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	skb_push(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static int batadv_interface_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	netif_start_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static int batadv_interface_release(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * batadv_sum_counter() - Sum the cpu-local counters for index 'idx'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  * @idx: index of counter to sum up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  * Return: sum of all cpu-local counters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static u64 batadv_sum_counter(struct batadv_priv *bat_priv,  size_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	u64 *counters, sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		counters = per_cpu_ptr(bat_priv->bat_counters, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		sum += counters[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	struct batadv_priv *bat_priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	struct net_device_stats *stats = &dev->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	stats->tx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_TX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	stats->tx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_TX_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	stats->tx_dropped = batadv_sum_counter(bat_priv, BATADV_CNT_TX_DROPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	stats->rx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_RX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	stats->rx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_RX_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	return stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	struct batadv_priv *bat_priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	struct sockaddr *addr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	u8 old_addr[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	if (!is_valid_ether_addr(addr->sa_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	ether_addr_copy(old_addr, dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	ether_addr_copy(dev->dev_addr, addr->sa_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	/* only modify transtable if it has been initialized before */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		batadv_tt_local_remove(bat_priv, old_addr, vlan->vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 				       "mac address changed", false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		batadv_tt_local_add(dev, addr->sa_data, vlan->vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 				    BATADV_NULL_IFINDEX, BATADV_NO_MARK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	/* check ranges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	if (new_mtu < 68 || new_mtu > batadv_hardif_min_mtu(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	dev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  * batadv_interface_set_rx_mode() - set the rx mode of a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * @dev: registered network device to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  * We do not actually need to set any rx filters for the virtual batman
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  * soft interface. However a dummy handler enables a user to set static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  * multicast listeners for instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) static void batadv_interface_set_rx_mode(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 				       struct net_device *soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	struct ethhdr *ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	struct batadv_priv *bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	struct batadv_hard_iface *primary_if = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	struct batadv_bcast_packet *bcast_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	static const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 					      0x00, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	static const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 					       0x00, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	u8 *dst_hint = NULL, chaddr[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	struct vlan_ethhdr *vhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	unsigned int header_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	int data_len = skb->len, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	unsigned long brd_delay = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	bool do_bcast = false, client_added;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	unsigned short vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	u32 seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	int gw_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	enum batadv_forw_mode forw_mode = BATADV_FORW_SINGLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	struct batadv_orig_node *mcast_single_orig = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	int mcast_is_routable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	int network_offset = ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	__be16 proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	/* reset control block to avoid left overs from previous users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	memset(skb->cb, 0, sizeof(struct batadv_skb_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	netif_trans_update(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	vid = batadv_get_vid(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	ethhdr = eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	proto = ethhdr->h_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	switch (ntohs(proto)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	case ETH_P_8021Q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		if (!pskb_may_pull(skb, sizeof(*vhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 			goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		vhdr = vlan_eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		proto = vhdr->h_vlan_encapsulated_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		/* drop batman-in-batman packets to prevent loops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		if (proto != htons(ETH_P_BATMAN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			network_offset += VLAN_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	case ETH_P_BATMAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	skb_set_network_header(skb, network_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (batadv_bla_tx(bat_priv, skb, vid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/* skb->data might have been reallocated by batadv_bla_tx() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	ethhdr = eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	/* Register the client MAC in the transtable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	if (!is_multicast_ether_addr(ethhdr->h_source) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	    !batadv_bla_is_loopdetect_mac(ethhdr->h_source)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		client_added = batadv_tt_local_add(soft_iface, ethhdr->h_source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 						   vid, skb->skb_iif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 						   skb->mark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		if (!client_added)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 			goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	/* Snoop address candidates from DHCPACKs for early DAT filling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	batadv_dat_snoop_outgoing_dhcp_ack(bat_priv, skb, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	/* don't accept stp packets. STP does not help in meshes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	 * better use the bridge loop avoidance ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	 * The same goes for ECTP sent at least by some Cisco Switches,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	 * it might confuse the mesh when used with bridge loop avoidance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	if (batadv_compare_eth(ethhdr->h_dest, stp_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	gw_mode = atomic_read(&bat_priv->gw.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	if (is_multicast_ether_addr(ethhdr->h_dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		/* if gw mode is off, broadcast every packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		if (gw_mode == BATADV_GW_MODE_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			do_bcast = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			goto send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		dhcp_rcp = batadv_gw_dhcp_recipient_get(skb, &header_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 							chaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		/* skb->data may have been modified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		 * batadv_gw_dhcp_recipient_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		ethhdr = eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		/* if gw_mode is on, broadcast any non-DHCP message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		 * All the DHCP packets are going to be sent as unicast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		if (dhcp_rcp == BATADV_DHCP_NO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 			do_bcast = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 			goto send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		if (dhcp_rcp == BATADV_DHCP_TO_CLIENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			dst_hint = chaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		else if ((gw_mode == BATADV_GW_MODE_SERVER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			 (dhcp_rcp == BATADV_DHCP_TO_SERVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			/* gateways should not forward any DHCP message if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			 * directed to a DHCP server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) send:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		if (do_bcast && !is_broadcast_ether_addr(ethhdr->h_dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			forw_mode = batadv_mcast_forw_mode(bat_priv, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 							   &mcast_single_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 							   &mcast_is_routable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			if (forw_mode == BATADV_FORW_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 				goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			if (forw_mode == BATADV_FORW_SINGLE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 			    forw_mode == BATADV_FORW_SOME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 				do_bcast = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	batadv_skb_set_priority(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	/* ethernet packet should be broadcasted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	if (do_bcast) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		if (!primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		/* in case of ARP request, we do not immediately broadcasti the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		 * packet, instead we first wait for DAT to try to retrieve the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		 * correct ARP entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			brd_delay = msecs_to_jiffies(ARP_REQ_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		if (batadv_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		bcast_packet = (struct batadv_bcast_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		bcast_packet->version = BATADV_COMPAT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		bcast_packet->ttl = BATADV_TTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		/* batman packet type: broadcast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		bcast_packet->packet_type = BATADV_BCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		bcast_packet->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		/* hw address of first interface is the orig mac because only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		 * this mac is known throughout the mesh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		ether_addr_copy(bcast_packet->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 				primary_if->net_dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		/* set broadcast sequence number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		seqno = atomic_inc_return(&bat_priv->bcast_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		bcast_packet->seqno = htonl(seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		/* a copy is stored in the bcast list, therefore removing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		 * the original skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	/* unicast packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		/* DHCP packets going to a server will use the GW feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		if (dhcp_rcp == BATADV_DHCP_TO_SERVER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			ret = batadv_gw_out_of_range(bat_priv, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 				goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			ret = batadv_send_skb_via_gw(bat_priv, skb, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		} else if (mcast_single_orig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			ret = batadv_mcast_forw_send_orig(bat_priv, skb, vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 							  mcast_single_orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		} else if (forw_mode == BATADV_FORW_SOME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			ret = batadv_mcast_forw_send(bat_priv, skb, vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 						     mcast_is_routable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			if (batadv_dat_snoop_outgoing_arp_request(bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 								  skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 				goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			ret = batadv_send_skb_via_tt(bat_priv, skb, dst_hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 						     vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		if (ret != NET_XMIT_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			goto dropped_freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	batadv_inc_counter(bat_priv, BATADV_CNT_TX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	batadv_add_counter(bat_priv, BATADV_CNT_TX_BYTES, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) dropped:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) dropped_freed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	if (mcast_single_orig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		batadv_orig_node_put(mcast_single_orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	if (primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	return NETDEV_TX_OK;
^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_interface_rx() - receive ethernet frame on local batman-adv interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  * @soft_iface: local interface which will receive the ethernet frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * @skb: ethernet frame for @soft_iface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  * @hdr_size: size of already parsed batman-adv header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  * @orig_node: originator from which the batman-adv packet was sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  * Sends an ethernet frame to the receive path of the local @soft_iface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  * skb->data has still point to the batman-adv header with the size @hdr_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  * The caller has to have parsed this header already and made sure that at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * @hdr_size bytes are still available for pull in @skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  * The packet may still get dropped. This can happen when the encapsulated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  * ethernet frame is invalid or contains again an batman-adv packet. Also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  * unicast packets will be dropped directly when it was sent between two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  * isolated clients.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) void batadv_interface_rx(struct net_device *soft_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			 struct sk_buff *skb, int hdr_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			 struct batadv_orig_node *orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct batadv_bcast_packet *batadv_bcast_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	struct batadv_priv *bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	struct vlan_ethhdr *vhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	struct ethhdr *ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	unsigned short vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	int packet_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	batadv_bcast_packet = (struct batadv_bcast_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	packet_type = batadv_bcast_packet->packet_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	skb_pull_rcsum(skb, hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	/* clean the netfilter state now that the batman-adv header has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	 * removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	nf_reset_ct(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	vid = batadv_get_vid(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	ethhdr = eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	switch (ntohs(ethhdr->h_proto)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	case ETH_P_8021Q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 			goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		vhdr = (struct vlan_ethhdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		/* drop batman-in-batman packets to prevent loops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	case ETH_P_BATMAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	/* skb->dev & skb->pkt_type are set here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	skb->protocol = eth_type_trans(skb, soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	batadv_inc_counter(bat_priv, BATADV_CNT_RX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			   skb->len + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	/* Let the bridge loop avoidance check the packet. If will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	 * not handle it, we can safely push it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (batadv_bla_rx(bat_priv, skb, vid, packet_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		batadv_tt_add_temporary_global_entry(bat_priv, orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 						     ethhdr->h_source, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	if (is_multicast_ether_addr(ethhdr->h_dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		/* set the mark on broadcast packets if AP isolation is ON and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		 * the packet is coming from an "isolated" client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		if (batadv_vlan_ap_isola_get(bat_priv, vid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		    batadv_tt_global_is_isolated(bat_priv, ethhdr->h_source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 						 vid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			/* save bits in skb->mark not covered by the mask and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			 * apply the mark on the rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			skb->mark &= ~bat_priv->isolation_mark_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			skb->mark |= bat_priv->isolation_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	} else if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 					 ethhdr->h_dest, vid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		goto dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) dropped:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511)  * batadv_softif_vlan_release() - release vlan from lists and queue for free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)  *  after rcu grace period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513)  * @ref: kref pointer of the vlan object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) void batadv_softif_vlan_release(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	vlan = container_of(ref, struct batadv_softif_vlan, refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	hlist_del_rcu(&vlan->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	kfree_rcu(vlan, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  * batadv_softif_vlan_get() - get the vlan object for a specific vid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  * @vid: the identifier of the vlan object to retrieve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  * Return: the private data of the vlan matching the vid passed as argument or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)  * NULL otherwise. The refcounter of the returned object is incremented by 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) struct batadv_softif_vlan *batadv_softif_vlan_get(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 						  unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	struct batadv_softif_vlan *vlan_tmp, *vlan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	hlist_for_each_entry_rcu(vlan_tmp, &bat_priv->softif_vlan_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		if (vlan_tmp->vid != vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		if (!kref_get_unless_zero(&vlan_tmp->refcount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		vlan = vlan_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	return vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558)  * batadv_softif_create_vlan() - allocate the needed resources for a new vlan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  * @vid: the VLAN identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * Return: 0 on success, a negative error otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	spin_lock_bh(&bat_priv->softif_vlan_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	vlan = batadv_softif_vlan_get(bat_priv, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	if (vlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (!vlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	vlan->bat_priv = bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	vlan->vid = vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	kref_init(&vlan->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	atomic_set(&vlan->ap_isolation, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	kref_get(&vlan->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	/* batadv_sysfs_add_vlan cannot be in the spinlock section due to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	 * sleeping behavior of the sysfs functions and the fs_reclaim lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	err = batadv_sysfs_add_vlan(bat_priv->soft_iface, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		/* ref for the function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		/* ref for the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	/* add a new TT local entry. This one will be marked with the NOPURGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	 * flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	batadv_tt_local_add(bat_priv->soft_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			    bat_priv->soft_iface->dev_addr, vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			    BATADV_NULL_IFINDEX, BATADV_NO_MARK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	/* don't return reference to new softif_vlan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)  * batadv_softif_destroy_vlan() - remove and destroy a softif_vlan object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)  * @vlan: the object to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) static void batadv_softif_destroy_vlan(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 				       struct batadv_softif_vlan *vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	/* explicitly remove the associated TT local entry because it is marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	 * with the NOPURGE flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	batadv_tt_local_remove(bat_priv, bat_priv->soft_iface->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			       vlan->vid, "vlan interface destroyed", false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	batadv_sysfs_del_vlan(bat_priv, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	batadv_softif_vlan_put(vlan);
^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_interface_add_vid() - ndo_add_vid API implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640)  * @dev: the netdev of the mesh interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641)  * @proto: protocol of the vlan id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)  * @vid: identifier of the new vlan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644)  * Set up all the internal structures for handling the new vlan on top of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)  * mesh interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)  * Return: 0 on success or a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) static int batadv_interface_add_vid(struct net_device *dev, __be16 proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 				    unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	struct batadv_priv *bat_priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	/* only 802.1Q vlans are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	 * batman-adv does not know how to handle other types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (proto != htons(ETH_P_8021Q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	vid |= BATADV_VLAN_HAS_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	/* if a new vlan is getting created and it already exists, it means that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	 * it was not deleted yet. batadv_softif_vlan_get() increases the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	 * refcount in order to revive the object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	 * if it does not exist then create it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	vlan = batadv_softif_vlan_get(bat_priv, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		return batadv_softif_create_vlan(bat_priv, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	/* recreate the sysfs object if it was already destroyed (and it should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	 * be since we received a kill_vid() for this vlan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	if (!vlan->kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		ret = batadv_sysfs_add_vlan(bat_priv->soft_iface, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	/* add a new TT local entry. This one will be marked with the NOPURGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	 * flag. This must be added again, even if the vlan object already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	 * exists, because the entry was deleted by kill_vid()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	batadv_tt_local_add(bat_priv->soft_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 			    bat_priv->soft_iface->dev_addr, vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			    BATADV_NULL_IFINDEX, BATADV_NO_MARK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697)  * batadv_interface_kill_vid() - ndo_kill_vid API implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698)  * @dev: the netdev of the mesh interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699)  * @proto: protocol of the vlan id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700)  * @vid: identifier of the deleted vlan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702)  * Destroy all the internal structures used to handle the vlan identified by vid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)  * on top of the mesh interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  * Return: 0 on success, -EINVAL if the specified prototype is not ETH_P_8021Q
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  * or -ENOENT if the specified vlan id wasn't registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) static int batadv_interface_kill_vid(struct net_device *dev, __be16 proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 				     unsigned short vid)
^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 = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	/* only 802.1Q vlans are supported. batman-adv does not know how to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	 * handle other types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	if (proto != htons(ETH_P_8021Q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	batadv_softif_destroy_vlan(bat_priv, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	/* finally free the vlan object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) /* batman-adv network devices have devices nesting below it and are a special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733)  * "super class" of normal network devices; split their locks off into a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734)  * separate class since they always nest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) static struct lock_class_key batadv_netdev_xmit_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) static struct lock_class_key batadv_netdev_addr_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)  * batadv_set_lockdep_class_one() - Set lockdep class for a single tx queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741)  * @dev: device which owns the tx queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742)  * @txq: tx queue to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743)  * @_unused: always NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) static void batadv_set_lockdep_class_one(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 					 struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 					 void *_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	lockdep_set_class(&txq->_xmit_lock, &batadv_netdev_xmit_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753)  * batadv_set_lockdep_class() - Set txq and addr_list lockdep class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754)  * @dev: network device to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) static void batadv_set_lockdep_class(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	lockdep_set_class(&dev->addr_list_lock, &batadv_netdev_addr_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763)  * batadv_softif_init_late() - late stage initialization of soft interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  * @dev: registered network device to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)  * Return: error code on failures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) static int batadv_softif_init_late(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	u32 random_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	batadv_set_lockdep_class(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	bat_priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	bat_priv->soft_iface = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	/* batadv_interface_stats() needs to be available as soon as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	 * register_netdevice() has been called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (!bat_priv->bat_counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	atomic_set(&bat_priv->aggregated_ogms, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	atomic_set(&bat_priv->bonding, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) #ifdef CONFIG_BATMAN_ADV_BLA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	atomic_set(&bat_priv->bridge_loop_avoidance, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) #ifdef CONFIG_BATMAN_ADV_DAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	atomic_set(&bat_priv->distributed_arp_table, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) #ifdef CONFIG_BATMAN_ADV_MCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	atomic_set(&bat_priv->multicast_mode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	atomic_set(&bat_priv->multicast_fanout, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	atomic_set(&bat_priv->mcast.num_want_all_unsnoopables, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	atomic_set(&bat_priv->gw.mode, BATADV_GW_MODE_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	atomic_set(&bat_priv->gw.bandwidth_down, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	atomic_set(&bat_priv->gw.bandwidth_up, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	atomic_set(&bat_priv->orig_interval, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	atomic_set(&bat_priv->hop_penalty, 30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) #ifdef CONFIG_BATMAN_ADV_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	atomic_set(&bat_priv->log_level, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	atomic_set(&bat_priv->fragmentation, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	atomic_set(&bat_priv->packet_size_max, ETH_DATA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	atomic_set(&bat_priv->bcast_seqno, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	atomic_set(&bat_priv->tt.vn, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	atomic_set(&bat_priv->tt.local_changes, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) #ifdef CONFIG_BATMAN_ADV_BLA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	atomic_set(&bat_priv->bla.num_requests, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	atomic_set(&bat_priv->tp_num, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	bat_priv->tt.last_changeset = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	bat_priv->tt.last_changeset_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	bat_priv->isolation_mark = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	bat_priv->isolation_mark_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	/* randomize initial seqno to avoid collision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	get_random_bytes(&random_seqno, sizeof(random_seqno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	atomic_set(&bat_priv->frag_seqno, random_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	bat_priv->primary_if = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	batadv_nc_init_bat_priv(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	ret = batadv_algo_select(bat_priv, batadv_routing_algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		goto free_bat_counters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	ret = batadv_debugfs_add_meshif(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		goto free_bat_counters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ret = batadv_mesh_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		goto unreg_debugfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) unreg_debugfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	batadv_debugfs_del_meshif(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) free_bat_counters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	free_percpu(bat_priv->bat_counters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	bat_priv->bat_counters = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)  * batadv_softif_slave_add() - Add a slave interface to a batadv_soft_interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)  * @dev: batadv_soft_interface used as master interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)  * @slave_dev: net_device which should become the slave interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865)  * @extack: extended ACK report struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  * Return: 0 if successful or error otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) static int batadv_softif_slave_add(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 				   struct net_device *slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 				   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	hard_iface = batadv_hardif_get_by_netdev(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	if (!hard_iface || hard_iface->soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	ret = batadv_hardif_enable_interface(hard_iface, net, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	if (hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		batadv_hardif_put(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)  * batadv_softif_slave_del() - Delete a slave iface from a batadv_soft_interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)  * @dev: batadv_soft_interface used as master interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)  * @slave_dev: net_device which should be removed from the master interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894)  * Return: 0 if successful or error otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) static int batadv_softif_slave_del(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 				   struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	hard_iface = batadv_hardif_get_by_netdev(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (!hard_iface || hard_iface->soft_iface != dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	batadv_hardif_disable_interface(hard_iface, BATADV_IF_CLEANUP_KEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	if (hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		batadv_hardif_put(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	return ret;
^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) static const struct net_device_ops batadv_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	.ndo_init = batadv_softif_init_late,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	.ndo_open = batadv_interface_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	.ndo_stop = batadv_interface_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	.ndo_get_stats = batadv_interface_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	.ndo_vlan_rx_add_vid = batadv_interface_add_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	.ndo_vlan_rx_kill_vid = batadv_interface_kill_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	.ndo_set_mac_address = batadv_interface_set_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	.ndo_change_mtu = batadv_interface_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	.ndo_set_rx_mode = batadv_interface_set_rx_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	.ndo_start_xmit = batadv_interface_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	.ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	.ndo_add_slave = batadv_softif_slave_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	.ndo_del_slave = batadv_softif_slave_del,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) static void batadv_get_drvinfo(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			       struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	strscpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	strscpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	strscpy(info->fw_version, "N/A", sizeof(info->fw_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	strscpy(info->bus_info, "batman", sizeof(info->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) /* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942)  * Declare each description string in struct.name[] to get fixed sized buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943)  * and compile time checking for strings longer than ETH_GSTRING_LEN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	const char name[ETH_GSTRING_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) } batadv_counters_strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	{ "tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	{ "tx_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	{ "tx_dropped" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	{ "rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	{ "rx_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	{ "forward" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	{ "forward_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	{ "mgmt_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	{ "mgmt_tx_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	{ "mgmt_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	{ "mgmt_rx_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	{ "frag_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	{ "frag_tx_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	{ "frag_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	{ "frag_rx_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	{ "frag_fwd" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	{ "frag_fwd_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	{ "tt_request_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	{ "tt_request_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	{ "tt_response_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	{ "tt_response_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	{ "tt_roam_adv_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	{ "tt_roam_adv_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) #ifdef CONFIG_BATMAN_ADV_DAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	{ "dat_get_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	{ "dat_get_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	{ "dat_put_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	{ "dat_put_rx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	{ "dat_cached_reply_tx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) #ifdef CONFIG_BATMAN_ADV_NC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	{ "nc_code" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	{ "nc_code_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	{ "nc_recode" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	{ "nc_recode_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	{ "nc_buffer" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	{ "nc_decode" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	{ "nc_decode_bytes" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	{ "nc_decode_failed" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	{ "nc_sniffed" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	if (stringset == ETH_SS_STATS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		memcpy(data, batadv_counters_strings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		       sizeof(batadv_counters_strings));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) static void batadv_get_ethtool_stats(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 				     struct ethtool_stats *stats, u64 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	struct batadv_priv *bat_priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	for (i = 0; i < BATADV_CNT_NUM; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		data[i] = batadv_sum_counter(bat_priv, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static int batadv_get_sset_count(struct net_device *dev, int stringset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (stringset == ETH_SS_STATS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		return BATADV_CNT_NUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) static const struct ethtool_ops batadv_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	.get_drvinfo = batadv_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	.get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	.get_strings = batadv_get_strings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	.get_ethtool_stats = batadv_get_ethtool_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	.get_sset_count = batadv_get_sset_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)  * batadv_softif_free() - Deconstructor of batadv_soft_interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)  * @dev: Device to cleanup and remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static void batadv_softif_free(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	batadv_debugfs_del_meshif(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	batadv_mesh_free(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	/* some scheduled RCU callbacks need the bat_priv struct to accomplish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	 * their tasks. Wait for them all to be finished before freeing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	 * netdev and its private data (bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)  * batadv_softif_init_early() - early stage initialization of soft interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)  * @dev: registered network device to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static void batadv_softif_init_early(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	ether_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	dev->netdev_ops = &batadv_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	dev->priv_destructor = batadv_softif_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_NETNS_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	dev->features |= NETIF_F_LLTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	dev->priv_flags |= IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	/* can't call min_mtu, because the needed variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	 * have not been initialized yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	dev->mtu = ETH_DATA_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	/* generate random address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	eth_hw_addr_random(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	dev->ethtool_ops = &batadv_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)  * batadv_softif_create() - Create and register soft interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)  * @net: the applicable net namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)  * @name: name of the new soft interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)  * Return: newly allocated soft_interface, NULL on errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) struct net_device *batadv_softif_create(struct net *net, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	struct net_device *soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	soft_iface = alloc_netdev(sizeof(struct batadv_priv), name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 				  NET_NAME_UNKNOWN, batadv_softif_init_early);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (!soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	dev_net_set(soft_iface, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	soft_iface->rtnl_link_ops = &batadv_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	ret = register_netdevice(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		pr_err("Unable to register the batman interface '%s': %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		       name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		free_netdev(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	return soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)  * batadv_softif_destroy_sysfs() - deletion of batadv_soft_interface via sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)  * @soft_iface: the to-be-removed batman-adv interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) void batadv_softif_destroy_sysfs(struct net_device *soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	struct batadv_priv *bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	/* destroy the "untagged" VLAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (vlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		batadv_softif_destroy_vlan(bat_priv, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	batadv_sysfs_del_meshif(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	unregister_netdevice(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  * batadv_softif_destroy_netlink() - deletion of batadv_soft_interface via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)  *  netlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  * @soft_iface: the to-be-removed batman-adv interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * @head: list pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static void batadv_softif_destroy_netlink(struct net_device *soft_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 					  struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	struct batadv_priv *bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	struct batadv_softif_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	list_for_each_entry(hard_iface, &batadv_hardif_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		if (hard_iface->soft_iface == soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 			batadv_hardif_disable_interface(hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 							BATADV_IF_CLEANUP_KEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	/* destroy the "untagged" VLAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	if (vlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		batadv_softif_destroy_vlan(bat_priv, vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		batadv_softif_vlan_put(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	batadv_sysfs_del_meshif(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	unregister_netdevice_queue(soft_iface, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * batadv_softif_is_valid() - Check whether device is a batadv soft interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * @net_dev: device which should be checked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  * Return: true when net_dev is a batman-adv interface, false otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) bool batadv_softif_is_valid(const struct net_device *net_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) struct rtnl_link_ops batadv_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	.kind		= "batadv",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	.priv_size	= sizeof(struct batadv_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	.setup		= batadv_softif_init_early,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	.dellink	= batadv_softif_destroy_netlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) };