]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/bridge/br_private.h
net: Introduce u64_stats_sync infrastructure
[mirror_ubuntu-bionic-kernel.git] / net / bridge / br_private.h
CommitLineData
1da177e4
LT
1/*
2 * Linux ethernet bridge
3 *
4 * Authors:
5 * Lennert Buytenhek <buytenh@gnu.org>
6 *
1da177e4
LT
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#ifndef _BR_PRIVATE_H
14#define _BR_PRIVATE_H
15
16#include <linux/netdevice.h>
1da177e4 17#include <linux/if_bridge.h>
91d2c34a 18#include <linux/netpoll.h>
4adf0af6 19#include <net/route.h>
1da177e4
LT
20
21#define BR_HASH_BITS 8
22#define BR_HASH_SIZE (1 << BR_HASH_BITS)
23
24#define BR_HOLD_TIME (1*HZ)
25
26#define BR_PORT_BITS 10
27#define BR_MAX_PORTS (1<<BR_PORT_BITS)
28
9cde0708
SH
29#define BR_VERSION "2.3"
30
31/* Path to usermode spanning tree program */
32#define BR_STP_PROG "/sbin/bridge-stp"
8cbb512e 33
1da177e4
LT
34typedef struct bridge_id bridge_id;
35typedef struct mac_addr mac_addr;
36typedef __u16 port_id;
37
38struct bridge_id
39{
40 unsigned char prio[2];
41 unsigned char addr[6];
42};
43
44struct mac_addr
45{
46 unsigned char addr[6];
47};
48
8ef2a9a5
YH
49struct br_ip
50{
51 union {
52 __be32 ip4;
08b202b6
YH
53#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
54 struct in6_addr ip6;
55#endif
8ef2a9a5
YH
56 } u;
57 __be16 proto;
58};
59
1da177e4
LT
60struct net_bridge_fdb_entry
61{
62 struct hlist_node hlist;
63 struct net_bridge_port *dst;
64
65 struct rcu_head rcu;
1da177e4
LT
66 unsigned long ageing_timer;
67 mac_addr addr;
68 unsigned char is_local;
69 unsigned char is_static;
70};
71
eb1d1641
HX
72struct net_bridge_port_group {
73 struct net_bridge_port *port;
74 struct net_bridge_port_group *next;
75 struct hlist_node mglist;
76 struct rcu_head rcu;
77 struct timer_list timer;
78 struct timer_list query_timer;
8ef2a9a5 79 struct br_ip addr;
eb1d1641
HX
80 u32 queries_sent;
81};
82
83struct net_bridge_mdb_entry
84{
85 struct hlist_node hlist[2];
86 struct hlist_node mglist;
87 struct net_bridge *br;
88 struct net_bridge_port_group *ports;
89 struct rcu_head rcu;
90 struct timer_list timer;
91 struct timer_list query_timer;
8ef2a9a5 92 struct br_ip addr;
eb1d1641
HX
93 u32 queries_sent;
94};
95
96struct net_bridge_mdb_htable
97{
98 struct hlist_head *mhash;
99 struct rcu_head rcu;
100 struct net_bridge_mdb_htable *old;
101 u32 size;
102 u32 max;
103 u32 secret;
104 u32 ver;
105};
106
1da177e4
LT
107struct net_bridge_port
108{
109 struct net_bridge *br;
110 struct net_device *dev;
111 struct list_head list;
112
113 /* STP */
114 u8 priority;
115 u8 state;
116 u16 port_no;
117 unsigned char topology_change_ack;
118 unsigned char config_pending;
119 port_id port_id;
120 port_id designated_port;
121 bridge_id designated_root;
122 bridge_id designated_bridge;
123 u32 path_cost;
124 u32 designated_cost;
125
126 struct timer_list forward_delay_timer;
127 struct timer_list hold_timer;
128 struct timer_list message_age_timer;
129 struct kobject kobj;
130 struct rcu_head rcu;
3982d3d2
FA
131
132 unsigned long flags;
133#define BR_HAIRPIN_MODE 0x00000001
eb1d1641
HX
134
135#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
136 u32 multicast_startup_queries_sent;
137 unsigned char multicast_router;
138 struct timer_list multicast_router_timer;
139 struct timer_list multicast_query_timer;
140 struct hlist_head mglist;
141 struct hlist_node rlist;
142#endif
e0f43752
SA
143
144#ifdef CONFIG_SYSFS
145 char sysfs_name[IFNAMSIZ];
146#endif
91d2c34a
HX
147
148#ifdef CONFIG_NET_POLL_CONTROLLER
149 struct netpoll *np;
150#endif
1da177e4
LT
151};
152
f350a0a8
JP
153#define br_port_get_rcu(dev) \
154 ((struct net_bridge_port *) rcu_dereference(dev->rx_handler_data))
155#define br_port_get(dev) ((struct net_bridge_port *) dev->rx_handler_data)
156#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
157
0eae88f3
ED
158struct br_cpu_netstats {
159 unsigned long rx_packets;
160 unsigned long rx_bytes;
161 unsigned long tx_packets;
162 unsigned long tx_bytes;
163};
164
1da177e4
LT
165struct net_bridge
166{
167 spinlock_t lock;
168 struct list_head port_list;
169 struct net_device *dev;
14bb4789 170
0eae88f3 171 struct br_cpu_netstats __percpu *stats;
1da177e4
LT
172 spinlock_t hash_lock;
173 struct hlist_head hash[BR_HASH_SIZE];
edb5e46f 174 unsigned long feature_mask;
4adf0af6
SW
175#ifdef CONFIG_BRIDGE_NETFILTER
176 struct rtable fake_rtable;
177#endif
92c0574f
SH
178 unsigned long flags;
179#define BR_SET_MAC_ADDR 0x00000001
1da177e4
LT
180
181 /* STP */
182 bridge_id designated_root;
183 bridge_id bridge_id;
184 u32 root_path_cost;
185 unsigned long max_age;
186 unsigned long hello_time;
187 unsigned long forward_delay;
188 unsigned long bridge_max_age;
189 unsigned long ageing_time;
190 unsigned long bridge_hello_time;
191 unsigned long bridge_forward_delay;
192
fda93d92 193 u8 group_addr[ETH_ALEN];
1da177e4 194 u16 root_port;
9cde0708
SH
195
196 enum {
197 BR_NO_STP, /* no spanning tree */
198 BR_KERNEL_STP, /* old STP in kernel */
199 BR_USER_STP, /* new RSTP in userspace */
200 } stp_enabled;
201
1da177e4
LT
202 unsigned char topology_change;
203 unsigned char topology_change_detected;
204
eb1d1641
HX
205#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
206 unsigned char multicast_router;
207
208 u8 multicast_disabled:1;
209
210 u32 hash_elasticity;
211 u32 hash_max;
212
213 u32 multicast_last_member_count;
214 u32 multicast_startup_queries_sent;
215 u32 multicast_startup_query_count;
216
217 unsigned long multicast_last_member_interval;
218 unsigned long multicast_membership_interval;
219 unsigned long multicast_querier_interval;
220 unsigned long multicast_query_interval;
221 unsigned long multicast_query_response_interval;
222 unsigned long multicast_startup_query_interval;
223
224 spinlock_t multicast_lock;
225 struct net_bridge_mdb_htable *mdb;
226 struct hlist_head router_list;
227 struct hlist_head mglist;
228
229 struct timer_list multicast_router_timer;
230 struct timer_list multicast_querier_timer;
231 struct timer_list multicast_query_timer;
232#endif
233
1da177e4
LT
234 struct timer_list hello_timer;
235 struct timer_list tcn_timer;
236 struct timer_list topology_change_timer;
237 struct timer_list gc_timer;
43b98c4a 238 struct kobject *ifobj;
1da177e4
LT
239};
240
68b7c895
HX
241struct br_input_skb_cb {
242 struct net_device *brdev;
32dec5dd 243#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
eb1d1641
HX
244 int igmp;
245 int mrouters_only;
32dec5dd 246#endif
68b7c895
HX
247};
248
249#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
250
32dec5dd
YH
251#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
252# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
253#else
254# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
255#endif
256
28a16c97 257#define br_printk(level, br, format, args...) \
258 printk(level "%s: " format, (br)->dev->name, ##args)
259
260#define br_err(__br, format, args...) \
261 br_printk(KERN_ERR, __br, format, ##args)
262#define br_warn(__br, format, args...) \
263 br_printk(KERN_WARNING, __br, format, ##args)
264#define br_notice(__br, format, args...) \
265 br_printk(KERN_NOTICE, __br, format, ##args)
266#define br_info(__br, format, args...) \
267 br_printk(KERN_INFO, __br, format, ##args)
268
269#define br_debug(br, format, args...) \
270 pr_debug("%s: " format, (br)->dev->name, ##args)
271
1da177e4 272extern struct notifier_block br_device_notifier;
fda93d92 273extern const u8 br_group_address[ETH_ALEN];
1da177e4
LT
274
275/* called under bridge lock */
276static inline int br_is_root_bridge(const struct net_bridge *br)
277{
278 return !memcmp(&br->bridge_id, &br->designated_root, 8);
279}
280
1da177e4
LT
281/* br_device.c */
282extern void br_dev_setup(struct net_device *dev);
6fef4c0c
SH
283extern netdev_tx_t br_dev_xmit(struct sk_buff *skb,
284 struct net_device *dev);
cfb478da 285#ifdef CONFIG_NET_POLL_CONTROLLER
91d2c34a
HX
286static inline struct netpoll_info *br_netpoll_info(struct net_bridge *br)
287{
288 return br->dev->npinfo;
289}
290
291static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
292 struct sk_buff *skb)
293{
294 struct netpoll *np = p->np;
295
296 if (np)
297 netpoll_send_skb(np, skb);
298}
299
300extern int br_netpoll_enable(struct net_bridge_port *p);
301extern void br_netpoll_disable(struct net_bridge_port *p);
cfb478da 302#else
91d2c34a
HX
303static inline struct netpoll_info *br_netpoll_info(struct net_bridge *br)
304{
305 return NULL;
306}
307
9f70b0fc 308static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
91d2c34a
HX
309 struct sk_buff *skb)
310{
311}
cfb478da 312
91d2c34a
HX
313static inline int br_netpoll_enable(struct net_bridge_port *p)
314{
315 return 0;
316}
317
318static inline void br_netpoll_disable(struct net_bridge_port *p)
319{
320}
cfb478da 321#endif
1da177e4
LT
322
323/* br_fdb.c */
87a596e0 324extern int br_fdb_init(void);
1da177e4 325extern void br_fdb_fini(void);
9cf63747 326extern void br_fdb_flush(struct net_bridge *br);
1da177e4
LT
327extern void br_fdb_changeaddr(struct net_bridge_port *p,
328 const unsigned char *newaddr);
329extern void br_fdb_cleanup(unsigned long arg);
330extern void br_fdb_delete_by_port(struct net_bridge *br,
1a620698 331 const struct net_bridge_port *p, int do_all);
1da177e4
LT
332extern struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
333 const unsigned char *addr);
da678292 334extern int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
9d6f229f 335extern int br_fdb_fillbuf(struct net_bridge *br, void *buf,
1da177e4
LT
336 unsigned long count, unsigned long off);
337extern int br_fdb_insert(struct net_bridge *br,
338 struct net_bridge_port *source,
339 const unsigned char *addr);
340extern void br_fdb_update(struct net_bridge *br,
341 struct net_bridge_port *source,
342 const unsigned char *addr);
343
344/* br_forward.c */
345extern void br_deliver(const struct net_bridge_port *to,
346 struct sk_buff *skb);
347extern int br_dev_queue_push_xmit(struct sk_buff *skb);
348extern void br_forward(const struct net_bridge_port *to,
7f7708f0 349 struct sk_buff *skb, struct sk_buff *skb0);
1da177e4 350extern int br_forward_finish(struct sk_buff *skb);
e081e1e3 351extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb);
b33084be
HX
352extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
353 struct sk_buff *skb2);
1da177e4
LT
354
355/* br_if.c */
269def7c 356extern void br_port_carrier_check(struct net_bridge_port *p);
4aa678ba
AD
357extern int br_add_bridge(struct net *net, const char *name);
358extern int br_del_bridge(struct net *net, const char *name);
712d6954 359extern void br_net_exit(struct net *net);
1da177e4
LT
360extern int br_add_if(struct net_bridge *br,
361 struct net_device *dev);
362extern int br_del_if(struct net_bridge *br,
363 struct net_device *dev);
364extern int br_min_mtu(const struct net_bridge *br);
81d35307 365extern void br_features_recompute(struct net_bridge *br);
1da177e4
LT
366
367/* br_input.c */
368extern int br_handle_frame_finish(struct sk_buff *skb);
ab95bfe0 369extern struct sk_buff *br_handle_frame(struct sk_buff *skb);
1da177e4
LT
370
371/* br_ioctl.c */
372extern int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
881d966b 373extern int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *arg);
1da177e4 374
eb1d1641
HX
375/* br_multicast.c */
376#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
377extern int br_multicast_rcv(struct net_bridge *br,
378 struct net_bridge_port *port,
379 struct sk_buff *skb);
380extern struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
381 struct sk_buff *skb);
382extern void br_multicast_add_port(struct net_bridge_port *port);
383extern void br_multicast_del_port(struct net_bridge_port *port);
384extern void br_multicast_enable_port(struct net_bridge_port *port);
385extern void br_multicast_disable_port(struct net_bridge_port *port);
386extern void br_multicast_init(struct net_bridge *br);
387extern void br_multicast_open(struct net_bridge *br);
388extern void br_multicast_stop(struct net_bridge *br);
5cb5e947
HX
389extern void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
390 struct sk_buff *skb);
391extern void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
392 struct sk_buff *skb, struct sk_buff *skb2);
0909e117
HX
393extern int br_multicast_set_router(struct net_bridge *br, unsigned long val);
394extern int br_multicast_set_port_router(struct net_bridge_port *p,
395 unsigned long val);
561f1103 396extern int br_multicast_toggle(struct net_bridge *br, unsigned long val);
b195167f 397extern int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
85b35269
SS
398
399static inline bool br_multicast_is_router(struct net_bridge *br)
400{
401 return br->multicast_router == 2 ||
402 (br->multicast_router == 1 &&
403 timer_pending(&br->multicast_router_timer));
404}
eb1d1641
HX
405#else
406static inline int br_multicast_rcv(struct net_bridge *br,
407 struct net_bridge_port *port,
408 struct sk_buff *skb)
409{
410 return 0;
411}
412
413static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
414 struct sk_buff *skb)
415{
416 return NULL;
417}
418
419static inline void br_multicast_add_port(struct net_bridge_port *port)
420{
421}
422
423static inline void br_multicast_del_port(struct net_bridge_port *port)
424{
425}
426
427static inline void br_multicast_enable_port(struct net_bridge_port *port)
428{
429}
430
431static inline void br_multicast_disable_port(struct net_bridge_port *port)
432{
433}
434
435static inline void br_multicast_init(struct net_bridge *br)
436{
437}
438
439static inline void br_multicast_open(struct net_bridge *br)
440{
441}
442
443static inline void br_multicast_stop(struct net_bridge *br)
444{
445}
5cb5e947
HX
446
447static inline void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
448 struct sk_buff *skb)
449{
450}
451
452static inline void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
453 struct sk_buff *skb,
454 struct sk_buff *skb2)
455{
456}
eb1d1641
HX
457static inline bool br_multicast_is_router(struct net_bridge *br)
458{
85b35269 459 return 0;
eb1d1641 460}
85b35269 461#endif
eb1d1641 462
1da177e4 463/* br_netfilter.c */
c0909713 464#ifdef CONFIG_BRIDGE_NETFILTER
1da177e4
LT
465extern int br_netfilter_init(void);
466extern void br_netfilter_fini(void);
4adf0af6 467extern void br_netfilter_rtable_init(struct net_bridge *);
c0909713
SH
468#else
469#define br_netfilter_init() (0)
470#define br_netfilter_fini() do { } while(0)
4adf0af6 471#define br_netfilter_rtable_init(x)
c0909713 472#endif
1da177e4
LT
473
474/* br_stp.c */
475extern void br_log_state(const struct net_bridge_port *p);
476extern struct net_bridge_port *br_get_port(struct net_bridge *br,
9d6f229f 477 u16 port_no);
1da177e4
LT
478extern void br_init_port(struct net_bridge_port *p);
479extern void br_become_designated_port(struct net_bridge_port *p);
480
481/* br_stp_if.c */
482extern void br_stp_enable_bridge(struct net_bridge *br);
483extern void br_stp_disable_bridge(struct net_bridge *br);
9cde0708 484extern void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
1da177e4
LT
485extern void br_stp_enable_port(struct net_bridge_port *p);
486extern void br_stp_disable_port(struct net_bridge_port *p);
487extern void br_stp_recalculate_bridge_id(struct net_bridge *br);
4505a3ef 488extern void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1da177e4
LT
489extern void br_stp_set_bridge_priority(struct net_bridge *br,
490 u16 newprio);
491extern void br_stp_set_port_priority(struct net_bridge_port *p,
492 u8 newprio);
493extern void br_stp_set_path_cost(struct net_bridge_port *p,
494 u32 path_cost);
495extern ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
496
497/* br_stp_bpdu.c */
7c85fbf0
PM
498struct stp_proto;
499extern void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
500 struct net_device *dev);
1da177e4
LT
501
502/* br_stp_timer.c */
503extern void br_stp_timer_init(struct net_bridge *br);
504extern void br_stp_port_timer_init(struct net_bridge_port *p);
505extern unsigned long br_timer_value(const struct timer_list *timer);
506
507/* br.c */
da678292
MM
508#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
509extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
510#endif
1da177e4 511
11dc1f36 512/* br_netlink.c */
32fe21c0 513extern int br_netlink_init(void);
11dc1f36
SH
514extern void br_netlink_fini(void);
515extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
516
1da177e4
LT
517#ifdef CONFIG_SYSFS
518/* br_sysfs_if.c */
52cf25d0 519extern const struct sysfs_ops brport_sysfs_ops;
1da177e4 520extern int br_sysfs_addif(struct net_bridge_port *p);
e0f43752 521extern int br_sysfs_renameif(struct net_bridge_port *p);
1da177e4
LT
522
523/* br_sysfs_br.c */
524extern int br_sysfs_addbr(struct net_device *dev);
525extern void br_sysfs_delbr(struct net_device *dev);
526
527#else
528
529#define br_sysfs_addif(p) (0)
e0f43752 530#define br_sysfs_renameif(p) (0)
1da177e4
LT
531#define br_sysfs_addbr(dev) (0)
532#define br_sysfs_delbr(dev) do { } while(0)
533#endif /* CONFIG_SYSFS */
534
535#endif