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