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)  *	Generic parts
^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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/netdevice.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/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/llc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/llc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <net/stp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/switchdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "br_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Handle changes in state of network devices enslaved to a bridge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Note: don't care about up/down if bridge itself is down, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *     port state is checked when bridge is brought up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct netdev_notifier_pre_changeaddr_info *prechaddr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct net_bridge *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	bool notified = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	bool changed_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (dev->priv_flags & IFF_EBRIDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		err = br_vlan_bridge_event(dev, event, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			return notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		if (event == NETDEV_REGISTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			/* register of bridge completed, add sysfs entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			err = br_sysfs_addbr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 				return notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* not a port of a bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	p = br_port_get_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	br = p->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	case NETDEV_CHANGEMTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		br_mtu_auto_adjust(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	case NETDEV_PRE_CHANGEADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (br->dev->addr_assign_type == NET_ADDR_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		prechaddr_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		err = dev_pre_changeaddr_notify(br->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 						prechaddr_info->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 						extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			return notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	case NETDEV_CHANGEADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		br_fdb_changeaddr(p, dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		changed_addr = br_stp_recalculate_bridge_id(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (changed_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			call_netdevice_notifiers(NETDEV_CHANGEADDR, br->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		br_port_carrier_check(p, &notified);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	case NETDEV_FEAT_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		netdev_update_features(br->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (br->dev->flags & IFF_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			br_stp_disable_port(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			notified = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (netif_running(br->dev) && netif_oper_up(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			br_stp_enable_port(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			notified = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case NETDEV_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		br_del_if(br, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	case NETDEV_CHANGENAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		err = br_sysfs_renameif(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			return notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	case NETDEV_PRE_TYPE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		/* Forbid underlaying device to change its type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return NOTIFY_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	case NETDEV_RESEND_IGMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		/* Propagate to master device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		call_netdevice_notifiers(event, br->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (event != NETDEV_UNREGISTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		br_vlan_port_event(p, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* Events that may cause spanning tree to refresh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (!notified && (event == NETDEV_CHANGEADDR || event == NETDEV_UP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			  event == NETDEV_CHANGE || event == NETDEV_DOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		br_ifinfo_notify(RTM_NEWLINK, NULL, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static struct notifier_block br_device_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	.notifier_call = br_device_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* called with RTNL or RCU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int br_switchdev_event(struct notifier_block *unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			      unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct net_bridge *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct switchdev_notifier_fdb_info *fdb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int err = NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	p = br_port_get_rtnl_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	br = p->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	case SWITCHDEV_FDB_ADD_TO_BRIDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		fdb_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		err = br_fdb_external_learn_add(br, p, fdb_info->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 						fdb_info->vid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			err = notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		br_fdb_offloaded_set(br, p, fdb_info->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				     fdb_info->vid, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	case SWITCHDEV_FDB_DEL_TO_BRIDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		fdb_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		err = br_fdb_external_learn_del(br, p, fdb_info->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 						fdb_info->vid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			err = notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	case SWITCHDEV_FDB_OFFLOADED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		fdb_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		br_fdb_offloaded_set(br, p, fdb_info->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				     fdb_info->vid, fdb_info->offloaded);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case SWITCHDEV_FDB_FLUSH_TO_BRIDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		fdb_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		/* Don't delete static entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		br_fdb_delete_by_port(br, p, fdb_info->vid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		break;
^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) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static struct notifier_block br_switchdev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.notifier_call = br_switchdev_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* br_boolopt_toggle - change user-controlled boolean option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * @br: bridge device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * @opt: id of the option to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * @on: new option value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * @extack: extack for error messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * Changes the value of the respective boolean option to @on taking care of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * any internal option value mapping and configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		      struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	switch (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	case BR_BOOLOPT_NO_LL_LEARN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		br_opt_toggle(br, BROPT_NO_LL_LEARN, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		/* shouldn't be called with unsupported options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	switch (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	case BR_BOOLOPT_NO_LL_LEARN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return br_opt_get(br, BROPT_NO_LL_LEARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		/* shouldn't be called with unsupported options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int br_boolopt_multi_toggle(struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			    struct br_boolopt_multi *bm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			    struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	unsigned long bitmap = bm->optmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	int opt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	for_each_set_bit(opt_id, &bitmap, BR_BOOLOPT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		bool on = !!(bm->optval & BIT(opt_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		err = br_boolopt_toggle(br, opt_id, on, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			br_debug(br, "boolopt multi-toggle error: option: %d current: %d new: %d error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				 opt_id, br_boolopt_get(br, opt_id), on, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) void br_boolopt_multi_get(const struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			  struct br_boolopt_multi *bm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	u32 optval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	int opt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	for (opt_id = 0; opt_id < BR_BOOLOPT_MAX; opt_id++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		optval |= (br_boolopt_get(br, opt_id) << opt_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	bm->optval = optval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	bm->optmask = GENMASK((BR_BOOLOPT_MAX - 1), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* private bridge options, controlled by the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	bool cur = !!br_opt_get(br, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	br_debug(br, "toggle option: %d state: %d -> %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		 opt, cur, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (cur == on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		set_bit(opt, &br->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		clear_bit(opt, &br->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void __net_exit br_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	for_each_netdev(net, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		if (dev->priv_flags & IFF_EBRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			br_dev_delete(dev, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	unregister_netdevice_many(&list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static struct pernet_operations br_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	.exit	= br_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static const struct stp_proto br_stp_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.rcv	= br_stp_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static int __init br_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	BUILD_BUG_ON(sizeof(struct br_input_skb_cb) > sizeof_field(struct sk_buff, cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	err = stp_proto_register(&br_stp_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		pr_err("bridge: can't register sap for STP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	err = br_fdb_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	err = register_pernet_subsys(&br_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		goto err_out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	err = br_nf_core_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		goto err_out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	err = register_netdevice_notifier(&br_device_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		goto err_out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	err = register_switchdev_notifier(&br_switchdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		goto err_out4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	err = br_netlink_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		goto err_out5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	brioctl_set(br_ioctl_deviceless_stub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #if IS_ENABLED(CONFIG_ATM_LANE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	br_fdb_test_addr_hook = br_fdb_test_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) #if IS_MODULE(CONFIG_BRIDGE_NETFILTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	pr_info("bridge: filtering via arp/ip/ip6tables is no longer available "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		"by default. Update your scripts to load br_netfilter if you "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		"need this.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) err_out5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	unregister_switchdev_notifier(&br_switchdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) err_out4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	unregister_netdevice_notifier(&br_device_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) err_out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	br_nf_core_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) err_out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	unregister_pernet_subsys(&br_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) err_out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	br_fdb_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	stp_proto_unregister(&br_stp_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static void __exit br_deinit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	stp_proto_unregister(&br_stp_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	br_netlink_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	unregister_switchdev_notifier(&br_switchdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	unregister_netdevice_notifier(&br_device_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	brioctl_set(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	unregister_pernet_subsys(&br_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	rcu_barrier(); /* Wait for completion of call_rcu()'s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	br_nf_core_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #if IS_ENABLED(CONFIG_ATM_LANE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	br_fdb_test_addr_hook = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	br_fdb_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) module_init(br_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) module_exit(br_deinit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) MODULE_VERSION(BR_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) MODULE_ALIAS_RTNL_LINK("bridge");