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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	Device handling code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	Linux ethernet bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Lennert Buytenhek		<buytenh@gnu.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/netpoll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/netfilter_bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "br_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define COMMON_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 			 NETIF_F_GSO_MASK | NETIF_F_HW_CSUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) const struct nf_br_ops __rcu *nf_br_ops __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) EXPORT_SYMBOL_GPL(nf_br_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* net device transmit always called with BH disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct net_bridge_fdb_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct net_bridge_mdb_entry *mdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct pcpu_sw_netstats *brstats = this_cpu_ptr(br->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	const struct nf_br_ops *nf_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u8 state = BR_STATE_FORWARDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	const unsigned char *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u16 vid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	memset(skb->cb, 0, sizeof(struct br_input_skb_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	nf_ops = rcu_dereference(nf_br_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (nf_ops && nf_ops->br_dev_xmit_hook(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u64_stats_update_begin(&brstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	brstats->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	brstats->tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u64_stats_update_end(&brstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	br_switchdev_frame_unmark(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	BR_INPUT_SKB_CB(skb)->brdev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	BR_INPUT_SKB_CB(skb)->frag_max_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	skb_pull(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (!br_allowed_ingress(br, br_vlan_group_rcu(br), skb, &vid, &state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (IS_ENABLED(CONFIG_INET) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	    (eth_hdr(skb)->h_proto == htons(ETH_P_ARP) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	     eth_hdr(skb)->h_proto == htons(ETH_P_RARP)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	    br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		br_do_proxy_suppress_arp(skb, br, vid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	} else if (IS_ENABLED(CONFIG_IPV6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		   skb->protocol == htons(ETH_P_IPV6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		   br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		   pskb_may_pull(skb, sizeof(struct ipv6hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				 sizeof(struct nd_msg)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		   ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			struct nd_msg *msg, _msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			msg = br_is_nd_neigh_msg(skb, &_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			if (msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				br_do_suppress_nd(skb, br, vid, NULL, msg);
^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) 	dest = eth_hdr(skb)->h_dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (is_broadcast_ether_addr(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		br_flood(br, skb, BR_PKT_BROADCAST, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	} else if (is_multicast_ether_addr(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (unlikely(netpoll_tx_running(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			br_flood(br, skb, BR_PKT_MULTICAST, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (br_multicast_rcv(br, NULL, skb, vid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		mdst = br_mdb_get(br, skb, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		    br_multicast_querier_exists(br, eth_hdr(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			br_multicast_flood(mdst, skb, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			br_flood(br, skb, BR_PKT_MULTICAST, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	} else if ((dst = br_fdb_find_rcu(br, dest, vid)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		br_forward(dst->dst, skb, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		br_flood(br, skb, BR_PKT_UNICAST, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static struct lock_class_key bridge_netdev_addr_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void br_set_lockdep_class(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	lockdep_set_class(&dev->addr_list_lock, &bridge_netdev_addr_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int br_dev_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	br->stats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (!br->stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	err = br_fdb_hash_init(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		free_percpu(br->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	err = br_mdb_hash_init(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		free_percpu(br->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		br_fdb_hash_fini(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	err = br_vlan_init(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		free_percpu(br->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		br_mdb_hash_fini(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		br_fdb_hash_fini(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	err = br_multicast_init_stats(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		free_percpu(br->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		br_vlan_flush(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		br_mdb_hash_fini(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		br_fdb_hash_fini(br);
^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) 	br_set_lockdep_class(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void br_dev_uninit(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	br_multicast_dev_del(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	br_multicast_uninit_stats(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	br_vlan_flush(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	br_mdb_hash_fini(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	br_fdb_hash_fini(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	free_percpu(br->stats);
^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) static int br_dev_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	netdev_update_features(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	netif_start_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	br_stp_enable_bridge(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	br_multicast_open(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		br_multicast_join_snoopers(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static void br_dev_set_multicast_list(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void br_dev_change_rx_flags(struct net_device *dev, int change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (change & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		br_manage_promisc(netdev_priv(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int br_dev_stop(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	br_stp_disable_bridge(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	br_multicast_stop(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		br_multicast_leave_snoopers(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void br_get_stats64(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			   struct rtnl_link_stats64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	netdev_stats_to_stats64(stats, &dev->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	dev_fetch_sw_netstats(stats, br->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int br_change_mtu(struct net_device *dev, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	dev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	/* this flag will be cleared if the MTU was automatically adjusted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	br_opt_toggle(br, BROPT_MTU_SET_BY_USER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	/* remember the MTU in the rtable for PMTU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	dst_metric_set(&br->fake_rtable.dst, RTAX_MTU, new_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Allow setting mac address to any valid ethernet address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int br_set_mac_address(struct net_device *dev, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct sockaddr *addr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (!is_valid_ether_addr(addr->sa_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/* dev_set_mac_addr() can be called by a master device on bridge's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * NETDEV_UNREGISTER, but since it's being destroyed do nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (dev->reg_state != NETREG_REGISTERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (!ether_addr_equal(dev->dev_addr, addr->sa_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		/* Mac address will be changed in br_stp_change_bridge_id(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		br_stp_change_bridge_id(br, addr->sa_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static void br_getinfo(struct net_device *dev, struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	strlcpy(info->driver, "bridge", sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	strlcpy(info->version, BR_VERSION, sizeof(info->version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	strlcpy(info->bus_info, "N/A", sizeof(info->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int br_get_link_ksettings(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				 struct ethtool_link_ksettings *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	cmd->base.duplex = DUPLEX_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	cmd->base.port = PORT_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	cmd->base.speed = SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		struct ethtool_link_ksettings ecmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		struct net_device *pdev = p->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		if (!netif_running(pdev) || !netif_oper_up(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (__ethtool_get_link_ksettings(pdev, &ecmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		if (ecmd.base.speed == (__u32)SPEED_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		if (cmd->base.speed == (__u32)SPEED_UNKNOWN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		    cmd->base.speed < ecmd.base.speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			cmd->base.speed = ecmd.base.speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static netdev_features_t br_fix_features(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	netdev_features_t features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return br_features_recompute(br, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static void br_poll_controller(struct net_device *br_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static void br_netpoll_cleanup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	list_for_each_entry(p, &br->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		br_netpoll_disable(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int __br_netpoll_enable(struct net_bridge_port *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct netpoll *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	np = kzalloc(sizeof(*p->np), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	err = __netpoll_setup(np, p->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		kfree(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	p->np = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int br_netpoll_enable(struct net_bridge_port *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (!p->br->dev->npinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return __br_netpoll_enable(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int br_netpoll_setup(struct net_device *dev, struct netpoll_info *ni)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (!p->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		err = __br_netpoll_enable(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	br_netpoll_cleanup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void br_netpoll_disable(struct net_bridge_port *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	struct netpoll *np = p->np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	p->np = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	__netpoll_free(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static int br_add_slave(struct net_device *dev, struct net_device *slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	return br_add_if(br, slave_dev, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int br_del_slave(struct net_device *dev, struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	return br_del_if(br, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static const struct ethtool_ops br_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	.get_drvinfo		 = br_getinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	.get_link		 = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	.get_link_ksettings	 = br_get_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static const struct net_device_ops br_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	.ndo_open		 = br_dev_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	.ndo_stop		 = br_dev_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	.ndo_init		 = br_dev_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	.ndo_uninit		 = br_dev_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	.ndo_start_xmit		 = br_dev_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	.ndo_get_stats64	 = br_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	.ndo_set_mac_address	 = br_set_mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	.ndo_set_rx_mode	 = br_dev_set_multicast_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	.ndo_change_rx_flags	 = br_dev_change_rx_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	.ndo_change_mtu		 = br_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	.ndo_do_ioctl		 = br_dev_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	.ndo_netpoll_setup	 = br_netpoll_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	.ndo_netpoll_cleanup	 = br_netpoll_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	.ndo_poll_controller	 = br_poll_controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	.ndo_add_slave		 = br_add_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	.ndo_del_slave		 = br_del_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	.ndo_fix_features        = br_fix_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	.ndo_fdb_add		 = br_fdb_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	.ndo_fdb_del		 = br_fdb_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	.ndo_fdb_dump		 = br_fdb_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	.ndo_fdb_get		 = br_fdb_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	.ndo_bridge_getlink	 = br_getlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	.ndo_bridge_setlink	 = br_setlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	.ndo_bridge_dellink	 = br_dellink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.ndo_features_check	 = passthru_features_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static struct device_type br_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.name	= "bridge",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) void br_dev_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	eth_hw_addr_random(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	ether_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	dev->netdev_ops = &br_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	dev->ethtool_ops = &br_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	SET_NETDEV_DEVTYPE(dev, &br_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	dev->priv_flags = IFF_EBRIDGE | IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	dev->features = COMMON_FEATURES | NETIF_F_LLTX | NETIF_F_NETNS_LOCAL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	dev->hw_features = COMMON_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			   NETIF_F_HW_VLAN_STAG_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	dev->vlan_features = COMMON_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	br->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	spin_lock_init(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	INIT_LIST_HEAD(&br->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	INIT_HLIST_HEAD(&br->fdb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #if IS_ENABLED(CONFIG_BRIDGE_MRP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	INIT_LIST_HEAD(&br->mrp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	spin_lock_init(&br->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	br->bridge_id.prio[0] = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	br->bridge_id.prio[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	ether_addr_copy(br->group_addr, eth_stp_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	br->stp_enabled = BR_NO_STP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	br->group_fwd_mask = BR_GROUPFWD_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	br->designated_root = br->bridge_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	br->bridge_max_age = br->max_age = 20 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	br->bridge_hello_time = br->hello_time = 2 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	br->bridge_forward_delay = br->forward_delay = 15 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	br->bridge_ageing_time = br->ageing_time = BR_DEFAULT_AGEING_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	dev->max_mtu = ETH_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	br_netfilter_rtable_init(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	br_stp_timer_init(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	br_multicast_init(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	INIT_DELAYED_WORK(&br->gc_work, br_fdb_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }