18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *	Bridge netlink control interface
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *	Authors:
68c2ecf20Sopenharmony_ci *	Stephen Hemminger		<shemminger@osdl.org>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/slab.h>
118c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
128c2ecf20Sopenharmony_ci#include <net/rtnetlink.h>
138c2ecf20Sopenharmony_ci#include <net/net_namespace.h>
148c2ecf20Sopenharmony_ci#include <net/sock.h>
158c2ecf20Sopenharmony_ci#include <uapi/linux/if_bridge.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "br_private.h"
188c2ecf20Sopenharmony_ci#include "br_private_stp.h"
198c2ecf20Sopenharmony_ci#include "br_private_tunnel.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic int __get_num_vlan_infos(struct net_bridge_vlan_group *vg,
228c2ecf20Sopenharmony_ci				u32 filter_mask)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	struct net_bridge_vlan *v;
258c2ecf20Sopenharmony_ci	u16 vid_range_start = 0, vid_range_end = 0, vid_range_flags = 0;
268c2ecf20Sopenharmony_ci	u16 flags, pvid;
278c2ecf20Sopenharmony_ci	int num_vlans = 0;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	if (!(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
308c2ecf20Sopenharmony_ci		return 0;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	pvid = br_get_pvid(vg);
338c2ecf20Sopenharmony_ci	/* Count number of vlan infos */
348c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(v, &vg->vlan_list, vlist) {
358c2ecf20Sopenharmony_ci		flags = 0;
368c2ecf20Sopenharmony_ci		/* only a context, bridge vlan not activated */
378c2ecf20Sopenharmony_ci		if (!br_vlan_should_use(v))
388c2ecf20Sopenharmony_ci			continue;
398c2ecf20Sopenharmony_ci		if (v->vid == pvid)
408c2ecf20Sopenharmony_ci			flags |= BRIDGE_VLAN_INFO_PVID;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci		if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
438c2ecf20Sopenharmony_ci			flags |= BRIDGE_VLAN_INFO_UNTAGGED;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci		if (vid_range_start == 0) {
468c2ecf20Sopenharmony_ci			goto initvars;
478c2ecf20Sopenharmony_ci		} else if ((v->vid - vid_range_end) == 1 &&
488c2ecf20Sopenharmony_ci			flags == vid_range_flags) {
498c2ecf20Sopenharmony_ci			vid_range_end = v->vid;
508c2ecf20Sopenharmony_ci			continue;
518c2ecf20Sopenharmony_ci		} else {
528c2ecf20Sopenharmony_ci			if ((vid_range_end - vid_range_start) > 0)
538c2ecf20Sopenharmony_ci				num_vlans += 2;
548c2ecf20Sopenharmony_ci			else
558c2ecf20Sopenharmony_ci				num_vlans += 1;
568c2ecf20Sopenharmony_ci		}
578c2ecf20Sopenharmony_ciinitvars:
588c2ecf20Sopenharmony_ci		vid_range_start = v->vid;
598c2ecf20Sopenharmony_ci		vid_range_end = v->vid;
608c2ecf20Sopenharmony_ci		vid_range_flags = flags;
618c2ecf20Sopenharmony_ci	}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	if (vid_range_start != 0) {
648c2ecf20Sopenharmony_ci		if ((vid_range_end - vid_range_start) > 0)
658c2ecf20Sopenharmony_ci			num_vlans += 2;
668c2ecf20Sopenharmony_ci		else
678c2ecf20Sopenharmony_ci			num_vlans += 1;
688c2ecf20Sopenharmony_ci	}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	return num_vlans;
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic int br_get_num_vlan_infos(struct net_bridge_vlan_group *vg,
748c2ecf20Sopenharmony_ci				 u32 filter_mask)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	int num_vlans;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	if (!vg)
798c2ecf20Sopenharmony_ci		return 0;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	if (filter_mask & RTEXT_FILTER_BRVLAN)
828c2ecf20Sopenharmony_ci		return vg->num_vlans;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	rcu_read_lock();
858c2ecf20Sopenharmony_ci	num_vlans = __get_num_vlan_infos(vg, filter_mask);
868c2ecf20Sopenharmony_ci	rcu_read_unlock();
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	return num_vlans;
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistatic size_t br_get_link_af_size_filtered(const struct net_device *dev,
928c2ecf20Sopenharmony_ci					   u32 filter_mask)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	struct net_bridge_vlan_group *vg = NULL;
958c2ecf20Sopenharmony_ci	struct net_bridge_port *p = NULL;
968c2ecf20Sopenharmony_ci	struct net_bridge *br;
978c2ecf20Sopenharmony_ci	int num_vlan_infos;
988c2ecf20Sopenharmony_ci	size_t vinfo_sz = 0;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	rcu_read_lock();
1018c2ecf20Sopenharmony_ci	if (netif_is_bridge_port(dev)) {
1028c2ecf20Sopenharmony_ci		p = br_port_get_check_rcu(dev);
1038c2ecf20Sopenharmony_ci		if (p)
1048c2ecf20Sopenharmony_ci			vg = nbp_vlan_group_rcu(p);
1058c2ecf20Sopenharmony_ci	} else if (dev->priv_flags & IFF_EBRIDGE) {
1068c2ecf20Sopenharmony_ci		br = netdev_priv(dev);
1078c2ecf20Sopenharmony_ci		vg = br_vlan_group_rcu(br);
1088c2ecf20Sopenharmony_ci	}
1098c2ecf20Sopenharmony_ci	num_vlan_infos = br_get_num_vlan_infos(vg, filter_mask);
1108c2ecf20Sopenharmony_ci	rcu_read_unlock();
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	if (p && (p->flags & BR_VLAN_TUNNEL))
1138c2ecf20Sopenharmony_ci		vinfo_sz += br_get_vlan_tunnel_info_size(vg);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	/* Each VLAN is returned in bridge_vlan_info along with flags */
1168c2ecf20Sopenharmony_ci	vinfo_sz += num_vlan_infos * nla_total_size(sizeof(struct bridge_vlan_info));
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	return vinfo_sz;
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline size_t br_port_info_size(void)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	return nla_total_size(1)	/* IFLA_BRPORT_STATE  */
1248c2ecf20Sopenharmony_ci		+ nla_total_size(2)	/* IFLA_BRPORT_PRIORITY */
1258c2ecf20Sopenharmony_ci		+ nla_total_size(4)	/* IFLA_BRPORT_COST */
1268c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_MODE */
1278c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_GUARD */
1288c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_PROTECT */
1298c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_FAST_LEAVE */
1308c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_MCAST_TO_UCAST */
1318c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_LEARNING */
1328c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_UNICAST_FLOOD */
1338c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_MCAST_FLOOD */
1348c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_BCAST_FLOOD */
1358c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_PROXYARP */
1368c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_PROXYARP_WIFI */
1378c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_VLAN_TUNNEL */
1388c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_NEIGH_SUPPRESS */
1398c2ecf20Sopenharmony_ci		+ nla_total_size(1)	/* IFLA_BRPORT_ISOLATED */
1408c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(struct ifla_bridge_id))	/* IFLA_BRPORT_ROOT_ID */
1418c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(struct ifla_bridge_id))	/* IFLA_BRPORT_BRIDGE_ID */
1428c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u16))	/* IFLA_BRPORT_DESIGNATED_PORT */
1438c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u16))	/* IFLA_BRPORT_DESIGNATED_COST */
1448c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u16))	/* IFLA_BRPORT_ID */
1458c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u16))	/* IFLA_BRPORT_NO */
1468c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u8))	/* IFLA_BRPORT_TOPOLOGY_CHANGE_ACK */
1478c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u8))	/* IFLA_BRPORT_CONFIG_PENDING */
1488c2ecf20Sopenharmony_ci		+ nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_MESSAGE_AGE_TIMER */
1498c2ecf20Sopenharmony_ci		+ nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_FORWARD_DELAY_TIMER */
1508c2ecf20Sopenharmony_ci		+ nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_HOLD_TIMER */
1518c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1528c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u8))	/* IFLA_BRPORT_MULTICAST_ROUTER */
1538c2ecf20Sopenharmony_ci#endif
1548c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u16))	/* IFLA_BRPORT_GROUP_FWD_MASK */
1558c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u8))	/* IFLA_BRPORT_MRP_RING_OPEN */
1568c2ecf20Sopenharmony_ci		+ nla_total_size(sizeof(u8))	/* IFLA_BRPORT_MRP_IN_OPEN */
1578c2ecf20Sopenharmony_ci		+ 0;
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic inline size_t br_nlmsg_size(struct net_device *dev, u32 filter_mask)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	return NLMSG_ALIGN(sizeof(struct ifinfomsg))
1638c2ecf20Sopenharmony_ci		+ nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
1648c2ecf20Sopenharmony_ci		+ nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
1658c2ecf20Sopenharmony_ci		+ nla_total_size(4) /* IFLA_MASTER */
1668c2ecf20Sopenharmony_ci		+ nla_total_size(4) /* IFLA_MTU */
1678c2ecf20Sopenharmony_ci		+ nla_total_size(4) /* IFLA_LINK */
1688c2ecf20Sopenharmony_ci		+ nla_total_size(1) /* IFLA_OPERSTATE */
1698c2ecf20Sopenharmony_ci		+ nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */
1708c2ecf20Sopenharmony_ci		+ nla_total_size(br_get_link_af_size_filtered(dev,
1718c2ecf20Sopenharmony_ci				 filter_mask)) /* IFLA_AF_SPEC */
1728c2ecf20Sopenharmony_ci		+ nla_total_size(4); /* IFLA_BRPORT_BACKUP_PORT */
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic int br_port_fill_attrs(struct sk_buff *skb,
1768c2ecf20Sopenharmony_ci			      const struct net_bridge_port *p)
1778c2ecf20Sopenharmony_ci{
1788c2ecf20Sopenharmony_ci	u8 mode = !!(p->flags & BR_HAIRPIN_MODE);
1798c2ecf20Sopenharmony_ci	struct net_bridge_port *backup_p;
1808c2ecf20Sopenharmony_ci	u64 timerval;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	if (nla_put_u8(skb, IFLA_BRPORT_STATE, p->state) ||
1838c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BRPORT_PRIORITY, p->priority) ||
1848c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BRPORT_COST, p->path_cost) ||
1858c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_MODE, mode) ||
1868c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) ||
1878c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_PROTECT,
1888c2ecf20Sopenharmony_ci		       !!(p->flags & BR_ROOT_BLOCK)) ||
1898c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE,
1908c2ecf20Sopenharmony_ci		       !!(p->flags & BR_MULTICAST_FAST_LEAVE)) ||
1918c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_MCAST_TO_UCAST,
1928c2ecf20Sopenharmony_ci		       !!(p->flags & BR_MULTICAST_TO_UNICAST)) ||
1938c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_LEARNING, !!(p->flags & BR_LEARNING)) ||
1948c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_UNICAST_FLOOD,
1958c2ecf20Sopenharmony_ci		       !!(p->flags & BR_FLOOD)) ||
1968c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_MCAST_FLOOD,
1978c2ecf20Sopenharmony_ci		       !!(p->flags & BR_MCAST_FLOOD)) ||
1988c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_BCAST_FLOOD,
1998c2ecf20Sopenharmony_ci		       !!(p->flags & BR_BCAST_FLOOD)) ||
2008c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_PROXYARP, !!(p->flags & BR_PROXYARP)) ||
2018c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_PROXYARP_WIFI,
2028c2ecf20Sopenharmony_ci		       !!(p->flags & BR_PROXYARP_WIFI)) ||
2038c2ecf20Sopenharmony_ci	    nla_put(skb, IFLA_BRPORT_ROOT_ID, sizeof(struct ifla_bridge_id),
2048c2ecf20Sopenharmony_ci		    &p->designated_root) ||
2058c2ecf20Sopenharmony_ci	    nla_put(skb, IFLA_BRPORT_BRIDGE_ID, sizeof(struct ifla_bridge_id),
2068c2ecf20Sopenharmony_ci		    &p->designated_bridge) ||
2078c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BRPORT_DESIGNATED_PORT, p->designated_port) ||
2088c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BRPORT_DESIGNATED_COST, p->designated_cost) ||
2098c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BRPORT_ID, p->port_id) ||
2108c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BRPORT_NO, p->port_no) ||
2118c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_TOPOLOGY_CHANGE_ACK,
2128c2ecf20Sopenharmony_ci		       p->topology_change_ack) ||
2138c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_CONFIG_PENDING, p->config_pending) ||
2148c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_VLAN_TUNNEL, !!(p->flags &
2158c2ecf20Sopenharmony_ci							BR_VLAN_TUNNEL)) ||
2168c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BRPORT_GROUP_FWD_MASK, p->group_fwd_mask) ||
2178c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_NEIGH_SUPPRESS,
2188c2ecf20Sopenharmony_ci		       !!(p->flags & BR_NEIGH_SUPPRESS)) ||
2198c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_MRP_RING_OPEN, !!(p->flags &
2208c2ecf20Sopenharmony_ci							  BR_MRP_LOST_CONT)) ||
2218c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_MRP_IN_OPEN,
2228c2ecf20Sopenharmony_ci		       !!(p->flags & BR_MRP_LOST_IN_CONT)) ||
2238c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BRPORT_ISOLATED, !!(p->flags & BR_ISOLATED)))
2248c2ecf20Sopenharmony_ci		return -EMSGSIZE;
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	timerval = br_timer_value(&p->message_age_timer);
2278c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BRPORT_MESSAGE_AGE_TIMER, timerval,
2288c2ecf20Sopenharmony_ci			      IFLA_BRPORT_PAD))
2298c2ecf20Sopenharmony_ci		return -EMSGSIZE;
2308c2ecf20Sopenharmony_ci	timerval = br_timer_value(&p->forward_delay_timer);
2318c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BRPORT_FORWARD_DELAY_TIMER, timerval,
2328c2ecf20Sopenharmony_ci			      IFLA_BRPORT_PAD))
2338c2ecf20Sopenharmony_ci		return -EMSGSIZE;
2348c2ecf20Sopenharmony_ci	timerval = br_timer_value(&p->hold_timer);
2358c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BRPORT_HOLD_TIMER, timerval,
2368c2ecf20Sopenharmony_ci			      IFLA_BRPORT_PAD))
2378c2ecf20Sopenharmony_ci		return -EMSGSIZE;
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
2408c2ecf20Sopenharmony_ci	if (nla_put_u8(skb, IFLA_BRPORT_MULTICAST_ROUTER,
2418c2ecf20Sopenharmony_ci		       p->multicast_router))
2428c2ecf20Sopenharmony_ci		return -EMSGSIZE;
2438c2ecf20Sopenharmony_ci#endif
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	/* we might be called only with br->lock */
2468c2ecf20Sopenharmony_ci	rcu_read_lock();
2478c2ecf20Sopenharmony_ci	backup_p = rcu_dereference(p->backup_port);
2488c2ecf20Sopenharmony_ci	if (backup_p)
2498c2ecf20Sopenharmony_ci		nla_put_u32(skb, IFLA_BRPORT_BACKUP_PORT,
2508c2ecf20Sopenharmony_ci			    backup_p->dev->ifindex);
2518c2ecf20Sopenharmony_ci	rcu_read_unlock();
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	return 0;
2548c2ecf20Sopenharmony_ci}
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_cistatic int br_fill_ifvlaninfo_range(struct sk_buff *skb, u16 vid_start,
2578c2ecf20Sopenharmony_ci				    u16 vid_end, u16 flags)
2588c2ecf20Sopenharmony_ci{
2598c2ecf20Sopenharmony_ci	struct  bridge_vlan_info vinfo;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	if ((vid_end - vid_start) > 0) {
2628c2ecf20Sopenharmony_ci		/* add range to skb */
2638c2ecf20Sopenharmony_ci		vinfo.vid = vid_start;
2648c2ecf20Sopenharmony_ci		vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_BEGIN;
2658c2ecf20Sopenharmony_ci		if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
2668c2ecf20Sopenharmony_ci			    sizeof(vinfo), &vinfo))
2678c2ecf20Sopenharmony_ci			goto nla_put_failure;
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci		vinfo.vid = vid_end;
2708c2ecf20Sopenharmony_ci		vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_END;
2718c2ecf20Sopenharmony_ci		if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
2728c2ecf20Sopenharmony_ci			    sizeof(vinfo), &vinfo))
2738c2ecf20Sopenharmony_ci			goto nla_put_failure;
2748c2ecf20Sopenharmony_ci	} else {
2758c2ecf20Sopenharmony_ci		vinfo.vid = vid_start;
2768c2ecf20Sopenharmony_ci		vinfo.flags = flags;
2778c2ecf20Sopenharmony_ci		if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
2788c2ecf20Sopenharmony_ci			    sizeof(vinfo), &vinfo))
2798c2ecf20Sopenharmony_ci			goto nla_put_failure;
2808c2ecf20Sopenharmony_ci	}
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	return 0;
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cinla_put_failure:
2858c2ecf20Sopenharmony_ci	return -EMSGSIZE;
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistatic int br_fill_ifvlaninfo_compressed(struct sk_buff *skb,
2898c2ecf20Sopenharmony_ci					 struct net_bridge_vlan_group *vg)
2908c2ecf20Sopenharmony_ci{
2918c2ecf20Sopenharmony_ci	struct net_bridge_vlan *v;
2928c2ecf20Sopenharmony_ci	u16 vid_range_start = 0, vid_range_end = 0, vid_range_flags = 0;
2938c2ecf20Sopenharmony_ci	u16 flags, pvid;
2948c2ecf20Sopenharmony_ci	int err = 0;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	/* Pack IFLA_BRIDGE_VLAN_INFO's for every vlan
2978c2ecf20Sopenharmony_ci	 * and mark vlan info with begin and end flags
2988c2ecf20Sopenharmony_ci	 * if vlaninfo represents a range
2998c2ecf20Sopenharmony_ci	 */
3008c2ecf20Sopenharmony_ci	pvid = br_get_pvid(vg);
3018c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(v, &vg->vlan_list, vlist) {
3028c2ecf20Sopenharmony_ci		flags = 0;
3038c2ecf20Sopenharmony_ci		if (!br_vlan_should_use(v))
3048c2ecf20Sopenharmony_ci			continue;
3058c2ecf20Sopenharmony_ci		if (v->vid == pvid)
3068c2ecf20Sopenharmony_ci			flags |= BRIDGE_VLAN_INFO_PVID;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci		if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
3098c2ecf20Sopenharmony_ci			flags |= BRIDGE_VLAN_INFO_UNTAGGED;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci		if (vid_range_start == 0) {
3128c2ecf20Sopenharmony_ci			goto initvars;
3138c2ecf20Sopenharmony_ci		} else if ((v->vid - vid_range_end) == 1 &&
3148c2ecf20Sopenharmony_ci			flags == vid_range_flags) {
3158c2ecf20Sopenharmony_ci			vid_range_end = v->vid;
3168c2ecf20Sopenharmony_ci			continue;
3178c2ecf20Sopenharmony_ci		} else {
3188c2ecf20Sopenharmony_ci			err = br_fill_ifvlaninfo_range(skb, vid_range_start,
3198c2ecf20Sopenharmony_ci						       vid_range_end,
3208c2ecf20Sopenharmony_ci						       vid_range_flags);
3218c2ecf20Sopenharmony_ci			if (err)
3228c2ecf20Sopenharmony_ci				return err;
3238c2ecf20Sopenharmony_ci		}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ciinitvars:
3268c2ecf20Sopenharmony_ci		vid_range_start = v->vid;
3278c2ecf20Sopenharmony_ci		vid_range_end = v->vid;
3288c2ecf20Sopenharmony_ci		vid_range_flags = flags;
3298c2ecf20Sopenharmony_ci	}
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	if (vid_range_start != 0) {
3328c2ecf20Sopenharmony_ci		/* Call it once more to send any left over vlans */
3338c2ecf20Sopenharmony_ci		err = br_fill_ifvlaninfo_range(skb, vid_range_start,
3348c2ecf20Sopenharmony_ci					       vid_range_end,
3358c2ecf20Sopenharmony_ci					       vid_range_flags);
3368c2ecf20Sopenharmony_ci		if (err)
3378c2ecf20Sopenharmony_ci			return err;
3388c2ecf20Sopenharmony_ci	}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	return 0;
3418c2ecf20Sopenharmony_ci}
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic int br_fill_ifvlaninfo(struct sk_buff *skb,
3448c2ecf20Sopenharmony_ci			      struct net_bridge_vlan_group *vg)
3458c2ecf20Sopenharmony_ci{
3468c2ecf20Sopenharmony_ci	struct bridge_vlan_info vinfo;
3478c2ecf20Sopenharmony_ci	struct net_bridge_vlan *v;
3488c2ecf20Sopenharmony_ci	u16 pvid;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	pvid = br_get_pvid(vg);
3518c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(v, &vg->vlan_list, vlist) {
3528c2ecf20Sopenharmony_ci		if (!br_vlan_should_use(v))
3538c2ecf20Sopenharmony_ci			continue;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci		vinfo.vid = v->vid;
3568c2ecf20Sopenharmony_ci		vinfo.flags = 0;
3578c2ecf20Sopenharmony_ci		if (v->vid == pvid)
3588c2ecf20Sopenharmony_ci			vinfo.flags |= BRIDGE_VLAN_INFO_PVID;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci		if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
3618c2ecf20Sopenharmony_ci			vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci		if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
3648c2ecf20Sopenharmony_ci			    sizeof(vinfo), &vinfo))
3658c2ecf20Sopenharmony_ci			goto nla_put_failure;
3668c2ecf20Sopenharmony_ci	}
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	return 0;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cinla_put_failure:
3718c2ecf20Sopenharmony_ci	return -EMSGSIZE;
3728c2ecf20Sopenharmony_ci}
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci/*
3758c2ecf20Sopenharmony_ci * Create one netlink message for one interface
3768c2ecf20Sopenharmony_ci * Contains port and master info as well as carrier and bridge state.
3778c2ecf20Sopenharmony_ci */
3788c2ecf20Sopenharmony_cistatic int br_fill_ifinfo(struct sk_buff *skb,
3798c2ecf20Sopenharmony_ci			  const struct net_bridge_port *port,
3808c2ecf20Sopenharmony_ci			  u32 pid, u32 seq, int event, unsigned int flags,
3818c2ecf20Sopenharmony_ci			  u32 filter_mask, const struct net_device *dev)
3828c2ecf20Sopenharmony_ci{
3838c2ecf20Sopenharmony_ci	u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
3848c2ecf20Sopenharmony_ci	struct nlattr *af = NULL;
3858c2ecf20Sopenharmony_ci	struct net_bridge *br;
3868c2ecf20Sopenharmony_ci	struct ifinfomsg *hdr;
3878c2ecf20Sopenharmony_ci	struct nlmsghdr *nlh;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	if (port)
3908c2ecf20Sopenharmony_ci		br = port->br;
3918c2ecf20Sopenharmony_ci	else
3928c2ecf20Sopenharmony_ci		br = netdev_priv(dev);
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	br_debug(br, "br_fill_info event %d port %s master %s\n",
3958c2ecf20Sopenharmony_ci		     event, dev->name, br->dev->name);
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags);
3988c2ecf20Sopenharmony_ci	if (nlh == NULL)
3998c2ecf20Sopenharmony_ci		return -EMSGSIZE;
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	hdr = nlmsg_data(nlh);
4028c2ecf20Sopenharmony_ci	hdr->ifi_family = AF_BRIDGE;
4038c2ecf20Sopenharmony_ci	hdr->__ifi_pad = 0;
4048c2ecf20Sopenharmony_ci	hdr->ifi_type = dev->type;
4058c2ecf20Sopenharmony_ci	hdr->ifi_index = dev->ifindex;
4068c2ecf20Sopenharmony_ci	hdr->ifi_flags = dev_get_flags(dev);
4078c2ecf20Sopenharmony_ci	hdr->ifi_change = 0;
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
4108c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_MASTER, br->dev->ifindex) ||
4118c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
4128c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_OPERSTATE, operstate) ||
4138c2ecf20Sopenharmony_ci	    (dev->addr_len &&
4148c2ecf20Sopenharmony_ci	     nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
4158c2ecf20Sopenharmony_ci	    (dev->ifindex != dev_get_iflink(dev) &&
4168c2ecf20Sopenharmony_ci	     nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
4178c2ecf20Sopenharmony_ci		goto nla_put_failure;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	if (event == RTM_NEWLINK && port) {
4208c2ecf20Sopenharmony_ci		struct nlattr *nest;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci		nest = nla_nest_start(skb, IFLA_PROTINFO);
4238c2ecf20Sopenharmony_ci		if (nest == NULL || br_port_fill_attrs(skb, port) < 0)
4248c2ecf20Sopenharmony_ci			goto nla_put_failure;
4258c2ecf20Sopenharmony_ci		nla_nest_end(skb, nest);
4268c2ecf20Sopenharmony_ci	}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	if (filter_mask & (RTEXT_FILTER_BRVLAN |
4298c2ecf20Sopenharmony_ci			   RTEXT_FILTER_BRVLAN_COMPRESSED |
4308c2ecf20Sopenharmony_ci			   RTEXT_FILTER_MRP)) {
4318c2ecf20Sopenharmony_ci		af = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
4328c2ecf20Sopenharmony_ci		if (!af)
4338c2ecf20Sopenharmony_ci			goto nla_put_failure;
4348c2ecf20Sopenharmony_ci	}
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	/* Check if  the VID information is requested */
4378c2ecf20Sopenharmony_ci	if ((filter_mask & RTEXT_FILTER_BRVLAN) ||
4388c2ecf20Sopenharmony_ci	    (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) {
4398c2ecf20Sopenharmony_ci		struct net_bridge_vlan_group *vg;
4408c2ecf20Sopenharmony_ci		int err;
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci		/* RCU needed because of the VLAN locking rules (rcu || rtnl) */
4438c2ecf20Sopenharmony_ci		rcu_read_lock();
4448c2ecf20Sopenharmony_ci		if (port)
4458c2ecf20Sopenharmony_ci			vg = nbp_vlan_group_rcu(port);
4468c2ecf20Sopenharmony_ci		else
4478c2ecf20Sopenharmony_ci			vg = br_vlan_group_rcu(br);
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci		if (!vg || !vg->num_vlans) {
4508c2ecf20Sopenharmony_ci			rcu_read_unlock();
4518c2ecf20Sopenharmony_ci			goto done;
4528c2ecf20Sopenharmony_ci		}
4538c2ecf20Sopenharmony_ci		if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)
4548c2ecf20Sopenharmony_ci			err = br_fill_ifvlaninfo_compressed(skb, vg);
4558c2ecf20Sopenharmony_ci		else
4568c2ecf20Sopenharmony_ci			err = br_fill_ifvlaninfo(skb, vg);
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci		if (port && (port->flags & BR_VLAN_TUNNEL))
4598c2ecf20Sopenharmony_ci			err = br_fill_vlan_tunnel_info(skb, vg);
4608c2ecf20Sopenharmony_ci		rcu_read_unlock();
4618c2ecf20Sopenharmony_ci		if (err)
4628c2ecf20Sopenharmony_ci			goto nla_put_failure;
4638c2ecf20Sopenharmony_ci	}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	if (filter_mask & RTEXT_FILTER_MRP) {
4668c2ecf20Sopenharmony_ci		int err;
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci		if (!br_mrp_enabled(br) || port)
4698c2ecf20Sopenharmony_ci			goto done;
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci		rcu_read_lock();
4728c2ecf20Sopenharmony_ci		err = br_mrp_fill_info(skb, br);
4738c2ecf20Sopenharmony_ci		rcu_read_unlock();
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci		if (err)
4768c2ecf20Sopenharmony_ci			goto nla_put_failure;
4778c2ecf20Sopenharmony_ci	}
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_cidone:
4808c2ecf20Sopenharmony_ci	if (af)
4818c2ecf20Sopenharmony_ci		nla_nest_end(skb, af);
4828c2ecf20Sopenharmony_ci	nlmsg_end(skb, nlh);
4838c2ecf20Sopenharmony_ci	return 0;
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_cinla_put_failure:
4868c2ecf20Sopenharmony_ci	nlmsg_cancel(skb, nlh);
4878c2ecf20Sopenharmony_ci	return -EMSGSIZE;
4888c2ecf20Sopenharmony_ci}
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci/* Notify listeners of a change in bridge or port information */
4918c2ecf20Sopenharmony_civoid br_ifinfo_notify(int event, const struct net_bridge *br,
4928c2ecf20Sopenharmony_ci		      const struct net_bridge_port *port)
4938c2ecf20Sopenharmony_ci{
4948c2ecf20Sopenharmony_ci	u32 filter = RTEXT_FILTER_BRVLAN_COMPRESSED;
4958c2ecf20Sopenharmony_ci	struct net_device *dev;
4968c2ecf20Sopenharmony_ci	struct sk_buff *skb;
4978c2ecf20Sopenharmony_ci	int err = -ENOBUFS;
4988c2ecf20Sopenharmony_ci	struct net *net;
4998c2ecf20Sopenharmony_ci	u16 port_no = 0;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	if (WARN_ON(!port && !br))
5028c2ecf20Sopenharmony_ci		return;
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci	if (port) {
5058c2ecf20Sopenharmony_ci		dev = port->dev;
5068c2ecf20Sopenharmony_ci		br = port->br;
5078c2ecf20Sopenharmony_ci		port_no = port->port_no;
5088c2ecf20Sopenharmony_ci	} else {
5098c2ecf20Sopenharmony_ci		dev = br->dev;
5108c2ecf20Sopenharmony_ci	}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	net = dev_net(dev);
5138c2ecf20Sopenharmony_ci	br_debug(br, "port %u(%s) event %d\n", port_no, dev->name, event);
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	skb = nlmsg_new(br_nlmsg_size(dev, filter), GFP_ATOMIC);
5168c2ecf20Sopenharmony_ci	if (skb == NULL)
5178c2ecf20Sopenharmony_ci		goto errout;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	err = br_fill_ifinfo(skb, port, 0, 0, event, 0, filter, dev);
5208c2ecf20Sopenharmony_ci	if (err < 0) {
5218c2ecf20Sopenharmony_ci		/* -EMSGSIZE implies BUG in br_nlmsg_size() */
5228c2ecf20Sopenharmony_ci		WARN_ON(err == -EMSGSIZE);
5238c2ecf20Sopenharmony_ci		kfree_skb(skb);
5248c2ecf20Sopenharmony_ci		goto errout;
5258c2ecf20Sopenharmony_ci	}
5268c2ecf20Sopenharmony_ci	rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
5278c2ecf20Sopenharmony_ci	return;
5288c2ecf20Sopenharmony_cierrout:
5298c2ecf20Sopenharmony_ci	rtnl_set_sk_err(net, RTNLGRP_LINK, err);
5308c2ecf20Sopenharmony_ci}
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci/*
5338c2ecf20Sopenharmony_ci * Dump information about all ports, in response to GETLINK
5348c2ecf20Sopenharmony_ci */
5358c2ecf20Sopenharmony_ciint br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
5368c2ecf20Sopenharmony_ci	       struct net_device *dev, u32 filter_mask, int nlflags)
5378c2ecf20Sopenharmony_ci{
5388c2ecf20Sopenharmony_ci	struct net_bridge_port *port = br_port_get_rtnl(dev);
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) &&
5418c2ecf20Sopenharmony_ci	    !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) &&
5428c2ecf20Sopenharmony_ci	    !(filter_mask & RTEXT_FILTER_MRP))
5438c2ecf20Sopenharmony_ci		return 0;
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_ci	return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
5468c2ecf20Sopenharmony_ci			      filter_mask, dev);
5478c2ecf20Sopenharmony_ci}
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic int br_vlan_info(struct net_bridge *br, struct net_bridge_port *p,
5508c2ecf20Sopenharmony_ci			int cmd, struct bridge_vlan_info *vinfo, bool *changed,
5518c2ecf20Sopenharmony_ci			struct netlink_ext_ack *extack)
5528c2ecf20Sopenharmony_ci{
5538c2ecf20Sopenharmony_ci	bool curr_change;
5548c2ecf20Sopenharmony_ci	int err = 0;
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	switch (cmd) {
5578c2ecf20Sopenharmony_ci	case RTM_SETLINK:
5588c2ecf20Sopenharmony_ci		if (p) {
5598c2ecf20Sopenharmony_ci			/* if the MASTER flag is set this will act on the global
5608c2ecf20Sopenharmony_ci			 * per-VLAN entry as well
5618c2ecf20Sopenharmony_ci			 */
5628c2ecf20Sopenharmony_ci			err = nbp_vlan_add(p, vinfo->vid, vinfo->flags,
5638c2ecf20Sopenharmony_ci					   &curr_change, extack);
5648c2ecf20Sopenharmony_ci		} else {
5658c2ecf20Sopenharmony_ci			vinfo->flags |= BRIDGE_VLAN_INFO_BRENTRY;
5668c2ecf20Sopenharmony_ci			err = br_vlan_add(br, vinfo->vid, vinfo->flags,
5678c2ecf20Sopenharmony_ci					  &curr_change, extack);
5688c2ecf20Sopenharmony_ci		}
5698c2ecf20Sopenharmony_ci		if (curr_change)
5708c2ecf20Sopenharmony_ci			*changed = true;
5718c2ecf20Sopenharmony_ci		break;
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci	case RTM_DELLINK:
5748c2ecf20Sopenharmony_ci		if (p) {
5758c2ecf20Sopenharmony_ci			if (!nbp_vlan_delete(p, vinfo->vid))
5768c2ecf20Sopenharmony_ci				*changed = true;
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ci			if ((vinfo->flags & BRIDGE_VLAN_INFO_MASTER) &&
5798c2ecf20Sopenharmony_ci			    !br_vlan_delete(p->br, vinfo->vid))
5808c2ecf20Sopenharmony_ci				*changed = true;
5818c2ecf20Sopenharmony_ci		} else if (!br_vlan_delete(br, vinfo->vid)) {
5828c2ecf20Sopenharmony_ci			*changed = true;
5838c2ecf20Sopenharmony_ci		}
5848c2ecf20Sopenharmony_ci		break;
5858c2ecf20Sopenharmony_ci	}
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	return err;
5888c2ecf20Sopenharmony_ci}
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ciint br_process_vlan_info(struct net_bridge *br,
5918c2ecf20Sopenharmony_ci			 struct net_bridge_port *p, int cmd,
5928c2ecf20Sopenharmony_ci			 struct bridge_vlan_info *vinfo_curr,
5938c2ecf20Sopenharmony_ci			 struct bridge_vlan_info **vinfo_last,
5948c2ecf20Sopenharmony_ci			 bool *changed,
5958c2ecf20Sopenharmony_ci			 struct netlink_ext_ack *extack)
5968c2ecf20Sopenharmony_ci{
5978c2ecf20Sopenharmony_ci	int err, rtm_cmd;
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	if (!br_vlan_valid_id(vinfo_curr->vid, extack))
6008c2ecf20Sopenharmony_ci		return -EINVAL;
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci	/* needed for vlan-only NEWVLAN/DELVLAN notifications */
6038c2ecf20Sopenharmony_ci	rtm_cmd = br_afspec_cmd_to_rtm(cmd);
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci	if (vinfo_curr->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
6068c2ecf20Sopenharmony_ci		if (!br_vlan_valid_range(vinfo_curr, *vinfo_last, extack))
6078c2ecf20Sopenharmony_ci			return -EINVAL;
6088c2ecf20Sopenharmony_ci		*vinfo_last = vinfo_curr;
6098c2ecf20Sopenharmony_ci		return 0;
6108c2ecf20Sopenharmony_ci	}
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	if (*vinfo_last) {
6138c2ecf20Sopenharmony_ci		struct bridge_vlan_info tmp_vinfo;
6148c2ecf20Sopenharmony_ci		int v, v_change_start = 0;
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_ci		if (!br_vlan_valid_range(vinfo_curr, *vinfo_last, extack))
6178c2ecf20Sopenharmony_ci			return -EINVAL;
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci		memcpy(&tmp_vinfo, *vinfo_last,
6208c2ecf20Sopenharmony_ci		       sizeof(struct bridge_vlan_info));
6218c2ecf20Sopenharmony_ci		for (v = (*vinfo_last)->vid; v <= vinfo_curr->vid; v++) {
6228c2ecf20Sopenharmony_ci			bool curr_change = false;
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci			tmp_vinfo.vid = v;
6258c2ecf20Sopenharmony_ci			err = br_vlan_info(br, p, cmd, &tmp_vinfo, &curr_change,
6268c2ecf20Sopenharmony_ci					   extack);
6278c2ecf20Sopenharmony_ci			if (err)
6288c2ecf20Sopenharmony_ci				break;
6298c2ecf20Sopenharmony_ci			if (curr_change) {
6308c2ecf20Sopenharmony_ci				*changed = curr_change;
6318c2ecf20Sopenharmony_ci				if (!v_change_start)
6328c2ecf20Sopenharmony_ci					v_change_start = v;
6338c2ecf20Sopenharmony_ci			} else {
6348c2ecf20Sopenharmony_ci				/* nothing to notify yet */
6358c2ecf20Sopenharmony_ci				if (!v_change_start)
6368c2ecf20Sopenharmony_ci					continue;
6378c2ecf20Sopenharmony_ci				br_vlan_notify(br, p, v_change_start,
6388c2ecf20Sopenharmony_ci					       v - 1, rtm_cmd);
6398c2ecf20Sopenharmony_ci				v_change_start = 0;
6408c2ecf20Sopenharmony_ci			}
6418c2ecf20Sopenharmony_ci			cond_resched();
6428c2ecf20Sopenharmony_ci		}
6438c2ecf20Sopenharmony_ci		/* v_change_start is set only if the last/whole range changed */
6448c2ecf20Sopenharmony_ci		if (v_change_start)
6458c2ecf20Sopenharmony_ci			br_vlan_notify(br, p, v_change_start,
6468c2ecf20Sopenharmony_ci				       v - 1, rtm_cmd);
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci		*vinfo_last = NULL;
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci		return err;
6518c2ecf20Sopenharmony_ci	}
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	err = br_vlan_info(br, p, cmd, vinfo_curr, changed, extack);
6548c2ecf20Sopenharmony_ci	if (*changed)
6558c2ecf20Sopenharmony_ci		br_vlan_notify(br, p, vinfo_curr->vid, 0, rtm_cmd);
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci	return err;
6588c2ecf20Sopenharmony_ci}
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_cistatic int br_afspec(struct net_bridge *br,
6618c2ecf20Sopenharmony_ci		     struct net_bridge_port *p,
6628c2ecf20Sopenharmony_ci		     struct nlattr *af_spec,
6638c2ecf20Sopenharmony_ci		     int cmd, bool *changed,
6648c2ecf20Sopenharmony_ci		     struct netlink_ext_ack *extack)
6658c2ecf20Sopenharmony_ci{
6668c2ecf20Sopenharmony_ci	struct bridge_vlan_info *vinfo_curr = NULL;
6678c2ecf20Sopenharmony_ci	struct bridge_vlan_info *vinfo_last = NULL;
6688c2ecf20Sopenharmony_ci	struct nlattr *attr;
6698c2ecf20Sopenharmony_ci	struct vtunnel_info tinfo_last = {};
6708c2ecf20Sopenharmony_ci	struct vtunnel_info tinfo_curr = {};
6718c2ecf20Sopenharmony_ci	int err = 0, rem;
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	nla_for_each_nested(attr, af_spec, rem) {
6748c2ecf20Sopenharmony_ci		err = 0;
6758c2ecf20Sopenharmony_ci		switch (nla_type(attr)) {
6768c2ecf20Sopenharmony_ci		case IFLA_BRIDGE_VLAN_TUNNEL_INFO:
6778c2ecf20Sopenharmony_ci			if (!p || !(p->flags & BR_VLAN_TUNNEL))
6788c2ecf20Sopenharmony_ci				return -EINVAL;
6798c2ecf20Sopenharmony_ci			err = br_parse_vlan_tunnel_info(attr, &tinfo_curr);
6808c2ecf20Sopenharmony_ci			if (err)
6818c2ecf20Sopenharmony_ci				return err;
6828c2ecf20Sopenharmony_ci			err = br_process_vlan_tunnel_info(br, p, cmd,
6838c2ecf20Sopenharmony_ci							  &tinfo_curr,
6848c2ecf20Sopenharmony_ci							  &tinfo_last,
6858c2ecf20Sopenharmony_ci							  changed);
6868c2ecf20Sopenharmony_ci			if (err)
6878c2ecf20Sopenharmony_ci				return err;
6888c2ecf20Sopenharmony_ci			break;
6898c2ecf20Sopenharmony_ci		case IFLA_BRIDGE_VLAN_INFO:
6908c2ecf20Sopenharmony_ci			if (nla_len(attr) != sizeof(struct bridge_vlan_info))
6918c2ecf20Sopenharmony_ci				return -EINVAL;
6928c2ecf20Sopenharmony_ci			vinfo_curr = nla_data(attr);
6938c2ecf20Sopenharmony_ci			err = br_process_vlan_info(br, p, cmd, vinfo_curr,
6948c2ecf20Sopenharmony_ci						   &vinfo_last, changed,
6958c2ecf20Sopenharmony_ci						   extack);
6968c2ecf20Sopenharmony_ci			if (err)
6978c2ecf20Sopenharmony_ci				return err;
6988c2ecf20Sopenharmony_ci			break;
6998c2ecf20Sopenharmony_ci		case IFLA_BRIDGE_MRP:
7008c2ecf20Sopenharmony_ci			err = br_mrp_parse(br, p, attr, cmd, extack);
7018c2ecf20Sopenharmony_ci			if (err)
7028c2ecf20Sopenharmony_ci				return err;
7038c2ecf20Sopenharmony_ci			break;
7048c2ecf20Sopenharmony_ci		}
7058c2ecf20Sopenharmony_ci	}
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci	return err;
7088c2ecf20Sopenharmony_ci}
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_cistatic const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = {
7118c2ecf20Sopenharmony_ci	[IFLA_BRPORT_STATE]	= { .type = NLA_U8 },
7128c2ecf20Sopenharmony_ci	[IFLA_BRPORT_COST]	= { .type = NLA_U32 },
7138c2ecf20Sopenharmony_ci	[IFLA_BRPORT_PRIORITY]	= { .type = NLA_U16 },
7148c2ecf20Sopenharmony_ci	[IFLA_BRPORT_MODE]	= { .type = NLA_U8 },
7158c2ecf20Sopenharmony_ci	[IFLA_BRPORT_GUARD]	= { .type = NLA_U8 },
7168c2ecf20Sopenharmony_ci	[IFLA_BRPORT_PROTECT]	= { .type = NLA_U8 },
7178c2ecf20Sopenharmony_ci	[IFLA_BRPORT_FAST_LEAVE]= { .type = NLA_U8 },
7188c2ecf20Sopenharmony_ci	[IFLA_BRPORT_LEARNING]	= { .type = NLA_U8 },
7198c2ecf20Sopenharmony_ci	[IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 },
7208c2ecf20Sopenharmony_ci	[IFLA_BRPORT_PROXYARP]	= { .type = NLA_U8 },
7218c2ecf20Sopenharmony_ci	[IFLA_BRPORT_PROXYARP_WIFI] = { .type = NLA_U8 },
7228c2ecf20Sopenharmony_ci	[IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NLA_U8 },
7238c2ecf20Sopenharmony_ci	[IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NLA_U8 },
7248c2ecf20Sopenharmony_ci	[IFLA_BRPORT_MCAST_FLOOD] = { .type = NLA_U8 },
7258c2ecf20Sopenharmony_ci	[IFLA_BRPORT_BCAST_FLOOD] = { .type = NLA_U8 },
7268c2ecf20Sopenharmony_ci	[IFLA_BRPORT_VLAN_TUNNEL] = { .type = NLA_U8 },
7278c2ecf20Sopenharmony_ci	[IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NLA_U16 },
7288c2ecf20Sopenharmony_ci	[IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NLA_U8 },
7298c2ecf20Sopenharmony_ci	[IFLA_BRPORT_ISOLATED]	= { .type = NLA_U8 },
7308c2ecf20Sopenharmony_ci	[IFLA_BRPORT_BACKUP_PORT] = { .type = NLA_U32 },
7318c2ecf20Sopenharmony_ci};
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci/* Change the state of the port and notify spanning tree */
7348c2ecf20Sopenharmony_cistatic int br_set_port_state(struct net_bridge_port *p, u8 state)
7358c2ecf20Sopenharmony_ci{
7368c2ecf20Sopenharmony_ci	if (state > BR_STATE_BLOCKING)
7378c2ecf20Sopenharmony_ci		return -EINVAL;
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	/* if kernel STP is running, don't allow changes */
7408c2ecf20Sopenharmony_ci	if (p->br->stp_enabled == BR_KERNEL_STP)
7418c2ecf20Sopenharmony_ci		return -EBUSY;
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	/* if device is not up, change is not allowed
7448c2ecf20Sopenharmony_ci	 * if link is not present, only allowable state is disabled
7458c2ecf20Sopenharmony_ci	 */
7468c2ecf20Sopenharmony_ci	if (!netif_running(p->dev) ||
7478c2ecf20Sopenharmony_ci	    (!netif_oper_up(p->dev) && state != BR_STATE_DISABLED))
7488c2ecf20Sopenharmony_ci		return -ENETDOWN;
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	br_set_state(p, state);
7518c2ecf20Sopenharmony_ci	br_port_state_selection(p->br);
7528c2ecf20Sopenharmony_ci	return 0;
7538c2ecf20Sopenharmony_ci}
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci/* Set/clear or port flags based on attribute */
7568c2ecf20Sopenharmony_cistatic int br_set_port_flag(struct net_bridge_port *p, struct nlattr *tb[],
7578c2ecf20Sopenharmony_ci			    int attrtype, unsigned long mask)
7588c2ecf20Sopenharmony_ci{
7598c2ecf20Sopenharmony_ci	unsigned long flags;
7608c2ecf20Sopenharmony_ci	int err;
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	if (!tb[attrtype])
7638c2ecf20Sopenharmony_ci		return 0;
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci	if (nla_get_u8(tb[attrtype]))
7668c2ecf20Sopenharmony_ci		flags = p->flags | mask;
7678c2ecf20Sopenharmony_ci	else
7688c2ecf20Sopenharmony_ci		flags = p->flags & ~mask;
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	err = br_switchdev_set_port_flag(p, flags, mask);
7718c2ecf20Sopenharmony_ci	if (err)
7728c2ecf20Sopenharmony_ci		return err;
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	p->flags = flags;
7758c2ecf20Sopenharmony_ci	return 0;
7768c2ecf20Sopenharmony_ci}
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci/* Process bridge protocol info on port */
7798c2ecf20Sopenharmony_cistatic int br_setport(struct net_bridge_port *p, struct nlattr *tb[])
7808c2ecf20Sopenharmony_ci{
7818c2ecf20Sopenharmony_ci	unsigned long old_flags = p->flags;
7828c2ecf20Sopenharmony_ci	bool br_vlan_tunnel_old = false;
7838c2ecf20Sopenharmony_ci	int err;
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_MODE, BR_HAIRPIN_MODE);
7868c2ecf20Sopenharmony_ci	if (err)
7878c2ecf20Sopenharmony_ci		return err;
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_GUARD, BR_BPDU_GUARD);
7908c2ecf20Sopenharmony_ci	if (err)
7918c2ecf20Sopenharmony_ci		return err;
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_FAST_LEAVE, BR_MULTICAST_FAST_LEAVE);
7948c2ecf20Sopenharmony_ci	if (err)
7958c2ecf20Sopenharmony_ci		return err;
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_PROTECT, BR_ROOT_BLOCK);
7988c2ecf20Sopenharmony_ci	if (err)
7998c2ecf20Sopenharmony_ci		return err;
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_LEARNING, BR_LEARNING);
8028c2ecf20Sopenharmony_ci	if (err)
8038c2ecf20Sopenharmony_ci		return err;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD);
8068c2ecf20Sopenharmony_ci	if (err)
8078c2ecf20Sopenharmony_ci		return err;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_MCAST_FLOOD, BR_MCAST_FLOOD);
8108c2ecf20Sopenharmony_ci	if (err)
8118c2ecf20Sopenharmony_ci		return err;
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_MCAST_TO_UCAST, BR_MULTICAST_TO_UNICAST);
8148c2ecf20Sopenharmony_ci	if (err)
8158c2ecf20Sopenharmony_ci		return err;
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_BCAST_FLOOD, BR_BCAST_FLOOD);
8188c2ecf20Sopenharmony_ci	if (err)
8198c2ecf20Sopenharmony_ci		return err;
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP, BR_PROXYARP);
8228c2ecf20Sopenharmony_ci	if (err)
8238c2ecf20Sopenharmony_ci		return err;
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP_WIFI, BR_PROXYARP_WIFI);
8268c2ecf20Sopenharmony_ci	if (err)
8278c2ecf20Sopenharmony_ci		return err;
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	br_vlan_tunnel_old = (p->flags & BR_VLAN_TUNNEL) ? true : false;
8308c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_VLAN_TUNNEL, BR_VLAN_TUNNEL);
8318c2ecf20Sopenharmony_ci	if (err)
8328c2ecf20Sopenharmony_ci		return err;
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	if (br_vlan_tunnel_old && !(p->flags & BR_VLAN_TUNNEL))
8358c2ecf20Sopenharmony_ci		nbp_vlan_tunnel_info_flush(p);
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_COST]) {
8388c2ecf20Sopenharmony_ci		err = br_stp_set_path_cost(p, nla_get_u32(tb[IFLA_BRPORT_COST]));
8398c2ecf20Sopenharmony_ci		if (err)
8408c2ecf20Sopenharmony_ci			return err;
8418c2ecf20Sopenharmony_ci	}
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_PRIORITY]) {
8448c2ecf20Sopenharmony_ci		err = br_stp_set_port_priority(p, nla_get_u16(tb[IFLA_BRPORT_PRIORITY]));
8458c2ecf20Sopenharmony_ci		if (err)
8468c2ecf20Sopenharmony_ci			return err;
8478c2ecf20Sopenharmony_ci	}
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_STATE]) {
8508c2ecf20Sopenharmony_ci		err = br_set_port_state(p, nla_get_u8(tb[IFLA_BRPORT_STATE]));
8518c2ecf20Sopenharmony_ci		if (err)
8528c2ecf20Sopenharmony_ci			return err;
8538c2ecf20Sopenharmony_ci	}
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_FLUSH])
8568c2ecf20Sopenharmony_ci		br_fdb_delete_by_port(p->br, p, 0, 0);
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
8598c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_MULTICAST_ROUTER]) {
8608c2ecf20Sopenharmony_ci		u8 mcast_router = nla_get_u8(tb[IFLA_BRPORT_MULTICAST_ROUTER]);
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci		err = br_multicast_set_port_router(p, mcast_router);
8638c2ecf20Sopenharmony_ci		if (err)
8648c2ecf20Sopenharmony_ci			return err;
8658c2ecf20Sopenharmony_ci	}
8668c2ecf20Sopenharmony_ci#endif
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) {
8698c2ecf20Sopenharmony_ci		u16 fwd_mask = nla_get_u16(tb[IFLA_BRPORT_GROUP_FWD_MASK]);
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci		if (fwd_mask & BR_GROUPFWD_MACPAUSE)
8728c2ecf20Sopenharmony_ci			return -EINVAL;
8738c2ecf20Sopenharmony_ci		p->group_fwd_mask = fwd_mask;
8748c2ecf20Sopenharmony_ci	}
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_NEIGH_SUPPRESS,
8778c2ecf20Sopenharmony_ci			       BR_NEIGH_SUPPRESS);
8788c2ecf20Sopenharmony_ci	if (err)
8798c2ecf20Sopenharmony_ci		return err;
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	err = br_set_port_flag(p, tb, IFLA_BRPORT_ISOLATED, BR_ISOLATED);
8828c2ecf20Sopenharmony_ci	if (err)
8838c2ecf20Sopenharmony_ci		return err;
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci	if (tb[IFLA_BRPORT_BACKUP_PORT]) {
8868c2ecf20Sopenharmony_ci		struct net_device *backup_dev = NULL;
8878c2ecf20Sopenharmony_ci		u32 backup_ifindex;
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci		backup_ifindex = nla_get_u32(tb[IFLA_BRPORT_BACKUP_PORT]);
8908c2ecf20Sopenharmony_ci		if (backup_ifindex) {
8918c2ecf20Sopenharmony_ci			backup_dev = __dev_get_by_index(dev_net(p->dev),
8928c2ecf20Sopenharmony_ci							backup_ifindex);
8938c2ecf20Sopenharmony_ci			if (!backup_dev)
8948c2ecf20Sopenharmony_ci				return -ENOENT;
8958c2ecf20Sopenharmony_ci		}
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci		err = nbp_backup_change(p, backup_dev);
8988c2ecf20Sopenharmony_ci		if (err)
8998c2ecf20Sopenharmony_ci			return err;
9008c2ecf20Sopenharmony_ci	}
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci	br_port_flags_change(p, old_flags ^ p->flags);
9038c2ecf20Sopenharmony_ci	return 0;
9048c2ecf20Sopenharmony_ci}
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci/* Change state and parameters on port. */
9078c2ecf20Sopenharmony_ciint br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags,
9088c2ecf20Sopenharmony_ci	       struct netlink_ext_ack *extack)
9098c2ecf20Sopenharmony_ci{
9108c2ecf20Sopenharmony_ci	struct net_bridge *br = (struct net_bridge *)netdev_priv(dev);
9118c2ecf20Sopenharmony_ci	struct nlattr *tb[IFLA_BRPORT_MAX + 1];
9128c2ecf20Sopenharmony_ci	struct net_bridge_port *p;
9138c2ecf20Sopenharmony_ci	struct nlattr *protinfo;
9148c2ecf20Sopenharmony_ci	struct nlattr *afspec;
9158c2ecf20Sopenharmony_ci	bool changed = false;
9168c2ecf20Sopenharmony_ci	int err = 0;
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_ci	protinfo = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_PROTINFO);
9198c2ecf20Sopenharmony_ci	afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
9208c2ecf20Sopenharmony_ci	if (!protinfo && !afspec)
9218c2ecf20Sopenharmony_ci		return 0;
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_ci	p = br_port_get_rtnl(dev);
9248c2ecf20Sopenharmony_ci	/* We want to accept dev as bridge itself if the AF_SPEC
9258c2ecf20Sopenharmony_ci	 * is set to see if someone is setting vlan info on the bridge
9268c2ecf20Sopenharmony_ci	 */
9278c2ecf20Sopenharmony_ci	if (!p && !afspec)
9288c2ecf20Sopenharmony_ci		return -EINVAL;
9298c2ecf20Sopenharmony_ci
9308c2ecf20Sopenharmony_ci	if (p && protinfo) {
9318c2ecf20Sopenharmony_ci		if (protinfo->nla_type & NLA_F_NESTED) {
9328c2ecf20Sopenharmony_ci			err = nla_parse_nested_deprecated(tb, IFLA_BRPORT_MAX,
9338c2ecf20Sopenharmony_ci							  protinfo,
9348c2ecf20Sopenharmony_ci							  br_port_policy,
9358c2ecf20Sopenharmony_ci							  NULL);
9368c2ecf20Sopenharmony_ci			if (err)
9378c2ecf20Sopenharmony_ci				return err;
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci			spin_lock_bh(&p->br->lock);
9408c2ecf20Sopenharmony_ci			err = br_setport(p, tb);
9418c2ecf20Sopenharmony_ci			spin_unlock_bh(&p->br->lock);
9428c2ecf20Sopenharmony_ci		} else {
9438c2ecf20Sopenharmony_ci			/* Binary compatibility with old RSTP */
9448c2ecf20Sopenharmony_ci			if (nla_len(protinfo) < sizeof(u8))
9458c2ecf20Sopenharmony_ci				return -EINVAL;
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_ci			spin_lock_bh(&p->br->lock);
9488c2ecf20Sopenharmony_ci			err = br_set_port_state(p, nla_get_u8(protinfo));
9498c2ecf20Sopenharmony_ci			spin_unlock_bh(&p->br->lock);
9508c2ecf20Sopenharmony_ci		}
9518c2ecf20Sopenharmony_ci		if (err)
9528c2ecf20Sopenharmony_ci			goto out;
9538c2ecf20Sopenharmony_ci		changed = true;
9548c2ecf20Sopenharmony_ci	}
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ci	if (afspec)
9578c2ecf20Sopenharmony_ci		err = br_afspec(br, p, afspec, RTM_SETLINK, &changed, extack);
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci	if (changed)
9608c2ecf20Sopenharmony_ci		br_ifinfo_notify(RTM_NEWLINK, br, p);
9618c2ecf20Sopenharmony_ciout:
9628c2ecf20Sopenharmony_ci	return err;
9638c2ecf20Sopenharmony_ci}
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci/* Delete port information */
9668c2ecf20Sopenharmony_ciint br_dellink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
9678c2ecf20Sopenharmony_ci{
9688c2ecf20Sopenharmony_ci	struct net_bridge *br = (struct net_bridge *)netdev_priv(dev);
9698c2ecf20Sopenharmony_ci	struct net_bridge_port *p;
9708c2ecf20Sopenharmony_ci	struct nlattr *afspec;
9718c2ecf20Sopenharmony_ci	bool changed = false;
9728c2ecf20Sopenharmony_ci	int err = 0;
9738c2ecf20Sopenharmony_ci
9748c2ecf20Sopenharmony_ci	afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
9758c2ecf20Sopenharmony_ci	if (!afspec)
9768c2ecf20Sopenharmony_ci		return 0;
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_ci	p = br_port_get_rtnl(dev);
9798c2ecf20Sopenharmony_ci	/* We want to accept dev as bridge itself as well */
9808c2ecf20Sopenharmony_ci	if (!p && !(dev->priv_flags & IFF_EBRIDGE))
9818c2ecf20Sopenharmony_ci		return -EINVAL;
9828c2ecf20Sopenharmony_ci
9838c2ecf20Sopenharmony_ci	err = br_afspec(br, p, afspec, RTM_DELLINK, &changed, NULL);
9848c2ecf20Sopenharmony_ci	if (changed)
9858c2ecf20Sopenharmony_ci		/* Send RTM_NEWLINK because userspace
9868c2ecf20Sopenharmony_ci		 * expects RTM_NEWLINK for vlan dels
9878c2ecf20Sopenharmony_ci		 */
9888c2ecf20Sopenharmony_ci		br_ifinfo_notify(RTM_NEWLINK, br, p);
9898c2ecf20Sopenharmony_ci
9908c2ecf20Sopenharmony_ci	return err;
9918c2ecf20Sopenharmony_ci}
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_cistatic int br_validate(struct nlattr *tb[], struct nlattr *data[],
9948c2ecf20Sopenharmony_ci		       struct netlink_ext_ack *extack)
9958c2ecf20Sopenharmony_ci{
9968c2ecf20Sopenharmony_ci	if (tb[IFLA_ADDRESS]) {
9978c2ecf20Sopenharmony_ci		if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
9988c2ecf20Sopenharmony_ci			return -EINVAL;
9998c2ecf20Sopenharmony_ci		if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
10008c2ecf20Sopenharmony_ci			return -EADDRNOTAVAIL;
10018c2ecf20Sopenharmony_ci	}
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci	if (!data)
10048c2ecf20Sopenharmony_ci		return 0;
10058c2ecf20Sopenharmony_ci
10068c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_VLAN_FILTERING
10078c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_PROTOCOL]) {
10088c2ecf20Sopenharmony_ci		switch (nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL])) {
10098c2ecf20Sopenharmony_ci		case htons(ETH_P_8021Q):
10108c2ecf20Sopenharmony_ci		case htons(ETH_P_8021AD):
10118c2ecf20Sopenharmony_ci			break;
10128c2ecf20Sopenharmony_ci		default:
10138c2ecf20Sopenharmony_ci			return -EPROTONOSUPPORT;
10148c2ecf20Sopenharmony_ci		}
10158c2ecf20Sopenharmony_ci	}
10168c2ecf20Sopenharmony_ci
10178c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_DEFAULT_PVID]) {
10188c2ecf20Sopenharmony_ci		__u16 defpvid = nla_get_u16(data[IFLA_BR_VLAN_DEFAULT_PVID]);
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_ci		if (defpvid >= VLAN_VID_MASK)
10218c2ecf20Sopenharmony_ci			return -EINVAL;
10228c2ecf20Sopenharmony_ci	}
10238c2ecf20Sopenharmony_ci#endif
10248c2ecf20Sopenharmony_ci
10258c2ecf20Sopenharmony_ci	return 0;
10268c2ecf20Sopenharmony_ci}
10278c2ecf20Sopenharmony_ci
10288c2ecf20Sopenharmony_cistatic int br_port_slave_changelink(struct net_device *brdev,
10298c2ecf20Sopenharmony_ci				    struct net_device *dev,
10308c2ecf20Sopenharmony_ci				    struct nlattr *tb[],
10318c2ecf20Sopenharmony_ci				    struct nlattr *data[],
10328c2ecf20Sopenharmony_ci				    struct netlink_ext_ack *extack)
10338c2ecf20Sopenharmony_ci{
10348c2ecf20Sopenharmony_ci	struct net_bridge *br = netdev_priv(brdev);
10358c2ecf20Sopenharmony_ci	int ret;
10368c2ecf20Sopenharmony_ci
10378c2ecf20Sopenharmony_ci	if (!data)
10388c2ecf20Sopenharmony_ci		return 0;
10398c2ecf20Sopenharmony_ci
10408c2ecf20Sopenharmony_ci	spin_lock_bh(&br->lock);
10418c2ecf20Sopenharmony_ci	ret = br_setport(br_port_get_rtnl(dev), data);
10428c2ecf20Sopenharmony_ci	spin_unlock_bh(&br->lock);
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci	return ret;
10458c2ecf20Sopenharmony_ci}
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_cistatic int br_port_fill_slave_info(struct sk_buff *skb,
10488c2ecf20Sopenharmony_ci				   const struct net_device *brdev,
10498c2ecf20Sopenharmony_ci				   const struct net_device *dev)
10508c2ecf20Sopenharmony_ci{
10518c2ecf20Sopenharmony_ci	return br_port_fill_attrs(skb, br_port_get_rtnl(dev));
10528c2ecf20Sopenharmony_ci}
10538c2ecf20Sopenharmony_ci
10548c2ecf20Sopenharmony_cistatic size_t br_port_get_slave_size(const struct net_device *brdev,
10558c2ecf20Sopenharmony_ci				     const struct net_device *dev)
10568c2ecf20Sopenharmony_ci{
10578c2ecf20Sopenharmony_ci	return br_port_info_size();
10588c2ecf20Sopenharmony_ci}
10598c2ecf20Sopenharmony_ci
10608c2ecf20Sopenharmony_cistatic const struct nla_policy br_policy[IFLA_BR_MAX + 1] = {
10618c2ecf20Sopenharmony_ci	[IFLA_BR_FORWARD_DELAY]	= { .type = NLA_U32 },
10628c2ecf20Sopenharmony_ci	[IFLA_BR_HELLO_TIME]	= { .type = NLA_U32 },
10638c2ecf20Sopenharmony_ci	[IFLA_BR_MAX_AGE]	= { .type = NLA_U32 },
10648c2ecf20Sopenharmony_ci	[IFLA_BR_AGEING_TIME] = { .type = NLA_U32 },
10658c2ecf20Sopenharmony_ci	[IFLA_BR_STP_STATE] = { .type = NLA_U32 },
10668c2ecf20Sopenharmony_ci	[IFLA_BR_PRIORITY] = { .type = NLA_U16 },
10678c2ecf20Sopenharmony_ci	[IFLA_BR_VLAN_FILTERING] = { .type = NLA_U8 },
10688c2ecf20Sopenharmony_ci	[IFLA_BR_VLAN_PROTOCOL] = { .type = NLA_U16 },
10698c2ecf20Sopenharmony_ci	[IFLA_BR_GROUP_FWD_MASK] = { .type = NLA_U16 },
10708c2ecf20Sopenharmony_ci	[IFLA_BR_GROUP_ADDR] = { .type = NLA_BINARY,
10718c2ecf20Sopenharmony_ci				 .len  = ETH_ALEN },
10728c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_ROUTER] = { .type = NLA_U8 },
10738c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_SNOOPING] = { .type = NLA_U8 },
10748c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NLA_U8 },
10758c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_QUERIER] = { .type = NLA_U8 },
10768c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NLA_U32 },
10778c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_HASH_MAX] = { .type = NLA_U32 },
10788c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NLA_U32 },
10798c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NLA_U32 },
10808c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NLA_U64 },
10818c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NLA_U64 },
10828c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NLA_U64 },
10838c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_QUERY_INTVL] = { .type = NLA_U64 },
10848c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NLA_U64 },
10858c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NLA_U64 },
10868c2ecf20Sopenharmony_ci	[IFLA_BR_NF_CALL_IPTABLES] = { .type = NLA_U8 },
10878c2ecf20Sopenharmony_ci	[IFLA_BR_NF_CALL_IP6TABLES] = { .type = NLA_U8 },
10888c2ecf20Sopenharmony_ci	[IFLA_BR_NF_CALL_ARPTABLES] = { .type = NLA_U8 },
10898c2ecf20Sopenharmony_ci	[IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NLA_U16 },
10908c2ecf20Sopenharmony_ci	[IFLA_BR_VLAN_STATS_ENABLED] = { .type = NLA_U8 },
10918c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_STATS_ENABLED] = { .type = NLA_U8 },
10928c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_IGMP_VERSION] = { .type = NLA_U8 },
10938c2ecf20Sopenharmony_ci	[IFLA_BR_MCAST_MLD_VERSION] = { .type = NLA_U8 },
10948c2ecf20Sopenharmony_ci	[IFLA_BR_VLAN_STATS_PER_PORT] = { .type = NLA_U8 },
10958c2ecf20Sopenharmony_ci	[IFLA_BR_MULTI_BOOLOPT] =
10968c2ecf20Sopenharmony_ci		NLA_POLICY_EXACT_LEN(sizeof(struct br_boolopt_multi)),
10978c2ecf20Sopenharmony_ci};
10988c2ecf20Sopenharmony_ci
10998c2ecf20Sopenharmony_cistatic int br_changelink(struct net_device *brdev, struct nlattr *tb[],
11008c2ecf20Sopenharmony_ci			 struct nlattr *data[],
11018c2ecf20Sopenharmony_ci			 struct netlink_ext_ack *extack)
11028c2ecf20Sopenharmony_ci{
11038c2ecf20Sopenharmony_ci	struct net_bridge *br = netdev_priv(brdev);
11048c2ecf20Sopenharmony_ci	int err;
11058c2ecf20Sopenharmony_ci
11068c2ecf20Sopenharmony_ci	if (!data)
11078c2ecf20Sopenharmony_ci		return 0;
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ci	if (data[IFLA_BR_FORWARD_DELAY]) {
11108c2ecf20Sopenharmony_ci		err = br_set_forward_delay(br, nla_get_u32(data[IFLA_BR_FORWARD_DELAY]));
11118c2ecf20Sopenharmony_ci		if (err)
11128c2ecf20Sopenharmony_ci			return err;
11138c2ecf20Sopenharmony_ci	}
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	if (data[IFLA_BR_HELLO_TIME]) {
11168c2ecf20Sopenharmony_ci		err = br_set_hello_time(br, nla_get_u32(data[IFLA_BR_HELLO_TIME]));
11178c2ecf20Sopenharmony_ci		if (err)
11188c2ecf20Sopenharmony_ci			return err;
11198c2ecf20Sopenharmony_ci	}
11208c2ecf20Sopenharmony_ci
11218c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MAX_AGE]) {
11228c2ecf20Sopenharmony_ci		err = br_set_max_age(br, nla_get_u32(data[IFLA_BR_MAX_AGE]));
11238c2ecf20Sopenharmony_ci		if (err)
11248c2ecf20Sopenharmony_ci			return err;
11258c2ecf20Sopenharmony_ci	}
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci	if (data[IFLA_BR_AGEING_TIME]) {
11288c2ecf20Sopenharmony_ci		err = br_set_ageing_time(br, nla_get_u32(data[IFLA_BR_AGEING_TIME]));
11298c2ecf20Sopenharmony_ci		if (err)
11308c2ecf20Sopenharmony_ci			return err;
11318c2ecf20Sopenharmony_ci	}
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_ci	if (data[IFLA_BR_STP_STATE]) {
11348c2ecf20Sopenharmony_ci		u32 stp_enabled = nla_get_u32(data[IFLA_BR_STP_STATE]);
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci		err = br_stp_set_enabled(br, stp_enabled, extack);
11378c2ecf20Sopenharmony_ci		if (err)
11388c2ecf20Sopenharmony_ci			return err;
11398c2ecf20Sopenharmony_ci	}
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci	if (data[IFLA_BR_PRIORITY]) {
11428c2ecf20Sopenharmony_ci		u32 priority = nla_get_u16(data[IFLA_BR_PRIORITY]);
11438c2ecf20Sopenharmony_ci
11448c2ecf20Sopenharmony_ci		br_stp_set_bridge_priority(br, priority);
11458c2ecf20Sopenharmony_ci	}
11468c2ecf20Sopenharmony_ci
11478c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_FILTERING]) {
11488c2ecf20Sopenharmony_ci		u8 vlan_filter = nla_get_u8(data[IFLA_BR_VLAN_FILTERING]);
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci		err = __br_vlan_filter_toggle(br, vlan_filter);
11518c2ecf20Sopenharmony_ci		if (err)
11528c2ecf20Sopenharmony_ci			return err;
11538c2ecf20Sopenharmony_ci	}
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_VLAN_FILTERING
11568c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_PROTOCOL]) {
11578c2ecf20Sopenharmony_ci		__be16 vlan_proto = nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL]);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci		err = __br_vlan_set_proto(br, vlan_proto);
11608c2ecf20Sopenharmony_ci		if (err)
11618c2ecf20Sopenharmony_ci			return err;
11628c2ecf20Sopenharmony_ci	}
11638c2ecf20Sopenharmony_ci
11648c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_DEFAULT_PVID]) {
11658c2ecf20Sopenharmony_ci		__u16 defpvid = nla_get_u16(data[IFLA_BR_VLAN_DEFAULT_PVID]);
11668c2ecf20Sopenharmony_ci
11678c2ecf20Sopenharmony_ci		err = __br_vlan_set_default_pvid(br, defpvid, extack);
11688c2ecf20Sopenharmony_ci		if (err)
11698c2ecf20Sopenharmony_ci			return err;
11708c2ecf20Sopenharmony_ci	}
11718c2ecf20Sopenharmony_ci
11728c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_STATS_ENABLED]) {
11738c2ecf20Sopenharmony_ci		__u8 vlan_stats = nla_get_u8(data[IFLA_BR_VLAN_STATS_ENABLED]);
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_ci		err = br_vlan_set_stats(br, vlan_stats);
11768c2ecf20Sopenharmony_ci		if (err)
11778c2ecf20Sopenharmony_ci			return err;
11788c2ecf20Sopenharmony_ci	}
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci	if (data[IFLA_BR_VLAN_STATS_PER_PORT]) {
11818c2ecf20Sopenharmony_ci		__u8 per_port = nla_get_u8(data[IFLA_BR_VLAN_STATS_PER_PORT]);
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci		err = br_vlan_set_stats_per_port(br, per_port);
11848c2ecf20Sopenharmony_ci		if (err)
11858c2ecf20Sopenharmony_ci			return err;
11868c2ecf20Sopenharmony_ci	}
11878c2ecf20Sopenharmony_ci#endif
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci	if (data[IFLA_BR_GROUP_FWD_MASK]) {
11908c2ecf20Sopenharmony_ci		u16 fwd_mask = nla_get_u16(data[IFLA_BR_GROUP_FWD_MASK]);
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci		if (fwd_mask & BR_GROUPFWD_RESTRICTED)
11938c2ecf20Sopenharmony_ci			return -EINVAL;
11948c2ecf20Sopenharmony_ci		br->group_fwd_mask = fwd_mask;
11958c2ecf20Sopenharmony_ci	}
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci	if (data[IFLA_BR_GROUP_ADDR]) {
11988c2ecf20Sopenharmony_ci		u8 new_addr[ETH_ALEN];
11998c2ecf20Sopenharmony_ci
12008c2ecf20Sopenharmony_ci		if (nla_len(data[IFLA_BR_GROUP_ADDR]) != ETH_ALEN)
12018c2ecf20Sopenharmony_ci			return -EINVAL;
12028c2ecf20Sopenharmony_ci		memcpy(new_addr, nla_data(data[IFLA_BR_GROUP_ADDR]), ETH_ALEN);
12038c2ecf20Sopenharmony_ci		if (!is_link_local_ether_addr(new_addr))
12048c2ecf20Sopenharmony_ci			return -EINVAL;
12058c2ecf20Sopenharmony_ci		if (new_addr[5] == 1 ||		/* 802.3x Pause address */
12068c2ecf20Sopenharmony_ci		    new_addr[5] == 2 ||		/* 802.3ad Slow protocols */
12078c2ecf20Sopenharmony_ci		    new_addr[5] == 3)		/* 802.1X PAE address */
12088c2ecf20Sopenharmony_ci			return -EINVAL;
12098c2ecf20Sopenharmony_ci		spin_lock_bh(&br->lock);
12108c2ecf20Sopenharmony_ci		memcpy(br->group_addr, new_addr, sizeof(br->group_addr));
12118c2ecf20Sopenharmony_ci		spin_unlock_bh(&br->lock);
12128c2ecf20Sopenharmony_ci		br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
12138c2ecf20Sopenharmony_ci		br_recalculate_fwd_mask(br);
12148c2ecf20Sopenharmony_ci	}
12158c2ecf20Sopenharmony_ci
12168c2ecf20Sopenharmony_ci	if (data[IFLA_BR_FDB_FLUSH])
12178c2ecf20Sopenharmony_ci		br_fdb_flush(br);
12188c2ecf20Sopenharmony_ci
12198c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
12208c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_ROUTER]) {
12218c2ecf20Sopenharmony_ci		u8 multicast_router = nla_get_u8(data[IFLA_BR_MCAST_ROUTER]);
12228c2ecf20Sopenharmony_ci
12238c2ecf20Sopenharmony_ci		err = br_multicast_set_router(br, multicast_router);
12248c2ecf20Sopenharmony_ci		if (err)
12258c2ecf20Sopenharmony_ci			return err;
12268c2ecf20Sopenharmony_ci	}
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_SNOOPING]) {
12298c2ecf20Sopenharmony_ci		u8 mcast_snooping = nla_get_u8(data[IFLA_BR_MCAST_SNOOPING]);
12308c2ecf20Sopenharmony_ci
12318c2ecf20Sopenharmony_ci		br_multicast_toggle(br, mcast_snooping);
12328c2ecf20Sopenharmony_ci	}
12338c2ecf20Sopenharmony_ci
12348c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_QUERY_USE_IFADDR]) {
12358c2ecf20Sopenharmony_ci		u8 val;
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci		val = nla_get_u8(data[IFLA_BR_MCAST_QUERY_USE_IFADDR]);
12388c2ecf20Sopenharmony_ci		br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
12398c2ecf20Sopenharmony_ci	}
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_QUERIER]) {
12428c2ecf20Sopenharmony_ci		u8 mcast_querier = nla_get_u8(data[IFLA_BR_MCAST_QUERIER]);
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci		err = br_multicast_set_querier(br, mcast_querier);
12458c2ecf20Sopenharmony_ci		if (err)
12468c2ecf20Sopenharmony_ci			return err;
12478c2ecf20Sopenharmony_ci	}
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_HASH_ELASTICITY])
12508c2ecf20Sopenharmony_ci		br_warn(br, "the hash_elasticity option has been deprecated and is always %u\n",
12518c2ecf20Sopenharmony_ci			RHT_ELASTICITY);
12528c2ecf20Sopenharmony_ci
12538c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_HASH_MAX])
12548c2ecf20Sopenharmony_ci		br->hash_max = nla_get_u32(data[IFLA_BR_MCAST_HASH_MAX]);
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_LAST_MEMBER_CNT]) {
12578c2ecf20Sopenharmony_ci		u32 val = nla_get_u32(data[IFLA_BR_MCAST_LAST_MEMBER_CNT]);
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci		br->multicast_last_member_count = val;
12608c2ecf20Sopenharmony_ci	}
12618c2ecf20Sopenharmony_ci
12628c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_STARTUP_QUERY_CNT]) {
12638c2ecf20Sopenharmony_ci		u32 val = nla_get_u32(data[IFLA_BR_MCAST_STARTUP_QUERY_CNT]);
12648c2ecf20Sopenharmony_ci
12658c2ecf20Sopenharmony_ci		br->multicast_startup_query_count = val;
12668c2ecf20Sopenharmony_ci	}
12678c2ecf20Sopenharmony_ci
12688c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_LAST_MEMBER_INTVL]) {
12698c2ecf20Sopenharmony_ci		u64 val = nla_get_u64(data[IFLA_BR_MCAST_LAST_MEMBER_INTVL]);
12708c2ecf20Sopenharmony_ci
12718c2ecf20Sopenharmony_ci		br->multicast_last_member_interval = clock_t_to_jiffies(val);
12728c2ecf20Sopenharmony_ci	}
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_MEMBERSHIP_INTVL]) {
12758c2ecf20Sopenharmony_ci		u64 val = nla_get_u64(data[IFLA_BR_MCAST_MEMBERSHIP_INTVL]);
12768c2ecf20Sopenharmony_ci
12778c2ecf20Sopenharmony_ci		br->multicast_membership_interval = clock_t_to_jiffies(val);
12788c2ecf20Sopenharmony_ci	}
12798c2ecf20Sopenharmony_ci
12808c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_QUERIER_INTVL]) {
12818c2ecf20Sopenharmony_ci		u64 val = nla_get_u64(data[IFLA_BR_MCAST_QUERIER_INTVL]);
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci		br->multicast_querier_interval = clock_t_to_jiffies(val);
12848c2ecf20Sopenharmony_ci	}
12858c2ecf20Sopenharmony_ci
12868c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_QUERY_INTVL]) {
12878c2ecf20Sopenharmony_ci		u64 val = nla_get_u64(data[IFLA_BR_MCAST_QUERY_INTVL]);
12888c2ecf20Sopenharmony_ci
12898c2ecf20Sopenharmony_ci		br->multicast_query_interval = clock_t_to_jiffies(val);
12908c2ecf20Sopenharmony_ci	}
12918c2ecf20Sopenharmony_ci
12928c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]) {
12938c2ecf20Sopenharmony_ci		u64 val = nla_get_u64(data[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]);
12948c2ecf20Sopenharmony_ci
12958c2ecf20Sopenharmony_ci		br->multicast_query_response_interval = clock_t_to_jiffies(val);
12968c2ecf20Sopenharmony_ci	}
12978c2ecf20Sopenharmony_ci
12988c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]) {
12998c2ecf20Sopenharmony_ci		u64 val = nla_get_u64(data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]);
13008c2ecf20Sopenharmony_ci
13018c2ecf20Sopenharmony_ci		br->multicast_startup_query_interval = clock_t_to_jiffies(val);
13028c2ecf20Sopenharmony_ci	}
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_STATS_ENABLED]) {
13058c2ecf20Sopenharmony_ci		__u8 mcast_stats;
13068c2ecf20Sopenharmony_ci
13078c2ecf20Sopenharmony_ci		mcast_stats = nla_get_u8(data[IFLA_BR_MCAST_STATS_ENABLED]);
13088c2ecf20Sopenharmony_ci		br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!mcast_stats);
13098c2ecf20Sopenharmony_ci	}
13108c2ecf20Sopenharmony_ci
13118c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_IGMP_VERSION]) {
13128c2ecf20Sopenharmony_ci		__u8 igmp_version;
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ci		igmp_version = nla_get_u8(data[IFLA_BR_MCAST_IGMP_VERSION]);
13158c2ecf20Sopenharmony_ci		err = br_multicast_set_igmp_version(br, igmp_version);
13168c2ecf20Sopenharmony_ci		if (err)
13178c2ecf20Sopenharmony_ci			return err;
13188c2ecf20Sopenharmony_ci	}
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6)
13218c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MCAST_MLD_VERSION]) {
13228c2ecf20Sopenharmony_ci		__u8 mld_version;
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci		mld_version = nla_get_u8(data[IFLA_BR_MCAST_MLD_VERSION]);
13258c2ecf20Sopenharmony_ci		err = br_multicast_set_mld_version(br, mld_version);
13268c2ecf20Sopenharmony_ci		if (err)
13278c2ecf20Sopenharmony_ci			return err;
13288c2ecf20Sopenharmony_ci	}
13298c2ecf20Sopenharmony_ci#endif
13308c2ecf20Sopenharmony_ci#endif
13318c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
13328c2ecf20Sopenharmony_ci	if (data[IFLA_BR_NF_CALL_IPTABLES]) {
13338c2ecf20Sopenharmony_ci		u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IPTABLES]);
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci		br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
13368c2ecf20Sopenharmony_ci	}
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_ci	if (data[IFLA_BR_NF_CALL_IP6TABLES]) {
13398c2ecf20Sopenharmony_ci		u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IP6TABLES]);
13408c2ecf20Sopenharmony_ci
13418c2ecf20Sopenharmony_ci		br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
13428c2ecf20Sopenharmony_ci	}
13438c2ecf20Sopenharmony_ci
13448c2ecf20Sopenharmony_ci	if (data[IFLA_BR_NF_CALL_ARPTABLES]) {
13458c2ecf20Sopenharmony_ci		u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_ARPTABLES]);
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci		br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
13488c2ecf20Sopenharmony_ci	}
13498c2ecf20Sopenharmony_ci#endif
13508c2ecf20Sopenharmony_ci
13518c2ecf20Sopenharmony_ci	if (data[IFLA_BR_MULTI_BOOLOPT]) {
13528c2ecf20Sopenharmony_ci		struct br_boolopt_multi *bm;
13538c2ecf20Sopenharmony_ci
13548c2ecf20Sopenharmony_ci		bm = nla_data(data[IFLA_BR_MULTI_BOOLOPT]);
13558c2ecf20Sopenharmony_ci		err = br_boolopt_multi_toggle(br, bm, extack);
13568c2ecf20Sopenharmony_ci		if (err)
13578c2ecf20Sopenharmony_ci			return err;
13588c2ecf20Sopenharmony_ci	}
13598c2ecf20Sopenharmony_ci
13608c2ecf20Sopenharmony_ci	return 0;
13618c2ecf20Sopenharmony_ci}
13628c2ecf20Sopenharmony_ci
13638c2ecf20Sopenharmony_cistatic int br_dev_newlink(struct net *src_net, struct net_device *dev,
13648c2ecf20Sopenharmony_ci			  struct nlattr *tb[], struct nlattr *data[],
13658c2ecf20Sopenharmony_ci			  struct netlink_ext_ack *extack)
13668c2ecf20Sopenharmony_ci{
13678c2ecf20Sopenharmony_ci	struct net_bridge *br = netdev_priv(dev);
13688c2ecf20Sopenharmony_ci	int err;
13698c2ecf20Sopenharmony_ci
13708c2ecf20Sopenharmony_ci	err = register_netdevice(dev);
13718c2ecf20Sopenharmony_ci	if (err)
13728c2ecf20Sopenharmony_ci		return err;
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci	if (tb[IFLA_ADDRESS]) {
13758c2ecf20Sopenharmony_ci		spin_lock_bh(&br->lock);
13768c2ecf20Sopenharmony_ci		br_stp_change_bridge_id(br, nla_data(tb[IFLA_ADDRESS]));
13778c2ecf20Sopenharmony_ci		spin_unlock_bh(&br->lock);
13788c2ecf20Sopenharmony_ci	}
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_ci	err = br_changelink(dev, tb, data, extack);
13818c2ecf20Sopenharmony_ci	if (err)
13828c2ecf20Sopenharmony_ci		br_dev_delete(dev, NULL);
13838c2ecf20Sopenharmony_ci
13848c2ecf20Sopenharmony_ci	return err;
13858c2ecf20Sopenharmony_ci}
13868c2ecf20Sopenharmony_ci
13878c2ecf20Sopenharmony_cistatic size_t br_get_size(const struct net_device *brdev)
13888c2ecf20Sopenharmony_ci{
13898c2ecf20Sopenharmony_ci	return nla_total_size(sizeof(u32)) +	/* IFLA_BR_FORWARD_DELAY  */
13908c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +	/* IFLA_BR_HELLO_TIME */
13918c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +	/* IFLA_BR_MAX_AGE */
13928c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_AGEING_TIME */
13938c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_STP_STATE */
13948c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u16)) +    /* IFLA_BR_PRIORITY */
13958c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_VLAN_FILTERING */
13968c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_VLAN_FILTERING
13978c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(__be16)) +	/* IFLA_BR_VLAN_PROTOCOL */
13988c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u16)) +    /* IFLA_BR_VLAN_DEFAULT_PVID */
13998c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_VLAN_STATS_ENABLED */
14008c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +	/* IFLA_BR_VLAN_STATS_PER_PORT */
14018c2ecf20Sopenharmony_ci#endif
14028c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u16)) +    /* IFLA_BR_GROUP_FWD_MASK */
14038c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(struct ifla_bridge_id)) +   /* IFLA_BR_ROOT_ID */
14048c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(struct ifla_bridge_id)) +   /* IFLA_BR_BRIDGE_ID */
14058c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u16)) +    /* IFLA_BR_ROOT_PORT */
14068c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_ROOT_PATH_COST */
14078c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_TOPOLOGY_CHANGE */
14088c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_TOPOLOGY_CHANGE_DETECTED */
14098c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_HELLO_TIMER */
14108c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_TCN_TIMER */
14118c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */
14128c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_GC_TIMER */
14138c2ecf20Sopenharmony_ci	       nla_total_size(ETH_ALEN) +       /* IFLA_BR_GROUP_ADDR */
14148c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
14158c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_MCAST_ROUTER */
14168c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_MCAST_SNOOPING */
14178c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_MCAST_QUERY_USE_IFADDR */
14188c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_MCAST_QUERIER */
14198c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_MCAST_STATS_ENABLED */
14208c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_MCAST_HASH_ELASTICITY */
14218c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_MCAST_HASH_MAX */
14228c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_MCAST_LAST_MEMBER_CNT */
14238c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u32)) +    /* IFLA_BR_MCAST_STARTUP_QUERY_CNT */
14248c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_LAST_MEMBER_INTVL */
14258c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_MEMBERSHIP_INTVL */
14268c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_QUERIER_INTVL */
14278c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_QUERY_INTVL */
14288c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_QUERY_RESPONSE_INTVL */
14298c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_STARTUP_QUERY_INTVL */
14308c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +	/* IFLA_BR_MCAST_IGMP_VERSION */
14318c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +	/* IFLA_BR_MCAST_MLD_VERSION */
14328c2ecf20Sopenharmony_ci#endif
14338c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
14348c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_NF_CALL_IPTABLES */
14358c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_NF_CALL_IP6TABLES */
14368c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(u8)) +     /* IFLA_BR_NF_CALL_ARPTABLES */
14378c2ecf20Sopenharmony_ci#endif
14388c2ecf20Sopenharmony_ci	       nla_total_size(sizeof(struct br_boolopt_multi)) + /* IFLA_BR_MULTI_BOOLOPT */
14398c2ecf20Sopenharmony_ci	       0;
14408c2ecf20Sopenharmony_ci}
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_cistatic int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
14438c2ecf20Sopenharmony_ci{
14448c2ecf20Sopenharmony_ci	struct net_bridge *br = netdev_priv(brdev);
14458c2ecf20Sopenharmony_ci	u32 forward_delay = jiffies_to_clock_t(br->forward_delay);
14468c2ecf20Sopenharmony_ci	u32 hello_time = jiffies_to_clock_t(br->hello_time);
14478c2ecf20Sopenharmony_ci	u32 age_time = jiffies_to_clock_t(br->max_age);
14488c2ecf20Sopenharmony_ci	u32 ageing_time = jiffies_to_clock_t(br->ageing_time);
14498c2ecf20Sopenharmony_ci	u32 stp_enabled = br->stp_enabled;
14508c2ecf20Sopenharmony_ci	u16 priority = (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1];
14518c2ecf20Sopenharmony_ci	u8 vlan_enabled = br_vlan_enabled(br->dev);
14528c2ecf20Sopenharmony_ci	struct br_boolopt_multi bm;
14538c2ecf20Sopenharmony_ci	u64 clockval;
14548c2ecf20Sopenharmony_ci
14558c2ecf20Sopenharmony_ci	clockval = br_timer_value(&br->hello_timer);
14568c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_HELLO_TIMER, clockval, IFLA_BR_PAD))
14578c2ecf20Sopenharmony_ci		return -EMSGSIZE;
14588c2ecf20Sopenharmony_ci	clockval = br_timer_value(&br->tcn_timer);
14598c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_TCN_TIMER, clockval, IFLA_BR_PAD))
14608c2ecf20Sopenharmony_ci		return -EMSGSIZE;
14618c2ecf20Sopenharmony_ci	clockval = br_timer_value(&br->topology_change_timer);
14628c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_TOPOLOGY_CHANGE_TIMER, clockval,
14638c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
14648c2ecf20Sopenharmony_ci		return -EMSGSIZE;
14658c2ecf20Sopenharmony_ci	clockval = br_timer_value(&br->gc_work.timer);
14668c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_GC_TIMER, clockval, IFLA_BR_PAD))
14678c2ecf20Sopenharmony_ci		return -EMSGSIZE;
14688c2ecf20Sopenharmony_ci
14698c2ecf20Sopenharmony_ci	br_boolopt_multi_get(br, &bm);
14708c2ecf20Sopenharmony_ci	if (nla_put_u32(skb, IFLA_BR_FORWARD_DELAY, forward_delay) ||
14718c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_HELLO_TIME, hello_time) ||
14728c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_MAX_AGE, age_time) ||
14738c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_AGEING_TIME, ageing_time) ||
14748c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_STP_STATE, stp_enabled) ||
14758c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BR_PRIORITY, priority) ||
14768c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_VLAN_FILTERING, vlan_enabled) ||
14778c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BR_GROUP_FWD_MASK, br->group_fwd_mask) ||
14788c2ecf20Sopenharmony_ci	    nla_put(skb, IFLA_BR_BRIDGE_ID, sizeof(struct ifla_bridge_id),
14798c2ecf20Sopenharmony_ci		    &br->bridge_id) ||
14808c2ecf20Sopenharmony_ci	    nla_put(skb, IFLA_BR_ROOT_ID, sizeof(struct ifla_bridge_id),
14818c2ecf20Sopenharmony_ci		    &br->designated_root) ||
14828c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BR_ROOT_PORT, br->root_port) ||
14838c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_ROOT_PATH_COST, br->root_path_cost) ||
14848c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE, br->topology_change) ||
14858c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE_DETECTED,
14868c2ecf20Sopenharmony_ci		       br->topology_change_detected) ||
14878c2ecf20Sopenharmony_ci	    nla_put(skb, IFLA_BR_GROUP_ADDR, ETH_ALEN, br->group_addr) ||
14888c2ecf20Sopenharmony_ci	    nla_put(skb, IFLA_BR_MULTI_BOOLOPT, sizeof(bm), &bm))
14898c2ecf20Sopenharmony_ci		return -EMSGSIZE;
14908c2ecf20Sopenharmony_ci
14918c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_VLAN_FILTERING
14928c2ecf20Sopenharmony_ci	if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto) ||
14938c2ecf20Sopenharmony_ci	    nla_put_u16(skb, IFLA_BR_VLAN_DEFAULT_PVID, br->default_pvid) ||
14948c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_VLAN_STATS_ENABLED,
14958c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) ||
14968c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_VLAN_STATS_PER_PORT,
14978c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_VLAN_STATS_PER_PORT)))
14988c2ecf20Sopenharmony_ci		return -EMSGSIZE;
14998c2ecf20Sopenharmony_ci#endif
15008c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
15018c2ecf20Sopenharmony_ci	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
15028c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING,
15038c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_MULTICAST_ENABLED)) ||
15048c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
15058c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR)) ||
15068c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_MCAST_QUERIER,
15078c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_MULTICAST_QUERIER)) ||
15088c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_MCAST_STATS_ENABLED,
15098c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED)) ||
15108c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_MCAST_HASH_ELASTICITY, RHT_ELASTICITY) ||
15118c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_MCAST_HASH_MAX, br->hash_max) ||
15128c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_MCAST_LAST_MEMBER_CNT,
15138c2ecf20Sopenharmony_ci			br->multicast_last_member_count) ||
15148c2ecf20Sopenharmony_ci	    nla_put_u32(skb, IFLA_BR_MCAST_STARTUP_QUERY_CNT,
15158c2ecf20Sopenharmony_ci			br->multicast_startup_query_count) ||
15168c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_MCAST_IGMP_VERSION,
15178c2ecf20Sopenharmony_ci		       br->multicast_igmp_version))
15188c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15198c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6)
15208c2ecf20Sopenharmony_ci	if (nla_put_u8(skb, IFLA_BR_MCAST_MLD_VERSION,
15218c2ecf20Sopenharmony_ci		       br->multicast_mld_version))
15228c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15238c2ecf20Sopenharmony_ci#endif
15248c2ecf20Sopenharmony_ci	clockval = jiffies_to_clock_t(br->multicast_last_member_interval);
15258c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_LAST_MEMBER_INTVL, clockval,
15268c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
15278c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15288c2ecf20Sopenharmony_ci	clockval = jiffies_to_clock_t(br->multicast_membership_interval);
15298c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_MEMBERSHIP_INTVL, clockval,
15308c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
15318c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15328c2ecf20Sopenharmony_ci	clockval = jiffies_to_clock_t(br->multicast_querier_interval);
15338c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_QUERIER_INTVL, clockval,
15348c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
15358c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15368c2ecf20Sopenharmony_ci	clockval = jiffies_to_clock_t(br->multicast_query_interval);
15378c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_QUERY_INTVL, clockval,
15388c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
15398c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15408c2ecf20Sopenharmony_ci	clockval = jiffies_to_clock_t(br->multicast_query_response_interval);
15418c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL, clockval,
15428c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
15438c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15448c2ecf20Sopenharmony_ci	clockval = jiffies_to_clock_t(br->multicast_startup_query_interval);
15458c2ecf20Sopenharmony_ci	if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_STARTUP_QUERY_INTVL, clockval,
15468c2ecf20Sopenharmony_ci			      IFLA_BR_PAD))
15478c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15488c2ecf20Sopenharmony_ci#endif
15498c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
15508c2ecf20Sopenharmony_ci	if (nla_put_u8(skb, IFLA_BR_NF_CALL_IPTABLES,
15518c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_NF_CALL_IPTABLES) ? 1 : 0) ||
15528c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_NF_CALL_IP6TABLES,
15538c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_NF_CALL_IP6TABLES) ? 1 : 0) ||
15548c2ecf20Sopenharmony_ci	    nla_put_u8(skb, IFLA_BR_NF_CALL_ARPTABLES,
15558c2ecf20Sopenharmony_ci		       br_opt_get(br, BROPT_NF_CALL_ARPTABLES) ? 1 : 0))
15568c2ecf20Sopenharmony_ci		return -EMSGSIZE;
15578c2ecf20Sopenharmony_ci#endif
15588c2ecf20Sopenharmony_ci
15598c2ecf20Sopenharmony_ci	return 0;
15608c2ecf20Sopenharmony_ci}
15618c2ecf20Sopenharmony_ci
15628c2ecf20Sopenharmony_cistatic size_t br_get_linkxstats_size(const struct net_device *dev, int attr)
15638c2ecf20Sopenharmony_ci{
15648c2ecf20Sopenharmony_ci	struct net_bridge_port *p = NULL;
15658c2ecf20Sopenharmony_ci	struct net_bridge_vlan_group *vg;
15668c2ecf20Sopenharmony_ci	struct net_bridge_vlan *v;
15678c2ecf20Sopenharmony_ci	struct net_bridge *br;
15688c2ecf20Sopenharmony_ci	int numvls = 0;
15698c2ecf20Sopenharmony_ci
15708c2ecf20Sopenharmony_ci	switch (attr) {
15718c2ecf20Sopenharmony_ci	case IFLA_STATS_LINK_XSTATS:
15728c2ecf20Sopenharmony_ci		br = netdev_priv(dev);
15738c2ecf20Sopenharmony_ci		vg = br_vlan_group(br);
15748c2ecf20Sopenharmony_ci		break;
15758c2ecf20Sopenharmony_ci	case IFLA_STATS_LINK_XSTATS_SLAVE:
15768c2ecf20Sopenharmony_ci		p = br_port_get_rtnl(dev);
15778c2ecf20Sopenharmony_ci		if (!p)
15788c2ecf20Sopenharmony_ci			return 0;
15798c2ecf20Sopenharmony_ci		br = p->br;
15808c2ecf20Sopenharmony_ci		vg = nbp_vlan_group(p);
15818c2ecf20Sopenharmony_ci		break;
15828c2ecf20Sopenharmony_ci	default:
15838c2ecf20Sopenharmony_ci		return 0;
15848c2ecf20Sopenharmony_ci	}
15858c2ecf20Sopenharmony_ci
15868c2ecf20Sopenharmony_ci	if (vg) {
15878c2ecf20Sopenharmony_ci		/* we need to count all, even placeholder entries */
15888c2ecf20Sopenharmony_ci		list_for_each_entry(v, &vg->vlan_list, vlist)
15898c2ecf20Sopenharmony_ci			numvls++;
15908c2ecf20Sopenharmony_ci	}
15918c2ecf20Sopenharmony_ci
15928c2ecf20Sopenharmony_ci	return numvls * nla_total_size(sizeof(struct bridge_vlan_xstats)) +
15938c2ecf20Sopenharmony_ci	       nla_total_size_64bit(sizeof(struct br_mcast_stats)) +
15948c2ecf20Sopenharmony_ci	       (p ? nla_total_size_64bit(sizeof(p->stp_xstats)) : 0) +
15958c2ecf20Sopenharmony_ci	       nla_total_size(0);
15968c2ecf20Sopenharmony_ci}
15978c2ecf20Sopenharmony_ci
15988c2ecf20Sopenharmony_cistatic int br_fill_linkxstats(struct sk_buff *skb,
15998c2ecf20Sopenharmony_ci			      const struct net_device *dev,
16008c2ecf20Sopenharmony_ci			      int *prividx, int attr)
16018c2ecf20Sopenharmony_ci{
16028c2ecf20Sopenharmony_ci	struct nlattr *nla __maybe_unused;
16038c2ecf20Sopenharmony_ci	struct net_bridge_port *p = NULL;
16048c2ecf20Sopenharmony_ci	struct net_bridge_vlan_group *vg;
16058c2ecf20Sopenharmony_ci	struct net_bridge_vlan *v;
16068c2ecf20Sopenharmony_ci	struct net_bridge *br;
16078c2ecf20Sopenharmony_ci	struct nlattr *nest;
16088c2ecf20Sopenharmony_ci	int vl_idx = 0;
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_ci	switch (attr) {
16118c2ecf20Sopenharmony_ci	case IFLA_STATS_LINK_XSTATS:
16128c2ecf20Sopenharmony_ci		br = netdev_priv(dev);
16138c2ecf20Sopenharmony_ci		vg = br_vlan_group(br);
16148c2ecf20Sopenharmony_ci		break;
16158c2ecf20Sopenharmony_ci	case IFLA_STATS_LINK_XSTATS_SLAVE:
16168c2ecf20Sopenharmony_ci		p = br_port_get_rtnl(dev);
16178c2ecf20Sopenharmony_ci		if (!p)
16188c2ecf20Sopenharmony_ci			return 0;
16198c2ecf20Sopenharmony_ci		br = p->br;
16208c2ecf20Sopenharmony_ci		vg = nbp_vlan_group(p);
16218c2ecf20Sopenharmony_ci		break;
16228c2ecf20Sopenharmony_ci	default:
16238c2ecf20Sopenharmony_ci		return -EINVAL;
16248c2ecf20Sopenharmony_ci	}
16258c2ecf20Sopenharmony_ci
16268c2ecf20Sopenharmony_ci	nest = nla_nest_start_noflag(skb, LINK_XSTATS_TYPE_BRIDGE);
16278c2ecf20Sopenharmony_ci	if (!nest)
16288c2ecf20Sopenharmony_ci		return -EMSGSIZE;
16298c2ecf20Sopenharmony_ci
16308c2ecf20Sopenharmony_ci	if (vg) {
16318c2ecf20Sopenharmony_ci		u16 pvid;
16328c2ecf20Sopenharmony_ci
16338c2ecf20Sopenharmony_ci		pvid = br_get_pvid(vg);
16348c2ecf20Sopenharmony_ci		list_for_each_entry(v, &vg->vlan_list, vlist) {
16358c2ecf20Sopenharmony_ci			struct bridge_vlan_xstats vxi;
16368c2ecf20Sopenharmony_ci			struct br_vlan_stats stats;
16378c2ecf20Sopenharmony_ci
16388c2ecf20Sopenharmony_ci			if (++vl_idx < *prividx)
16398c2ecf20Sopenharmony_ci				continue;
16408c2ecf20Sopenharmony_ci			memset(&vxi, 0, sizeof(vxi));
16418c2ecf20Sopenharmony_ci			vxi.vid = v->vid;
16428c2ecf20Sopenharmony_ci			vxi.flags = v->flags;
16438c2ecf20Sopenharmony_ci			if (v->vid == pvid)
16448c2ecf20Sopenharmony_ci				vxi.flags |= BRIDGE_VLAN_INFO_PVID;
16458c2ecf20Sopenharmony_ci			br_vlan_get_stats(v, &stats);
16468c2ecf20Sopenharmony_ci			vxi.rx_bytes = stats.rx_bytes;
16478c2ecf20Sopenharmony_ci			vxi.rx_packets = stats.rx_packets;
16488c2ecf20Sopenharmony_ci			vxi.tx_bytes = stats.tx_bytes;
16498c2ecf20Sopenharmony_ci			vxi.tx_packets = stats.tx_packets;
16508c2ecf20Sopenharmony_ci
16518c2ecf20Sopenharmony_ci			if (nla_put(skb, BRIDGE_XSTATS_VLAN, sizeof(vxi), &vxi))
16528c2ecf20Sopenharmony_ci				goto nla_put_failure;
16538c2ecf20Sopenharmony_ci		}
16548c2ecf20Sopenharmony_ci	}
16558c2ecf20Sopenharmony_ci
16568c2ecf20Sopenharmony_ci#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
16578c2ecf20Sopenharmony_ci	if (++vl_idx >= *prividx) {
16588c2ecf20Sopenharmony_ci		nla = nla_reserve_64bit(skb, BRIDGE_XSTATS_MCAST,
16598c2ecf20Sopenharmony_ci					sizeof(struct br_mcast_stats),
16608c2ecf20Sopenharmony_ci					BRIDGE_XSTATS_PAD);
16618c2ecf20Sopenharmony_ci		if (!nla)
16628c2ecf20Sopenharmony_ci			goto nla_put_failure;
16638c2ecf20Sopenharmony_ci		br_multicast_get_stats(br, p, nla_data(nla));
16648c2ecf20Sopenharmony_ci	}
16658c2ecf20Sopenharmony_ci#endif
16668c2ecf20Sopenharmony_ci
16678c2ecf20Sopenharmony_ci	if (p) {
16688c2ecf20Sopenharmony_ci		nla = nla_reserve_64bit(skb, BRIDGE_XSTATS_STP,
16698c2ecf20Sopenharmony_ci					sizeof(p->stp_xstats),
16708c2ecf20Sopenharmony_ci					BRIDGE_XSTATS_PAD);
16718c2ecf20Sopenharmony_ci		if (!nla)
16728c2ecf20Sopenharmony_ci			goto nla_put_failure;
16738c2ecf20Sopenharmony_ci
16748c2ecf20Sopenharmony_ci		spin_lock_bh(&br->lock);
16758c2ecf20Sopenharmony_ci		memcpy(nla_data(nla), &p->stp_xstats, sizeof(p->stp_xstats));
16768c2ecf20Sopenharmony_ci		spin_unlock_bh(&br->lock);
16778c2ecf20Sopenharmony_ci	}
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
16808c2ecf20Sopenharmony_ci	*prividx = 0;
16818c2ecf20Sopenharmony_ci
16828c2ecf20Sopenharmony_ci	return 0;
16838c2ecf20Sopenharmony_ci
16848c2ecf20Sopenharmony_cinla_put_failure:
16858c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
16868c2ecf20Sopenharmony_ci	*prividx = vl_idx;
16878c2ecf20Sopenharmony_ci
16888c2ecf20Sopenharmony_ci	return -EMSGSIZE;
16898c2ecf20Sopenharmony_ci}
16908c2ecf20Sopenharmony_ci
16918c2ecf20Sopenharmony_cistatic struct rtnl_af_ops br_af_ops __read_mostly = {
16928c2ecf20Sopenharmony_ci	.family			= AF_BRIDGE,
16938c2ecf20Sopenharmony_ci	.get_link_af_size	= br_get_link_af_size_filtered,
16948c2ecf20Sopenharmony_ci};
16958c2ecf20Sopenharmony_ci
16968c2ecf20Sopenharmony_cistruct rtnl_link_ops br_link_ops __read_mostly = {
16978c2ecf20Sopenharmony_ci	.kind			= "bridge",
16988c2ecf20Sopenharmony_ci	.priv_size		= sizeof(struct net_bridge),
16998c2ecf20Sopenharmony_ci	.setup			= br_dev_setup,
17008c2ecf20Sopenharmony_ci	.maxtype		= IFLA_BR_MAX,
17018c2ecf20Sopenharmony_ci	.policy			= br_policy,
17028c2ecf20Sopenharmony_ci	.validate		= br_validate,
17038c2ecf20Sopenharmony_ci	.newlink		= br_dev_newlink,
17048c2ecf20Sopenharmony_ci	.changelink		= br_changelink,
17058c2ecf20Sopenharmony_ci	.dellink		= br_dev_delete,
17068c2ecf20Sopenharmony_ci	.get_size		= br_get_size,
17078c2ecf20Sopenharmony_ci	.fill_info		= br_fill_info,
17088c2ecf20Sopenharmony_ci	.fill_linkxstats	= br_fill_linkxstats,
17098c2ecf20Sopenharmony_ci	.get_linkxstats_size	= br_get_linkxstats_size,
17108c2ecf20Sopenharmony_ci
17118c2ecf20Sopenharmony_ci	.slave_maxtype		= IFLA_BRPORT_MAX,
17128c2ecf20Sopenharmony_ci	.slave_policy		= br_port_policy,
17138c2ecf20Sopenharmony_ci	.slave_changelink	= br_port_slave_changelink,
17148c2ecf20Sopenharmony_ci	.get_slave_size		= br_port_get_slave_size,
17158c2ecf20Sopenharmony_ci	.fill_slave_info	= br_port_fill_slave_info,
17168c2ecf20Sopenharmony_ci};
17178c2ecf20Sopenharmony_ci
17188c2ecf20Sopenharmony_ciint __init br_netlink_init(void)
17198c2ecf20Sopenharmony_ci{
17208c2ecf20Sopenharmony_ci	int err;
17218c2ecf20Sopenharmony_ci
17228c2ecf20Sopenharmony_ci	br_mdb_init();
17238c2ecf20Sopenharmony_ci	br_vlan_rtnl_init();
17248c2ecf20Sopenharmony_ci	rtnl_af_register(&br_af_ops);
17258c2ecf20Sopenharmony_ci
17268c2ecf20Sopenharmony_ci	err = rtnl_link_register(&br_link_ops);
17278c2ecf20Sopenharmony_ci	if (err)
17288c2ecf20Sopenharmony_ci		goto out_af;
17298c2ecf20Sopenharmony_ci
17308c2ecf20Sopenharmony_ci	return 0;
17318c2ecf20Sopenharmony_ci
17328c2ecf20Sopenharmony_ciout_af:
17338c2ecf20Sopenharmony_ci	rtnl_af_unregister(&br_af_ops);
17348c2ecf20Sopenharmony_ci	br_mdb_uninit();
17358c2ecf20Sopenharmony_ci	return err;
17368c2ecf20Sopenharmony_ci}
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_civoid br_netlink_fini(void)
17398c2ecf20Sopenharmony_ci{
17408c2ecf20Sopenharmony_ci	br_mdb_uninit();
17418c2ecf20Sopenharmony_ci	br_vlan_rtnl_uninit();
17428c2ecf20Sopenharmony_ci	rtnl_af_unregister(&br_af_ops);
17438c2ecf20Sopenharmony_ci	rtnl_link_unregister(&br_link_ops);
17448c2ecf20Sopenharmony_ci}
1745