xref: /openbmc/linux/net/bridge/br_private.h (revision f323aa54)
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_VERSION	"2.3"
33 
34 /* Control of forwarding link local multicast */
35 #define BR_GROUPFWD_DEFAULT	0
36 /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
37 enum {
38 	BR_GROUPFWD_STP		= BIT(0),
39 	BR_GROUPFWD_MACPAUSE	= BIT(1),
40 	BR_GROUPFWD_LACP	= BIT(2),
41 };
42 
43 #define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \
44 				BR_GROUPFWD_LACP)
45 /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
46 #define BR_GROUPFWD_8021AD	0xB801u
47 
48 /* Path to usermode spanning tree program */
49 #define BR_STP_PROG	"/sbin/bridge-stp"
50 
51 #define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT)
52 
53 typedef struct bridge_id bridge_id;
54 typedef struct mac_addr mac_addr;
55 typedef __u16 port_id;
56 
57 struct bridge_id {
58 	unsigned char	prio[2];
59 	unsigned char	addr[ETH_ALEN];
60 };
61 
62 struct mac_addr {
63 	unsigned char	addr[ETH_ALEN];
64 };
65 
66 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
67 /* our own querier */
68 struct bridge_mcast_own_query {
69 	struct timer_list	timer;
70 	u32			startup_sent;
71 };
72 
73 /* other querier */
74 struct bridge_mcast_other_query {
75 	struct timer_list		timer;
76 	unsigned long			delay_time;
77 };
78 
79 /* selected querier */
80 struct bridge_mcast_querier {
81 	struct br_ip addr;
82 	struct net_bridge_port __rcu	*port;
83 };
84 
85 /* IGMP/MLD statistics */
86 struct bridge_mcast_stats {
87 	struct br_mcast_stats mstats;
88 	struct u64_stats_sync syncp;
89 };
90 #endif
91 
92 struct br_vlan_stats {
93 	u64 rx_bytes;
94 	u64 rx_packets;
95 	u64 tx_bytes;
96 	u64 tx_packets;
97 	struct u64_stats_sync syncp;
98 };
99 
100 struct br_tunnel_info {
101 	__be64			tunnel_id;
102 	struct metadata_dst	*tunnel_dst;
103 };
104 
105 /* private vlan flags */
106 enum {
107 	BR_VLFLAG_PER_PORT_STATS = BIT(0),
108 	BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1),
109 };
110 
111 /**
112  * struct net_bridge_vlan - per-vlan entry
113  *
114  * @vnode: rhashtable member
115  * @vid: VLAN id
116  * @flags: bridge vlan flags
117  * @priv_flags: private (in-kernel) bridge vlan flags
118  * @state: STP state (e.g. blocking, learning, forwarding)
119  * @stats: per-cpu VLAN statistics
120  * @br: if MASTER flag set, this points to a bridge struct
121  * @port: if MASTER flag unset, this points to a port struct
122  * @refcnt: if MASTER flag set, this is bumped for each port referencing it
123  * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
124  *          for this VLAN entry
125  * @vlist: sorted list of VLAN entries
126  * @rcu: used for entry destruction
127  *
128  * This structure is shared between the global per-VLAN entries contained in
129  * the bridge rhashtable and the local per-port per-VLAN entries contained in
130  * the port's rhashtable. The union entries should be interpreted depending on
131  * the entry flags that are set.
132  */
133 struct net_bridge_vlan {
134 	struct rhash_head		vnode;
135 	struct rhash_head		tnode;
136 	u16				vid;
137 	u16				flags;
138 	u16				priv_flags;
139 	u8				state;
140 	struct br_vlan_stats __percpu	*stats;
141 	union {
142 		struct net_bridge	*br;
143 		struct net_bridge_port	*port;
144 	};
145 	union {
146 		refcount_t		refcnt;
147 		struct net_bridge_vlan	*brvlan;
148 	};
149 
150 	struct br_tunnel_info		tinfo;
151 
152 	struct list_head		vlist;
153 
154 	struct rcu_head			rcu;
155 };
156 
157 /**
158  * struct net_bridge_vlan_group
159  *
160  * @vlan_hash: VLAN entry rhashtable
161  * @vlan_list: sorted VLAN entry list
162  * @num_vlans: number of total VLAN entries
163  * @pvid: PVID VLAN id
164  * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking)
165  *
166  * IMPORTANT: Be careful when checking if there're VLAN entries using list
167  *            primitives because the bridge can have entries in its list which
168  *            are just for global context but not for filtering, i.e. they have
169  *            the master flag set but not the brentry flag. If you have to check
170  *            if there're "real" entries in the bridge please test @num_vlans
171  */
172 struct net_bridge_vlan_group {
173 	struct rhashtable		vlan_hash;
174 	struct rhashtable		tunnel_hash;
175 	struct list_head		vlan_list;
176 	u16				num_vlans;
177 	u16				pvid;
178 	u8				pvid_state;
179 };
180 
181 /* bridge fdb flags */
182 enum {
183 	BR_FDB_LOCAL,
184 	BR_FDB_STATIC,
185 	BR_FDB_STICKY,
186 	BR_FDB_ADDED_BY_USER,
187 	BR_FDB_ADDED_BY_EXT_LEARN,
188 	BR_FDB_OFFLOADED,
189 	BR_FDB_NOTIFY,
190 	BR_FDB_NOTIFY_INACTIVE
191 };
192 
193 struct net_bridge_fdb_key {
194 	mac_addr addr;
195 	u16 vlan_id;
196 };
197 
198 struct net_bridge_fdb_entry {
199 	struct rhash_head		rhnode;
200 	struct net_bridge_port		*dst;
201 
202 	struct net_bridge_fdb_key	key;
203 	struct hlist_node		fdb_node;
204 	unsigned long			flags;
205 
206 	/* write-heavy members should not affect lookups */
207 	unsigned long			updated ____cacheline_aligned_in_smp;
208 	unsigned long			used;
209 
210 	struct rcu_head			rcu;
211 };
212 
213 #define MDB_PG_FLAGS_PERMANENT	BIT(0)
214 #define MDB_PG_FLAGS_OFFLOAD	BIT(1)
215 #define MDB_PG_FLAGS_FAST_LEAVE	BIT(2)
216 #define MDB_PG_FLAGS_STAR_EXCL	BIT(3)
217 #define MDB_PG_FLAGS_BLOCKED	BIT(4)
218 
219 #define PG_SRC_ENT_LIMIT	32
220 
221 #define BR_SGRP_F_DELETE	BIT(0)
222 #define BR_SGRP_F_SEND		BIT(1)
223 #define BR_SGRP_F_INSTALLED	BIT(2)
224 
225 struct net_bridge_mcast_gc {
226 	struct hlist_node		gc_node;
227 	void				(*destroy)(struct net_bridge_mcast_gc *gc);
228 };
229 
230 struct net_bridge_group_src {
231 	struct hlist_node		node;
232 
233 	struct br_ip			addr;
234 	struct net_bridge_port_group	*pg;
235 	u8				flags;
236 	u8				src_query_rexmit_cnt;
237 	struct timer_list		timer;
238 
239 	struct net_bridge		*br;
240 	struct net_bridge_mcast_gc	mcast_gc;
241 	struct rcu_head			rcu;
242 };
243 
244 struct net_bridge_port_group_sg_key {
245 	struct net_bridge_port		*port;
246 	struct br_ip			addr;
247 };
248 
249 struct net_bridge_port_group {
250 	struct net_bridge_port_group __rcu *next;
251 	struct net_bridge_port_group_sg_key key;
252 	unsigned char			eth_addr[ETH_ALEN] __aligned(2);
253 	unsigned char			flags;
254 	unsigned char			filter_mode;
255 	unsigned char			grp_query_rexmit_cnt;
256 	unsigned char			rt_protocol;
257 
258 	struct hlist_head		src_list;
259 	unsigned int			src_ents;
260 	struct timer_list		timer;
261 	struct timer_list		rexmit_timer;
262 	struct hlist_node		mglist;
263 
264 	struct rhash_head		rhnode;
265 	struct net_bridge_mcast_gc	mcast_gc;
266 	struct rcu_head			rcu;
267 };
268 
269 struct net_bridge_mdb_entry {
270 	struct rhash_head		rhnode;
271 	struct net_bridge		*br;
272 	struct net_bridge_port_group __rcu *ports;
273 	struct br_ip			addr;
274 	bool				host_joined;
275 
276 	struct timer_list		timer;
277 	struct hlist_node		mdb_node;
278 
279 	struct net_bridge_mcast_gc	mcast_gc;
280 	struct rcu_head			rcu;
281 };
282 
283 struct net_bridge_port {
284 	struct net_bridge		*br;
285 	struct net_device		*dev;
286 	struct list_head		list;
287 
288 	unsigned long			flags;
289 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
290 	struct net_bridge_vlan_group	__rcu *vlgrp;
291 #endif
292 	struct net_bridge_port		__rcu *backup_port;
293 
294 	/* STP */
295 	u8				priority;
296 	u8				state;
297 	u16				port_no;
298 	unsigned char			topology_change_ack;
299 	unsigned char			config_pending;
300 	port_id				port_id;
301 	port_id				designated_port;
302 	bridge_id			designated_root;
303 	bridge_id			designated_bridge;
304 	u32				path_cost;
305 	u32				designated_cost;
306 	unsigned long			designated_age;
307 
308 	struct timer_list		forward_delay_timer;
309 	struct timer_list		hold_timer;
310 	struct timer_list		message_age_timer;
311 	struct kobject			kobj;
312 	struct rcu_head			rcu;
313 
314 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
315 	struct bridge_mcast_own_query	ip4_own_query;
316 #if IS_ENABLED(CONFIG_IPV6)
317 	struct bridge_mcast_own_query	ip6_own_query;
318 #endif /* IS_ENABLED(CONFIG_IPV6) */
319 	unsigned char			multicast_router;
320 	struct bridge_mcast_stats	__percpu *mcast_stats;
321 	struct timer_list		multicast_router_timer;
322 	struct hlist_head		mglist;
323 	struct hlist_node		rlist;
324 #endif
325 
326 #ifdef CONFIG_SYSFS
327 	char				sysfs_name[IFNAMSIZ];
328 #endif
329 
330 #ifdef CONFIG_NET_POLL_CONTROLLER
331 	struct netpoll			*np;
332 #endif
333 #ifdef CONFIG_NET_SWITCHDEV
334 	int				offload_fwd_mark;
335 #endif
336 	u16				group_fwd_mask;
337 	u16				backup_redirected_cnt;
338 
339 	struct bridge_stp_xstats	stp_xstats;
340 };
341 
342 #define kobj_to_brport(obj)	container_of(obj, struct net_bridge_port, kobj)
343 
344 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
345 #define br_promisc_port(p) ((p)->flags & BR_PROMISC)
346 
347 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
348 {
349 	return rcu_dereference(dev->rx_handler_data);
350 }
351 
352 static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
353 {
354 	return netif_is_bridge_port(dev) ?
355 		rtnl_dereference(dev->rx_handler_data) : NULL;
356 }
357 
358 static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
359 {
360 	return netif_is_bridge_port(dev) ?
361 		rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
362 }
363 
364 enum net_bridge_opts {
365 	BROPT_VLAN_ENABLED,
366 	BROPT_VLAN_STATS_ENABLED,
367 	BROPT_NF_CALL_IPTABLES,
368 	BROPT_NF_CALL_IP6TABLES,
369 	BROPT_NF_CALL_ARPTABLES,
370 	BROPT_GROUP_ADDR_SET,
371 	BROPT_MULTICAST_ENABLED,
372 	BROPT_MULTICAST_QUERIER,
373 	BROPT_MULTICAST_QUERY_USE_IFADDR,
374 	BROPT_MULTICAST_STATS_ENABLED,
375 	BROPT_HAS_IPV6_ADDR,
376 	BROPT_NEIGH_SUPPRESS_ENABLED,
377 	BROPT_MTU_SET_BY_USER,
378 	BROPT_VLAN_STATS_PER_PORT,
379 	BROPT_NO_LL_LEARN,
380 	BROPT_VLAN_BRIDGE_BINDING,
381 };
382 
383 struct net_bridge {
384 	spinlock_t			lock;
385 	spinlock_t			hash_lock;
386 	struct hlist_head		frame_type_list;
387 	struct net_device		*dev;
388 	struct pcpu_sw_netstats		__percpu *stats;
389 	unsigned long			options;
390 	/* These fields are accessed on each packet */
391 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
392 	__be16				vlan_proto;
393 	u16				default_pvid;
394 	struct net_bridge_vlan_group	__rcu *vlgrp;
395 #endif
396 
397 	struct rhashtable		fdb_hash_tbl;
398 	struct list_head		port_list;
399 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
400 	union {
401 		struct rtable		fake_rtable;
402 		struct rt6_info		fake_rt6_info;
403 	};
404 #endif
405 	u16				group_fwd_mask;
406 	u16				group_fwd_mask_required;
407 
408 	/* STP */
409 	bridge_id			designated_root;
410 	bridge_id			bridge_id;
411 	unsigned char			topology_change;
412 	unsigned char			topology_change_detected;
413 	u16				root_port;
414 	unsigned long			max_age;
415 	unsigned long			hello_time;
416 	unsigned long			forward_delay;
417 	unsigned long			ageing_time;
418 	unsigned long			bridge_max_age;
419 	unsigned long			bridge_hello_time;
420 	unsigned long			bridge_forward_delay;
421 	unsigned long			bridge_ageing_time;
422 	u32				root_path_cost;
423 
424 	u8				group_addr[ETH_ALEN];
425 
426 	enum {
427 		BR_NO_STP, 		/* no spanning tree */
428 		BR_KERNEL_STP,		/* old STP in kernel */
429 		BR_USER_STP,		/* new RSTP in userspace */
430 	} stp_enabled;
431 
432 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
433 
434 	u32				hash_max;
435 
436 	u32				multicast_last_member_count;
437 	u32				multicast_startup_query_count;
438 
439 	u8				multicast_igmp_version;
440 	u8				multicast_router;
441 #if IS_ENABLED(CONFIG_IPV6)
442 	u8				multicast_mld_version;
443 #endif
444 	spinlock_t			multicast_lock;
445 	unsigned long			multicast_last_member_interval;
446 	unsigned long			multicast_membership_interval;
447 	unsigned long			multicast_querier_interval;
448 	unsigned long			multicast_query_interval;
449 	unsigned long			multicast_query_response_interval;
450 	unsigned long			multicast_startup_query_interval;
451 
452 	struct rhashtable		mdb_hash_tbl;
453 	struct rhashtable		sg_port_tbl;
454 
455 	struct hlist_head		mcast_gc_list;
456 	struct hlist_head		mdb_list;
457 	struct hlist_head		router_list;
458 
459 	struct timer_list		multicast_router_timer;
460 	struct bridge_mcast_other_query	ip4_other_query;
461 	struct bridge_mcast_own_query	ip4_own_query;
462 	struct bridge_mcast_querier	ip4_querier;
463 	struct bridge_mcast_stats	__percpu *mcast_stats;
464 #if IS_ENABLED(CONFIG_IPV6)
465 	struct bridge_mcast_other_query	ip6_other_query;
466 	struct bridge_mcast_own_query	ip6_own_query;
467 	struct bridge_mcast_querier	ip6_querier;
468 #endif /* IS_ENABLED(CONFIG_IPV6) */
469 	struct work_struct		mcast_gc_work;
470 #endif
471 
472 	struct timer_list		hello_timer;
473 	struct timer_list		tcn_timer;
474 	struct timer_list		topology_change_timer;
475 	struct delayed_work		gc_work;
476 	struct kobject			*ifobj;
477 	u32				auto_cnt;
478 
479 #ifdef CONFIG_NET_SWITCHDEV
480 	int offload_fwd_mark;
481 #endif
482 	struct hlist_head		fdb_list;
483 
484 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
485 	struct list_head		mrp_list;
486 #endif
487 #if IS_ENABLED(CONFIG_BRIDGE_CFM)
488 	struct hlist_head		mep_list;
489 #endif
490 };
491 
492 struct br_input_skb_cb {
493 	struct net_device *brdev;
494 
495 	u16 frag_max_size;
496 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
497 	u8 igmp;
498 	u8 mrouters_only:1;
499 #endif
500 	u8 proxyarp_replied:1;
501 	u8 src_port_isolated:1;
502 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
503 	u8 vlan_filtered:1;
504 #endif
505 #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
506 	u8 br_netfilter_broute:1;
507 #endif
508 
509 #ifdef CONFIG_NET_SWITCHDEV
510 	int offload_fwd_mark;
511 #endif
512 };
513 
514 #define BR_INPUT_SKB_CB(__skb)	((struct br_input_skb_cb *)(__skb)->cb)
515 
516 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
517 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(BR_INPUT_SKB_CB(__skb)->mrouters_only)
518 #else
519 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(0)
520 #endif
521 
522 #define br_printk(level, br, format, args...)	\
523 	printk(level "%s: " format, (br)->dev->name, ##args)
524 
525 #define br_err(__br, format, args...)			\
526 	br_printk(KERN_ERR, __br, format, ##args)
527 #define br_warn(__br, format, args...)			\
528 	br_printk(KERN_WARNING, __br, format, ##args)
529 #define br_notice(__br, format, args...)		\
530 	br_printk(KERN_NOTICE, __br, format, ##args)
531 #define br_info(__br, format, args...)			\
532 	br_printk(KERN_INFO, __br, format, ##args)
533 
534 #define br_debug(br, format, args...)			\
535 	pr_debug("%s: " format,  (br)->dev->name, ##args)
536 
537 /* called under bridge lock */
538 static inline int br_is_root_bridge(const struct net_bridge *br)
539 {
540 	return !memcmp(&br->bridge_id, &br->designated_root, 8);
541 }
542 
543 /* check if a VLAN entry is global */
544 static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
545 {
546 	return v->flags & BRIDGE_VLAN_INFO_MASTER;
547 }
548 
549 /* check if a VLAN entry is used by the bridge */
550 static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
551 {
552 	return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
553 }
554 
555 /* check if we should use the vlan entry, returns false if it's only context */
556 static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
557 {
558 	if (br_vlan_is_master(v)) {
559 		if (br_vlan_is_brentry(v))
560 			return true;
561 		else
562 			return false;
563 	}
564 
565 	return true;
566 }
567 
568 static inline bool nbp_state_should_learn(const struct net_bridge_port *p)
569 {
570 	return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING;
571 }
572 
573 static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack)
574 {
575 	bool ret = vid > 0 && vid < VLAN_VID_MASK;
576 
577 	if (!ret)
578 		NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid");
579 
580 	return ret;
581 }
582 
583 static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
584 				       const struct bridge_vlan_info *last,
585 				       struct netlink_ext_ack *extack)
586 {
587 	/* pvid flag is not allowed in ranges */
588 	if (cur->flags & BRIDGE_VLAN_INFO_PVID) {
589 		NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range");
590 		return false;
591 	}
592 
593 	/* when cur is the range end, check if:
594 	 *  - it has range start flag
595 	 *  - range ids are invalid (end is equal to or before start)
596 	 */
597 	if (last) {
598 		if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
599 			NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one");
600 			return false;
601 		} else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) {
602 			NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing");
603 			return false;
604 		} else if (cur->vid <= last->vid) {
605 			NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
606 			return false;
607 		}
608 	}
609 
610 	/* check for required range flags */
611 	if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
612 			    BRIDGE_VLAN_INFO_RANGE_END))) {
613 		NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing");
614 		return false;
615 	}
616 
617 	return true;
618 }
619 
620 static inline int br_afspec_cmd_to_rtm(int cmd)
621 {
622 	switch (cmd) {
623 	case RTM_SETLINK:
624 		return RTM_NEWVLAN;
625 	case RTM_DELLINK:
626 		return RTM_DELVLAN;
627 	}
628 
629 	return 0;
630 }
631 
632 static inline int br_opt_get(const struct net_bridge *br,
633 			     enum net_bridge_opts opt)
634 {
635 	return test_bit(opt, &br->options);
636 }
637 
638 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
639 		      struct netlink_ext_ack *extack);
640 int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
641 int br_boolopt_multi_toggle(struct net_bridge *br,
642 			    struct br_boolopt_multi *bm,
643 			    struct netlink_ext_ack *extack);
644 void br_boolopt_multi_get(const struct net_bridge *br,
645 			  struct br_boolopt_multi *bm);
646 void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
647 
648 /* br_device.c */
649 void br_dev_setup(struct net_device *dev);
650 void br_dev_delete(struct net_device *dev, struct list_head *list);
651 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
652 #ifdef CONFIG_NET_POLL_CONTROLLER
653 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
654 				       struct sk_buff *skb)
655 {
656 	netpoll_send_skb(p->np, skb);
657 }
658 
659 int br_netpoll_enable(struct net_bridge_port *p);
660 void br_netpoll_disable(struct net_bridge_port *p);
661 #else
662 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
663 				       struct sk_buff *skb)
664 {
665 }
666 
667 static inline int br_netpoll_enable(struct net_bridge_port *p)
668 {
669 	return 0;
670 }
671 
672 static inline void br_netpoll_disable(struct net_bridge_port *p)
673 {
674 }
675 #endif
676 
677 /* br_fdb.c */
678 int br_fdb_init(void);
679 void br_fdb_fini(void);
680 int br_fdb_hash_init(struct net_bridge *br);
681 void br_fdb_hash_fini(struct net_bridge *br);
682 void br_fdb_flush(struct net_bridge *br);
683 void br_fdb_find_delete_local(struct net_bridge *br,
684 			      const struct net_bridge_port *p,
685 			      const unsigned char *addr, u16 vid);
686 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
687 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
688 void br_fdb_cleanup(struct work_struct *work);
689 void br_fdb_delete_by_port(struct net_bridge *br,
690 			   const struct net_bridge_port *p, u16 vid, int do_all);
691 struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
692 					     const unsigned char *addr,
693 					     __u16 vid);
694 int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
695 int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
696 		   unsigned long off);
697 int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
698 		  const unsigned char *addr, u16 vid);
699 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
700 		   const unsigned char *addr, u16 vid, unsigned long flags);
701 
702 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
703 		  struct net_device *dev, const unsigned char *addr, u16 vid);
704 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
705 	       const unsigned char *addr, u16 vid, u16 nlh_flags,
706 	       struct netlink_ext_ack *extack);
707 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
708 		struct net_device *dev, struct net_device *fdev, int *idx);
709 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
710 	       const unsigned char *addr, u16 vid, u32 portid, u32 seq,
711 	       struct netlink_ext_ack *extack);
712 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
713 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
714 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
715 			      const unsigned char *addr, u16 vid,
716 			      bool swdev_notify);
717 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
718 			      const unsigned char *addr, u16 vid,
719 			      bool swdev_notify);
720 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
721 			  const unsigned char *addr, u16 vid, bool offloaded);
722 
723 /* br_forward.c */
724 enum br_pkt_type {
725 	BR_PKT_UNICAST,
726 	BR_PKT_MULTICAST,
727 	BR_PKT_BROADCAST
728 };
729 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
730 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
731 		bool local_rcv, bool local_orig);
732 int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
733 void br_flood(struct net_bridge *br, struct sk_buff *skb,
734 	      enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
735 
736 /* return true if both source port and dest port are isolated */
737 static inline bool br_skb_isolated(const struct net_bridge_port *to,
738 				   const struct sk_buff *skb)
739 {
740 	return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
741 	       (to->flags & BR_ISOLATED);
742 }
743 
744 /* br_if.c */
745 void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
746 int br_add_bridge(struct net *net, const char *name);
747 int br_del_bridge(struct net *net, const char *name);
748 int br_add_if(struct net_bridge *br, struct net_device *dev,
749 	      struct netlink_ext_ack *extack);
750 int br_del_if(struct net_bridge *br, struct net_device *dev);
751 void br_mtu_auto_adjust(struct net_bridge *br);
752 netdev_features_t br_features_recompute(struct net_bridge *br,
753 					netdev_features_t features);
754 void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
755 void br_manage_promisc(struct net_bridge *br);
756 int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
757 
758 /* br_input.c */
759 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
760 rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
761 
762 struct br_frame_type {
763 	__be16			type;
764 	int			(*frame_handler)(struct net_bridge_port *port,
765 						 struct sk_buff *skb);
766 	struct hlist_node	list;
767 };
768 
769 void br_add_frame(struct net_bridge *br, struct br_frame_type *ft);
770 void br_del_frame(struct net_bridge *br, struct br_frame_type *ft);
771 
772 static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
773 {
774 	return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
775 }
776 
777 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
778 {
779 	return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev);
780 }
781 
782 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
783 {
784 	return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
785 }
786 
787 static inline struct net_bridge_port *
788 br_port_get_check_rtnl(const struct net_device *dev)
789 {
790 	return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
791 }
792 
793 /* br_ioctl.c */
794 int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
795 int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
796 			     void __user *arg);
797 
798 /* br_multicast.c */
799 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
800 int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
801 		     struct sk_buff *skb, u16 vid);
802 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
803 					struct sk_buff *skb, u16 vid);
804 int br_multicast_add_port(struct net_bridge_port *port);
805 void br_multicast_del_port(struct net_bridge_port *port);
806 void br_multicast_enable_port(struct net_bridge_port *port);
807 void br_multicast_disable_port(struct net_bridge_port *port);
808 void br_multicast_init(struct net_bridge *br);
809 void br_multicast_open(struct net_bridge *br);
810 void br_multicast_stop(struct net_bridge *br);
811 void br_multicast_dev_del(struct net_bridge *br);
812 void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
813 			struct sk_buff *skb, bool local_rcv, bool local_orig);
814 int br_multicast_set_router(struct net_bridge *br, unsigned long val);
815 int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
816 int br_multicast_toggle(struct net_bridge *br, unsigned long val);
817 int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
818 int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
819 int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val);
820 #if IS_ENABLED(CONFIG_IPV6)
821 int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val);
822 #endif
823 struct net_bridge_mdb_entry *
824 br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
825 struct net_bridge_mdb_entry *
826 br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
827 struct net_bridge_port_group *
828 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
829 			    struct net_bridge_port_group __rcu *next,
830 			    unsigned char flags, const unsigned char *src,
831 			    u8 filter_mode, u8 rt_protocol);
832 int br_mdb_hash_init(struct net_bridge *br);
833 void br_mdb_hash_fini(struct net_bridge *br);
834 void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp,
835 		   struct net_bridge_port_group *pg, int type);
836 void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
837 		   int type);
838 void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
839 			 struct net_bridge_port_group *pg,
840 			 struct net_bridge_port_group __rcu **pp);
841 void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p,
842 			const struct sk_buff *skb, u8 type, u8 dir);
843 int br_multicast_init_stats(struct net_bridge *br);
844 void br_multicast_uninit_stats(struct net_bridge *br);
845 void br_multicast_get_stats(const struct net_bridge *br,
846 			    const struct net_bridge_port *p,
847 			    struct br_mcast_stats *dest);
848 void br_mdb_init(void);
849 void br_mdb_uninit(void);
850 void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify);
851 void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
852 void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg,
853 				     u8 filter_mode);
854 void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp,
855 				       struct net_bridge_port_group *sg);
856 
857 #define mlock_dereference(X, br) \
858 	rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
859 
860 static inline bool br_multicast_is_router(struct net_bridge *br)
861 {
862 	return br->multicast_router == 2 ||
863 	       (br->multicast_router == 1 &&
864 		timer_pending(&br->multicast_router_timer));
865 }
866 
867 static inline bool
868 __br_multicast_querier_exists(struct net_bridge *br,
869 				struct bridge_mcast_other_query *querier,
870 				const bool is_ipv6)
871 {
872 	bool own_querier_enabled;
873 
874 	if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
875 		if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR))
876 			own_querier_enabled = false;
877 		else
878 			own_querier_enabled = true;
879 	} else {
880 		own_querier_enabled = false;
881 	}
882 
883 	return time_is_before_jiffies(querier->delay_time) &&
884 	       (own_querier_enabled || timer_pending(&querier->timer));
885 }
886 
887 static inline bool br_multicast_querier_exists(struct net_bridge *br,
888 					       struct ethhdr *eth)
889 {
890 	switch (eth->h_proto) {
891 	case (htons(ETH_P_IP)):
892 		return __br_multicast_querier_exists(br,
893 			&br->ip4_other_query, false);
894 #if IS_ENABLED(CONFIG_IPV6)
895 	case (htons(ETH_P_IPV6)):
896 		return __br_multicast_querier_exists(br,
897 			&br->ip6_other_query, true);
898 #endif
899 	default:
900 		return false;
901 	}
902 }
903 
904 static inline bool br_multicast_is_star_g(const struct br_ip *ip)
905 {
906 	switch (ip->proto) {
907 	case htons(ETH_P_IP):
908 		return ipv4_is_zeronet(ip->src.ip4);
909 #if IS_ENABLED(CONFIG_IPV6)
910 	case htons(ETH_P_IPV6):
911 		return ipv6_addr_any(&ip->src.ip6);
912 #endif
913 	default:
914 		return false;
915 	}
916 }
917 
918 static inline bool br_multicast_should_handle_mode(const struct net_bridge *br,
919 						   __be16 proto)
920 {
921 	switch (proto) {
922 	case htons(ETH_P_IP):
923 		return !!(br->multicast_igmp_version == 3);
924 #if IS_ENABLED(CONFIG_IPV6)
925 	case htons(ETH_P_IPV6):
926 		return !!(br->multicast_mld_version == 2);
927 #endif
928 	default:
929 		return false;
930 	}
931 }
932 
933 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
934 {
935 	return BR_INPUT_SKB_CB(skb)->igmp;
936 }
937 
938 static inline unsigned long br_multicast_lmqt(const struct net_bridge *br)
939 {
940 	return br->multicast_last_member_interval *
941 	       br->multicast_last_member_count;
942 }
943 
944 static inline unsigned long br_multicast_gmi(const struct net_bridge *br)
945 {
946 	/* use the RFC default of 2 for QRV */
947 	return 2 * br->multicast_query_interval +
948 	       br->multicast_query_response_interval;
949 }
950 #else
951 static inline int br_multicast_rcv(struct net_bridge *br,
952 				   struct net_bridge_port *port,
953 				   struct sk_buff *skb,
954 				   u16 vid)
955 {
956 	return 0;
957 }
958 
959 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
960 						      struct sk_buff *skb, u16 vid)
961 {
962 	return NULL;
963 }
964 
965 static inline int br_multicast_add_port(struct net_bridge_port *port)
966 {
967 	return 0;
968 }
969 
970 static inline void br_multicast_del_port(struct net_bridge_port *port)
971 {
972 }
973 
974 static inline void br_multicast_enable_port(struct net_bridge_port *port)
975 {
976 }
977 
978 static inline void br_multicast_disable_port(struct net_bridge_port *port)
979 {
980 }
981 
982 static inline void br_multicast_init(struct net_bridge *br)
983 {
984 }
985 
986 static inline void br_multicast_open(struct net_bridge *br)
987 {
988 }
989 
990 static inline void br_multicast_stop(struct net_bridge *br)
991 {
992 }
993 
994 static inline void br_multicast_dev_del(struct net_bridge *br)
995 {
996 }
997 
998 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
999 				      struct sk_buff *skb,
1000 				      bool local_rcv, bool local_orig)
1001 {
1002 }
1003 
1004 static inline bool br_multicast_is_router(struct net_bridge *br)
1005 {
1006 	return false;
1007 }
1008 
1009 static inline bool br_multicast_querier_exists(struct net_bridge *br,
1010 					       struct ethhdr *eth)
1011 {
1012 	return false;
1013 }
1014 
1015 static inline void br_mdb_init(void)
1016 {
1017 }
1018 
1019 static inline void br_mdb_uninit(void)
1020 {
1021 }
1022 
1023 static inline int br_mdb_hash_init(struct net_bridge *br)
1024 {
1025 	return 0;
1026 }
1027 
1028 static inline void br_mdb_hash_fini(struct net_bridge *br)
1029 {
1030 }
1031 
1032 static inline void br_multicast_count(struct net_bridge *br,
1033 				      const struct net_bridge_port *p,
1034 				      const struct sk_buff *skb,
1035 				      u8 type, u8 dir)
1036 {
1037 }
1038 
1039 static inline int br_multicast_init_stats(struct net_bridge *br)
1040 {
1041 	return 0;
1042 }
1043 
1044 static inline void br_multicast_uninit_stats(struct net_bridge *br)
1045 {
1046 }
1047 
1048 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1049 {
1050 	return 0;
1051 }
1052 #endif
1053 
1054 /* br_vlan.c */
1055 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1056 bool br_allowed_ingress(const struct net_bridge *br,
1057 			struct net_bridge_vlan_group *vg, struct sk_buff *skb,
1058 			u16 *vid, u8 *state);
1059 bool br_allowed_egress(struct net_bridge_vlan_group *vg,
1060 		       const struct sk_buff *skb);
1061 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
1062 struct sk_buff *br_handle_vlan(struct net_bridge *br,
1063 			       const struct net_bridge_port *port,
1064 			       struct net_bridge_vlan_group *vg,
1065 			       struct sk_buff *skb);
1066 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
1067 		bool *changed, struct netlink_ext_ack *extack);
1068 int br_vlan_delete(struct net_bridge *br, u16 vid);
1069 void br_vlan_flush(struct net_bridge *br);
1070 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
1071 void br_recalculate_fwd_mask(struct net_bridge *br);
1072 int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
1073 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
1074 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
1075 int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
1076 int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
1077 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
1078 int br_vlan_init(struct net_bridge *br);
1079 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
1080 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
1081 			       struct netlink_ext_ack *extack);
1082 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1083 		 bool *changed, struct netlink_ext_ack *extack);
1084 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
1085 void nbp_vlan_flush(struct net_bridge_port *port);
1086 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
1087 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
1088 void br_vlan_get_stats(const struct net_bridge_vlan *v,
1089 		       struct br_vlan_stats *stats);
1090 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
1091 int br_vlan_bridge_event(struct net_device *dev, unsigned long event,
1092 			 void *ptr);
1093 void br_vlan_rtnl_init(void);
1094 void br_vlan_rtnl_uninit(void);
1095 void br_vlan_notify(const struct net_bridge *br,
1096 		    const struct net_bridge_port *p,
1097 		    u16 vid, u16 vid_range,
1098 		    int cmd);
1099 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1100 			     const struct net_bridge_vlan *range_end);
1101 
1102 static inline struct net_bridge_vlan_group *br_vlan_group(
1103 					const struct net_bridge *br)
1104 {
1105 	return rtnl_dereference(br->vlgrp);
1106 }
1107 
1108 static inline struct net_bridge_vlan_group *nbp_vlan_group(
1109 					const struct net_bridge_port *p)
1110 {
1111 	return rtnl_dereference(p->vlgrp);
1112 }
1113 
1114 static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1115 					const struct net_bridge *br)
1116 {
1117 	return rcu_dereference(br->vlgrp);
1118 }
1119 
1120 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1121 					const struct net_bridge_port *p)
1122 {
1123 	return rcu_dereference(p->vlgrp);
1124 }
1125 
1126 /* Since bridge now depends on 8021Q module, but the time bridge sees the
1127  * skb, the vlan tag will always be present if the frame was tagged.
1128  */
1129 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
1130 {
1131 	int err = 0;
1132 
1133 	if (skb_vlan_tag_present(skb)) {
1134 		*vid = skb_vlan_tag_get_id(skb);
1135 	} else {
1136 		*vid = 0;
1137 		err = -EINVAL;
1138 	}
1139 
1140 	return err;
1141 }
1142 
1143 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
1144 {
1145 	if (!vg)
1146 		return 0;
1147 
1148 	smp_rmb();
1149 	return vg->pvid;
1150 }
1151 
1152 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1153 {
1154 	return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags;
1155 }
1156 #else
1157 static inline bool br_allowed_ingress(const struct net_bridge *br,
1158 				      struct net_bridge_vlan_group *vg,
1159 				      struct sk_buff *skb,
1160 				      u16 *vid, u8 *state)
1161 {
1162 	return true;
1163 }
1164 
1165 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
1166 				     const struct sk_buff *skb)
1167 {
1168 	return true;
1169 }
1170 
1171 static inline bool br_should_learn(struct net_bridge_port *p,
1172 				   struct sk_buff *skb, u16 *vid)
1173 {
1174 	return true;
1175 }
1176 
1177 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
1178 					     const struct net_bridge_port *port,
1179 					     struct net_bridge_vlan_group *vg,
1180 					     struct sk_buff *skb)
1181 {
1182 	return skb;
1183 }
1184 
1185 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
1186 			      bool *changed, struct netlink_ext_ack *extack)
1187 {
1188 	*changed = false;
1189 	return -EOPNOTSUPP;
1190 }
1191 
1192 static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
1193 {
1194 	return -EOPNOTSUPP;
1195 }
1196 
1197 static inline void br_vlan_flush(struct net_bridge *br)
1198 {
1199 }
1200 
1201 static inline void br_recalculate_fwd_mask(struct net_bridge *br)
1202 {
1203 }
1204 
1205 static inline int br_vlan_init(struct net_bridge *br)
1206 {
1207 	return 0;
1208 }
1209 
1210 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1211 			       bool *changed, struct netlink_ext_ack *extack)
1212 {
1213 	*changed = false;
1214 	return -EOPNOTSUPP;
1215 }
1216 
1217 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1218 {
1219 	return -EOPNOTSUPP;
1220 }
1221 
1222 static inline void nbp_vlan_flush(struct net_bridge_port *port)
1223 {
1224 }
1225 
1226 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1227 						   u16 vid)
1228 {
1229 	return NULL;
1230 }
1231 
1232 static inline int nbp_vlan_init(struct net_bridge_port *port,
1233 				struct netlink_ext_ack *extack)
1234 {
1235 	return 0;
1236 }
1237 
1238 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
1239 {
1240 	return 0;
1241 }
1242 
1243 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
1244 {
1245 	return 0;
1246 }
1247 
1248 static inline int __br_vlan_filter_toggle(struct net_bridge *br,
1249 					  unsigned long val)
1250 {
1251 	return -EOPNOTSUPP;
1252 }
1253 
1254 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1255 					 u32 filter_mask)
1256 {
1257 	return 0;
1258 }
1259 
1260 static inline struct net_bridge_vlan_group *br_vlan_group(
1261 					const struct net_bridge *br)
1262 {
1263 	return NULL;
1264 }
1265 
1266 static inline struct net_bridge_vlan_group *nbp_vlan_group(
1267 					const struct net_bridge_port *p)
1268 {
1269 	return NULL;
1270 }
1271 
1272 static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1273 					const struct net_bridge *br)
1274 {
1275 	return NULL;
1276 }
1277 
1278 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1279 					const struct net_bridge_port *p)
1280 {
1281 	return NULL;
1282 }
1283 
1284 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1285 				     struct br_vlan_stats *stats)
1286 {
1287 }
1288 
1289 static inline void br_vlan_port_event(struct net_bridge_port *p,
1290 				      unsigned long event)
1291 {
1292 }
1293 
1294 static inline int br_vlan_bridge_event(struct net_device *dev,
1295 				       unsigned long event, void *ptr)
1296 {
1297 	return 0;
1298 }
1299 
1300 static inline void br_vlan_rtnl_init(void)
1301 {
1302 }
1303 
1304 static inline void br_vlan_rtnl_uninit(void)
1305 {
1306 }
1307 
1308 static inline void br_vlan_notify(const struct net_bridge *br,
1309 				  const struct net_bridge_port *p,
1310 				  u16 vid, u16 vid_range,
1311 				  int cmd)
1312 {
1313 }
1314 
1315 static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1316 					   const struct net_bridge_vlan *range_end)
1317 {
1318 	return true;
1319 }
1320 #endif
1321 
1322 /* br_vlan_options.c */
1323 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1324 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
1325 			   const struct net_bridge_vlan *range_end);
1326 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
1327 size_t br_vlan_opts_nl_size(void);
1328 int br_vlan_process_options(const struct net_bridge *br,
1329 			    const struct net_bridge_port *p,
1330 			    struct net_bridge_vlan *range_start,
1331 			    struct net_bridge_vlan *range_end,
1332 			    struct nlattr **tb,
1333 			    struct netlink_ext_ack *extack);
1334 
1335 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */
1336 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v)
1337 {
1338 	return READ_ONCE(v->state);
1339 }
1340 
1341 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state)
1342 {
1343 	WRITE_ONCE(v->state, state);
1344 }
1345 
1346 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg)
1347 {
1348 	return READ_ONCE(vg->pvid_state);
1349 }
1350 
1351 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg,
1352 					  u8 state)
1353 {
1354 	WRITE_ONCE(vg->pvid_state, state);
1355 }
1356 
1357 /* learn_allow is true at ingress and false at egress */
1358 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow)
1359 {
1360 	switch (state) {
1361 	case BR_STATE_LEARNING:
1362 		return learn_allow;
1363 	case BR_STATE_FORWARDING:
1364 		return true;
1365 	default:
1366 		return false;
1367 	}
1368 }
1369 #endif
1370 
1371 struct nf_br_ops {
1372 	int (*br_dev_xmit_hook)(struct sk_buff *skb);
1373 };
1374 extern const struct nf_br_ops __rcu *nf_br_ops;
1375 
1376 /* br_netfilter.c */
1377 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1378 int br_nf_core_init(void);
1379 void br_nf_core_fini(void);
1380 void br_netfilter_rtable_init(struct net_bridge *);
1381 #else
1382 static inline int br_nf_core_init(void) { return 0; }
1383 static inline void br_nf_core_fini(void) {}
1384 #define br_netfilter_rtable_init(x)
1385 #endif
1386 
1387 /* br_stp.c */
1388 void br_set_state(struct net_bridge_port *p, unsigned int state);
1389 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1390 void br_init_port(struct net_bridge_port *p);
1391 void br_become_designated_port(struct net_bridge_port *p);
1392 
1393 void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1394 int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1395 int br_set_hello_time(struct net_bridge *br, unsigned long x);
1396 int br_set_max_age(struct net_bridge *br, unsigned long x);
1397 int __set_ageing_time(struct net_device *dev, unsigned long t);
1398 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
1399 
1400 
1401 /* br_stp_if.c */
1402 void br_stp_enable_bridge(struct net_bridge *br);
1403 void br_stp_disable_bridge(struct net_bridge *br);
1404 int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
1405 		       struct netlink_ext_ack *extack);
1406 void br_stp_enable_port(struct net_bridge_port *p);
1407 void br_stp_disable_port(struct net_bridge_port *p);
1408 bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1409 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1410 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1411 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1412 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1413 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
1414 
1415 /* br_stp_bpdu.c */
1416 struct stp_proto;
1417 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1418 		struct net_device *dev);
1419 
1420 /* br_stp_timer.c */
1421 void br_stp_timer_init(struct net_bridge *br);
1422 void br_stp_port_timer_init(struct net_bridge_port *p);
1423 unsigned long br_timer_value(const struct timer_list *timer);
1424 
1425 /* br.c */
1426 #if IS_ENABLED(CONFIG_ATM_LANE)
1427 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1428 #endif
1429 
1430 /* br_mrp.c */
1431 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
1432 int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1433 		 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1434 bool br_mrp_enabled(struct net_bridge *br);
1435 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
1436 int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
1437 #else
1438 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1439 			       struct nlattr *attr, int cmd,
1440 			       struct netlink_ext_ack *extack)
1441 {
1442 	return -EOPNOTSUPP;
1443 }
1444 
1445 static inline bool br_mrp_enabled(struct net_bridge *br)
1446 {
1447 	return false;
1448 }
1449 
1450 static inline void br_mrp_port_del(struct net_bridge *br,
1451 				   struct net_bridge_port *p)
1452 {
1453 }
1454 
1455 static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
1456 {
1457 	return 0;
1458 }
1459 
1460 #endif
1461 
1462 /* br_netlink.c */
1463 extern struct rtnl_link_ops br_link_ops;
1464 int br_netlink_init(void);
1465 void br_netlink_fini(void);
1466 void br_ifinfo_notify(int event, const struct net_bridge *br,
1467 		      const struct net_bridge_port *port);
1468 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1469 	       struct netlink_ext_ack *extack);
1470 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
1471 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
1472 	       u32 filter_mask, int nlflags);
1473 int br_process_vlan_info(struct net_bridge *br,
1474 			 struct net_bridge_port *p, int cmd,
1475 			 struct bridge_vlan_info *vinfo_curr,
1476 			 struct bridge_vlan_info **vinfo_last,
1477 			 bool *changed,
1478 			 struct netlink_ext_ack *extack);
1479 
1480 #ifdef CONFIG_SYSFS
1481 /* br_sysfs_if.c */
1482 extern const struct sysfs_ops brport_sysfs_ops;
1483 int br_sysfs_addif(struct net_bridge_port *p);
1484 int br_sysfs_renameif(struct net_bridge_port *p);
1485 
1486 /* br_sysfs_br.c */
1487 int br_sysfs_addbr(struct net_device *dev);
1488 void br_sysfs_delbr(struct net_device *dev);
1489 
1490 #else
1491 
1492 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1493 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1494 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1495 static inline void br_sysfs_delbr(struct net_device *dev) { return; }
1496 #endif /* CONFIG_SYSFS */
1497 
1498 /* br_switchdev.c */
1499 #ifdef CONFIG_NET_SWITCHDEV
1500 int nbp_switchdev_mark_set(struct net_bridge_port *p);
1501 void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1502 			      struct sk_buff *skb);
1503 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1504 				  const struct sk_buff *skb);
1505 int br_switchdev_set_port_flag(struct net_bridge_port *p,
1506 			       unsigned long flags,
1507 			       unsigned long mask);
1508 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
1509 			     int type);
1510 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1511 			       struct netlink_ext_ack *extack);
1512 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
1513 
1514 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1515 {
1516 	skb->offload_fwd_mark = 0;
1517 }
1518 #else
1519 static inline int nbp_switchdev_mark_set(struct net_bridge_port *p)
1520 {
1521 	return 0;
1522 }
1523 
1524 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1525 					    struct sk_buff *skb)
1526 {
1527 }
1528 
1529 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1530 						const struct sk_buff *skb)
1531 {
1532 	return true;
1533 }
1534 
1535 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
1536 					     unsigned long flags,
1537 					     unsigned long mask)
1538 {
1539 	return 0;
1540 }
1541 
1542 static inline int br_switchdev_port_vlan_add(struct net_device *dev,
1543 					     u16 vid, u16 flags,
1544 					     struct netlink_ext_ack *extack)
1545 {
1546 	return -EOPNOTSUPP;
1547 }
1548 
1549 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
1550 {
1551 	return -EOPNOTSUPP;
1552 }
1553 
1554 static inline void
1555 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
1556 {
1557 }
1558 
1559 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1560 {
1561 }
1562 #endif /* CONFIG_NET_SWITCHDEV */
1563 
1564 /* br_arp_nd_proxy.c */
1565 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
1566 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
1567 			      u16 vid, struct net_bridge_port *p);
1568 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
1569 		       u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
1570 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
1571 #endif
1572