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