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