xref: /openbmc/linux/net/bridge/br_private.h (revision 85826610)
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 #endif
396 	u16				group_fwd_mask;
397 	u16				backup_redirected_cnt;
398 
399 	struct bridge_stp_xstats	stp_xstats;
400 };
401 
402 #define kobj_to_brport(obj)	container_of(obj, struct net_bridge_port, kobj)
403 
404 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
405 #define br_promisc_port(p) ((p)->flags & BR_PROMISC)
406 
407 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
408 {
409 	return rcu_dereference(dev->rx_handler_data);
410 }
411 
412 static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
413 {
414 	return netif_is_bridge_port(dev) ?
415 		rtnl_dereference(dev->rx_handler_data) : NULL;
416 }
417 
418 static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
419 {
420 	return netif_is_bridge_port(dev) ?
421 		rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
422 }
423 
424 enum net_bridge_opts {
425 	BROPT_VLAN_ENABLED,
426 	BROPT_VLAN_STATS_ENABLED,
427 	BROPT_NF_CALL_IPTABLES,
428 	BROPT_NF_CALL_IP6TABLES,
429 	BROPT_NF_CALL_ARPTABLES,
430 	BROPT_GROUP_ADDR_SET,
431 	BROPT_MULTICAST_ENABLED,
432 	BROPT_MULTICAST_QUERIER,
433 	BROPT_MULTICAST_QUERY_USE_IFADDR,
434 	BROPT_MULTICAST_STATS_ENABLED,
435 	BROPT_HAS_IPV6_ADDR,
436 	BROPT_NEIGH_SUPPRESS_ENABLED,
437 	BROPT_MTU_SET_BY_USER,
438 	BROPT_VLAN_STATS_PER_PORT,
439 	BROPT_NO_LL_LEARN,
440 	BROPT_VLAN_BRIDGE_BINDING,
441 	BROPT_MCAST_VLAN_SNOOPING_ENABLED,
442 };
443 
444 struct net_bridge {
445 	spinlock_t			lock;
446 	spinlock_t			hash_lock;
447 	struct hlist_head		frame_type_list;
448 	struct net_device		*dev;
449 	unsigned long			options;
450 	/* These fields are accessed on each packet */
451 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
452 	__be16				vlan_proto;
453 	u16				default_pvid;
454 	struct net_bridge_vlan_group	__rcu *vlgrp;
455 #endif
456 
457 	struct rhashtable		fdb_hash_tbl;
458 	struct list_head		port_list;
459 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
460 	union {
461 		struct rtable		fake_rtable;
462 		struct rt6_info		fake_rt6_info;
463 	};
464 #endif
465 	u16				group_fwd_mask;
466 	u16				group_fwd_mask_required;
467 
468 	/* STP */
469 	bridge_id			designated_root;
470 	bridge_id			bridge_id;
471 	unsigned char			topology_change;
472 	unsigned char			topology_change_detected;
473 	u16				root_port;
474 	unsigned long			max_age;
475 	unsigned long			hello_time;
476 	unsigned long			forward_delay;
477 	unsigned long			ageing_time;
478 	unsigned long			bridge_max_age;
479 	unsigned long			bridge_hello_time;
480 	unsigned long			bridge_forward_delay;
481 	unsigned long			bridge_ageing_time;
482 	u32				root_path_cost;
483 
484 	u8				group_addr[ETH_ALEN];
485 
486 	enum {
487 		BR_NO_STP, 		/* no spanning tree */
488 		BR_KERNEL_STP,		/* old STP in kernel */
489 		BR_USER_STP,		/* new RSTP in userspace */
490 	} stp_enabled;
491 
492 	struct net_bridge_mcast		multicast_ctx;
493 
494 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
495 	struct bridge_mcast_stats	__percpu *mcast_stats;
496 
497 	u32				hash_max;
498 
499 	spinlock_t			multicast_lock;
500 
501 	struct rhashtable		mdb_hash_tbl;
502 	struct rhashtable		sg_port_tbl;
503 
504 	struct hlist_head		mcast_gc_list;
505 	struct hlist_head		mdb_list;
506 
507 	struct work_struct		mcast_gc_work;
508 #endif
509 
510 	struct timer_list		hello_timer;
511 	struct timer_list		tcn_timer;
512 	struct timer_list		topology_change_timer;
513 	struct delayed_work		gc_work;
514 	struct kobject			*ifobj;
515 	u32				auto_cnt;
516 
517 #ifdef CONFIG_NET_SWITCHDEV
518 	/* Counter used to make sure that hardware domains get unique
519 	 * identifiers in case a bridge spans multiple switchdev instances.
520 	 */
521 	int				last_hwdom;
522 	/* Bit mask of hardware domain numbers in use */
523 	unsigned long			busy_hwdoms;
524 #endif
525 	struct hlist_head		fdb_list;
526 
527 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
528 	struct hlist_head		mrp_list;
529 #endif
530 #if IS_ENABLED(CONFIG_BRIDGE_CFM)
531 	struct hlist_head		mep_list;
532 #endif
533 };
534 
535 struct br_input_skb_cb {
536 	struct net_device *brdev;
537 
538 	u16 frag_max_size;
539 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
540 	u8 igmp;
541 	u8 mrouters_only:1;
542 #endif
543 	u8 proxyarp_replied:1;
544 	u8 src_port_isolated:1;
545 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
546 	u8 vlan_filtered:1;
547 #endif
548 #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
549 	u8 br_netfilter_broute:1;
550 #endif
551 
552 #ifdef CONFIG_NET_SWITCHDEV
553 	/* The switchdev hardware domain from which this packet was received.
554 	 * If skb->offload_fwd_mark was set, then this packet was already
555 	 * forwarded by hardware to the other ports in the source hardware
556 	 * domain, otherwise it wasn't.
557 	 */
558 	int src_hwdom;
559 #endif
560 };
561 
562 #define BR_INPUT_SKB_CB(__skb)	((struct br_input_skb_cb *)(__skb)->cb)
563 
564 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
565 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(BR_INPUT_SKB_CB(__skb)->mrouters_only)
566 #else
567 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(0)
568 #endif
569 
570 #define br_printk(level, br, format, args...)	\
571 	printk(level "%s: " format, (br)->dev->name, ##args)
572 
573 #define br_err(__br, format, args...)			\
574 	br_printk(KERN_ERR, __br, format, ##args)
575 #define br_warn(__br, format, args...)			\
576 	br_printk(KERN_WARNING, __br, format, ##args)
577 #define br_notice(__br, format, args...)		\
578 	br_printk(KERN_NOTICE, __br, format, ##args)
579 #define br_info(__br, format, args...)			\
580 	br_printk(KERN_INFO, __br, format, ##args)
581 
582 #define br_debug(br, format, args...)			\
583 	pr_debug("%s: " format,  (br)->dev->name, ##args)
584 
585 /* called under bridge lock */
586 static inline int br_is_root_bridge(const struct net_bridge *br)
587 {
588 	return !memcmp(&br->bridge_id, &br->designated_root, 8);
589 }
590 
591 /* check if a VLAN entry is global */
592 static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
593 {
594 	return v->flags & BRIDGE_VLAN_INFO_MASTER;
595 }
596 
597 /* check if a VLAN entry is used by the bridge */
598 static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
599 {
600 	return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
601 }
602 
603 /* check if we should use the vlan entry, returns false if it's only context */
604 static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
605 {
606 	if (br_vlan_is_master(v)) {
607 		if (br_vlan_is_brentry(v))
608 			return true;
609 		else
610 			return false;
611 	}
612 
613 	return true;
614 }
615 
616 static inline bool nbp_state_should_learn(const struct net_bridge_port *p)
617 {
618 	return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING;
619 }
620 
621 static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack)
622 {
623 	bool ret = vid > 0 && vid < VLAN_VID_MASK;
624 
625 	if (!ret)
626 		NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid");
627 
628 	return ret;
629 }
630 
631 static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
632 				       const struct bridge_vlan_info *last,
633 				       struct netlink_ext_ack *extack)
634 {
635 	/* pvid flag is not allowed in ranges */
636 	if (cur->flags & BRIDGE_VLAN_INFO_PVID) {
637 		NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range");
638 		return false;
639 	}
640 
641 	/* when cur is the range end, check if:
642 	 *  - it has range start flag
643 	 *  - range ids are invalid (end is equal to or before start)
644 	 */
645 	if (last) {
646 		if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
647 			NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one");
648 			return false;
649 		} else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) {
650 			NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing");
651 			return false;
652 		} else if (cur->vid <= last->vid) {
653 			NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
654 			return false;
655 		}
656 	}
657 
658 	/* check for required range flags */
659 	if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
660 			    BRIDGE_VLAN_INFO_RANGE_END))) {
661 		NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing");
662 		return false;
663 	}
664 
665 	return true;
666 }
667 
668 static inline int br_afspec_cmd_to_rtm(int cmd)
669 {
670 	switch (cmd) {
671 	case RTM_SETLINK:
672 		return RTM_NEWVLAN;
673 	case RTM_DELLINK:
674 		return RTM_DELVLAN;
675 	}
676 
677 	return 0;
678 }
679 
680 static inline int br_opt_get(const struct net_bridge *br,
681 			     enum net_bridge_opts opt)
682 {
683 	return test_bit(opt, &br->options);
684 }
685 
686 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
687 		      struct netlink_ext_ack *extack);
688 int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
689 int br_boolopt_multi_toggle(struct net_bridge *br,
690 			    struct br_boolopt_multi *bm,
691 			    struct netlink_ext_ack *extack);
692 void br_boolopt_multi_get(const struct net_bridge *br,
693 			  struct br_boolopt_multi *bm);
694 void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
695 
696 /* br_device.c */
697 void br_dev_setup(struct net_device *dev);
698 void br_dev_delete(struct net_device *dev, struct list_head *list);
699 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
700 #ifdef CONFIG_NET_POLL_CONTROLLER
701 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
702 				       struct sk_buff *skb)
703 {
704 	netpoll_send_skb(p->np, skb);
705 }
706 
707 int br_netpoll_enable(struct net_bridge_port *p);
708 void br_netpoll_disable(struct net_bridge_port *p);
709 #else
710 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
711 				       struct sk_buff *skb)
712 {
713 }
714 
715 static inline int br_netpoll_enable(struct net_bridge_port *p)
716 {
717 	return 0;
718 }
719 
720 static inline void br_netpoll_disable(struct net_bridge_port *p)
721 {
722 }
723 #endif
724 
725 /* br_fdb.c */
726 int br_fdb_init(void);
727 void br_fdb_fini(void);
728 int br_fdb_hash_init(struct net_bridge *br);
729 void br_fdb_hash_fini(struct net_bridge *br);
730 void br_fdb_flush(struct net_bridge *br);
731 void br_fdb_find_delete_local(struct net_bridge *br,
732 			      const struct net_bridge_port *p,
733 			      const unsigned char *addr, u16 vid);
734 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
735 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
736 void br_fdb_cleanup(struct work_struct *work);
737 void br_fdb_delete_by_port(struct net_bridge *br,
738 			   const struct net_bridge_port *p, u16 vid, int do_all);
739 struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
740 					     const unsigned char *addr,
741 					     __u16 vid);
742 int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
743 int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
744 		   unsigned long off);
745 int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
746 		  const unsigned char *addr, u16 vid);
747 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
748 		   const unsigned char *addr, u16 vid, unsigned long flags);
749 
750 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
751 		  struct net_device *dev, const unsigned char *addr, u16 vid);
752 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
753 	       const unsigned char *addr, u16 vid, u16 nlh_flags,
754 	       struct netlink_ext_ack *extack);
755 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
756 		struct net_device *dev, struct net_device *fdev, int *idx);
757 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
758 	       const unsigned char *addr, u16 vid, u32 portid, u32 seq,
759 	       struct netlink_ext_ack *extack);
760 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
761 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
762 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
763 			      const unsigned char *addr, u16 vid,
764 			      bool swdev_notify);
765 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
766 			      const unsigned char *addr, u16 vid,
767 			      bool swdev_notify);
768 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
769 			  const unsigned char *addr, u16 vid, bool offloaded);
770 
771 /* br_forward.c */
772 enum br_pkt_type {
773 	BR_PKT_UNICAST,
774 	BR_PKT_MULTICAST,
775 	BR_PKT_BROADCAST
776 };
777 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
778 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
779 		bool local_rcv, bool local_orig);
780 int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
781 void br_flood(struct net_bridge *br, struct sk_buff *skb,
782 	      enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
783 
784 /* return true if both source port and dest port are isolated */
785 static inline bool br_skb_isolated(const struct net_bridge_port *to,
786 				   const struct sk_buff *skb)
787 {
788 	return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
789 	       (to->flags & BR_ISOLATED);
790 }
791 
792 /* br_if.c */
793 void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
794 int br_add_bridge(struct net *net, const char *name);
795 int br_del_bridge(struct net *net, const char *name);
796 int br_add_if(struct net_bridge *br, struct net_device *dev,
797 	      struct netlink_ext_ack *extack);
798 int br_del_if(struct net_bridge *br, struct net_device *dev);
799 void br_mtu_auto_adjust(struct net_bridge *br);
800 netdev_features_t br_features_recompute(struct net_bridge *br,
801 					netdev_features_t features);
802 void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
803 void br_manage_promisc(struct net_bridge *br);
804 int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
805 
806 /* br_input.c */
807 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
808 rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
809 
810 struct br_frame_type {
811 	__be16			type;
812 	int			(*frame_handler)(struct net_bridge_port *port,
813 						 struct sk_buff *skb);
814 	struct hlist_node	list;
815 };
816 
817 void br_add_frame(struct net_bridge *br, struct br_frame_type *ft);
818 void br_del_frame(struct net_bridge *br, struct br_frame_type *ft);
819 
820 static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
821 {
822 	return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
823 }
824 
825 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
826 {
827 	return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev);
828 }
829 
830 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
831 {
832 	return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
833 }
834 
835 static inline struct net_bridge_port *
836 br_port_get_check_rtnl(const struct net_device *dev)
837 {
838 	return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
839 }
840 
841 /* br_ioctl.c */
842 int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
843 int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
844 			     void __user *arg);
845 
846 /* br_multicast.c */
847 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
848 int br_multicast_rcv(struct net_bridge_mcast **brmctx,
849 		     struct net_bridge_mcast_port **pmctx,
850 		     struct net_bridge_vlan *vlan,
851 		     struct sk_buff *skb, u16 vid);
852 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx,
853 					struct sk_buff *skb, u16 vid);
854 int br_multicast_add_port(struct net_bridge_port *port);
855 void br_multicast_del_port(struct net_bridge_port *port);
856 void br_multicast_enable_port(struct net_bridge_port *port);
857 void br_multicast_disable_port(struct net_bridge_port *port);
858 void br_multicast_init(struct net_bridge *br);
859 void br_multicast_join_snoopers(struct net_bridge *br);
860 void br_multicast_leave_snoopers(struct net_bridge *br);
861 void br_multicast_open(struct net_bridge *br);
862 void br_multicast_stop(struct net_bridge *br);
863 void br_multicast_dev_del(struct net_bridge *br);
864 void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb,
865 			struct net_bridge_mcast *brmctx,
866 			bool local_rcv, bool local_orig);
867 int br_multicast_set_router(struct net_bridge *br, unsigned long val);
868 int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
869 int br_multicast_toggle(struct net_bridge *br, unsigned long val,
870 			struct netlink_ext_ack *extack);
871 int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
872 int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
873 int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val);
874 #if IS_ENABLED(CONFIG_IPV6)
875 int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val);
876 #endif
877 struct net_bridge_mdb_entry *
878 br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
879 struct net_bridge_mdb_entry *
880 br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
881 struct net_bridge_port_group *
882 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
883 			    struct net_bridge_port_group __rcu *next,
884 			    unsigned char flags, const unsigned char *src,
885 			    u8 filter_mode, u8 rt_protocol);
886 int br_mdb_hash_init(struct net_bridge *br);
887 void br_mdb_hash_fini(struct net_bridge *br);
888 void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp,
889 		   struct net_bridge_port_group *pg, int type);
890 void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx,
891 		   int type);
892 void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
893 			 struct net_bridge_port_group *pg,
894 			 struct net_bridge_port_group __rcu **pp);
895 void br_multicast_count(struct net_bridge *br,
896 			const struct net_bridge_port *p,
897 			const struct sk_buff *skb, u8 type, u8 dir);
898 int br_multicast_init_stats(struct net_bridge *br);
899 void br_multicast_uninit_stats(struct net_bridge *br);
900 void br_multicast_get_stats(const struct net_bridge *br,
901 			    const struct net_bridge_port *p,
902 			    struct br_mcast_stats *dest);
903 void br_mdb_init(void);
904 void br_mdb_uninit(void);
905 void br_multicast_host_join(const struct net_bridge_mcast *brmctx,
906 			    struct net_bridge_mdb_entry *mp, bool notify);
907 void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
908 void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg,
909 				     u8 filter_mode);
910 void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp,
911 				       struct net_bridge_port_group *sg);
912 struct net_bridge_group_src *
913 br_multicast_find_group_src(struct net_bridge_port_group *pg, struct br_ip *ip);
914 void br_multicast_del_group_src(struct net_bridge_group_src *src,
915 				bool fastleave);
916 void br_multicast_ctx_init(struct net_bridge *br,
917 			   struct net_bridge_vlan *vlan,
918 			   struct net_bridge_mcast *brmctx);
919 void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx);
920 void br_multicast_port_ctx_init(struct net_bridge_port *port,
921 				struct net_bridge_vlan *vlan,
922 				struct net_bridge_mcast_port *pmctx);
923 void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx);
924 void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on);
925 void br_multicast_toggle_vlan(struct net_bridge_vlan *vlan, bool on);
926 int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on,
927 				      struct netlink_ext_ack *extack);
928 bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on);
929 
930 static inline bool br_group_is_l2(const struct br_ip *group)
931 {
932 	return group->proto == 0;
933 }
934 
935 #define mlock_dereference(X, br) \
936 	rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
937 
938 static inline struct hlist_node *
939 br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx,
940 				  struct sk_buff *skb)
941 {
942 #if IS_ENABLED(CONFIG_IPV6)
943 	if (skb->protocol == htons(ETH_P_IPV6))
944 		return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list));
945 #endif
946 	return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list));
947 }
948 
949 static inline struct net_bridge_port *
950 br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb)
951 {
952 	struct net_bridge_mcast_port *mctx;
953 
954 #if IS_ENABLED(CONFIG_IPV6)
955 	if (skb->protocol == htons(ETH_P_IPV6))
956 		mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port,
957 					ip6_rlist);
958 	else
959 #endif
960 		mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port,
961 					ip4_rlist);
962 
963 	if (mctx)
964 		return mctx->port;
965 	else
966 		return NULL;
967 }
968 
969 static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx)
970 {
971 	return timer_pending(&brmctx->ip4_mc_router_timer);
972 }
973 
974 static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx)
975 {
976 #if IS_ENABLED(CONFIG_IPV6)
977 	return timer_pending(&brmctx->ip6_mc_router_timer);
978 #else
979 	return false;
980 #endif
981 }
982 
983 static inline bool
984 br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb)
985 {
986 	switch (brmctx->multicast_router) {
987 	case MDB_RTR_TYPE_PERM:
988 		return true;
989 	case MDB_RTR_TYPE_TEMP_QUERY:
990 		if (skb) {
991 			if (skb->protocol == htons(ETH_P_IP))
992 				return br_ip4_multicast_is_router(brmctx);
993 			else if (skb->protocol == htons(ETH_P_IPV6))
994 				return br_ip6_multicast_is_router(brmctx);
995 		} else {
996 			return br_ip4_multicast_is_router(brmctx) ||
997 			       br_ip6_multicast_is_router(brmctx);
998 		}
999 		fallthrough;
1000 	default:
1001 		return false;
1002 	}
1003 }
1004 
1005 static inline bool
1006 __br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1007 			      struct bridge_mcast_other_query *querier,
1008 			      const bool is_ipv6)
1009 {
1010 	bool own_querier_enabled;
1011 
1012 	if (br_opt_get(brmctx->br, BROPT_MULTICAST_QUERIER)) {
1013 		if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR))
1014 			own_querier_enabled = false;
1015 		else
1016 			own_querier_enabled = true;
1017 	} else {
1018 		own_querier_enabled = false;
1019 	}
1020 
1021 	return time_is_before_jiffies(querier->delay_time) &&
1022 	       (own_querier_enabled || timer_pending(&querier->timer));
1023 }
1024 
1025 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1026 					       struct ethhdr *eth,
1027 					       const struct net_bridge_mdb_entry *mdb)
1028 {
1029 	switch (eth->h_proto) {
1030 	case (htons(ETH_P_IP)):
1031 		return __br_multicast_querier_exists(brmctx,
1032 			&brmctx->ip4_other_query, false);
1033 #if IS_ENABLED(CONFIG_IPV6)
1034 	case (htons(ETH_P_IPV6)):
1035 		return __br_multicast_querier_exists(brmctx,
1036 			&brmctx->ip6_other_query, true);
1037 #endif
1038 	default:
1039 		return !!mdb && br_group_is_l2(&mdb->addr);
1040 	}
1041 }
1042 
1043 static inline bool br_multicast_is_star_g(const struct br_ip *ip)
1044 {
1045 	switch (ip->proto) {
1046 	case htons(ETH_P_IP):
1047 		return ipv4_is_zeronet(ip->src.ip4);
1048 #if IS_ENABLED(CONFIG_IPV6)
1049 	case htons(ETH_P_IPV6):
1050 		return ipv6_addr_any(&ip->src.ip6);
1051 #endif
1052 	default:
1053 		return false;
1054 	}
1055 }
1056 
1057 static inline bool
1058 br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx,
1059 				__be16 proto)
1060 {
1061 	switch (proto) {
1062 	case htons(ETH_P_IP):
1063 		return !!(brmctx->multicast_igmp_version == 3);
1064 #if IS_ENABLED(CONFIG_IPV6)
1065 	case htons(ETH_P_IPV6):
1066 		return !!(brmctx->multicast_mld_version == 2);
1067 #endif
1068 	default:
1069 		return false;
1070 	}
1071 }
1072 
1073 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1074 {
1075 	return BR_INPUT_SKB_CB(skb)->igmp;
1076 }
1077 
1078 static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx)
1079 {
1080 	return brmctx->multicast_last_member_interval *
1081 	       brmctx->multicast_last_member_count;
1082 }
1083 
1084 static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx)
1085 {
1086 	/* use the RFC default of 2 for QRV */
1087 	return 2 * brmctx->multicast_query_interval +
1088 	       brmctx->multicast_query_response_interval;
1089 }
1090 
1091 static inline bool
1092 br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx)
1093 {
1094 	return !!brmctx->vlan;
1095 }
1096 
1097 static inline bool
1098 br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx)
1099 {
1100 	return !!pmctx->vlan;
1101 }
1102 
1103 static inline struct net_bridge_mcast *
1104 br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx)
1105 {
1106 	if (!br_multicast_port_ctx_is_vlan(pmctx))
1107 		return &pmctx->port->br->multicast_ctx;
1108 	else
1109 		return &pmctx->vlan->brvlan->br_mcast_ctx;
1110 }
1111 
1112 static inline bool
1113 br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx)
1114 {
1115 	return br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) &&
1116 	       br_multicast_ctx_is_vlan(brmctx) &&
1117 	       !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED);
1118 }
1119 
1120 static inline bool
1121 br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx)
1122 {
1123 	return br_multicast_ctx_is_vlan(brmctx) &&
1124 	       !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED);
1125 }
1126 
1127 static inline bool
1128 br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx)
1129 {
1130 	return br_multicast_port_ctx_is_vlan(pmctx) &&
1131 	       !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED);
1132 }
1133 
1134 static inline bool
1135 br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx)
1136 {
1137 	return pmctx->port->state == BR_STATE_DISABLED ||
1138 	       (br_multicast_port_ctx_is_vlan(pmctx) &&
1139 		(br_multicast_port_ctx_vlan_disabled(pmctx) ||
1140 		 pmctx->vlan->state == BR_STATE_DISABLED));
1141 }
1142 
1143 static inline bool
1144 br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx)
1145 {
1146 	return br_multicast_port_ctx_state_disabled(pmctx) ||
1147 	       pmctx->port->state == BR_STATE_BLOCKING ||
1148 	       (br_multicast_port_ctx_is_vlan(pmctx) &&
1149 		pmctx->vlan->state == BR_STATE_BLOCKING);
1150 }
1151 #else
1152 static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx,
1153 				   struct net_bridge_mcast_port **pmctx,
1154 				   struct net_bridge_vlan *vlan,
1155 				   struct sk_buff *skb,
1156 				   u16 vid)
1157 {
1158 	return 0;
1159 }
1160 
1161 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx,
1162 						      struct sk_buff *skb, u16 vid)
1163 {
1164 	return NULL;
1165 }
1166 
1167 static inline int br_multicast_add_port(struct net_bridge_port *port)
1168 {
1169 	return 0;
1170 }
1171 
1172 static inline void br_multicast_del_port(struct net_bridge_port *port)
1173 {
1174 }
1175 
1176 static inline void br_multicast_enable_port(struct net_bridge_port *port)
1177 {
1178 }
1179 
1180 static inline void br_multicast_disable_port(struct net_bridge_port *port)
1181 {
1182 }
1183 
1184 static inline void br_multicast_init(struct net_bridge *br)
1185 {
1186 }
1187 
1188 static inline void br_multicast_join_snoopers(struct net_bridge *br)
1189 {
1190 }
1191 
1192 static inline void br_multicast_leave_snoopers(struct net_bridge *br)
1193 {
1194 }
1195 
1196 static inline void br_multicast_open(struct net_bridge *br)
1197 {
1198 }
1199 
1200 static inline void br_multicast_stop(struct net_bridge *br)
1201 {
1202 }
1203 
1204 static inline void br_multicast_dev_del(struct net_bridge *br)
1205 {
1206 }
1207 
1208 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
1209 				      struct sk_buff *skb,
1210 				      struct net_bridge_mcast *brmctx,
1211 				      bool local_rcv, bool local_orig)
1212 {
1213 }
1214 
1215 static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx,
1216 					  struct sk_buff *skb)
1217 {
1218 	return false;
1219 }
1220 
1221 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1222 					       struct ethhdr *eth,
1223 					       const struct net_bridge_mdb_entry *mdb)
1224 {
1225 	return false;
1226 }
1227 
1228 static inline void br_mdb_init(void)
1229 {
1230 }
1231 
1232 static inline void br_mdb_uninit(void)
1233 {
1234 }
1235 
1236 static inline int br_mdb_hash_init(struct net_bridge *br)
1237 {
1238 	return 0;
1239 }
1240 
1241 static inline void br_mdb_hash_fini(struct net_bridge *br)
1242 {
1243 }
1244 
1245 static inline void br_multicast_count(struct net_bridge *br,
1246 				      const struct net_bridge_port *p,
1247 				      const struct sk_buff *skb,
1248 				      u8 type, u8 dir)
1249 {
1250 }
1251 
1252 static inline int br_multicast_init_stats(struct net_bridge *br)
1253 {
1254 	return 0;
1255 }
1256 
1257 static inline void br_multicast_uninit_stats(struct net_bridge *br)
1258 {
1259 }
1260 
1261 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1262 {
1263 	return 0;
1264 }
1265 
1266 static inline void br_multicast_ctx_init(struct net_bridge *br,
1267 					 struct net_bridge_vlan *vlan,
1268 					 struct net_bridge_mcast *brmctx)
1269 {
1270 }
1271 
1272 static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx)
1273 {
1274 }
1275 
1276 static inline void br_multicast_port_ctx_init(struct net_bridge_port *port,
1277 					      struct net_bridge_vlan *vlan,
1278 					      struct net_bridge_mcast_port *pmctx)
1279 {
1280 }
1281 
1282 static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx)
1283 {
1284 }
1285 
1286 static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan,
1287 						bool on)
1288 {
1289 }
1290 
1291 static inline void br_multicast_toggle_vlan(struct net_bridge_vlan *vlan,
1292 					    bool on)
1293 {
1294 }
1295 
1296 static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br,
1297 						    bool on,
1298 						    struct netlink_ext_ack *extack)
1299 {
1300 	return -EOPNOTSUPP;
1301 }
1302 
1303 static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan,
1304 						   bool on)
1305 {
1306 	return false;
1307 }
1308 #endif
1309 
1310 /* br_vlan.c */
1311 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1312 bool br_allowed_ingress(const struct net_bridge *br,
1313 			struct net_bridge_vlan_group *vg, struct sk_buff *skb,
1314 			u16 *vid, u8 *state,
1315 			struct net_bridge_vlan **vlan);
1316 bool br_allowed_egress(struct net_bridge_vlan_group *vg,
1317 		       const struct sk_buff *skb);
1318 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
1319 struct sk_buff *br_handle_vlan(struct net_bridge *br,
1320 			       const struct net_bridge_port *port,
1321 			       struct net_bridge_vlan_group *vg,
1322 			       struct sk_buff *skb);
1323 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
1324 		bool *changed, struct netlink_ext_ack *extack);
1325 int br_vlan_delete(struct net_bridge *br, u16 vid);
1326 void br_vlan_flush(struct net_bridge *br);
1327 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
1328 void br_recalculate_fwd_mask(struct net_bridge *br);
1329 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val,
1330 			  struct netlink_ext_ack *extack);
1331 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto,
1332 			struct netlink_ext_ack *extack);
1333 int br_vlan_set_proto(struct net_bridge *br, unsigned long val,
1334 		      struct netlink_ext_ack *extack);
1335 int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
1336 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
1337 int br_vlan_init(struct net_bridge *br);
1338 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val,
1339 			     struct netlink_ext_ack *extack);
1340 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
1341 			       struct netlink_ext_ack *extack);
1342 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1343 		 bool *changed, struct netlink_ext_ack *extack);
1344 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
1345 void nbp_vlan_flush(struct net_bridge_port *port);
1346 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
1347 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
1348 void br_vlan_get_stats(const struct net_bridge_vlan *v,
1349 		       struct pcpu_sw_netstats *stats);
1350 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
1351 int br_vlan_bridge_event(struct net_device *dev, unsigned long event,
1352 			 void *ptr);
1353 void br_vlan_rtnl_init(void);
1354 void br_vlan_rtnl_uninit(void);
1355 void br_vlan_notify(const struct net_bridge *br,
1356 		    const struct net_bridge_port *p,
1357 		    u16 vid, u16 vid_range,
1358 		    int cmd);
1359 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1360 			     const struct net_bridge_vlan *range_end);
1361 
1362 void br_vlan_fill_forward_path_pvid(struct net_bridge *br,
1363 				    struct net_device_path_ctx *ctx,
1364 				    struct net_device_path *path);
1365 int br_vlan_fill_forward_path_mode(struct net_bridge *br,
1366 				   struct net_bridge_port *dst,
1367 				   struct net_device_path *path);
1368 
1369 static inline struct net_bridge_vlan_group *br_vlan_group(
1370 					const struct net_bridge *br)
1371 {
1372 	return rtnl_dereference(br->vlgrp);
1373 }
1374 
1375 static inline struct net_bridge_vlan_group *nbp_vlan_group(
1376 					const struct net_bridge_port *p)
1377 {
1378 	return rtnl_dereference(p->vlgrp);
1379 }
1380 
1381 static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1382 					const struct net_bridge *br)
1383 {
1384 	return rcu_dereference(br->vlgrp);
1385 }
1386 
1387 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1388 					const struct net_bridge_port *p)
1389 {
1390 	return rcu_dereference(p->vlgrp);
1391 }
1392 
1393 /* Since bridge now depends on 8021Q module, but the time bridge sees the
1394  * skb, the vlan tag will always be present if the frame was tagged.
1395  */
1396 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
1397 {
1398 	int err = 0;
1399 
1400 	if (skb_vlan_tag_present(skb)) {
1401 		*vid = skb_vlan_tag_get_id(skb);
1402 	} else {
1403 		*vid = 0;
1404 		err = -EINVAL;
1405 	}
1406 
1407 	return err;
1408 }
1409 
1410 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
1411 {
1412 	if (!vg)
1413 		return 0;
1414 
1415 	smp_rmb();
1416 	return vg->pvid;
1417 }
1418 
1419 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1420 {
1421 	return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags;
1422 }
1423 #else
1424 static inline bool br_allowed_ingress(const struct net_bridge *br,
1425 				      struct net_bridge_vlan_group *vg,
1426 				      struct sk_buff *skb,
1427 				      u16 *vid, u8 *state,
1428 				      struct net_bridge_vlan **vlan)
1429 
1430 {
1431 	*vlan = NULL;
1432 	return true;
1433 }
1434 
1435 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
1436 				     const struct sk_buff *skb)
1437 {
1438 	return true;
1439 }
1440 
1441 static inline bool br_should_learn(struct net_bridge_port *p,
1442 				   struct sk_buff *skb, u16 *vid)
1443 {
1444 	return true;
1445 }
1446 
1447 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
1448 					     const struct net_bridge_port *port,
1449 					     struct net_bridge_vlan_group *vg,
1450 					     struct sk_buff *skb)
1451 {
1452 	return skb;
1453 }
1454 
1455 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
1456 			      bool *changed, struct netlink_ext_ack *extack)
1457 {
1458 	*changed = false;
1459 	return -EOPNOTSUPP;
1460 }
1461 
1462 static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
1463 {
1464 	return -EOPNOTSUPP;
1465 }
1466 
1467 static inline void br_vlan_flush(struct net_bridge *br)
1468 {
1469 }
1470 
1471 static inline void br_recalculate_fwd_mask(struct net_bridge *br)
1472 {
1473 }
1474 
1475 static inline int br_vlan_init(struct net_bridge *br)
1476 {
1477 	return 0;
1478 }
1479 
1480 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1481 			       bool *changed, struct netlink_ext_ack *extack)
1482 {
1483 	*changed = false;
1484 	return -EOPNOTSUPP;
1485 }
1486 
1487 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1488 {
1489 	return -EOPNOTSUPP;
1490 }
1491 
1492 static inline void nbp_vlan_flush(struct net_bridge_port *port)
1493 {
1494 }
1495 
1496 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1497 						   u16 vid)
1498 {
1499 	return NULL;
1500 }
1501 
1502 static inline int nbp_vlan_init(struct net_bridge_port *port,
1503 				struct netlink_ext_ack *extack)
1504 {
1505 	return 0;
1506 }
1507 
1508 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
1509 {
1510 	return 0;
1511 }
1512 
1513 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
1514 {
1515 	return 0;
1516 }
1517 
1518 static inline int br_vlan_filter_toggle(struct net_bridge *br,
1519 					unsigned long val,
1520 					struct netlink_ext_ack *extack)
1521 {
1522 	return -EOPNOTSUPP;
1523 }
1524 
1525 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1526 					 u32 filter_mask)
1527 {
1528 	return 0;
1529 }
1530 
1531 static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br,
1532 						  struct net_device_path_ctx *ctx,
1533 						  struct net_device_path *path)
1534 {
1535 }
1536 
1537 static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br,
1538 						 struct net_bridge_port *dst,
1539 						 struct net_device_path *path)
1540 {
1541 	return 0;
1542 }
1543 
1544 static inline struct net_bridge_vlan_group *br_vlan_group(
1545 					const struct net_bridge *br)
1546 {
1547 	return NULL;
1548 }
1549 
1550 static inline struct net_bridge_vlan_group *nbp_vlan_group(
1551 					const struct net_bridge_port *p)
1552 {
1553 	return NULL;
1554 }
1555 
1556 static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1557 					const struct net_bridge *br)
1558 {
1559 	return NULL;
1560 }
1561 
1562 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1563 					const struct net_bridge_port *p)
1564 {
1565 	return NULL;
1566 }
1567 
1568 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1569 				     struct pcpu_sw_netstats *stats)
1570 {
1571 }
1572 
1573 static inline void br_vlan_port_event(struct net_bridge_port *p,
1574 				      unsigned long event)
1575 {
1576 }
1577 
1578 static inline int br_vlan_bridge_event(struct net_device *dev,
1579 				       unsigned long event, void *ptr)
1580 {
1581 	return 0;
1582 }
1583 
1584 static inline void br_vlan_rtnl_init(void)
1585 {
1586 }
1587 
1588 static inline void br_vlan_rtnl_uninit(void)
1589 {
1590 }
1591 
1592 static inline void br_vlan_notify(const struct net_bridge *br,
1593 				  const struct net_bridge_port *p,
1594 				  u16 vid, u16 vid_range,
1595 				  int cmd)
1596 {
1597 }
1598 
1599 static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1600 					   const struct net_bridge_vlan *range_end)
1601 {
1602 	return true;
1603 }
1604 #endif
1605 
1606 /* br_vlan_options.c */
1607 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1608 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
1609 			   const struct net_bridge_vlan *range_end);
1610 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
1611 size_t br_vlan_opts_nl_size(void);
1612 int br_vlan_process_options(const struct net_bridge *br,
1613 			    const struct net_bridge_port *p,
1614 			    struct net_bridge_vlan *range_start,
1615 			    struct net_bridge_vlan *range_end,
1616 			    struct nlattr **tb,
1617 			    struct netlink_ext_ack *extack);
1618 int br_vlan_rtm_process_global_options(struct net_device *dev,
1619 				       const struct nlattr *attr,
1620 				       int cmd,
1621 				       struct netlink_ext_ack *extack);
1622 bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr,
1623 					 const struct net_bridge_vlan *r_end);
1624 bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
1625 			      const struct net_bridge_vlan *v_opts);
1626 
1627 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */
1628 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v)
1629 {
1630 	return READ_ONCE(v->state);
1631 }
1632 
1633 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state)
1634 {
1635 	WRITE_ONCE(v->state, state);
1636 }
1637 
1638 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg)
1639 {
1640 	return READ_ONCE(vg->pvid_state);
1641 }
1642 
1643 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg,
1644 					  u8 state)
1645 {
1646 	WRITE_ONCE(vg->pvid_state, state);
1647 }
1648 
1649 /* learn_allow is true at ingress and false at egress */
1650 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow)
1651 {
1652 	switch (state) {
1653 	case BR_STATE_LEARNING:
1654 		return learn_allow;
1655 	case BR_STATE_FORWARDING:
1656 		return true;
1657 	default:
1658 		return false;
1659 	}
1660 }
1661 #endif
1662 
1663 struct nf_br_ops {
1664 	int (*br_dev_xmit_hook)(struct sk_buff *skb);
1665 };
1666 extern const struct nf_br_ops __rcu *nf_br_ops;
1667 
1668 /* br_netfilter.c */
1669 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1670 int br_nf_core_init(void);
1671 void br_nf_core_fini(void);
1672 void br_netfilter_rtable_init(struct net_bridge *);
1673 #else
1674 static inline int br_nf_core_init(void) { return 0; }
1675 static inline void br_nf_core_fini(void) {}
1676 #define br_netfilter_rtable_init(x)
1677 #endif
1678 
1679 /* br_stp.c */
1680 void br_set_state(struct net_bridge_port *p, unsigned int state);
1681 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1682 void br_init_port(struct net_bridge_port *p);
1683 void br_become_designated_port(struct net_bridge_port *p);
1684 
1685 void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1686 int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1687 int br_set_hello_time(struct net_bridge *br, unsigned long x);
1688 int br_set_max_age(struct net_bridge *br, unsigned long x);
1689 int __set_ageing_time(struct net_device *dev, unsigned long t);
1690 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
1691 
1692 
1693 /* br_stp_if.c */
1694 void br_stp_enable_bridge(struct net_bridge *br);
1695 void br_stp_disable_bridge(struct net_bridge *br);
1696 int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
1697 		       struct netlink_ext_ack *extack);
1698 void br_stp_enable_port(struct net_bridge_port *p);
1699 void br_stp_disable_port(struct net_bridge_port *p);
1700 bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1701 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1702 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1703 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1704 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1705 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
1706 
1707 /* br_stp_bpdu.c */
1708 struct stp_proto;
1709 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1710 		struct net_device *dev);
1711 
1712 /* br_stp_timer.c */
1713 void br_stp_timer_init(struct net_bridge *br);
1714 void br_stp_port_timer_init(struct net_bridge_port *p);
1715 unsigned long br_timer_value(const struct timer_list *timer);
1716 
1717 /* br.c */
1718 #if IS_ENABLED(CONFIG_ATM_LANE)
1719 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1720 #endif
1721 
1722 /* br_mrp.c */
1723 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
1724 int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1725 		 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1726 bool br_mrp_enabled(struct net_bridge *br);
1727 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
1728 int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
1729 #else
1730 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1731 			       struct nlattr *attr, int cmd,
1732 			       struct netlink_ext_ack *extack)
1733 {
1734 	return -EOPNOTSUPP;
1735 }
1736 
1737 static inline bool br_mrp_enabled(struct net_bridge *br)
1738 {
1739 	return false;
1740 }
1741 
1742 static inline void br_mrp_port_del(struct net_bridge *br,
1743 				   struct net_bridge_port *p)
1744 {
1745 }
1746 
1747 static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
1748 {
1749 	return 0;
1750 }
1751 
1752 #endif
1753 
1754 /* br_cfm.c */
1755 #if IS_ENABLED(CONFIG_BRIDGE_CFM)
1756 int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
1757 		 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1758 bool br_cfm_created(struct net_bridge *br);
1759 void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p);
1760 int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br);
1761 int br_cfm_status_fill_info(struct sk_buff *skb,
1762 			    struct net_bridge *br,
1763 			    bool getlink);
1764 int br_cfm_mep_count(struct net_bridge *br, u32 *count);
1765 int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count);
1766 #else
1767 static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
1768 			       struct nlattr *attr, int cmd,
1769 			       struct netlink_ext_ack *extack)
1770 {
1771 	return -EOPNOTSUPP;
1772 }
1773 
1774 static inline bool br_cfm_created(struct net_bridge *br)
1775 {
1776 	return false;
1777 }
1778 
1779 static inline void br_cfm_port_del(struct net_bridge *br,
1780 				   struct net_bridge_port *p)
1781 {
1782 }
1783 
1784 static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br)
1785 {
1786 	return -EOPNOTSUPP;
1787 }
1788 
1789 static inline int br_cfm_status_fill_info(struct sk_buff *skb,
1790 					  struct net_bridge *br,
1791 					  bool getlink)
1792 {
1793 	return -EOPNOTSUPP;
1794 }
1795 
1796 static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count)
1797 {
1798 	return -EOPNOTSUPP;
1799 }
1800 
1801 static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count)
1802 {
1803 	return -EOPNOTSUPP;
1804 }
1805 #endif
1806 
1807 /* br_netlink.c */
1808 extern struct rtnl_link_ops br_link_ops;
1809 int br_netlink_init(void);
1810 void br_netlink_fini(void);
1811 void br_ifinfo_notify(int event, const struct net_bridge *br,
1812 		      const struct net_bridge_port *port);
1813 void br_info_notify(int event, const struct net_bridge *br,
1814 		    const struct net_bridge_port *port, u32 filter);
1815 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1816 	       struct netlink_ext_ack *extack);
1817 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
1818 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
1819 	       u32 filter_mask, int nlflags);
1820 int br_process_vlan_info(struct net_bridge *br,
1821 			 struct net_bridge_port *p, int cmd,
1822 			 struct bridge_vlan_info *vinfo_curr,
1823 			 struct bridge_vlan_info **vinfo_last,
1824 			 bool *changed,
1825 			 struct netlink_ext_ack *extack);
1826 
1827 #ifdef CONFIG_SYSFS
1828 /* br_sysfs_if.c */
1829 extern const struct sysfs_ops brport_sysfs_ops;
1830 int br_sysfs_addif(struct net_bridge_port *p);
1831 int br_sysfs_renameif(struct net_bridge_port *p);
1832 
1833 /* br_sysfs_br.c */
1834 int br_sysfs_addbr(struct net_device *dev);
1835 void br_sysfs_delbr(struct net_device *dev);
1836 
1837 #else
1838 
1839 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1840 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1841 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1842 static inline void br_sysfs_delbr(struct net_device *dev) { return; }
1843 #endif /* CONFIG_SYSFS */
1844 
1845 /* br_switchdev.c */
1846 #ifdef CONFIG_NET_SWITCHDEV
1847 void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1848 			      struct sk_buff *skb);
1849 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1850 				  const struct sk_buff *skb);
1851 int br_switchdev_set_port_flag(struct net_bridge_port *p,
1852 			       unsigned long flags,
1853 			       unsigned long mask,
1854 			       struct netlink_ext_ack *extack);
1855 void br_switchdev_fdb_notify(struct net_bridge *br,
1856 			     const struct net_bridge_fdb_entry *fdb, int type);
1857 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1858 			       struct netlink_ext_ack *extack);
1859 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
1860 int nbp_switchdev_add(struct net_bridge_port *p);
1861 void nbp_switchdev_del(struct net_bridge_port *p);
1862 void br_switchdev_init(struct net_bridge *br);
1863 
1864 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1865 {
1866 	skb->offload_fwd_mark = 0;
1867 }
1868 #else
1869 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1870 					    struct sk_buff *skb)
1871 {
1872 }
1873 
1874 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1875 						const struct sk_buff *skb)
1876 {
1877 	return true;
1878 }
1879 
1880 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
1881 					     unsigned long flags,
1882 					     unsigned long mask,
1883 					     struct netlink_ext_ack *extack)
1884 {
1885 	return 0;
1886 }
1887 
1888 static inline int br_switchdev_port_vlan_add(struct net_device *dev,
1889 					     u16 vid, u16 flags,
1890 					     struct netlink_ext_ack *extack)
1891 {
1892 	return -EOPNOTSUPP;
1893 }
1894 
1895 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
1896 {
1897 	return -EOPNOTSUPP;
1898 }
1899 
1900 static inline void
1901 br_switchdev_fdb_notify(struct net_bridge *br,
1902 			const struct net_bridge_fdb_entry *fdb, int type)
1903 {
1904 }
1905 
1906 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1907 {
1908 }
1909 
1910 static inline int nbp_switchdev_add(struct net_bridge_port *p)
1911 {
1912 	return 0;
1913 }
1914 
1915 static inline void nbp_switchdev_del(struct net_bridge_port *p)
1916 {
1917 }
1918 
1919 static inline void br_switchdev_init(struct net_bridge *br)
1920 {
1921 }
1922 
1923 #endif /* CONFIG_NET_SWITCHDEV */
1924 
1925 /* br_arp_nd_proxy.c */
1926 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
1927 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
1928 			      u16 vid, struct net_bridge_port *p);
1929 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
1930 		       u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
1931 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
1932 #endif
1933