xref: /openbmc/linux/net/bridge/br_private.h (revision ae039350)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *	Linux ethernet bridge
4  *
5  *	Authors:
6  *	Lennert Buytenhek		<buytenh@gnu.org>
7  */
8 
9 #ifndef _BR_PRIVATE_H
10 #define _BR_PRIVATE_H
11 
12 #include <linux/netdevice.h>
13 #include <linux/if_bridge.h>
14 #include <linux/netpoll.h>
15 #include <linux/u64_stats_sync.h>
16 #include <net/route.h>
17 #include <net/ip6_fib.h>
18 #include <linux/if_vlan.h>
19 #include <linux/rhashtable.h>
20 #include <linux/refcount.h>
21 
22 #define BR_HASH_BITS 8
23 #define BR_HASH_SIZE (1 << BR_HASH_BITS)
24 
25 #define BR_HOLD_TIME (1*HZ)
26 
27 #define BR_PORT_BITS	10
28 #define BR_MAX_PORTS	(1<<BR_PORT_BITS)
29 
30 #define BR_MULTICAST_DEFAULT_HASH_MAX 4096
31 
32 #define BR_HWDOM_MAX BITS_PER_LONG
33 
34 #define BR_VERSION	"2.3"
35 
36 /* Control of forwarding link local multicast */
37 #define BR_GROUPFWD_DEFAULT	0
38 /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
39 enum {
40 	BR_GROUPFWD_STP		= BIT(0),
41 	BR_GROUPFWD_MACPAUSE	= BIT(1),
42 	BR_GROUPFWD_LACP	= BIT(2),
43 };
44 
45 #define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \
46 				BR_GROUPFWD_LACP)
47 /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
48 #define BR_GROUPFWD_8021AD	0xB801u
49 
50 /* Path to usermode spanning tree program */
51 #define BR_STP_PROG	"/sbin/bridge-stp"
52 
53 #define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT)
54 
55 typedef struct bridge_id bridge_id;
56 typedef struct mac_addr mac_addr;
57 typedef __u16 port_id;
58 
59 struct bridge_id {
60 	unsigned char	prio[2];
61 	unsigned char	addr[ETH_ALEN];
62 };
63 
64 struct mac_addr {
65 	unsigned char	addr[ETH_ALEN];
66 };
67 
68 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
69 /* our own querier */
70 struct bridge_mcast_own_query {
71 	struct timer_list	timer;
72 	u32			startup_sent;
73 };
74 
75 /* other querier */
76 struct bridge_mcast_other_query {
77 	struct timer_list		timer;
78 	unsigned long			delay_time;
79 };
80 
81 /* selected querier */
82 struct bridge_mcast_querier {
83 	struct br_ip addr;
84 	int port_ifidx;
85 	seqcount_spinlock_t seq;
86 };
87 
88 /* IGMP/MLD statistics */
89 struct bridge_mcast_stats {
90 	struct br_mcast_stats mstats;
91 	struct u64_stats_sync syncp;
92 };
93 #endif
94 
95 /* net_bridge_mcast_port must be always defined due to forwarding stubs */
96 struct net_bridge_mcast_port {
97 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
98 	struct net_bridge_port		*port;
99 	struct net_bridge_vlan		*vlan;
100 
101 	struct bridge_mcast_own_query	ip4_own_query;
102 	struct timer_list		ip4_mc_router_timer;
103 	struct hlist_node		ip4_rlist;
104 #if IS_ENABLED(CONFIG_IPV6)
105 	struct bridge_mcast_own_query	ip6_own_query;
106 	struct timer_list		ip6_mc_router_timer;
107 	struct hlist_node		ip6_rlist;
108 #endif /* IS_ENABLED(CONFIG_IPV6) */
109 	unsigned char			multicast_router;
110 #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */
111 };
112 
113 /* net_bridge_mcast must be always defined due to forwarding stubs */
114 struct net_bridge_mcast {
115 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
116 	struct net_bridge		*br;
117 	struct net_bridge_vlan		*vlan;
118 
119 	u32				multicast_last_member_count;
120 	u32				multicast_startup_query_count;
121 
122 	u8				multicast_querier;
123 	u8				multicast_igmp_version;
124 	u8				multicast_router;
125 #if IS_ENABLED(CONFIG_IPV6)
126 	u8				multicast_mld_version;
127 #endif
128 	unsigned long			multicast_last_member_interval;
129 	unsigned long			multicast_membership_interval;
130 	unsigned long			multicast_querier_interval;
131 	unsigned long			multicast_query_interval;
132 	unsigned long			multicast_query_response_interval;
133 	unsigned long			multicast_startup_query_interval;
134 	struct hlist_head		ip4_mc_router_list;
135 	struct timer_list		ip4_mc_router_timer;
136 	struct bridge_mcast_other_query	ip4_other_query;
137 	struct bridge_mcast_own_query	ip4_own_query;
138 	struct bridge_mcast_querier	ip4_querier;
139 #if IS_ENABLED(CONFIG_IPV6)
140 	struct hlist_head		ip6_mc_router_list;
141 	struct timer_list		ip6_mc_router_timer;
142 	struct bridge_mcast_other_query	ip6_other_query;
143 	struct bridge_mcast_own_query	ip6_own_query;
144 	struct bridge_mcast_querier	ip6_querier;
145 #endif /* IS_ENABLED(CONFIG_IPV6) */
146 #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */
147 };
148 
149 struct br_tunnel_info {
150 	__be64				tunnel_id;
151 	struct metadata_dst __rcu	*tunnel_dst;
152 };
153 
154 /* private vlan flags */
155 enum {
156 	BR_VLFLAG_PER_PORT_STATS = BIT(0),
157 	BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1),
158 	BR_VLFLAG_MCAST_ENABLED = BIT(2),
159 	BR_VLFLAG_GLOBAL_MCAST_ENABLED = BIT(3),
160 };
161 
162 /**
163  * struct net_bridge_vlan - per-vlan entry
164  *
165  * @vnode: rhashtable member
166  * @vid: VLAN id
167  * @flags: bridge vlan flags
168  * @priv_flags: private (in-kernel) bridge vlan flags
169  * @state: STP state (e.g. blocking, learning, forwarding)
170  * @stats: per-cpu VLAN statistics
171  * @br: if MASTER flag set, this points to a bridge struct
172  * @port: if MASTER flag unset, this points to a port struct
173  * @refcnt: if MASTER flag set, this is bumped for each port referencing it
174  * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
175  *          for this VLAN entry
176  * @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context
177  * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast
178  *                  context
179  * @vlist: sorted list of VLAN entries
180  * @rcu: used for entry destruction
181  *
182  * This structure is shared between the global per-VLAN entries contained in
183  * the bridge rhashtable and the local per-port per-VLAN entries contained in
184  * the port's rhashtable. The union entries should be interpreted depending on
185  * the entry flags that are set.
186  */
187 struct net_bridge_vlan {
188 	struct rhash_head		vnode;
189 	struct rhash_head		tnode;
190 	u16				vid;
191 	u16				flags;
192 	u16				priv_flags;
193 	u8				state;
194 	struct pcpu_sw_netstats __percpu *stats;
195 	union {
196 		struct net_bridge	*br;
197 		struct net_bridge_port	*port;
198 	};
199 	union {
200 		refcount_t		refcnt;
201 		struct net_bridge_vlan	*brvlan;
202 	};
203 
204 	struct br_tunnel_info		tinfo;
205 
206 	union {
207 		struct net_bridge_mcast		br_mcast_ctx;
208 		struct net_bridge_mcast_port	port_mcast_ctx;
209 	};
210 
211 	struct list_head		vlist;
212 
213 	struct rcu_head			rcu;
214 };
215 
216 /**
217  * struct net_bridge_vlan_group
218  *
219  * @vlan_hash: VLAN entry rhashtable
220  * @vlan_list: sorted VLAN entry list
221  * @num_vlans: number of total VLAN entries
222  * @pvid: PVID VLAN id
223  * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking)
224  *
225  * IMPORTANT: Be careful when checking if there're VLAN entries using list
226  *            primitives because the bridge can have entries in its list which
227  *            are just for global context but not for filtering, i.e. they have
228  *            the master flag set but not the brentry flag. If you have to check
229  *            if there're "real" entries in the bridge please test @num_vlans
230  */
231 struct net_bridge_vlan_group {
232 	struct rhashtable		vlan_hash;
233 	struct rhashtable		tunnel_hash;
234 	struct list_head		vlan_list;
235 	u16				num_vlans;
236 	u16				pvid;
237 	u8				pvid_state;
238 };
239 
240 /* bridge fdb flags */
241 enum {
242 	BR_FDB_LOCAL,
243 	BR_FDB_STATIC,
244 	BR_FDB_STICKY,
245 	BR_FDB_ADDED_BY_USER,
246 	BR_FDB_ADDED_BY_EXT_LEARN,
247 	BR_FDB_OFFLOADED,
248 	BR_FDB_NOTIFY,
249 	BR_FDB_NOTIFY_INACTIVE
250 };
251 
252 struct net_bridge_fdb_key {
253 	mac_addr addr;
254 	u16 vlan_id;
255 };
256 
257 struct net_bridge_fdb_entry {
258 	struct rhash_head		rhnode;
259 	struct net_bridge_port		*dst;
260 
261 	struct net_bridge_fdb_key	key;
262 	struct hlist_node		fdb_node;
263 	unsigned long			flags;
264 
265 	/* write-heavy members should not affect lookups */
266 	unsigned long			updated ____cacheline_aligned_in_smp;
267 	unsigned long			used;
268 
269 	struct rcu_head			rcu;
270 };
271 
272 #define MDB_PG_FLAGS_PERMANENT	BIT(0)
273 #define MDB_PG_FLAGS_OFFLOAD	BIT(1)
274 #define MDB_PG_FLAGS_FAST_LEAVE	BIT(2)
275 #define MDB_PG_FLAGS_STAR_EXCL	BIT(3)
276 #define MDB_PG_FLAGS_BLOCKED	BIT(4)
277 
278 #define PG_SRC_ENT_LIMIT	32
279 
280 #define BR_SGRP_F_DELETE	BIT(0)
281 #define BR_SGRP_F_SEND		BIT(1)
282 #define BR_SGRP_F_INSTALLED	BIT(2)
283 
284 struct net_bridge_mcast_gc {
285 	struct hlist_node		gc_node;
286 	void				(*destroy)(struct net_bridge_mcast_gc *gc);
287 };
288 
289 struct net_bridge_group_src {
290 	struct hlist_node		node;
291 
292 	struct br_ip			addr;
293 	struct net_bridge_port_group	*pg;
294 	u8				flags;
295 	u8				src_query_rexmit_cnt;
296 	struct timer_list		timer;
297 
298 	struct net_bridge		*br;
299 	struct net_bridge_mcast_gc	mcast_gc;
300 	struct rcu_head			rcu;
301 };
302 
303 struct net_bridge_port_group_sg_key {
304 	struct net_bridge_port		*port;
305 	struct br_ip			addr;
306 };
307 
308 struct net_bridge_port_group {
309 	struct net_bridge_port_group __rcu *next;
310 	struct net_bridge_port_group_sg_key key;
311 	unsigned char			eth_addr[ETH_ALEN] __aligned(2);
312 	unsigned char			flags;
313 	unsigned char			filter_mode;
314 	unsigned char			grp_query_rexmit_cnt;
315 	unsigned char			rt_protocol;
316 
317 	struct hlist_head		src_list;
318 	unsigned int			src_ents;
319 	struct timer_list		timer;
320 	struct timer_list		rexmit_timer;
321 	struct hlist_node		mglist;
322 	struct rb_root			eht_set_tree;
323 	struct rb_root			eht_host_tree;
324 
325 	struct rhash_head		rhnode;
326 	struct net_bridge_mcast_gc	mcast_gc;
327 	struct rcu_head			rcu;
328 };
329 
330 struct net_bridge_mdb_entry {
331 	struct rhash_head		rhnode;
332 	struct net_bridge		*br;
333 	struct net_bridge_port_group __rcu *ports;
334 	struct br_ip			addr;
335 	bool				host_joined;
336 
337 	struct timer_list		timer;
338 	struct hlist_node		mdb_node;
339 
340 	struct net_bridge_mcast_gc	mcast_gc;
341 	struct rcu_head			rcu;
342 };
343 
344 struct net_bridge_port {
345 	struct net_bridge		*br;
346 	struct net_device		*dev;
347 	struct list_head		list;
348 
349 	unsigned long			flags;
350 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
351 	struct net_bridge_vlan_group	__rcu *vlgrp;
352 #endif
353 	struct net_bridge_port		__rcu *backup_port;
354 
355 	/* STP */
356 	u8				priority;
357 	u8				state;
358 	u16				port_no;
359 	unsigned char			topology_change_ack;
360 	unsigned char			config_pending;
361 	port_id				port_id;
362 	port_id				designated_port;
363 	bridge_id			designated_root;
364 	bridge_id			designated_bridge;
365 	u32				path_cost;
366 	u32				designated_cost;
367 	unsigned long			designated_age;
368 
369 	struct timer_list		forward_delay_timer;
370 	struct timer_list		hold_timer;
371 	struct timer_list		message_age_timer;
372 	struct kobject			kobj;
373 	struct rcu_head			rcu;
374 
375 	struct net_bridge_mcast_port	multicast_ctx;
376 
377 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
378 	struct bridge_mcast_stats	__percpu *mcast_stats;
379 
380 	u32				multicast_eht_hosts_limit;
381 	u32				multicast_eht_hosts_cnt;
382 	struct hlist_head		mglist;
383 #endif
384 
385 #ifdef CONFIG_SYSFS
386 	char				sysfs_name[IFNAMSIZ];
387 #endif
388 
389 #ifdef CONFIG_NET_POLL_CONTROLLER
390 	struct netpoll			*np;
391 #endif
392 #ifdef CONFIG_NET_SWITCHDEV
393 	/* Identifier used to group ports that share the same switchdev
394 	 * hardware domain.
395 	 */
396 	int				hwdom;
397 	int				offload_count;
398 	struct netdev_phys_item_id	ppid;
399 #endif
400 	u16				group_fwd_mask;
401 	u16				backup_redirected_cnt;
402 
403 	struct bridge_stp_xstats	stp_xstats;
404 };
405 
406 #define kobj_to_brport(obj)	container_of(obj, struct net_bridge_port, kobj)
407 
408 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
409 #define br_promisc_port(p) ((p)->flags & BR_PROMISC)
410 
411 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
412 {
413 	return rcu_dereference(dev->rx_handler_data);
414 }
415 
416 static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
417 {
418 	return netif_is_bridge_port(dev) ?
419 		rtnl_dereference(dev->rx_handler_data) : NULL;
420 }
421 
422 static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
423 {
424 	return netif_is_bridge_port(dev) ?
425 		rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
426 }
427 
428 enum net_bridge_opts {
429 	BROPT_VLAN_ENABLED,
430 	BROPT_VLAN_STATS_ENABLED,
431 	BROPT_NF_CALL_IPTABLES,
432 	BROPT_NF_CALL_IP6TABLES,
433 	BROPT_NF_CALL_ARPTABLES,
434 	BROPT_GROUP_ADDR_SET,
435 	BROPT_MULTICAST_ENABLED,
436 	BROPT_MULTICAST_QUERY_USE_IFADDR,
437 	BROPT_MULTICAST_STATS_ENABLED,
438 	BROPT_HAS_IPV6_ADDR,
439 	BROPT_NEIGH_SUPPRESS_ENABLED,
440 	BROPT_MTU_SET_BY_USER,
441 	BROPT_VLAN_STATS_PER_PORT,
442 	BROPT_NO_LL_LEARN,
443 	BROPT_VLAN_BRIDGE_BINDING,
444 	BROPT_MCAST_VLAN_SNOOPING_ENABLED,
445 };
446 
447 struct net_bridge {
448 	spinlock_t			lock;
449 	spinlock_t			hash_lock;
450 	struct hlist_head		frame_type_list;
451 	struct net_device		*dev;
452 	unsigned long			options;
453 	/* These fields are accessed on each packet */
454 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
455 	__be16				vlan_proto;
456 	u16				default_pvid;
457 	struct net_bridge_vlan_group	__rcu *vlgrp;
458 #endif
459 
460 	struct rhashtable		fdb_hash_tbl;
461 	struct list_head		port_list;
462 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
463 	union {
464 		struct rtable		fake_rtable;
465 		struct rt6_info		fake_rt6_info;
466 	};
467 #endif
468 	u16				group_fwd_mask;
469 	u16				group_fwd_mask_required;
470 
471 	/* STP */
472 	bridge_id			designated_root;
473 	bridge_id			bridge_id;
474 	unsigned char			topology_change;
475 	unsigned char			topology_change_detected;
476 	u16				root_port;
477 	unsigned long			max_age;
478 	unsigned long			hello_time;
479 	unsigned long			forward_delay;
480 	unsigned long			ageing_time;
481 	unsigned long			bridge_max_age;
482 	unsigned long			bridge_hello_time;
483 	unsigned long			bridge_forward_delay;
484 	unsigned long			bridge_ageing_time;
485 	u32				root_path_cost;
486 
487 	u8				group_addr[ETH_ALEN];
488 
489 	enum {
490 		BR_NO_STP, 		/* no spanning tree */
491 		BR_KERNEL_STP,		/* old STP in kernel */
492 		BR_USER_STP,		/* new RSTP in userspace */
493 	} stp_enabled;
494 
495 	struct net_bridge_mcast		multicast_ctx;
496 
497 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
498 	struct bridge_mcast_stats	__percpu *mcast_stats;
499 
500 	u32				hash_max;
501 
502 	spinlock_t			multicast_lock;
503 
504 	struct rhashtable		mdb_hash_tbl;
505 	struct rhashtable		sg_port_tbl;
506 
507 	struct hlist_head		mcast_gc_list;
508 	struct hlist_head		mdb_list;
509 
510 	struct work_struct		mcast_gc_work;
511 #endif
512 
513 	struct timer_list		hello_timer;
514 	struct timer_list		tcn_timer;
515 	struct timer_list		topology_change_timer;
516 	struct delayed_work		gc_work;
517 	struct kobject			*ifobj;
518 	u32				auto_cnt;
519 
520 #ifdef CONFIG_NET_SWITCHDEV
521 	/* Counter used to make sure that hardware domains get unique
522 	 * identifiers in case a bridge spans multiple switchdev instances.
523 	 */
524 	int				last_hwdom;
525 	/* Bit mask of hardware domain numbers in use */
526 	unsigned long			busy_hwdoms;
527 #endif
528 	struct hlist_head		fdb_list;
529 
530 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
531 	struct hlist_head		mrp_list;
532 #endif
533 #if IS_ENABLED(CONFIG_BRIDGE_CFM)
534 	struct hlist_head		mep_list;
535 #endif
536 };
537 
538 struct br_input_skb_cb {
539 	struct net_device *brdev;
540 
541 	u16 frag_max_size;
542 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
543 	u8 igmp;
544 	u8 mrouters_only:1;
545 #endif
546 	u8 proxyarp_replied:1;
547 	u8 src_port_isolated:1;
548 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
549 	u8 vlan_filtered:1;
550 #endif
551 #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
552 	u8 br_netfilter_broute:1;
553 #endif
554 
555 #ifdef CONFIG_NET_SWITCHDEV
556 	/* Set if TX data plane offloading is used towards at least one
557 	 * hardware domain.
558 	 */
559 	u8 tx_fwd_offload:1;
560 	/* The switchdev hardware domain from which this packet was received.
561 	 * If skb->offload_fwd_mark was set, then this packet was already
562 	 * forwarded by hardware to the other ports in the source hardware
563 	 * domain, otherwise it wasn't.
564 	 */
565 	int src_hwdom;
566 	/* Bit mask of hardware domains towards this packet has already been
567 	 * transmitted using the TX data plane offload.
568 	 */
569 	unsigned long fwd_hwdoms;
570 #endif
571 };
572 
573 #define BR_INPUT_SKB_CB(__skb)	((struct br_input_skb_cb *)(__skb)->cb)
574 
575 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
576 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(BR_INPUT_SKB_CB(__skb)->mrouters_only)
577 #else
578 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(0)
579 #endif
580 
581 #define br_printk(level, br, format, args...)	\
582 	printk(level "%s: " format, (br)->dev->name, ##args)
583 
584 #define br_err(__br, format, args...)			\
585 	br_printk(KERN_ERR, __br, format, ##args)
586 #define br_warn(__br, format, args...)			\
587 	br_printk(KERN_WARNING, __br, format, ##args)
588 #define br_notice(__br, format, args...)		\
589 	br_printk(KERN_NOTICE, __br, format, ##args)
590 #define br_info(__br, format, args...)			\
591 	br_printk(KERN_INFO, __br, format, ##args)
592 
593 #define br_debug(br, format, args...)			\
594 	pr_debug("%s: " format,  (br)->dev->name, ##args)
595 
596 /* called under bridge lock */
597 static inline int br_is_root_bridge(const struct net_bridge *br)
598 {
599 	return !memcmp(&br->bridge_id, &br->designated_root, 8);
600 }
601 
602 /* check if a VLAN entry is global */
603 static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
604 {
605 	return v->flags & BRIDGE_VLAN_INFO_MASTER;
606 }
607 
608 /* check if a VLAN entry is used by the bridge */
609 static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
610 {
611 	return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
612 }
613 
614 /* check if we should use the vlan entry, returns false if it's only context */
615 static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
616 {
617 	if (br_vlan_is_master(v)) {
618 		if (br_vlan_is_brentry(v))
619 			return true;
620 		else
621 			return false;
622 	}
623 
624 	return true;
625 }
626 
627 static inline bool nbp_state_should_learn(const struct net_bridge_port *p)
628 {
629 	return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING;
630 }
631 
632 static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack)
633 {
634 	bool ret = vid > 0 && vid < VLAN_VID_MASK;
635 
636 	if (!ret)
637 		NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid");
638 
639 	return ret;
640 }
641 
642 static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
643 				       const struct bridge_vlan_info *last,
644 				       struct netlink_ext_ack *extack)
645 {
646 	/* pvid flag is not allowed in ranges */
647 	if (cur->flags & BRIDGE_VLAN_INFO_PVID) {
648 		NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range");
649 		return false;
650 	}
651 
652 	/* when cur is the range end, check if:
653 	 *  - it has range start flag
654 	 *  - range ids are invalid (end is equal to or before start)
655 	 */
656 	if (last) {
657 		if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
658 			NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one");
659 			return false;
660 		} else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) {
661 			NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing");
662 			return false;
663 		} else if (cur->vid <= last->vid) {
664 			NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
665 			return false;
666 		}
667 	}
668 
669 	/* check for required range flags */
670 	if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
671 			    BRIDGE_VLAN_INFO_RANGE_END))) {
672 		NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing");
673 		return false;
674 	}
675 
676 	return true;
677 }
678 
679 static inline u8 br_vlan_multicast_router(const struct net_bridge_vlan *v)
680 {
681 	u8 mcast_router = MDB_RTR_TYPE_DISABLED;
682 
683 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
684 	if (!br_vlan_is_master(v))
685 		mcast_router = v->port_mcast_ctx.multicast_router;
686 	else
687 		mcast_router = v->br_mcast_ctx.multicast_router;
688 #endif
689 
690 	return mcast_router;
691 }
692 
693 static inline int br_afspec_cmd_to_rtm(int cmd)
694 {
695 	switch (cmd) {
696 	case RTM_SETLINK:
697 		return RTM_NEWVLAN;
698 	case RTM_DELLINK:
699 		return RTM_DELVLAN;
700 	}
701 
702 	return 0;
703 }
704 
705 static inline int br_opt_get(const struct net_bridge *br,
706 			     enum net_bridge_opts opt)
707 {
708 	return test_bit(opt, &br->options);
709 }
710 
711 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
712 		      struct netlink_ext_ack *extack);
713 int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
714 int br_boolopt_multi_toggle(struct net_bridge *br,
715 			    struct br_boolopt_multi *bm,
716 			    struct netlink_ext_ack *extack);
717 void br_boolopt_multi_get(const struct net_bridge *br,
718 			  struct br_boolopt_multi *bm);
719 void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
720 
721 /* br_device.c */
722 void br_dev_setup(struct net_device *dev);
723 void br_dev_delete(struct net_device *dev, struct list_head *list);
724 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
725 #ifdef CONFIG_NET_POLL_CONTROLLER
726 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
727 				       struct sk_buff *skb)
728 {
729 	netpoll_send_skb(p->np, skb);
730 }
731 
732 int br_netpoll_enable(struct net_bridge_port *p);
733 void br_netpoll_disable(struct net_bridge_port *p);
734 #else
735 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
736 				       struct sk_buff *skb)
737 {
738 }
739 
740 static inline int br_netpoll_enable(struct net_bridge_port *p)
741 {
742 	return 0;
743 }
744 
745 static inline void br_netpoll_disable(struct net_bridge_port *p)
746 {
747 }
748 #endif
749 
750 /* br_fdb.c */
751 int br_fdb_init(void);
752 void br_fdb_fini(void);
753 int br_fdb_hash_init(struct net_bridge *br);
754 void br_fdb_hash_fini(struct net_bridge *br);
755 void br_fdb_flush(struct net_bridge *br);
756 void br_fdb_find_delete_local(struct net_bridge *br,
757 			      const struct net_bridge_port *p,
758 			      const unsigned char *addr, u16 vid);
759 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
760 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
761 void br_fdb_cleanup(struct work_struct *work);
762 void br_fdb_delete_by_port(struct net_bridge *br,
763 			   const struct net_bridge_port *p, u16 vid, int do_all);
764 struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
765 					     const unsigned char *addr,
766 					     __u16 vid);
767 int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
768 int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
769 		   unsigned long off);
770 int br_fdb_add_local(struct net_bridge *br, struct net_bridge_port *source,
771 		     const unsigned char *addr, u16 vid);
772 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
773 		   const unsigned char *addr, u16 vid, unsigned long flags);
774 
775 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
776 		  struct net_device *dev, const unsigned char *addr, u16 vid);
777 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
778 	       const unsigned char *addr, u16 vid, u16 nlh_flags,
779 	       struct netlink_ext_ack *extack);
780 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
781 		struct net_device *dev, struct net_device *fdev, int *idx);
782 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
783 	       const unsigned char *addr, u16 vid, u32 portid, u32 seq,
784 	       struct netlink_ext_ack *extack);
785 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
786 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
787 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
788 			      const unsigned char *addr, u16 vid,
789 			      bool swdev_notify);
790 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
791 			      const unsigned char *addr, u16 vid,
792 			      bool swdev_notify);
793 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
794 			  const unsigned char *addr, u16 vid, bool offloaded);
795 
796 /* br_forward.c */
797 enum br_pkt_type {
798 	BR_PKT_UNICAST,
799 	BR_PKT_MULTICAST,
800 	BR_PKT_BROADCAST
801 };
802 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
803 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
804 		bool local_rcv, bool local_orig);
805 int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
806 void br_flood(struct net_bridge *br, struct sk_buff *skb,
807 	      enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
808 
809 /* return true if both source port and dest port are isolated */
810 static inline bool br_skb_isolated(const struct net_bridge_port *to,
811 				   const struct sk_buff *skb)
812 {
813 	return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
814 	       (to->flags & BR_ISOLATED);
815 }
816 
817 /* br_if.c */
818 void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
819 int br_add_bridge(struct net *net, const char *name);
820 int br_del_bridge(struct net *net, const char *name);
821 int br_add_if(struct net_bridge *br, struct net_device *dev,
822 	      struct netlink_ext_ack *extack);
823 int br_del_if(struct net_bridge *br, struct net_device *dev);
824 void br_mtu_auto_adjust(struct net_bridge *br);
825 netdev_features_t br_features_recompute(struct net_bridge *br,
826 					netdev_features_t features);
827 void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
828 void br_manage_promisc(struct net_bridge *br);
829 int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
830 
831 /* br_input.c */
832 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
833 rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
834 
835 struct br_frame_type {
836 	__be16			type;
837 	int			(*frame_handler)(struct net_bridge_port *port,
838 						 struct sk_buff *skb);
839 	struct hlist_node	list;
840 };
841 
842 void br_add_frame(struct net_bridge *br, struct br_frame_type *ft);
843 void br_del_frame(struct net_bridge *br, struct br_frame_type *ft);
844 
845 static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
846 {
847 	return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
848 }
849 
850 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
851 {
852 	return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev);
853 }
854 
855 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
856 {
857 	return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
858 }
859 
860 static inline struct net_bridge_port *
861 br_port_get_check_rtnl(const struct net_device *dev)
862 {
863 	return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
864 }
865 
866 /* br_ioctl.c */
867 int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq,
868 			  void __user *data, int cmd);
869 int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd,
870 		  struct ifreq *ifr, void __user *uarg);
871 
872 /* br_multicast.c */
873 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
874 int br_multicast_rcv(struct net_bridge_mcast **brmctx,
875 		     struct net_bridge_mcast_port **pmctx,
876 		     struct net_bridge_vlan *vlan,
877 		     struct sk_buff *skb, u16 vid);
878 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx,
879 					struct sk_buff *skb, u16 vid);
880 int br_multicast_add_port(struct net_bridge_port *port);
881 void br_multicast_del_port(struct net_bridge_port *port);
882 void br_multicast_enable_port(struct net_bridge_port *port);
883 void br_multicast_disable_port(struct net_bridge_port *port);
884 void br_multicast_init(struct net_bridge *br);
885 void br_multicast_join_snoopers(struct net_bridge *br);
886 void br_multicast_leave_snoopers(struct net_bridge *br);
887 void br_multicast_open(struct net_bridge *br);
888 void br_multicast_stop(struct net_bridge *br);
889 void br_multicast_dev_del(struct net_bridge *br);
890 void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb,
891 			struct net_bridge_mcast *brmctx,
892 			bool local_rcv, bool local_orig);
893 int br_multicast_set_router(struct net_bridge_mcast *brmctx, unsigned long val);
894 int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx,
895 				 unsigned long val);
896 int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router);
897 int br_multicast_toggle(struct net_bridge *br, unsigned long val,
898 			struct netlink_ext_ack *extack);
899 int br_multicast_set_querier(struct net_bridge_mcast *brmctx, unsigned long val);
900 int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
901 int br_multicast_set_igmp_version(struct net_bridge_mcast *brmctx,
902 				  unsigned long val);
903 #if IS_ENABLED(CONFIG_IPV6)
904 int br_multicast_set_mld_version(struct net_bridge_mcast *brmctx,
905 				 unsigned long val);
906 #endif
907 struct net_bridge_mdb_entry *
908 br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
909 struct net_bridge_mdb_entry *
910 br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
911 struct net_bridge_port_group *
912 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
913 			    struct net_bridge_port_group __rcu *next,
914 			    unsigned char flags, const unsigned char *src,
915 			    u8 filter_mode, u8 rt_protocol);
916 int br_mdb_hash_init(struct net_bridge *br);
917 void br_mdb_hash_fini(struct net_bridge *br);
918 void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp,
919 		   struct net_bridge_port_group *pg, int type);
920 void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx,
921 		   int type);
922 void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
923 			 struct net_bridge_port_group *pg,
924 			 struct net_bridge_port_group __rcu **pp);
925 void br_multicast_count(struct net_bridge *br,
926 			const struct net_bridge_port *p,
927 			const struct sk_buff *skb, u8 type, u8 dir);
928 int br_multicast_init_stats(struct net_bridge *br);
929 void br_multicast_uninit_stats(struct net_bridge *br);
930 void br_multicast_get_stats(const struct net_bridge *br,
931 			    const struct net_bridge_port *p,
932 			    struct br_mcast_stats *dest);
933 void br_mdb_init(void);
934 void br_mdb_uninit(void);
935 void br_multicast_host_join(const struct net_bridge_mcast *brmctx,
936 			    struct net_bridge_mdb_entry *mp, bool notify);
937 void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
938 void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg,
939 				     u8 filter_mode);
940 void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp,
941 				       struct net_bridge_port_group *sg);
942 struct net_bridge_group_src *
943 br_multicast_find_group_src(struct net_bridge_port_group *pg, struct br_ip *ip);
944 void br_multicast_del_group_src(struct net_bridge_group_src *src,
945 				bool fastleave);
946 void br_multicast_ctx_init(struct net_bridge *br,
947 			   struct net_bridge_vlan *vlan,
948 			   struct net_bridge_mcast *brmctx);
949 void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx);
950 void br_multicast_port_ctx_init(struct net_bridge_port *port,
951 				struct net_bridge_vlan *vlan,
952 				struct net_bridge_mcast_port *pmctx);
953 void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx);
954 void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on);
955 int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on,
956 				      struct netlink_ext_ack *extack);
957 bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on);
958 
959 int br_rports_fill_info(struct sk_buff *skb,
960 			const struct net_bridge_mcast *brmctx);
961 int br_multicast_dump_querier_state(struct sk_buff *skb,
962 				    const struct net_bridge_mcast *brmctx,
963 				    int nest_attr);
964 size_t br_multicast_querier_state_size(void);
965 size_t br_rports_size(const struct net_bridge_mcast *brmctx);
966 
967 static inline bool br_group_is_l2(const struct br_ip *group)
968 {
969 	return group->proto == 0;
970 }
971 
972 #define mlock_dereference(X, br) \
973 	rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
974 
975 static inline struct hlist_node *
976 br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx,
977 				  struct sk_buff *skb)
978 {
979 #if IS_ENABLED(CONFIG_IPV6)
980 	if (skb->protocol == htons(ETH_P_IPV6))
981 		return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list));
982 #endif
983 	return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list));
984 }
985 
986 static inline struct net_bridge_port *
987 br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb)
988 {
989 	struct net_bridge_mcast_port *mctx;
990 
991 #if IS_ENABLED(CONFIG_IPV6)
992 	if (skb->protocol == htons(ETH_P_IPV6))
993 		mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port,
994 					ip6_rlist);
995 	else
996 #endif
997 		mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port,
998 					ip4_rlist);
999 
1000 	if (mctx)
1001 		return mctx->port;
1002 	else
1003 		return NULL;
1004 }
1005 
1006 static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx)
1007 {
1008 	return timer_pending(&brmctx->ip4_mc_router_timer);
1009 }
1010 
1011 static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx)
1012 {
1013 #if IS_ENABLED(CONFIG_IPV6)
1014 	return timer_pending(&brmctx->ip6_mc_router_timer);
1015 #else
1016 	return false;
1017 #endif
1018 }
1019 
1020 static inline bool
1021 br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb)
1022 {
1023 	switch (brmctx->multicast_router) {
1024 	case MDB_RTR_TYPE_PERM:
1025 		return true;
1026 	case MDB_RTR_TYPE_TEMP_QUERY:
1027 		if (skb) {
1028 			if (skb->protocol == htons(ETH_P_IP))
1029 				return br_ip4_multicast_is_router(brmctx);
1030 			else if (skb->protocol == htons(ETH_P_IPV6))
1031 				return br_ip6_multicast_is_router(brmctx);
1032 		} else {
1033 			return br_ip4_multicast_is_router(brmctx) ||
1034 			       br_ip6_multicast_is_router(brmctx);
1035 		}
1036 		fallthrough;
1037 	default:
1038 		return false;
1039 	}
1040 }
1041 
1042 static inline bool
1043 __br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1044 			      struct bridge_mcast_other_query *querier,
1045 			      const bool is_ipv6)
1046 {
1047 	bool own_querier_enabled;
1048 
1049 	if (brmctx->multicast_querier) {
1050 		if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR))
1051 			own_querier_enabled = false;
1052 		else
1053 			own_querier_enabled = true;
1054 	} else {
1055 		own_querier_enabled = false;
1056 	}
1057 
1058 	return time_is_before_jiffies(querier->delay_time) &&
1059 	       (own_querier_enabled || timer_pending(&querier->timer));
1060 }
1061 
1062 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1063 					       struct ethhdr *eth,
1064 					       const struct net_bridge_mdb_entry *mdb)
1065 {
1066 	switch (eth->h_proto) {
1067 	case (htons(ETH_P_IP)):
1068 		return __br_multicast_querier_exists(brmctx,
1069 			&brmctx->ip4_other_query, false);
1070 #if IS_ENABLED(CONFIG_IPV6)
1071 	case (htons(ETH_P_IPV6)):
1072 		return __br_multicast_querier_exists(brmctx,
1073 			&brmctx->ip6_other_query, true);
1074 #endif
1075 	default:
1076 		return !!mdb && br_group_is_l2(&mdb->addr);
1077 	}
1078 }
1079 
1080 static inline bool br_multicast_is_star_g(const struct br_ip *ip)
1081 {
1082 	switch (ip->proto) {
1083 	case htons(ETH_P_IP):
1084 		return ipv4_is_zeronet(ip->src.ip4);
1085 #if IS_ENABLED(CONFIG_IPV6)
1086 	case htons(ETH_P_IPV6):
1087 		return ipv6_addr_any(&ip->src.ip6);
1088 #endif
1089 	default:
1090 		return false;
1091 	}
1092 }
1093 
1094 static inline bool
1095 br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx,
1096 				__be16 proto)
1097 {
1098 	switch (proto) {
1099 	case htons(ETH_P_IP):
1100 		return !!(brmctx->multicast_igmp_version == 3);
1101 #if IS_ENABLED(CONFIG_IPV6)
1102 	case htons(ETH_P_IPV6):
1103 		return !!(brmctx->multicast_mld_version == 2);
1104 #endif
1105 	default:
1106 		return false;
1107 	}
1108 }
1109 
1110 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1111 {
1112 	return BR_INPUT_SKB_CB(skb)->igmp;
1113 }
1114 
1115 static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx)
1116 {
1117 	return brmctx->multicast_last_member_interval *
1118 	       brmctx->multicast_last_member_count;
1119 }
1120 
1121 static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx)
1122 {
1123 	return brmctx->multicast_membership_interval;
1124 }
1125 
1126 static inline bool
1127 br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx)
1128 {
1129 	return !!brmctx->vlan;
1130 }
1131 
1132 static inline bool
1133 br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx)
1134 {
1135 	return !!pmctx->vlan;
1136 }
1137 
1138 static inline struct net_bridge_mcast *
1139 br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx)
1140 {
1141 	if (!br_multicast_port_ctx_is_vlan(pmctx))
1142 		return &pmctx->port->br->multicast_ctx;
1143 	else
1144 		return &pmctx->vlan->brvlan->br_mcast_ctx;
1145 }
1146 
1147 static inline bool
1148 br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx)
1149 {
1150 	return br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) &&
1151 	       br_multicast_ctx_is_vlan(brmctx) &&
1152 	       !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED);
1153 }
1154 
1155 static inline bool
1156 br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx)
1157 {
1158 	return br_multicast_ctx_is_vlan(brmctx) &&
1159 	       !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED);
1160 }
1161 
1162 static inline bool
1163 br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx)
1164 {
1165 	return br_multicast_port_ctx_is_vlan(pmctx) &&
1166 	       !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED);
1167 }
1168 
1169 static inline bool
1170 br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx)
1171 {
1172 	return pmctx->port->state == BR_STATE_DISABLED ||
1173 	       (br_multicast_port_ctx_is_vlan(pmctx) &&
1174 		(br_multicast_port_ctx_vlan_disabled(pmctx) ||
1175 		 pmctx->vlan->state == BR_STATE_DISABLED));
1176 }
1177 
1178 static inline bool
1179 br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx)
1180 {
1181 	return br_multicast_port_ctx_state_disabled(pmctx) ||
1182 	       pmctx->port->state == BR_STATE_BLOCKING ||
1183 	       (br_multicast_port_ctx_is_vlan(pmctx) &&
1184 		pmctx->vlan->state == BR_STATE_BLOCKING);
1185 }
1186 
1187 static inline bool
1188 br_rports_have_mc_router(const struct net_bridge_mcast *brmctx)
1189 {
1190 #if IS_ENABLED(CONFIG_IPV6)
1191 	return !hlist_empty(&brmctx->ip4_mc_router_list) ||
1192 	       !hlist_empty(&brmctx->ip6_mc_router_list);
1193 #else
1194 	return !hlist_empty(&brmctx->ip4_mc_router_list);
1195 #endif
1196 }
1197 
1198 static inline bool
1199 br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1,
1200 			       const struct net_bridge_mcast *brmctx2)
1201 {
1202 	return brmctx1->multicast_igmp_version ==
1203 	       brmctx2->multicast_igmp_version &&
1204 	       brmctx1->multicast_last_member_count ==
1205 	       brmctx2->multicast_last_member_count &&
1206 	       brmctx1->multicast_startup_query_count ==
1207 	       brmctx2->multicast_startup_query_count &&
1208 	       brmctx1->multicast_last_member_interval ==
1209 	       brmctx2->multicast_last_member_interval &&
1210 	       brmctx1->multicast_membership_interval ==
1211 	       brmctx2->multicast_membership_interval &&
1212 	       brmctx1->multicast_querier_interval ==
1213 	       brmctx2->multicast_querier_interval &&
1214 	       brmctx1->multicast_query_interval ==
1215 	       brmctx2->multicast_query_interval &&
1216 	       brmctx1->multicast_query_response_interval ==
1217 	       brmctx2->multicast_query_response_interval &&
1218 	       brmctx1->multicast_startup_query_interval ==
1219 	       brmctx2->multicast_startup_query_interval &&
1220 	       brmctx1->multicast_querier == brmctx2->multicast_querier &&
1221 	       brmctx1->multicast_router == brmctx2->multicast_router &&
1222 	       !br_rports_have_mc_router(brmctx1) &&
1223 	       !br_rports_have_mc_router(brmctx2) &&
1224 #if IS_ENABLED(CONFIG_IPV6)
1225 	       brmctx1->multicast_mld_version ==
1226 	       brmctx2->multicast_mld_version &&
1227 #endif
1228 	       true;
1229 }
1230 
1231 static inline bool
1232 br_multicast_ctx_matches_vlan_snooping(const struct net_bridge_mcast *brmctx)
1233 {
1234 	bool vlan_snooping_enabled;
1235 
1236 	vlan_snooping_enabled = !!br_opt_get(brmctx->br,
1237 					     BROPT_MCAST_VLAN_SNOOPING_ENABLED);
1238 
1239 	return !!(vlan_snooping_enabled == br_multicast_ctx_is_vlan(brmctx));
1240 }
1241 #else
1242 static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx,
1243 				   struct net_bridge_mcast_port **pmctx,
1244 				   struct net_bridge_vlan *vlan,
1245 				   struct sk_buff *skb,
1246 				   u16 vid)
1247 {
1248 	return 0;
1249 }
1250 
1251 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx,
1252 						      struct sk_buff *skb, u16 vid)
1253 {
1254 	return NULL;
1255 }
1256 
1257 static inline int br_multicast_add_port(struct net_bridge_port *port)
1258 {
1259 	return 0;
1260 }
1261 
1262 static inline void br_multicast_del_port(struct net_bridge_port *port)
1263 {
1264 }
1265 
1266 static inline void br_multicast_enable_port(struct net_bridge_port *port)
1267 {
1268 }
1269 
1270 static inline void br_multicast_disable_port(struct net_bridge_port *port)
1271 {
1272 }
1273 
1274 static inline void br_multicast_init(struct net_bridge *br)
1275 {
1276 }
1277 
1278 static inline void br_multicast_join_snoopers(struct net_bridge *br)
1279 {
1280 }
1281 
1282 static inline void br_multicast_leave_snoopers(struct net_bridge *br)
1283 {
1284 }
1285 
1286 static inline void br_multicast_open(struct net_bridge *br)
1287 {
1288 }
1289 
1290 static inline void br_multicast_stop(struct net_bridge *br)
1291 {
1292 }
1293 
1294 static inline void br_multicast_dev_del(struct net_bridge *br)
1295 {
1296 }
1297 
1298 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
1299 				      struct sk_buff *skb,
1300 				      struct net_bridge_mcast *brmctx,
1301 				      bool local_rcv, bool local_orig)
1302 {
1303 }
1304 
1305 static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx,
1306 					  struct sk_buff *skb)
1307 {
1308 	return false;
1309 }
1310 
1311 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1312 					       struct ethhdr *eth,
1313 					       const struct net_bridge_mdb_entry *mdb)
1314 {
1315 	return false;
1316 }
1317 
1318 static inline void br_mdb_init(void)
1319 {
1320 }
1321 
1322 static inline void br_mdb_uninit(void)
1323 {
1324 }
1325 
1326 static inline int br_mdb_hash_init(struct net_bridge *br)
1327 {
1328 	return 0;
1329 }
1330 
1331 static inline void br_mdb_hash_fini(struct net_bridge *br)
1332 {
1333 }
1334 
1335 static inline void br_multicast_count(struct net_bridge *br,
1336 				      const struct net_bridge_port *p,
1337 				      const struct sk_buff *skb,
1338 				      u8 type, u8 dir)
1339 {
1340 }
1341 
1342 static inline int br_multicast_init_stats(struct net_bridge *br)
1343 {
1344 	return 0;
1345 }
1346 
1347 static inline void br_multicast_uninit_stats(struct net_bridge *br)
1348 {
1349 }
1350 
1351 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1352 {
1353 	return 0;
1354 }
1355 
1356 static inline void br_multicast_ctx_init(struct net_bridge *br,
1357 					 struct net_bridge_vlan *vlan,
1358 					 struct net_bridge_mcast *brmctx)
1359 {
1360 }
1361 
1362 static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx)
1363 {
1364 }
1365 
1366 static inline void br_multicast_port_ctx_init(struct net_bridge_port *port,
1367 					      struct net_bridge_vlan *vlan,
1368 					      struct net_bridge_mcast_port *pmctx)
1369 {
1370 }
1371 
1372 static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx)
1373 {
1374 }
1375 
1376 static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan,
1377 						bool on)
1378 {
1379 }
1380 
1381 static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br,
1382 						    bool on,
1383 						    struct netlink_ext_ack *extack)
1384 {
1385 	return -EOPNOTSUPP;
1386 }
1387 
1388 static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan,
1389 						   bool on)
1390 {
1391 	return false;
1392 }
1393 
1394 static inline bool
1395 br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1,
1396 			       const struct net_bridge_mcast *brmctx2)
1397 {
1398 	return true;
1399 }
1400 #endif
1401 
1402 /* br_vlan.c */
1403 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1404 bool br_allowed_ingress(const struct net_bridge *br,
1405 			struct net_bridge_vlan_group *vg, struct sk_buff *skb,
1406 			u16 *vid, u8 *state,
1407 			struct net_bridge_vlan **vlan);
1408 bool br_allowed_egress(struct net_bridge_vlan_group *vg,
1409 		       const struct sk_buff *skb);
1410 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
1411 struct sk_buff *br_handle_vlan(struct net_bridge *br,
1412 			       const struct net_bridge_port *port,
1413 			       struct net_bridge_vlan_group *vg,
1414 			       struct sk_buff *skb);
1415 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
1416 		bool *changed, struct netlink_ext_ack *extack);
1417 int br_vlan_delete(struct net_bridge *br, u16 vid);
1418 void br_vlan_flush(struct net_bridge *br);
1419 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
1420 void br_recalculate_fwd_mask(struct net_bridge *br);
1421 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val,
1422 			  struct netlink_ext_ack *extack);
1423 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto,
1424 			struct netlink_ext_ack *extack);
1425 int br_vlan_set_proto(struct net_bridge *br, unsigned long val,
1426 		      struct netlink_ext_ack *extack);
1427 int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
1428 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
1429 int br_vlan_init(struct net_bridge *br);
1430 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val,
1431 			     struct netlink_ext_ack *extack);
1432 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
1433 			       struct netlink_ext_ack *extack);
1434 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1435 		 bool *changed, struct netlink_ext_ack *extack);
1436 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
1437 void nbp_vlan_flush(struct net_bridge_port *port);
1438 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
1439 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
1440 void br_vlan_get_stats(const struct net_bridge_vlan *v,
1441 		       struct pcpu_sw_netstats *stats);
1442 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
1443 int br_vlan_bridge_event(struct net_device *dev, unsigned long event,
1444 			 void *ptr);
1445 void br_vlan_rtnl_init(void);
1446 void br_vlan_rtnl_uninit(void);
1447 void br_vlan_notify(const struct net_bridge *br,
1448 		    const struct net_bridge_port *p,
1449 		    u16 vid, u16 vid_range,
1450 		    int cmd);
1451 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1452 			     const struct net_bridge_vlan *range_end);
1453 
1454 void br_vlan_fill_forward_path_pvid(struct net_bridge *br,
1455 				    struct net_device_path_ctx *ctx,
1456 				    struct net_device_path *path);
1457 int br_vlan_fill_forward_path_mode(struct net_bridge *br,
1458 				   struct net_bridge_port *dst,
1459 				   struct net_device_path *path);
1460 
1461 static inline struct net_bridge_vlan_group *br_vlan_group(
1462 					const struct net_bridge *br)
1463 {
1464 	return rtnl_dereference(br->vlgrp);
1465 }
1466 
1467 static inline struct net_bridge_vlan_group *nbp_vlan_group(
1468 					const struct net_bridge_port *p)
1469 {
1470 	return rtnl_dereference(p->vlgrp);
1471 }
1472 
1473 static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1474 					const struct net_bridge *br)
1475 {
1476 	return rcu_dereference(br->vlgrp);
1477 }
1478 
1479 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1480 					const struct net_bridge_port *p)
1481 {
1482 	return rcu_dereference(p->vlgrp);
1483 }
1484 
1485 /* Since bridge now depends on 8021Q module, but the time bridge sees the
1486  * skb, the vlan tag will always be present if the frame was tagged.
1487  */
1488 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
1489 {
1490 	int err = 0;
1491 
1492 	if (skb_vlan_tag_present(skb)) {
1493 		*vid = skb_vlan_tag_get_id(skb);
1494 	} else {
1495 		*vid = 0;
1496 		err = -EINVAL;
1497 	}
1498 
1499 	return err;
1500 }
1501 
1502 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
1503 {
1504 	if (!vg)
1505 		return 0;
1506 
1507 	smp_rmb();
1508 	return vg->pvid;
1509 }
1510 
1511 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1512 {
1513 	return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags;
1514 }
1515 #else
1516 static inline bool br_allowed_ingress(const struct net_bridge *br,
1517 				      struct net_bridge_vlan_group *vg,
1518 				      struct sk_buff *skb,
1519 				      u16 *vid, u8 *state,
1520 				      struct net_bridge_vlan **vlan)
1521 
1522 {
1523 	*vlan = NULL;
1524 	return true;
1525 }
1526 
1527 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
1528 				     const struct sk_buff *skb)
1529 {
1530 	return true;
1531 }
1532 
1533 static inline bool br_should_learn(struct net_bridge_port *p,
1534 				   struct sk_buff *skb, u16 *vid)
1535 {
1536 	return true;
1537 }
1538 
1539 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
1540 					     const struct net_bridge_port *port,
1541 					     struct net_bridge_vlan_group *vg,
1542 					     struct sk_buff *skb)
1543 {
1544 	return skb;
1545 }
1546 
1547 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
1548 			      bool *changed, struct netlink_ext_ack *extack)
1549 {
1550 	*changed = false;
1551 	return -EOPNOTSUPP;
1552 }
1553 
1554 static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
1555 {
1556 	return -EOPNOTSUPP;
1557 }
1558 
1559 static inline void br_vlan_flush(struct net_bridge *br)
1560 {
1561 }
1562 
1563 static inline void br_recalculate_fwd_mask(struct net_bridge *br)
1564 {
1565 }
1566 
1567 static inline int br_vlan_init(struct net_bridge *br)
1568 {
1569 	return 0;
1570 }
1571 
1572 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1573 			       bool *changed, struct netlink_ext_ack *extack)
1574 {
1575 	*changed = false;
1576 	return -EOPNOTSUPP;
1577 }
1578 
1579 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1580 {
1581 	return -EOPNOTSUPP;
1582 }
1583 
1584 static inline void nbp_vlan_flush(struct net_bridge_port *port)
1585 {
1586 }
1587 
1588 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1589 						   u16 vid)
1590 {
1591 	return NULL;
1592 }
1593 
1594 static inline int nbp_vlan_init(struct net_bridge_port *port,
1595 				struct netlink_ext_ack *extack)
1596 {
1597 	return 0;
1598 }
1599 
1600 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
1601 {
1602 	return 0;
1603 }
1604 
1605 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
1606 {
1607 	return 0;
1608 }
1609 
1610 static inline int br_vlan_filter_toggle(struct net_bridge *br,
1611 					unsigned long val,
1612 					struct netlink_ext_ack *extack)
1613 {
1614 	return -EOPNOTSUPP;
1615 }
1616 
1617 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1618 					 u32 filter_mask)
1619 {
1620 	return 0;
1621 }
1622 
1623 static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br,
1624 						  struct net_device_path_ctx *ctx,
1625 						  struct net_device_path *path)
1626 {
1627 }
1628 
1629 static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br,
1630 						 struct net_bridge_port *dst,
1631 						 struct net_device_path *path)
1632 {
1633 	return 0;
1634 }
1635 
1636 static inline struct net_bridge_vlan_group *br_vlan_group(
1637 					const struct net_bridge *br)
1638 {
1639 	return NULL;
1640 }
1641 
1642 static inline struct net_bridge_vlan_group *nbp_vlan_group(
1643 					const struct net_bridge_port *p)
1644 {
1645 	return NULL;
1646 }
1647 
1648 static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1649 					const struct net_bridge *br)
1650 {
1651 	return NULL;
1652 }
1653 
1654 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1655 					const struct net_bridge_port *p)
1656 {
1657 	return NULL;
1658 }
1659 
1660 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1661 				     struct pcpu_sw_netstats *stats)
1662 {
1663 }
1664 
1665 static inline void br_vlan_port_event(struct net_bridge_port *p,
1666 				      unsigned long event)
1667 {
1668 }
1669 
1670 static inline int br_vlan_bridge_event(struct net_device *dev,
1671 				       unsigned long event, void *ptr)
1672 {
1673 	return 0;
1674 }
1675 
1676 static inline void br_vlan_rtnl_init(void)
1677 {
1678 }
1679 
1680 static inline void br_vlan_rtnl_uninit(void)
1681 {
1682 }
1683 
1684 static inline void br_vlan_notify(const struct net_bridge *br,
1685 				  const struct net_bridge_port *p,
1686 				  u16 vid, u16 vid_range,
1687 				  int cmd)
1688 {
1689 }
1690 
1691 static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1692 					   const struct net_bridge_vlan *range_end)
1693 {
1694 	return true;
1695 }
1696 
1697 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1698 {
1699 	return 0;
1700 }
1701 
1702 #endif
1703 
1704 /* br_vlan_options.c */
1705 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1706 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
1707 			   const struct net_bridge_vlan *range_end);
1708 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
1709 size_t br_vlan_opts_nl_size(void);
1710 int br_vlan_process_options(const struct net_bridge *br,
1711 			    const struct net_bridge_port *p,
1712 			    struct net_bridge_vlan *range_start,
1713 			    struct net_bridge_vlan *range_end,
1714 			    struct nlattr **tb,
1715 			    struct netlink_ext_ack *extack);
1716 int br_vlan_rtm_process_global_options(struct net_device *dev,
1717 				       const struct nlattr *attr,
1718 				       int cmd,
1719 				       struct netlink_ext_ack *extack);
1720 bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr,
1721 					 const struct net_bridge_vlan *r_end);
1722 bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
1723 			      const struct net_bridge_vlan *v_opts);
1724 
1725 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */
1726 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v)
1727 {
1728 	return READ_ONCE(v->state);
1729 }
1730 
1731 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state)
1732 {
1733 	WRITE_ONCE(v->state, state);
1734 }
1735 
1736 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg)
1737 {
1738 	return READ_ONCE(vg->pvid_state);
1739 }
1740 
1741 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg,
1742 					  u8 state)
1743 {
1744 	WRITE_ONCE(vg->pvid_state, state);
1745 }
1746 
1747 /* learn_allow is true at ingress and false at egress */
1748 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow)
1749 {
1750 	switch (state) {
1751 	case BR_STATE_LEARNING:
1752 		return learn_allow;
1753 	case BR_STATE_FORWARDING:
1754 		return true;
1755 	default:
1756 		return false;
1757 	}
1758 }
1759 #endif
1760 
1761 struct nf_br_ops {
1762 	int (*br_dev_xmit_hook)(struct sk_buff *skb);
1763 };
1764 extern const struct nf_br_ops __rcu *nf_br_ops;
1765 
1766 /* br_netfilter.c */
1767 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1768 int br_nf_core_init(void);
1769 void br_nf_core_fini(void);
1770 void br_netfilter_rtable_init(struct net_bridge *);
1771 #else
1772 static inline int br_nf_core_init(void) { return 0; }
1773 static inline void br_nf_core_fini(void) {}
1774 #define br_netfilter_rtable_init(x)
1775 #endif
1776 
1777 /* br_stp.c */
1778 void br_set_state(struct net_bridge_port *p, unsigned int state);
1779 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1780 void br_init_port(struct net_bridge_port *p);
1781 void br_become_designated_port(struct net_bridge_port *p);
1782 
1783 void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1784 int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1785 int br_set_hello_time(struct net_bridge *br, unsigned long x);
1786 int br_set_max_age(struct net_bridge *br, unsigned long x);
1787 int __set_ageing_time(struct net_device *dev, unsigned long t);
1788 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
1789 
1790 
1791 /* br_stp_if.c */
1792 void br_stp_enable_bridge(struct net_bridge *br);
1793 void br_stp_disable_bridge(struct net_bridge *br);
1794 int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
1795 		       struct netlink_ext_ack *extack);
1796 void br_stp_enable_port(struct net_bridge_port *p);
1797 void br_stp_disable_port(struct net_bridge_port *p);
1798 bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1799 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1800 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1801 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1802 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1803 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
1804 
1805 /* br_stp_bpdu.c */
1806 struct stp_proto;
1807 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1808 		struct net_device *dev);
1809 
1810 /* br_stp_timer.c */
1811 void br_stp_timer_init(struct net_bridge *br);
1812 void br_stp_port_timer_init(struct net_bridge_port *p);
1813 unsigned long br_timer_value(const struct timer_list *timer);
1814 
1815 /* br.c */
1816 #if IS_ENABLED(CONFIG_ATM_LANE)
1817 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1818 #endif
1819 
1820 /* br_mrp.c */
1821 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
1822 int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1823 		 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1824 bool br_mrp_enabled(struct net_bridge *br);
1825 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
1826 int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
1827 #else
1828 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1829 			       struct nlattr *attr, int cmd,
1830 			       struct netlink_ext_ack *extack)
1831 {
1832 	return -EOPNOTSUPP;
1833 }
1834 
1835 static inline bool br_mrp_enabled(struct net_bridge *br)
1836 {
1837 	return false;
1838 }
1839 
1840 static inline void br_mrp_port_del(struct net_bridge *br,
1841 				   struct net_bridge_port *p)
1842 {
1843 }
1844 
1845 static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
1846 {
1847 	return 0;
1848 }
1849 
1850 #endif
1851 
1852 /* br_cfm.c */
1853 #if IS_ENABLED(CONFIG_BRIDGE_CFM)
1854 int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
1855 		 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1856 bool br_cfm_created(struct net_bridge *br);
1857 void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p);
1858 int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br);
1859 int br_cfm_status_fill_info(struct sk_buff *skb,
1860 			    struct net_bridge *br,
1861 			    bool getlink);
1862 int br_cfm_mep_count(struct net_bridge *br, u32 *count);
1863 int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count);
1864 #else
1865 static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
1866 			       struct nlattr *attr, int cmd,
1867 			       struct netlink_ext_ack *extack)
1868 {
1869 	return -EOPNOTSUPP;
1870 }
1871 
1872 static inline bool br_cfm_created(struct net_bridge *br)
1873 {
1874 	return false;
1875 }
1876 
1877 static inline void br_cfm_port_del(struct net_bridge *br,
1878 				   struct net_bridge_port *p)
1879 {
1880 }
1881 
1882 static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br)
1883 {
1884 	return -EOPNOTSUPP;
1885 }
1886 
1887 static inline int br_cfm_status_fill_info(struct sk_buff *skb,
1888 					  struct net_bridge *br,
1889 					  bool getlink)
1890 {
1891 	return -EOPNOTSUPP;
1892 }
1893 
1894 static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count)
1895 {
1896 	return -EOPNOTSUPP;
1897 }
1898 
1899 static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count)
1900 {
1901 	return -EOPNOTSUPP;
1902 }
1903 #endif
1904 
1905 /* br_netlink.c */
1906 extern struct rtnl_link_ops br_link_ops;
1907 int br_netlink_init(void);
1908 void br_netlink_fini(void);
1909 void br_ifinfo_notify(int event, const struct net_bridge *br,
1910 		      const struct net_bridge_port *port);
1911 void br_info_notify(int event, const struct net_bridge *br,
1912 		    const struct net_bridge_port *port, u32 filter);
1913 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1914 	       struct netlink_ext_ack *extack);
1915 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
1916 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
1917 	       u32 filter_mask, int nlflags);
1918 int br_process_vlan_info(struct net_bridge *br,
1919 			 struct net_bridge_port *p, int cmd,
1920 			 struct bridge_vlan_info *vinfo_curr,
1921 			 struct bridge_vlan_info **vinfo_last,
1922 			 bool *changed,
1923 			 struct netlink_ext_ack *extack);
1924 
1925 #ifdef CONFIG_SYSFS
1926 /* br_sysfs_if.c */
1927 extern const struct sysfs_ops brport_sysfs_ops;
1928 int br_sysfs_addif(struct net_bridge_port *p);
1929 int br_sysfs_renameif(struct net_bridge_port *p);
1930 
1931 /* br_sysfs_br.c */
1932 int br_sysfs_addbr(struct net_device *dev);
1933 void br_sysfs_delbr(struct net_device *dev);
1934 
1935 #else
1936 
1937 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1938 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1939 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1940 static inline void br_sysfs_delbr(struct net_device *dev) { return; }
1941 #endif /* CONFIG_SYSFS */
1942 
1943 /* br_switchdev.c */
1944 #ifdef CONFIG_NET_SWITCHDEV
1945 int br_switchdev_port_offload(struct net_bridge_port *p,
1946 			      struct net_device *dev, const void *ctx,
1947 			      struct notifier_block *atomic_nb,
1948 			      struct notifier_block *blocking_nb,
1949 			      bool tx_fwd_offload,
1950 			      struct netlink_ext_ack *extack);
1951 
1952 void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
1953 				 struct notifier_block *atomic_nb,
1954 				 struct notifier_block *blocking_nb);
1955 
1956 bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb);
1957 
1958 void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb);
1959 
1960 void nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p,
1961 					     struct sk_buff *skb);
1962 void nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p,
1963 					      struct sk_buff *skb);
1964 void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1965 			      struct sk_buff *skb);
1966 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1967 				  const struct sk_buff *skb);
1968 int br_switchdev_set_port_flag(struct net_bridge_port *p,
1969 			       unsigned long flags,
1970 			       unsigned long mask,
1971 			       struct netlink_ext_ack *extack);
1972 void br_switchdev_fdb_notify(struct net_bridge *br,
1973 			     const struct net_bridge_fdb_entry *fdb, int type);
1974 void br_switchdev_mdb_notify(struct net_device *dev,
1975 			     struct net_bridge_mdb_entry *mp,
1976 			     struct net_bridge_port_group *pg,
1977 			     int type);
1978 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1979 			       struct netlink_ext_ack *extack);
1980 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
1981 void br_switchdev_init(struct net_bridge *br);
1982 
1983 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1984 {
1985 	skb->offload_fwd_mark = 0;
1986 }
1987 #else
1988 static inline int
1989 br_switchdev_port_offload(struct net_bridge_port *p,
1990 			  struct net_device *dev, const void *ctx,
1991 			  struct notifier_block *atomic_nb,
1992 			  struct notifier_block *blocking_nb,
1993 			  bool tx_fwd_offload,
1994 			  struct netlink_ext_ack *extack)
1995 {
1996 	return -EOPNOTSUPP;
1997 }
1998 
1999 static inline void
2000 br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
2001 			    struct notifier_block *atomic_nb,
2002 			    struct notifier_block *blocking_nb)
2003 {
2004 }
2005 
2006 static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb)
2007 {
2008 	return false;
2009 }
2010 
2011 static inline void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb)
2012 {
2013 }
2014 
2015 static inline void
2016 nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p,
2017 					struct sk_buff *skb)
2018 {
2019 }
2020 
2021 static inline void
2022 nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p,
2023 					 struct sk_buff *skb)
2024 {
2025 }
2026 
2027 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
2028 					    struct sk_buff *skb)
2029 {
2030 }
2031 
2032 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
2033 						const struct sk_buff *skb)
2034 {
2035 	return true;
2036 }
2037 
2038 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
2039 					     unsigned long flags,
2040 					     unsigned long mask,
2041 					     struct netlink_ext_ack *extack)
2042 {
2043 	return 0;
2044 }
2045 
2046 static inline int br_switchdev_port_vlan_add(struct net_device *dev,
2047 					     u16 vid, u16 flags,
2048 					     struct netlink_ext_ack *extack)
2049 {
2050 	return -EOPNOTSUPP;
2051 }
2052 
2053 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
2054 {
2055 	return -EOPNOTSUPP;
2056 }
2057 
2058 static inline void
2059 br_switchdev_fdb_notify(struct net_bridge *br,
2060 			const struct net_bridge_fdb_entry *fdb, int type)
2061 {
2062 }
2063 
2064 static inline void br_switchdev_mdb_notify(struct net_device *dev,
2065 					   struct net_bridge_mdb_entry *mp,
2066 					   struct net_bridge_port_group *pg,
2067 					   int type)
2068 {
2069 }
2070 
2071 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
2072 {
2073 }
2074 
2075 static inline void br_switchdev_init(struct net_bridge *br)
2076 {
2077 }
2078 
2079 #endif /* CONFIG_NET_SWITCHDEV */
2080 
2081 /* br_arp_nd_proxy.c */
2082 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
2083 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
2084 			      u16 vid, struct net_bridge_port *p);
2085 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
2086 		       u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
2087 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
2088 #endif
2089