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