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