xref: /openbmc/linux/net/bridge/br_private.h (revision ccb1c31a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *	Linux ethernet bridge
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *	Authors:
51da177e4SLinus Torvalds  *	Lennert Buytenhek		<buytenh@gnu.org>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *	This program is free software; you can redistribute it and/or
81da177e4SLinus Torvalds  *	modify it under the terms of the GNU General Public License
91da177e4SLinus Torvalds  *	as published by the Free Software Foundation; either version
101da177e4SLinus Torvalds  *	2 of the License, or (at your option) any later version.
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds #ifndef _BR_PRIVATE_H
141da177e4SLinus Torvalds #define _BR_PRIVATE_H
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #include <linux/netdevice.h>
171da177e4SLinus Torvalds #include <linux/if_bridge.h>
1891d2c34aSHerbert Xu #include <linux/netpoll.h>
19406818ffSEric Dumazet #include <linux/u64_stats_sync.h>
204adf0af6SSimon Wunderlich #include <net/route.h>
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #define BR_HASH_BITS 8
231da177e4SLinus Torvalds #define BR_HASH_SIZE (1 << BR_HASH_BITS)
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #define BR_HOLD_TIME (1*HZ)
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #define BR_PORT_BITS	10
281da177e4SLinus Torvalds #define BR_MAX_PORTS	(1<<BR_PORT_BITS)
291da177e4SLinus Torvalds 
309cde0708SStephen Hemminger #define BR_VERSION	"2.3"
319cde0708SStephen Hemminger 
32515853ccSstephen hemminger /* Control of forwarding link local multicast */
33515853ccSstephen hemminger #define BR_GROUPFWD_DEFAULT	0
34515853ccSstephen hemminger /* Don't allow forwarding control protocols like STP and LLDP */
35515853ccSstephen hemminger #define BR_GROUPFWD_RESTRICTED	0x4007u
36515853ccSstephen hemminger 
379cde0708SStephen Hemminger /* Path to usermode spanning tree program */
389cde0708SStephen Hemminger #define BR_STP_PROG	"/sbin/bridge-stp"
398cbb512eSStephen Hemminger 
401da177e4SLinus Torvalds typedef struct bridge_id bridge_id;
411da177e4SLinus Torvalds typedef struct mac_addr mac_addr;
421da177e4SLinus Torvalds typedef __u16 port_id;
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds struct bridge_id
451da177e4SLinus Torvalds {
461da177e4SLinus Torvalds 	unsigned char	prio[2];
471da177e4SLinus Torvalds 	unsigned char	addr[6];
481da177e4SLinus Torvalds };
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds struct mac_addr
511da177e4SLinus Torvalds {
521da177e4SLinus Torvalds 	unsigned char	addr[6];
531da177e4SLinus Torvalds };
541da177e4SLinus Torvalds 
558ef2a9a5SYOSHIFUJI Hideaki struct br_ip
568ef2a9a5SYOSHIFUJI Hideaki {
578ef2a9a5SYOSHIFUJI Hideaki 	union {
588ef2a9a5SYOSHIFUJI Hideaki 		__be32	ip4;
59dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6)
6008b202b6SYOSHIFUJI Hideaki 		struct in6_addr ip6;
6108b202b6SYOSHIFUJI Hideaki #endif
628ef2a9a5SYOSHIFUJI Hideaki 	} u;
638ef2a9a5SYOSHIFUJI Hideaki 	__be16		proto;
648ef2a9a5SYOSHIFUJI Hideaki };
658ef2a9a5SYOSHIFUJI Hideaki 
661da177e4SLinus Torvalds struct net_bridge_fdb_entry
671da177e4SLinus Torvalds {
681da177e4SLinus Torvalds 	struct hlist_node		hlist;
691da177e4SLinus Torvalds 	struct net_bridge_port		*dst;
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds 	struct rcu_head			rcu;
727cd8861aSstephen hemminger 	unsigned long			updated;
737cd8861aSstephen hemminger 	unsigned long			used;
741da177e4SLinus Torvalds 	mac_addr			addr;
751da177e4SLinus Torvalds 	unsigned char			is_local;
761da177e4SLinus Torvalds 	unsigned char			is_static;
771da177e4SLinus Torvalds };
781da177e4SLinus Torvalds 
79eb1d1641SHerbert Xu struct net_bridge_port_group {
80eb1d1641SHerbert Xu 	struct net_bridge_port		*port;
81e8051688SEric Dumazet 	struct net_bridge_port_group __rcu *next;
82eb1d1641SHerbert Xu 	struct hlist_node		mglist;
83eb1d1641SHerbert Xu 	struct rcu_head			rcu;
84eb1d1641SHerbert Xu 	struct timer_list		timer;
858ef2a9a5SYOSHIFUJI Hideaki 	struct br_ip			addr;
86ccb1c31aSAmerigo Wang 	unsigned char			state;
87eb1d1641SHerbert Xu };
88eb1d1641SHerbert Xu 
89eb1d1641SHerbert Xu struct net_bridge_mdb_entry
90eb1d1641SHerbert Xu {
91eb1d1641SHerbert Xu 	struct hlist_node		hlist[2];
92eb1d1641SHerbert Xu 	struct net_bridge		*br;
93e8051688SEric Dumazet 	struct net_bridge_port_group __rcu *ports;
94eb1d1641SHerbert Xu 	struct rcu_head			rcu;
95eb1d1641SHerbert Xu 	struct timer_list		timer;
968ef2a9a5SYOSHIFUJI Hideaki 	struct br_ip			addr;
978a870178SHerbert Xu 	bool				mglist;
98eb1d1641SHerbert Xu };
99eb1d1641SHerbert Xu 
100eb1d1641SHerbert Xu struct net_bridge_mdb_htable
101eb1d1641SHerbert Xu {
102eb1d1641SHerbert Xu 	struct hlist_head		*mhash;
103eb1d1641SHerbert Xu 	struct rcu_head			rcu;
104eb1d1641SHerbert Xu 	struct net_bridge_mdb_htable	*old;
105eb1d1641SHerbert Xu 	u32				size;
106eb1d1641SHerbert Xu 	u32				max;
107eb1d1641SHerbert Xu 	u32				secret;
108eb1d1641SHerbert Xu 	u32				ver;
109eb1d1641SHerbert Xu };
110eb1d1641SHerbert Xu 
1111da177e4SLinus Torvalds struct net_bridge_port
1121da177e4SLinus Torvalds {
1131da177e4SLinus Torvalds 	struct net_bridge		*br;
1141da177e4SLinus Torvalds 	struct net_device		*dev;
1151da177e4SLinus Torvalds 	struct list_head		list;
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds 	/* STP */
1181da177e4SLinus Torvalds 	u8				priority;
1191da177e4SLinus Torvalds 	u8				state;
1201da177e4SLinus Torvalds 	u16				port_no;
1211da177e4SLinus Torvalds 	unsigned char			topology_change_ack;
1221da177e4SLinus Torvalds 	unsigned char			config_pending;
1231da177e4SLinus Torvalds 	port_id				port_id;
1241da177e4SLinus Torvalds 	port_id				designated_port;
1251da177e4SLinus Torvalds 	bridge_id			designated_root;
1261da177e4SLinus Torvalds 	bridge_id			designated_bridge;
1271da177e4SLinus Torvalds 	u32				path_cost;
1281da177e4SLinus Torvalds 	u32				designated_cost;
1290c03150eSstephen hemminger 	unsigned long			designated_age;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds 	struct timer_list		forward_delay_timer;
1321da177e4SLinus Torvalds 	struct timer_list		hold_timer;
1331da177e4SLinus Torvalds 	struct timer_list		message_age_timer;
1341da177e4SLinus Torvalds 	struct kobject			kobj;
1351da177e4SLinus Torvalds 	struct rcu_head			rcu;
1363982d3d2SFischer, Anna 
1373982d3d2SFischer, Anna 	unsigned long 			flags;
1383982d3d2SFischer, Anna #define BR_HAIRPIN_MODE		0x00000001
139a2e01a65Sstephen hemminger #define BR_BPDU_GUARD           0x00000002
1401007dd1aSstephen hemminger #define BR_ROOT_BLOCK		0x00000004
141c2d3babfSDavid S. Miller #define BR_MULTICAST_FAST_LEAVE	0x00000008
142eb1d1641SHerbert Xu 
143eb1d1641SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
144eb1d1641SHerbert Xu 	u32				multicast_startup_queries_sent;
145eb1d1641SHerbert Xu 	unsigned char			multicast_router;
146eb1d1641SHerbert Xu 	struct timer_list		multicast_router_timer;
147eb1d1641SHerbert Xu 	struct timer_list		multicast_query_timer;
148eb1d1641SHerbert Xu 	struct hlist_head		mglist;
149eb1d1641SHerbert Xu 	struct hlist_node		rlist;
150eb1d1641SHerbert Xu #endif
151e0f43752SSimon Arlott 
152e0f43752SSimon Arlott #ifdef CONFIG_SYSFS
153e0f43752SSimon Arlott 	char				sysfs_name[IFNAMSIZ];
154e0f43752SSimon Arlott #endif
15591d2c34aSHerbert Xu 
15691d2c34aSHerbert Xu #ifdef CONFIG_NET_POLL_CONTROLLER
15791d2c34aSHerbert Xu 	struct netpoll			*np;
15891d2c34aSHerbert Xu #endif
1591da177e4SLinus Torvalds };
1601da177e4SLinus Torvalds 
161f350a0a8SJiri Pirko #define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
162f350a0a8SJiri Pirko 
163b5ed54e9Sstephen hemminger static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
164b5ed54e9Sstephen hemminger {
1652469ffd7SJohn Fastabend 	struct net_bridge_port *port =
1662469ffd7SJohn Fastabend 			rcu_dereference_rtnl(dev->rx_handler_data);
1672469ffd7SJohn Fastabend 
168b5ed54e9Sstephen hemminger 	return br_port_exists(dev) ? port : NULL;
169b5ed54e9Sstephen hemminger }
170b5ed54e9Sstephen hemminger 
171ec1e5610SEric Dumazet static inline struct net_bridge_port *br_port_get_rtnl(struct net_device *dev)
172b5ed54e9Sstephen hemminger {
173ec1e5610SEric Dumazet 	return br_port_exists(dev) ?
174ec1e5610SEric Dumazet 		rtnl_dereference(dev->rx_handler_data) : NULL;
175b5ed54e9Sstephen hemminger }
176b5ed54e9Sstephen hemminger 
1770eae88f3SEric Dumazet struct br_cpu_netstats {
178406818ffSEric Dumazet 	u64			rx_packets;
179406818ffSEric Dumazet 	u64			rx_bytes;
180406818ffSEric Dumazet 	u64			tx_packets;
181406818ffSEric Dumazet 	u64			tx_bytes;
182406818ffSEric Dumazet 	struct u64_stats_sync	syncp;
1830eae88f3SEric Dumazet };
1840eae88f3SEric Dumazet 
1851da177e4SLinus Torvalds struct net_bridge
1861da177e4SLinus Torvalds {
1871da177e4SLinus Torvalds 	spinlock_t			lock;
1881da177e4SLinus Torvalds 	struct list_head		port_list;
1891da177e4SLinus Torvalds 	struct net_device		*dev;
19014bb4789Sstephen hemminger 
1910eae88f3SEric Dumazet 	struct br_cpu_netstats __percpu *stats;
1921da177e4SLinus Torvalds 	spinlock_t			hash_lock;
1931da177e4SLinus Torvalds 	struct hlist_head		hash[BR_HASH_SIZE];
1944adf0af6SSimon Wunderlich #ifdef CONFIG_BRIDGE_NETFILTER
1954adf0af6SSimon Wunderlich 	struct rtable 			fake_rtable;
1964df53d8bSPatrick McHardy 	bool				nf_call_iptables;
1974df53d8bSPatrick McHardy 	bool				nf_call_ip6tables;
1984df53d8bSPatrick McHardy 	bool				nf_call_arptables;
1994adf0af6SSimon Wunderlich #endif
20092c0574fSStephen Hemminger 	unsigned long			flags;
20192c0574fSStephen Hemminger #define BR_SET_MAC_ADDR		0x00000001
2021da177e4SLinus Torvalds 
203515853ccSstephen hemminger 	u16				group_fwd_mask;
204515853ccSstephen hemminger 
2051da177e4SLinus Torvalds 	/* STP */
2061da177e4SLinus Torvalds 	bridge_id			designated_root;
2071da177e4SLinus Torvalds 	bridge_id			bridge_id;
2081da177e4SLinus Torvalds 	u32				root_path_cost;
2091da177e4SLinus Torvalds 	unsigned long			max_age;
2101da177e4SLinus Torvalds 	unsigned long			hello_time;
2111da177e4SLinus Torvalds 	unsigned long			forward_delay;
2121da177e4SLinus Torvalds 	unsigned long			bridge_max_age;
2131da177e4SLinus Torvalds 	unsigned long			ageing_time;
2141da177e4SLinus Torvalds 	unsigned long			bridge_hello_time;
2151da177e4SLinus Torvalds 	unsigned long			bridge_forward_delay;
2161da177e4SLinus Torvalds 
217fda93d92SStephen Hemminger 	u8				group_addr[ETH_ALEN];
2181da177e4SLinus Torvalds 	u16				root_port;
2199cde0708SStephen Hemminger 
2209cde0708SStephen Hemminger 	enum {
2219cde0708SStephen Hemminger 		BR_NO_STP, 		/* no spanning tree */
2229cde0708SStephen Hemminger 		BR_KERNEL_STP,		/* old STP in kernel */
2239cde0708SStephen Hemminger 		BR_USER_STP,		/* new RSTP in userspace */
2249cde0708SStephen Hemminger 	} stp_enabled;
2259cde0708SStephen Hemminger 
2261da177e4SLinus Torvalds 	unsigned char			topology_change;
2271da177e4SLinus Torvalds 	unsigned char			topology_change_detected;
2281da177e4SLinus Torvalds 
229eb1d1641SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
230eb1d1641SHerbert Xu 	unsigned char			multicast_router;
231eb1d1641SHerbert Xu 
232eb1d1641SHerbert Xu 	u8				multicast_disabled:1;
233c5c23260SHerbert Xu 	u8				multicast_querier:1;
234eb1d1641SHerbert Xu 
235eb1d1641SHerbert Xu 	u32				hash_elasticity;
236eb1d1641SHerbert Xu 	u32				hash_max;
237eb1d1641SHerbert Xu 
238eb1d1641SHerbert Xu 	u32				multicast_last_member_count;
239eb1d1641SHerbert Xu 	u32				multicast_startup_queries_sent;
240eb1d1641SHerbert Xu 	u32				multicast_startup_query_count;
241eb1d1641SHerbert Xu 
242eb1d1641SHerbert Xu 	unsigned long			multicast_last_member_interval;
243eb1d1641SHerbert Xu 	unsigned long			multicast_membership_interval;
244eb1d1641SHerbert Xu 	unsigned long			multicast_querier_interval;
245eb1d1641SHerbert Xu 	unsigned long			multicast_query_interval;
246eb1d1641SHerbert Xu 	unsigned long			multicast_query_response_interval;
247eb1d1641SHerbert Xu 	unsigned long			multicast_startup_query_interval;
248eb1d1641SHerbert Xu 
249eb1d1641SHerbert Xu 	spinlock_t			multicast_lock;
250e8051688SEric Dumazet 	struct net_bridge_mdb_htable __rcu *mdb;
251eb1d1641SHerbert Xu 	struct hlist_head		router_list;
252eb1d1641SHerbert Xu 
253eb1d1641SHerbert Xu 	struct timer_list		multicast_router_timer;
254eb1d1641SHerbert Xu 	struct timer_list		multicast_querier_timer;
255eb1d1641SHerbert Xu 	struct timer_list		multicast_query_timer;
256eb1d1641SHerbert Xu #endif
257eb1d1641SHerbert Xu 
2581da177e4SLinus Torvalds 	struct timer_list		hello_timer;
2591da177e4SLinus Torvalds 	struct timer_list		tcn_timer;
2601da177e4SLinus Torvalds 	struct timer_list		topology_change_timer;
2611da177e4SLinus Torvalds 	struct timer_list		gc_timer;
26243b98c4aSGreg Kroah-Hartman 	struct kobject			*ifobj;
2631da177e4SLinus Torvalds };
2641da177e4SLinus Torvalds 
26568b7c895SHerbert Xu struct br_input_skb_cb {
26668b7c895SHerbert Xu 	struct net_device *brdev;
26732dec5ddSYOSHIFUJI Hideaki / 吉藤英明 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
268eb1d1641SHerbert Xu 	int igmp;
269eb1d1641SHerbert Xu 	int mrouters_only;
27032dec5ddSYOSHIFUJI Hideaki / 吉藤英明 #endif
27168b7c895SHerbert Xu };
27268b7c895SHerbert Xu 
27368b7c895SHerbert Xu #define BR_INPUT_SKB_CB(__skb)	((struct br_input_skb_cb *)(__skb)->cb)
27468b7c895SHerbert Xu 
27532dec5ddSYOSHIFUJI Hideaki / 吉藤英明 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
27632dec5ddSYOSHIFUJI Hideaki / 吉藤英明 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(BR_INPUT_SKB_CB(__skb)->mrouters_only)
27732dec5ddSYOSHIFUJI Hideaki / 吉藤英明 #else
27832dec5ddSYOSHIFUJI Hideaki / 吉藤英明 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(0)
27932dec5ddSYOSHIFUJI Hideaki / 吉藤英明 #endif
28032dec5ddSYOSHIFUJI Hideaki / 吉藤英明 
28128a16c97Sstephen hemminger #define br_printk(level, br, format, args...)	\
28228a16c97Sstephen hemminger 	printk(level "%s: " format, (br)->dev->name, ##args)
28328a16c97Sstephen hemminger 
28428a16c97Sstephen hemminger #define br_err(__br, format, args...)			\
28528a16c97Sstephen hemminger 	br_printk(KERN_ERR, __br, format, ##args)
28628a16c97Sstephen hemminger #define br_warn(__br, format, args...)			\
28728a16c97Sstephen hemminger 	br_printk(KERN_WARNING, __br, format, ##args)
28828a16c97Sstephen hemminger #define br_notice(__br, format, args...)		\
28928a16c97Sstephen hemminger 	br_printk(KERN_NOTICE, __br, format, ##args)
29028a16c97Sstephen hemminger #define br_info(__br, format, args...)			\
29128a16c97Sstephen hemminger 	br_printk(KERN_INFO, __br, format, ##args)
29228a16c97Sstephen hemminger 
29328a16c97Sstephen hemminger #define br_debug(br, format, args...)			\
29428a16c97Sstephen hemminger 	pr_debug("%s: " format,  (br)->dev->name, ##args)
29528a16c97Sstephen hemminger 
2961da177e4SLinus Torvalds extern struct notifier_block br_device_notifier;
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds /* called under bridge lock */
2991da177e4SLinus Torvalds static inline int br_is_root_bridge(const struct net_bridge *br)
3001da177e4SLinus Torvalds {
3011da177e4SLinus Torvalds 	return !memcmp(&br->bridge_id, &br->designated_root, 8);
3021da177e4SLinus Torvalds }
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds /* br_device.c */
3051da177e4SLinus Torvalds extern void br_dev_setup(struct net_device *dev);
3061ce5cce8Sstephen hemminger extern void br_dev_delete(struct net_device *dev, struct list_head *list);
3076fef4c0cSStephen Hemminger extern netdev_tx_t br_dev_xmit(struct sk_buff *skb,
3086fef4c0cSStephen Hemminger 			       struct net_device *dev);
309cfb478daSstephen hemminger #ifdef CONFIG_NET_POLL_CONTROLLER
31091d2c34aSHerbert Xu static inline struct netpoll_info *br_netpoll_info(struct net_bridge *br)
31191d2c34aSHerbert Xu {
31291d2c34aSHerbert Xu 	return br->dev->npinfo;
31391d2c34aSHerbert Xu }
314cfb478daSstephen hemminger 
31591d2c34aSHerbert Xu static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
31691d2c34aSHerbert Xu 				       struct sk_buff *skb)
31791d2c34aSHerbert Xu {
31891d2c34aSHerbert Xu 	struct netpoll *np = p->np;
31991d2c34aSHerbert Xu 
32091d2c34aSHerbert Xu 	if (np)
32191d2c34aSHerbert Xu 		netpoll_send_skb(np, skb);
32291d2c34aSHerbert Xu }
32391d2c34aSHerbert Xu 
32447be03a2SAmerigo Wang extern int br_netpoll_enable(struct net_bridge_port *p, gfp_t gfp);
32591d2c34aSHerbert Xu extern void br_netpoll_disable(struct net_bridge_port *p);
32691d2c34aSHerbert Xu #else
32791d2c34aSHerbert Xu static inline struct netpoll_info *br_netpoll_info(struct net_bridge *br)
32891d2c34aSHerbert Xu {
32991d2c34aSHerbert Xu 	return NULL;
33091d2c34aSHerbert Xu }
33191d2c34aSHerbert Xu 
3329f70b0fcSHerbert Xu static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
33391d2c34aSHerbert Xu 				       struct sk_buff *skb)
33491d2c34aSHerbert Xu {
33591d2c34aSHerbert Xu }
33691d2c34aSHerbert Xu 
33747be03a2SAmerigo Wang static inline int br_netpoll_enable(struct net_bridge_port *p, gfp_t gfp)
33891d2c34aSHerbert Xu {
33991d2c34aSHerbert Xu 	return 0;
34091d2c34aSHerbert Xu }
34191d2c34aSHerbert Xu 
34291d2c34aSHerbert Xu static inline void br_netpoll_disable(struct net_bridge_port *p)
34391d2c34aSHerbert Xu {
34491d2c34aSHerbert Xu }
345cfb478daSstephen hemminger #endif
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds /* br_fdb.c */
34887a596e0SAkinobu Mita extern int br_fdb_init(void);
3491da177e4SLinus Torvalds extern void br_fdb_fini(void);
3509cf63747SStephen Hemminger extern void br_fdb_flush(struct net_bridge *br);
3511da177e4SLinus Torvalds extern void br_fdb_changeaddr(struct net_bridge_port *p,
3521da177e4SLinus Torvalds 			      const unsigned char *newaddr);
35343598813Sstephen hemminger extern void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
3541da177e4SLinus Torvalds extern void br_fdb_cleanup(unsigned long arg);
3551da177e4SLinus Torvalds extern void br_fdb_delete_by_port(struct net_bridge *br,
3561a620698SStephen Hemminger 				  const struct net_bridge_port *p, int do_all);
3571da177e4SLinus Torvalds extern struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
3581da177e4SLinus Torvalds 						 const unsigned char *addr);
359da678292SMichał Mirosław extern int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
3601da177e4SLinus Torvalds extern int br_fdb_fillbuf(struct net_bridge *br, void *buf,
3611da177e4SLinus Torvalds 			  unsigned long count, unsigned long off);
3621da177e4SLinus Torvalds extern int br_fdb_insert(struct net_bridge *br,
3631da177e4SLinus Torvalds 			 struct net_bridge_port *source,
3641da177e4SLinus Torvalds 			 const unsigned char *addr);
3651da177e4SLinus Torvalds extern void br_fdb_update(struct net_bridge *br,
3661da177e4SLinus Torvalds 			  struct net_bridge_port *source,
3671da177e4SLinus Torvalds 			  const unsigned char *addr);
36877162022SJohn Fastabend 
36977162022SJohn Fastabend extern int br_fdb_delete(struct ndmsg *ndm,
37077162022SJohn Fastabend 			 struct net_device *dev,
3716b6e2725Sstephen hemminger 			 const unsigned char *addr);
372edc7d573Sstephen hemminger extern int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[],
37377162022SJohn Fastabend 		      struct net_device *dev,
3746b6e2725Sstephen hemminger 		      const unsigned char *addr,
37577162022SJohn Fastabend 		      u16 nlh_flags);
37677162022SJohn Fastabend extern int br_fdb_dump(struct sk_buff *skb,
37777162022SJohn Fastabend 		       struct netlink_callback *cb,
37877162022SJohn Fastabend 		       struct net_device *dev,
37977162022SJohn Fastabend 		       int idx);
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds /* br_forward.c */
3821da177e4SLinus Torvalds extern void br_deliver(const struct net_bridge_port *to,
3831da177e4SLinus Torvalds 		struct sk_buff *skb);
3841da177e4SLinus Torvalds extern int br_dev_queue_push_xmit(struct sk_buff *skb);
3851da177e4SLinus Torvalds extern void br_forward(const struct net_bridge_port *to,
3867f7708f0SMichael Braun 		struct sk_buff *skb, struct sk_buff *skb0);
3871da177e4SLinus Torvalds extern int br_forward_finish(struct sk_buff *skb);
388e081e1e3SHerbert Xu extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb);
389b33084beSHerbert Xu extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
390b33084beSHerbert Xu 			     struct sk_buff *skb2);
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds /* br_if.c */
393269def7cSStephen Hemminger extern void br_port_carrier_check(struct net_bridge_port *p);
3944aa678baSAlexey Dobriyan extern int br_add_bridge(struct net *net, const char *name);
3954aa678baSAlexey Dobriyan extern int br_del_bridge(struct net *net, const char *name);
396712d6954SAlexey Dobriyan extern void br_net_exit(struct net *net);
3971da177e4SLinus Torvalds extern int br_add_if(struct net_bridge *br,
3981da177e4SLinus Torvalds 	      struct net_device *dev);
3991da177e4SLinus Torvalds extern int br_del_if(struct net_bridge *br,
4001da177e4SLinus Torvalds 	      struct net_device *dev);
4011da177e4SLinus Torvalds extern int br_min_mtu(const struct net_bridge *br);
402c8f44affSMichał Mirosław extern netdev_features_t br_features_recompute(struct net_bridge *br,
403c8f44affSMichał Mirosław 	netdev_features_t features);
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds /* br_input.c */
4061da177e4SLinus Torvalds extern int br_handle_frame_finish(struct sk_buff *skb);
4078a4eb573SJiri Pirko extern rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds /* br_ioctl.c */
4101da177e4SLinus Torvalds extern int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
411881d966bSEric W. Biederman extern int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *arg);
4121da177e4SLinus Torvalds 
413eb1d1641SHerbert Xu /* br_multicast.c */
414eb1d1641SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
4152ce297fcSCong Wang extern unsigned int br_mdb_rehash_seq;
416eb1d1641SHerbert Xu extern int br_multicast_rcv(struct net_bridge *br,
417eb1d1641SHerbert Xu 			    struct net_bridge_port *port,
418eb1d1641SHerbert Xu 			    struct sk_buff *skb);
419eb1d1641SHerbert Xu extern struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
420eb1d1641SHerbert Xu 					       struct sk_buff *skb);
421eb1d1641SHerbert Xu extern void br_multicast_add_port(struct net_bridge_port *port);
422eb1d1641SHerbert Xu extern void br_multicast_del_port(struct net_bridge_port *port);
423eb1d1641SHerbert Xu extern void br_multicast_enable_port(struct net_bridge_port *port);
424eb1d1641SHerbert Xu extern void br_multicast_disable_port(struct net_bridge_port *port);
425eb1d1641SHerbert Xu extern void br_multicast_init(struct net_bridge *br);
426eb1d1641SHerbert Xu extern void br_multicast_open(struct net_bridge *br);
427eb1d1641SHerbert Xu extern void br_multicast_stop(struct net_bridge *br);
4285cb5e947SHerbert Xu extern void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
4295cb5e947SHerbert Xu 				 struct sk_buff *skb);
4305cb5e947SHerbert Xu extern void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
4315cb5e947SHerbert Xu 				 struct sk_buff *skb, struct sk_buff *skb2);
4320909e117SHerbert Xu extern int br_multicast_set_router(struct net_bridge *br, unsigned long val);
4330909e117SHerbert Xu extern int br_multicast_set_port_router(struct net_bridge_port *p,
4340909e117SHerbert Xu 					unsigned long val);
435561f1103SHerbert Xu extern int br_multicast_toggle(struct net_bridge *br, unsigned long val);
436c5c23260SHerbert Xu extern int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
437b195167fSHerbert Xu extern int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
438cfd56754SCong Wang extern struct net_bridge_mdb_entry *br_mdb_ip_get(
439cfd56754SCong Wang 				struct net_bridge_mdb_htable *mdb,
440cfd56754SCong Wang 				struct br_ip *dst);
441cfd56754SCong Wang extern struct net_bridge_mdb_entry *br_multicast_new_group(struct net_bridge *br,
442cfd56754SCong Wang 				struct net_bridge_port *port, struct br_ip *group);
443cfd56754SCong Wang extern void br_multicast_free_pg(struct rcu_head *head);
444cfd56754SCong Wang extern struct net_bridge_port_group *br_multicast_new_port_group(
445cfd56754SCong Wang 				struct net_bridge_port *port,
446cfd56754SCong Wang 				struct br_ip *group,
447ccb1c31aSAmerigo Wang 				struct net_bridge_port_group *next,
448ccb1c31aSAmerigo Wang 				unsigned char state);
449ee07c6e7SCong Wang extern void br_mdb_init(void);
45037a393bcSCong Wang extern void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
45137a393bcSCong Wang 			  struct br_ip *group, int type);
45285b35269SSridhar Samudrala 
453cfd56754SCong Wang #define mlock_dereference(X, br) \
454cfd56754SCong Wang 	rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
455cfd56754SCong Wang 
456cfd56754SCong Wang #if IS_ENABLED(CONFIG_IPV6)
457cfd56754SCong Wang #include <net/addrconf.h>
458cfd56754SCong Wang static inline int ipv6_is_transient_multicast(const struct in6_addr *addr)
459cfd56754SCong Wang {
460cfd56754SCong Wang 	if (ipv6_addr_is_multicast(addr) && IPV6_ADDR_MC_FLAG_TRANSIENT(addr))
461cfd56754SCong Wang 		return 1;
462cfd56754SCong Wang 	return 0;
463cfd56754SCong Wang }
464cfd56754SCong Wang #endif
465cfd56754SCong Wang 
46685b35269SSridhar Samudrala static inline bool br_multicast_is_router(struct net_bridge *br)
46785b35269SSridhar Samudrala {
46885b35269SSridhar Samudrala 	return br->multicast_router == 2 ||
46985b35269SSridhar Samudrala 	       (br->multicast_router == 1 &&
47085b35269SSridhar Samudrala 		timer_pending(&br->multicast_router_timer));
47185b35269SSridhar Samudrala }
472eb1d1641SHerbert Xu #else
473eb1d1641SHerbert Xu static inline int br_multicast_rcv(struct net_bridge *br,
474eb1d1641SHerbert Xu 				   struct net_bridge_port *port,
475eb1d1641SHerbert Xu 				   struct sk_buff *skb)
476eb1d1641SHerbert Xu {
477eb1d1641SHerbert Xu 	return 0;
478eb1d1641SHerbert Xu }
479eb1d1641SHerbert Xu 
480eb1d1641SHerbert Xu static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
481eb1d1641SHerbert Xu 						      struct sk_buff *skb)
482eb1d1641SHerbert Xu {
483eb1d1641SHerbert Xu 	return NULL;
484eb1d1641SHerbert Xu }
485eb1d1641SHerbert Xu 
486eb1d1641SHerbert Xu static inline void br_multicast_add_port(struct net_bridge_port *port)
487eb1d1641SHerbert Xu {
488eb1d1641SHerbert Xu }
489eb1d1641SHerbert Xu 
490eb1d1641SHerbert Xu static inline void br_multicast_del_port(struct net_bridge_port *port)
491eb1d1641SHerbert Xu {
492eb1d1641SHerbert Xu }
493eb1d1641SHerbert Xu 
494eb1d1641SHerbert Xu static inline void br_multicast_enable_port(struct net_bridge_port *port)
495eb1d1641SHerbert Xu {
496eb1d1641SHerbert Xu }
497eb1d1641SHerbert Xu 
498eb1d1641SHerbert Xu static inline void br_multicast_disable_port(struct net_bridge_port *port)
499eb1d1641SHerbert Xu {
500eb1d1641SHerbert Xu }
501eb1d1641SHerbert Xu 
502eb1d1641SHerbert Xu static inline void br_multicast_init(struct net_bridge *br)
503eb1d1641SHerbert Xu {
504eb1d1641SHerbert Xu }
505eb1d1641SHerbert Xu 
506eb1d1641SHerbert Xu static inline void br_multicast_open(struct net_bridge *br)
507eb1d1641SHerbert Xu {
508eb1d1641SHerbert Xu }
509eb1d1641SHerbert Xu 
510eb1d1641SHerbert Xu static inline void br_multicast_stop(struct net_bridge *br)
511eb1d1641SHerbert Xu {
512eb1d1641SHerbert Xu }
5135cb5e947SHerbert Xu 
5145cb5e947SHerbert Xu static inline void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
5155cb5e947SHerbert Xu 					struct sk_buff *skb)
5165cb5e947SHerbert Xu {
5175cb5e947SHerbert Xu }
5185cb5e947SHerbert Xu 
5195cb5e947SHerbert Xu static inline void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
5205cb5e947SHerbert Xu 					struct sk_buff *skb,
5215cb5e947SHerbert Xu 					struct sk_buff *skb2)
5225cb5e947SHerbert Xu {
5235cb5e947SHerbert Xu }
524eb1d1641SHerbert Xu static inline bool br_multicast_is_router(struct net_bridge *br)
525eb1d1641SHerbert Xu {
52685b35269SSridhar Samudrala 	return 0;
527eb1d1641SHerbert Xu }
52885b35269SSridhar Samudrala #endif
529eb1d1641SHerbert Xu 
5301da177e4SLinus Torvalds /* br_netfilter.c */
531c0909713SStephen Hemminger #ifdef CONFIG_BRIDGE_NETFILTER
5321da177e4SLinus Torvalds extern int br_netfilter_init(void);
5331da177e4SLinus Torvalds extern void br_netfilter_fini(void);
5344adf0af6SSimon Wunderlich extern void br_netfilter_rtable_init(struct net_bridge *);
535c0909713SStephen Hemminger #else
536c0909713SStephen Hemminger #define br_netfilter_init()	(0)
537c0909713SStephen Hemminger #define br_netfilter_fini()	do { } while(0)
5384adf0af6SSimon Wunderlich #define br_netfilter_rtable_init(x)
539c0909713SStephen Hemminger #endif
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds /* br_stp.c */
5421da177e4SLinus Torvalds extern void br_log_state(const struct net_bridge_port *p);
5431da177e4SLinus Torvalds extern struct net_bridge_port *br_get_port(struct net_bridge *br,
5441da177e4SLinus Torvalds 					   u16 port_no);
5451da177e4SLinus Torvalds extern void br_init_port(struct net_bridge_port *p);
5461da177e4SLinus Torvalds extern void br_become_designated_port(struct net_bridge_port *p);
5471da177e4SLinus Torvalds 
54814f98f25Sstephen hemminger extern int br_set_forward_delay(struct net_bridge *br, unsigned long x);
54914f98f25Sstephen hemminger extern int br_set_hello_time(struct net_bridge *br, unsigned long x);
55014f98f25Sstephen hemminger extern int br_set_max_age(struct net_bridge *br, unsigned long x);
55114f98f25Sstephen hemminger 
55214f98f25Sstephen hemminger 
5531da177e4SLinus Torvalds /* br_stp_if.c */
5541da177e4SLinus Torvalds extern void br_stp_enable_bridge(struct net_bridge *br);
5551da177e4SLinus Torvalds extern void br_stp_disable_bridge(struct net_bridge *br);
5569cde0708SStephen Hemminger extern void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
5571da177e4SLinus Torvalds extern void br_stp_enable_port(struct net_bridge_port *p);
5581da177e4SLinus Torvalds extern void br_stp_disable_port(struct net_bridge_port *p);
559edf947f1Sstephen hemminger extern bool br_stp_recalculate_bridge_id(struct net_bridge *br);
5604505a3efSStephen Hemminger extern void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
5611da177e4SLinus Torvalds extern void br_stp_set_bridge_priority(struct net_bridge *br,
5621da177e4SLinus Torvalds 				       u16 newprio);
56314f98f25Sstephen hemminger extern int br_stp_set_port_priority(struct net_bridge_port *p,
56414f98f25Sstephen hemminger 				    unsigned long newprio);
56514f98f25Sstephen hemminger extern int br_stp_set_path_cost(struct net_bridge_port *p,
56614f98f25Sstephen hemminger 				unsigned long path_cost);
5671da177e4SLinus Torvalds extern ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
5681da177e4SLinus Torvalds 
5691da177e4SLinus Torvalds /* br_stp_bpdu.c */
5707c85fbf0SPatrick McHardy struct stp_proto;
5717c85fbf0SPatrick McHardy extern void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
5727c85fbf0SPatrick McHardy 		       struct net_device *dev);
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds /* br_stp_timer.c */
5751da177e4SLinus Torvalds extern void br_stp_timer_init(struct net_bridge *br);
5761da177e4SLinus Torvalds extern void br_stp_port_timer_init(struct net_bridge_port *p);
5771da177e4SLinus Torvalds extern unsigned long br_timer_value(const struct timer_list *timer);
5781da177e4SLinus Torvalds 
5791da177e4SLinus Torvalds /* br.c */
580e6373c4cSIgor Maravić #if IS_ENABLED(CONFIG_ATM_LANE)
581da678292SMichał Mirosław extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
582da678292SMichał Mirosław #endif
5831da177e4SLinus Torvalds 
58411dc1f36SStephen Hemminger /* br_netlink.c */
585149ddd83Sstephen hemminger extern struct rtnl_link_ops br_link_ops;
58632fe21c0SThomas Graf extern int br_netlink_init(void);
58711dc1f36SStephen Hemminger extern void br_netlink_fini(void);
58811dc1f36SStephen Hemminger extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
589e5a55a89SJohn Fastabend extern int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg);
590e5a55a89SJohn Fastabend extern int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
591e5a55a89SJohn Fastabend 		      struct net_device *dev);
59211dc1f36SStephen Hemminger 
5931da177e4SLinus Torvalds #ifdef CONFIG_SYSFS
5941da177e4SLinus Torvalds /* br_sysfs_if.c */
59552cf25d0SEmese Revfy extern const struct sysfs_ops brport_sysfs_ops;
5961da177e4SLinus Torvalds extern int br_sysfs_addif(struct net_bridge_port *p);
597e0f43752SSimon Arlott extern int br_sysfs_renameif(struct net_bridge_port *p);
5981da177e4SLinus Torvalds 
5991da177e4SLinus Torvalds /* br_sysfs_br.c */
6001da177e4SLinus Torvalds extern int br_sysfs_addbr(struct net_device *dev);
6011da177e4SLinus Torvalds extern void br_sysfs_delbr(struct net_device *dev);
6021da177e4SLinus Torvalds 
6031da177e4SLinus Torvalds #else
6041da177e4SLinus Torvalds 
6050cb2bbbeSLee Jones static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
6060cb2bbbeSLee Jones static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
6070cb2bbbeSLee Jones static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
6080cb2bbbeSLee Jones static inline void br_sysfs_delbr(struct net_device *dev) { return; }
6091da177e4SLinus Torvalds #endif /* CONFIG_SYSFS */
6101da177e4SLinus Torvalds 
6111da177e4SLinus Torvalds #endif
612