blob: 1b5d145dfcbf28beb5d7dfd3a28fcdaf919e26aa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux ethernet bridge
3 *
4 * Authors:
5 * Lennert Buytenhek <buytenh@gnu.org>
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/if_bridge.h>
Herbert Xu91d2c342010-06-10 16:12:50 +000018#include <linux/netpoll.h>
Eric Dumazet406818f2010-06-23 13:00:48 -070019#include <linux/u64_stats_sync.h>
Simon Wunderlich4adf0af2008-07-30 16:27:55 -070020#include <net/route.h>
Bernhard Thalerefb6de92015-05-30 15:30:16 +020021#include <net/ip6_fib.h>
Vlad Yasevich243a2e62013-02-13 12:00:09 +000022#include <linux/if_vlan.h>
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +020023#include <linux/rhashtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#define BR_HASH_BITS 8
26#define BR_HASH_SIZE (1 << BR_HASH_BITS)
27
28#define BR_HOLD_TIME (1*HZ)
29
30#define BR_PORT_BITS 10
31#define BR_MAX_PORTS (1<<BR_PORT_BITS)
32
Stephen Hemminger9cde0702007-03-21 14:22:44 -070033#define BR_VERSION "2.3"
34
stephen hemminger515853c2011-10-03 18:14:46 +000035/* Control of forwarding link local multicast */
36#define BR_GROUPFWD_DEFAULT 0
Bernhard Thaler784b58a2015-05-04 22:47:13 +020037/* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
38#define BR_GROUPFWD_RESTRICTED 0x0007u
Toshiaki Makitaf2808d22014-06-10 20:59:24 +090039/* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
40#define BR_GROUPFWD_8021AD 0xB801u
stephen hemminger515853c2011-10-03 18:14:46 +000041
Stephen Hemminger9cde0702007-03-21 14:22:44 -070042/* Path to usermode spanning tree program */
43#define BR_STP_PROG "/sbin/bridge-stp"
Stephen Hemminger8cbb512e2005-12-21 19:01:30 -080044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045typedef struct bridge_id bridge_id;
46typedef struct mac_addr mac_addr;
47typedef __u16 port_id;
48
49struct bridge_id
50{
51 unsigned char prio[2];
Joe Perchese5a727f2014-02-23 00:05:25 -080052 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
55struct mac_addr
56{
Joe Perchese5a727f2014-02-23 00:05:25 -080057 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070058};
59
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020060#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
61/* our own querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020062struct bridge_mcast_own_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020063 struct timer_list timer;
64 u32 startup_sent;
65};
66
67/* other querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020068struct bridge_mcast_other_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020069 struct timer_list timer;
70 unsigned long delay_time;
71};
Linus Lüssingdc4eb532014-06-07 18:26:27 +020072
73/* selected querier */
74struct bridge_mcast_querier {
75 struct br_ip addr;
Linus Lüssing2cd41432014-06-07 18:26:29 +020076 struct net_bridge_port __rcu *port;
Linus Lüssingdc4eb532014-06-07 18:26:27 +020077};
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020078#endif
79
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +020080/**
81 * struct net_bridge_vlan - per-vlan entry
82 *
83 * @vnode: rhashtable member
84 * @vid: VLAN id
85 * @flags: bridge vlan flags
86 * @br: if MASTER flag set, this points to a bridge struct
87 * @port: if MASTER flag unset, this points to a port struct
88 * @refcnt: if MASTER flag set, this is bumped for each port referencing it
89 * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
90 * for this VLAN entry
91 * @vlist: sorted list of VLAN entries
92 * @rcu: used for entry destruction
93 *
94 * This structure is shared between the global per-VLAN entries contained in
95 * the bridge rhashtable and the local per-port per-VLAN entries contained in
96 * the port's rhashtable. The union entries should be interpreted depending on
97 * the entry flags that are set.
98 */
99struct net_bridge_vlan {
100 struct rhash_head vnode;
101 u16 vid;
102 u16 flags;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000103 union {
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200104 struct net_bridge *br;
105 struct net_bridge_port *port;
106 };
107 union {
108 atomic_t refcnt;
109 struct net_bridge_vlan *brvlan;
110 };
111 struct list_head vlist;
112
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000113 struct rcu_head rcu;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200114};
115
116/**
117 * struct net_bridge_vlan_group
118 *
119 * @vlan_hash: VLAN entry rhashtable
120 * @vlan_list: sorted VLAN entry list
121 * @num_vlans: number of total VLAN entries
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200122 * @pvid: PVID VLAN id
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200123 *
124 * IMPORTANT: Be careful when checking if there're VLAN entries using list
125 * primitives because the bridge can have entries in its list which
126 * are just for global context but not for filtering, i.e. they have
127 * the master flag set but not the brentry flag. If you have to check
128 * if there're "real" entries in the bridge please test @num_vlans
129 */
130struct net_bridge_vlan_group {
131 struct rhashtable vlan_hash;
132 struct list_head vlan_list;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000133 u16 num_vlans;
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200134 u16 pvid;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000135};
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137struct net_bridge_fdb_entry
138{
139 struct hlist_node hlist;
140 struct net_bridge_port *dst;
141
stephen hemminger7cd88612011-04-04 14:03:28 +0000142 unsigned long updated;
143 unsigned long used;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 mac_addr addr;
Nikolay Aleksandrovb22fbf22015-08-27 14:19:20 -0700145 __u16 vlan_id;
Jiri Pirko93859b12014-11-28 14:34:14 +0100146 unsigned char is_local:1,
147 is_static:1,
Scott Feldmancf6b8e12014-11-28 14:34:21 +0100148 added_by_user:1,
149 added_by_external_learn:1;
Nikolay Aleksandrovb22fbf22015-08-27 14:19:20 -0700150 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
Elad Raz9d06b6d2016-02-03 09:57:05 +0100153#define MDB_PG_FLAGS_PERMANENT BIT(0)
154#define MDB_PG_FLAGS_OFFLOAD BIT(1)
155
Herbert Xueb1d1642010-02-27 19:41:45 +0000156struct net_bridge_port_group {
157 struct net_bridge_port *port;
Eric Dumazete8051682010-11-15 06:38:10 +0000158 struct net_bridge_port_group __rcu *next;
Herbert Xueb1d1642010-02-27 19:41:45 +0000159 struct hlist_node mglist;
160 struct rcu_head rcu;
161 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900162 struct br_ip addr;
Elad Raz9d06b6d2016-02-03 09:57:05 +0100163 unsigned char flags;
Herbert Xueb1d1642010-02-27 19:41:45 +0000164};
165
166struct net_bridge_mdb_entry
167{
168 struct hlist_node hlist[2];
Herbert Xueb1d1642010-02-27 19:41:45 +0000169 struct net_bridge *br;
Eric Dumazete8051682010-11-15 06:38:10 +0000170 struct net_bridge_port_group __rcu *ports;
Herbert Xueb1d1642010-02-27 19:41:45 +0000171 struct rcu_head rcu;
172 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900173 struct br_ip addr;
Herbert Xu8a870172011-02-12 01:05:42 -0800174 bool mglist;
Herbert Xueb1d1642010-02-27 19:41:45 +0000175};
176
177struct net_bridge_mdb_htable
178{
179 struct hlist_head *mhash;
180 struct rcu_head rcu;
181 struct net_bridge_mdb_htable *old;
182 u32 size;
183 u32 max;
184 u32 secret;
185 u32 ver;
186};
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188struct net_bridge_port
189{
190 struct net_bridge *br;
191 struct net_device *dev;
192 struct list_head list;
193
194 /* STP */
195 u8 priority;
196 u8 state;
197 u16 port_no;
198 unsigned char topology_change_ack;
199 unsigned char config_pending;
200 port_id port_id;
201 port_id designated_port;
202 bridge_id designated_root;
203 bridge_id designated_bridge;
204 u32 path_cost;
205 u32 designated_cost;
stephen hemminger0c031502011-07-22 07:47:06 +0000206 unsigned long designated_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 struct timer_list forward_delay_timer;
209 struct timer_list hold_timer;
210 struct timer_list message_age_timer;
211 struct kobject kobj;
212 struct rcu_head rcu;
Fischer, Anna3982d3d2009-08-13 06:55:16 +0000213
214 unsigned long flags;
Herbert Xueb1d1642010-02-27 19:41:45 +0000215
216#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Linus Lüssing90010b32014-06-07 18:26:26 +0200217 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200218#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200219 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200220#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000221 unsigned char multicast_router;
222 struct timer_list multicast_router_timer;
Herbert Xueb1d1642010-02-27 19:41:45 +0000223 struct hlist_head mglist;
224 struct hlist_node rlist;
225#endif
Simon Arlotte0f43752010-05-10 09:31:11 +0000226
227#ifdef CONFIG_SYSFS
228 char sysfs_name[IFNAMSIZ];
229#endif
Herbert Xu91d2c342010-06-10 16:12:50 +0000230
231#ifdef CONFIG_NET_POLL_CONTROLLER
232 struct netpoll *np;
233#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000234#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200235 struct net_bridge_vlan_group __rcu *vlgrp;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000236#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237};
238
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400239#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
Vlad Yasevichf3a6ddf2014-05-16 09:59:18 -0400240#define br_promisc_port(p) ((p)->flags & BR_PROMISC)
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400241
Jiri Pirkof350a0a82010-06-15 06:50:45 +0000242#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
243
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000244static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
245{
Hong Zhiguo716ec052013-09-14 22:42:28 +0800246 return rcu_dereference(dev->rx_handler_data);
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000247}
248
Hong Zhiguo1fb17542013-09-14 22:42:27 +0800249static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000250{
Eric Dumazetec1e5612010-11-15 06:38:14 +0000251 return br_port_exists(dev) ?
252 rtnl_dereference(dev->rx_handler_data) : NULL;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000253}
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255struct net_bridge
256{
257 spinlock_t lock;
258 struct list_head port_list;
259 struct net_device *dev;
stephen hemminger14bb4782010-03-02 13:32:09 +0000260
Li RongQing8f849852014-01-04 13:57:59 +0800261 struct pcpu_sw_netstats __percpu *stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 spinlock_t hash_lock;
263 struct hlist_head hash[BR_HASH_SIZE];
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200264#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Bernhard Thalerefb6de92015-05-30 15:30:16 +0200265 union {
266 struct rtable fake_rtable;
267 struct rt6_info fake_rt6_info;
268 };
Patrick McHardy4df53d82010-07-02 09:32:57 +0200269 bool nf_call_iptables;
270 bool nf_call_ip6tables;
271 bool nf_call_arptables;
Simon Wunderlich4adf0af2008-07-30 16:27:55 -0700272#endif
stephen hemminger515853c2011-10-03 18:14:46 +0000273 u16 group_fwd_mask;
Toshiaki Makitaf2808d22014-06-10 20:59:24 +0900274 u16 group_fwd_mask_required;
stephen hemminger515853c2011-10-03 18:14:46 +0000275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* STP */
277 bridge_id designated_root;
278 bridge_id bridge_id;
279 u32 root_path_cost;
280 unsigned long max_age;
281 unsigned long hello_time;
282 unsigned long forward_delay;
283 unsigned long bridge_max_age;
284 unsigned long ageing_time;
285 unsigned long bridge_hello_time;
286 unsigned long bridge_forward_delay;
287
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800288 u8 group_addr[ETH_ALEN];
Toshiaki Makita204177f2014-06-10 20:59:25 +0900289 bool group_addr_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 u16 root_port;
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700291
292 enum {
293 BR_NO_STP, /* no spanning tree */
294 BR_KERNEL_STP, /* old STP in kernel */
295 BR_USER_STP, /* new RSTP in userspace */
296 } stp_enabled;
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 unsigned char topology_change;
299 unsigned char topology_change_detected;
300
Herbert Xueb1d1642010-02-27 19:41:45 +0000301#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
302 unsigned char multicast_router;
303
304 u8 multicast_disabled:1;
Herbert Xuc5c23262012-04-13 02:37:42 +0000305 u8 multicast_querier:1;
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000306 u8 multicast_query_use_ifaddr:1;
Herbert Xueb1d1642010-02-27 19:41:45 +0000307
308 u32 hash_elasticity;
309 u32 hash_max;
310
311 u32 multicast_last_member_count;
Herbert Xueb1d1642010-02-27 19:41:45 +0000312 u32 multicast_startup_query_count;
313
314 unsigned long multicast_last_member_interval;
315 unsigned long multicast_membership_interval;
316 unsigned long multicast_querier_interval;
317 unsigned long multicast_query_interval;
318 unsigned long multicast_query_response_interval;
319 unsigned long multicast_startup_query_interval;
320
321 spinlock_t multicast_lock;
Eric Dumazete8051682010-11-15 06:38:10 +0000322 struct net_bridge_mdb_htable __rcu *mdb;
Herbert Xueb1d1642010-02-27 19:41:45 +0000323 struct hlist_head router_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000324
325 struct timer_list multicast_router_timer;
Linus Lüssing90010b32014-06-07 18:26:26 +0200326 struct bridge_mcast_other_query ip4_other_query;
327 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200328 struct bridge_mcast_querier ip4_querier;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200329#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200330 struct bridge_mcast_other_query ip6_other_query;
331 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200332 struct bridge_mcast_querier ip6_querier;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200333#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000334#endif
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 struct timer_list hello_timer;
337 struct timer_list tcn_timer;
338 struct timer_list topology_change_timer;
339 struct timer_list gc_timer;
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400340 struct kobject *ifobj;
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400341 u32 auto_cnt;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000342#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200343 struct net_bridge_vlan_group __rcu *vlgrp;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000344 u8 vlan_enabled;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900345 __be16 vlan_proto;
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400346 u16 default_pvid;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000347#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348};
349
Herbert Xu68b7c892010-02-27 19:41:40 +0000350struct br_input_skb_cb {
351 struct net_device *brdev;
Herbert Xu93fdd472014-10-05 12:00:22 +0800352
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000353#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Herbert Xueb1d1642010-02-27 19:41:45 +0000354 int igmp;
355 int mrouters_only;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000356#endif
Herbert Xu93fdd472014-10-05 12:00:22 +0800357
Jouni Malinen842a9ae2015-03-04 12:54:21 +0200358 bool proxyarp_replied;
Herbert Xu93fdd472014-10-05 12:00:22 +0800359
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400360#ifdef CONFIG_BRIDGE_VLAN_FILTERING
361 bool vlan_filtered;
362#endif
Herbert Xu68b7c892010-02-27 19:41:40 +0000363};
364
365#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
366
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000367#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
368# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
369#else
370# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
371#endif
372
stephen hemminger28a16c92010-05-10 09:31:09 +0000373#define br_printk(level, br, format, args...) \
374 printk(level "%s: " format, (br)->dev->name, ##args)
375
376#define br_err(__br, format, args...) \
377 br_printk(KERN_ERR, __br, format, ##args)
378#define br_warn(__br, format, args...) \
379 br_printk(KERN_WARNING, __br, format, ##args)
380#define br_notice(__br, format, args...) \
381 br_printk(KERN_NOTICE, __br, format, ##args)
382#define br_info(__br, format, args...) \
383 br_printk(KERN_INFO, __br, format, ##args)
384
385#define br_debug(br, format, args...) \
386 pr_debug("%s: " format, (br)->dev->name, ##args)
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/* called under bridge lock */
389static inline int br_is_root_bridge(const struct net_bridge *br)
390{
391 return !memcmp(&br->bridge_id, &br->designated_root, 8);
392}
393
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200394/* check if a VLAN entry is global */
395static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
396{
397 return v->flags & BRIDGE_VLAN_INFO_MASTER;
398}
399
400/* check if a VLAN entry is used by the bridge */
401static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
402{
403 return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
404}
405
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200406/* check if we should use the vlan entry, returns false if it's only context */
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200407static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
408{
409 if (br_vlan_is_master(v)) {
410 if (br_vlan_is_brentry(v))
411 return true;
412 else
413 return false;
414 }
415
416 return true;
417}
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419/* br_device.c */
Joe Perches348662a2013-10-18 13:48:22 -0700420void br_dev_setup(struct net_device *dev);
421void br_dev_delete(struct net_device *dev, struct list_head *list);
422netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
stephen hemmingercfb478d2010-05-10 09:31:08 +0000423#ifdef CONFIG_NET_POLL_CONTROLLER
Herbert Xu91d2c342010-06-10 16:12:50 +0000424static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
425 struct sk_buff *skb)
426{
427 struct netpoll *np = p->np;
428
429 if (np)
430 netpoll_send_skb(np, skb);
431}
432
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700433int br_netpoll_enable(struct net_bridge_port *p);
Joe Perches348662a2013-10-18 13:48:22 -0700434void br_netpoll_disable(struct net_bridge_port *p);
Herbert Xu91d2c342010-06-10 16:12:50 +0000435#else
Herbert Xu9f70b0f2010-06-15 21:43:48 -0700436static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
Herbert Xu91d2c342010-06-10 16:12:50 +0000437 struct sk_buff *skb)
438{
439}
440
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700441static inline int br_netpoll_enable(struct net_bridge_port *p)
Herbert Xu91d2c342010-06-10 16:12:50 +0000442{
443 return 0;
444}
445
446static inline void br_netpoll_disable(struct net_bridge_port *p)
447{
448}
stephen hemmingercfb478d2010-05-10 09:31:08 +0000449#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/* br_fdb.c */
Joe Perches348662a2013-10-18 13:48:22 -0700452int br_fdb_init(void);
453void br_fdb_fini(void);
454void br_fdb_flush(struct net_bridge *br);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900455void br_fdb_find_delete_local(struct net_bridge *br,
456 const struct net_bridge_port *p,
457 const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700458void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
459void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
460void br_fdb_cleanup(unsigned long arg);
461void br_fdb_delete_by_port(struct net_bridge *br,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700462 const struct net_bridge_port *p, u16 vid, int do_all);
Joe Perches348662a2013-10-18 13:48:22 -0700463struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
464 const unsigned char *addr, __u16 vid);
465int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
466int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
467 unsigned long off);
468int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
469 const unsigned char *addr, u16 vid);
470void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900471 const unsigned char *addr, u16 vid, bool added_by_user);
John Fastabend77162022012-04-15 06:43:56 +0000472
Joe Perches348662a2013-10-18 13:48:22 -0700473int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
Jiri Pirkof6f64242014-11-28 14:34:15 +0100474 struct net_device *dev, const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700475int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100476 const unsigned char *addr, u16 vid, u16 nlh_flags);
Joe Perches348662a2013-10-18 13:48:22 -0700477int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400478 struct net_device *dev, struct net_device *fdev, int idx);
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400479int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
480void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100481int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
482 const unsigned char *addr, u16 vid);
483int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
484 const unsigned char *addr, u16 vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486/* br_forward.c */
Joe Perches348662a2013-10-18 13:48:22 -0700487void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500488int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
Joe Perches348662a2013-10-18 13:48:22 -0700489void br_forward(const struct net_bridge_port *to,
Michael Braun7f7708f2010-03-16 00:26:22 -0700490 struct sk_buff *skb, struct sk_buff *skb0);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500491int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Joe Perches348662a2013-10-18 13:48:22 -0700492void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, bool unicast);
493void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
494 struct sk_buff *skb2, bool unicast);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496/* br_if.c */
Joe Perches348662a2013-10-18 13:48:22 -0700497void br_port_carrier_check(struct net_bridge_port *p);
498int br_add_bridge(struct net *net, const char *name);
499int br_del_bridge(struct net *net, const char *name);
Joe Perches348662a2013-10-18 13:48:22 -0700500int br_add_if(struct net_bridge *br, struct net_device *dev);
501int br_del_if(struct net_bridge *br, struct net_device *dev);
502int br_min_mtu(const struct net_bridge *br);
503netdev_features_t br_features_recompute(struct net_bridge *br,
504 netdev_features_t features);
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400505void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400506void br_manage_promisc(struct net_bridge *br);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508/* br_input.c */
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500509int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Joe Perches348662a2013-10-18 13:48:22 -0700510rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Jiri Pirko859828c2013-12-05 16:27:37 +0100512static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
513{
514 return rcu_dereference(dev->rx_handler) == br_handle_frame;
515}
516
517static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
518{
519 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
520}
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522/* br_ioctl.c */
Joe Perches348662a2013-10-18 13:48:22 -0700523int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
524int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
525 void __user *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Herbert Xueb1d1642010-02-27 19:41:45 +0000527/* br_multicast.c */
528#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Cong Wang2ce297f2012-12-10 02:15:35 +0000529extern unsigned int br_mdb_rehash_seq;
Joe Perches348662a2013-10-18 13:48:22 -0700530int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
David S. Miller394efd12013-11-04 13:48:30 -0500531 struct sk_buff *skb, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700532struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
533 struct sk_buff *skb, u16 vid);
534void br_multicast_add_port(struct net_bridge_port *port);
535void br_multicast_del_port(struct net_bridge_port *port);
536void br_multicast_enable_port(struct net_bridge_port *port);
537void br_multicast_disable_port(struct net_bridge_port *port);
538void br_multicast_init(struct net_bridge *br);
539void br_multicast_open(struct net_bridge *br);
540void br_multicast_stop(struct net_bridge *br);
Satish Ashoke10177a2015-07-15 07:16:51 -0700541void br_multicast_dev_del(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700542void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
543 struct sk_buff *skb);
544void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
545 struct sk_buff *skb, struct sk_buff *skb2);
546int br_multicast_set_router(struct net_bridge *br, unsigned long val);
547int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
548int br_multicast_toggle(struct net_bridge *br, unsigned long val);
549int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
550int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
551struct net_bridge_mdb_entry *
552br_mdb_ip_get(struct net_bridge_mdb_htable *mdb, struct br_ip *dst);
553struct net_bridge_mdb_entry *
554br_multicast_new_group(struct net_bridge *br, struct net_bridge_port *port,
555 struct br_ip *group);
556void br_multicast_free_pg(struct rcu_head *head);
557struct net_bridge_port_group *
558br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
559 struct net_bridge_port_group __rcu *next,
Elad Raz9d06b6d2016-02-03 09:57:05 +0100560 unsigned char flags);
Joe Perches348662a2013-10-18 13:48:22 -0700561void br_mdb_init(void);
562void br_mdb_uninit(void);
Elad Raz9e8430f2016-02-03 09:57:06 +0100563void br_mdb_notify(struct net_device *dev, struct net_bridge_port_group *pg,
564 int type);
Satish Ashok949f1e32015-07-23 05:00:53 -0700565void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
566 int type);
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000567
Cong Wangcfd56752012-12-11 22:23:08 +0000568#define mlock_dereference(X, br) \
569 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
570
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000571static inline bool br_multicast_is_router(struct net_bridge *br)
572{
573 return br->multicast_router == 2 ||
574 (br->multicast_router == 1 &&
575 timer_pending(&br->multicast_router_timer));
576}
Linus Lüssingb00589a2013-08-01 01:06:20 +0200577
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200578static inline bool
579__br_multicast_querier_exists(struct net_bridge *br,
Linus Lüssing90010b32014-06-07 18:26:26 +0200580 struct bridge_mcast_other_query *querier)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200581{
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200582 return time_is_before_jiffies(querier->delay_time) &&
583 (br->multicast_querier || timer_pending(&querier->timer));
584}
585
586static inline bool br_multicast_querier_exists(struct net_bridge *br,
587 struct ethhdr *eth)
588{
589 switch (eth->h_proto) {
590 case (htons(ETH_P_IP)):
Linus Lüssing90010b32014-06-07 18:26:26 +0200591 return __br_multicast_querier_exists(br, &br->ip4_other_query);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200592#if IS_ENABLED(CONFIG_IPV6)
593 case (htons(ETH_P_IPV6)):
Linus Lüssing90010b32014-06-07 18:26:26 +0200594 return __br_multicast_querier_exists(br, &br->ip6_other_query);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200595#endif
596 default:
597 return false;
598 }
Linus Lüssingb00589a2013-08-01 01:06:20 +0200599}
Herbert Xueb1d1642010-02-27 19:41:45 +0000600#else
601static inline int br_multicast_rcv(struct net_bridge *br,
602 struct net_bridge_port *port,
Vlad Yasevich06499092013-10-28 15:45:07 -0400603 struct sk_buff *skb,
604 u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000605{
606 return 0;
607}
608
609static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
Cong Wangfbca58a2013-03-07 03:05:33 +0000610 struct sk_buff *skb, u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000611{
612 return NULL;
613}
614
615static inline void br_multicast_add_port(struct net_bridge_port *port)
616{
617}
618
619static inline void br_multicast_del_port(struct net_bridge_port *port)
620{
621}
622
623static inline void br_multicast_enable_port(struct net_bridge_port *port)
624{
625}
626
627static inline void br_multicast_disable_port(struct net_bridge_port *port)
628{
629}
630
631static inline void br_multicast_init(struct net_bridge *br)
632{
633}
634
635static inline void br_multicast_open(struct net_bridge *br)
636{
637}
638
639static inline void br_multicast_stop(struct net_bridge *br)
640{
641}
Herbert Xu5cb5e942010-02-27 19:41:46 +0000642
Nikolay Aleksandrova7ce45a2015-07-20 23:03:45 +0200643static inline void br_multicast_dev_del(struct net_bridge *br)
644{
645}
646
Herbert Xu5cb5e942010-02-27 19:41:46 +0000647static inline void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
648 struct sk_buff *skb)
649{
650}
651
652static inline void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
653 struct sk_buff *skb,
654 struct sk_buff *skb2)
655{
656}
Herbert Xueb1d1642010-02-27 19:41:45 +0000657static inline bool br_multicast_is_router(struct net_bridge *br)
658{
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000659 return 0;
Herbert Xueb1d1642010-02-27 19:41:45 +0000660}
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200661static inline bool br_multicast_querier_exists(struct net_bridge *br,
662 struct ethhdr *eth)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200663{
664 return false;
665}
Rami Rosenfdb184d2013-01-03 13:30:43 +0200666static inline void br_mdb_init(void)
667{
668}
669static inline void br_mdb_uninit(void)
670{
671}
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000672#endif
Herbert Xueb1d1642010-02-27 19:41:45 +0000673
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000674/* br_vlan.c */
675#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200676bool br_allowed_ingress(const struct net_bridge *br,
677 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
678 u16 *vid);
679bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700680 const struct sk_buff *skb);
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900681bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
Joe Perches348662a2013-10-18 13:48:22 -0700682struct sk_buff *br_handle_vlan(struct net_bridge *br,
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200683 struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700684 struct sk_buff *skb);
685int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags);
686int br_vlan_delete(struct net_bridge *br, u16 vid);
687void br_vlan_flush(struct net_bridge *br);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200688struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900689void br_recalculate_fwd_mask(struct net_bridge *br);
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300690int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Joe Perches348662a2013-10-18 13:48:22 -0700691int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900692int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900693int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400694int br_vlan_init(struct net_bridge *br);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400695int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov0f963b72015-10-04 14:23:47 +0200696int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid);
Joe Perches348662a2013-10-18 13:48:22 -0700697int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
698int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
699void nbp_vlan_flush(struct net_bridge_port *port);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400700int nbp_vlan_init(struct net_bridge_port *port);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200701int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000702
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200703static inline struct net_bridge_vlan_group *br_vlan_group(
704 const struct net_bridge *br)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000705{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200706 return rtnl_dereference(br->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000707}
708
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200709static inline struct net_bridge_vlan_group *nbp_vlan_group(
710 const struct net_bridge_port *p)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000711{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200712 return rtnl_dereference(p->vlgrp);
713}
714
715static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
716 const struct net_bridge *br)
717{
718 return rcu_dereference(br->vlgrp);
719}
720
721static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
722 const struct net_bridge_port *p)
723{
724 return rcu_dereference(p->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000725}
726
727/* Since bridge now depends on 8021Q module, but the time bridge sees the
728 * skb, the vlan tag will always be present if the frame was tagged.
729 */
730static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
731{
732 int err = 0;
733
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200734 if (skb_vlan_tag_present(skb)) {
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100735 *vid = skb_vlan_tag_get(skb) & VLAN_VID_MASK;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200736 } else {
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000737 *vid = 0;
738 err = -EINVAL;
739 }
740
741 return err;
742}
Vlad Yasevich78851982013-02-13 12:00:14 +0000743
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200744static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +0000745{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200746 if (!vg)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400747 return 0;
748
Vlad Yasevich78851982013-02-13 12:00:14 +0000749 smp_rmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200750 return vg->pvid;
Vlad Yasevich78851982013-02-13 12:00:14 +0000751}
752
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400753static inline int br_vlan_enabled(struct net_bridge *br)
754{
755 return br->vlan_enabled;
756}
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000757#else
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200758static inline bool br_allowed_ingress(const struct net_bridge *br,
759 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000760 struct sk_buff *skb,
761 u16 *vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000762{
763 return true;
764}
765
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200766static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000767 const struct sk_buff *skb)
768{
769 return true;
770}
771
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900772static inline bool br_should_learn(struct net_bridge_port *p,
773 struct sk_buff *skb, u16 *vid)
774{
775 return true;
776}
777
Vlad Yasevich78851982013-02-13 12:00:14 +0000778static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200779 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000780 struct sk_buff *skb)
781{
782 return skb;
783}
784
Vlad Yasevich552406c2013-02-13 12:00:15 +0000785static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000786{
787 return -EOPNOTSUPP;
788}
789
790static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
791{
792 return -EOPNOTSUPP;
793}
794
795static inline void br_vlan_flush(struct net_bridge *br)
796{
797}
798
Toshiaki Makita204177f2014-06-10 20:59:25 +0900799static inline void br_recalculate_fwd_mask(struct net_bridge *br)
800{
801}
802
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400803static inline int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +0900804{
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400805 return 0;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900806}
807
Vlad Yasevich552406c2013-02-13 12:00:15 +0000808static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000809{
810 return -EOPNOTSUPP;
811}
812
813static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
814{
815 return -EOPNOTSUPP;
816}
817
818static inline void nbp_vlan_flush(struct net_bridge_port *port)
819{
820}
821
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200822static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
823 u16 vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000824{
825 return NULL;
826}
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000827
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400828static inline int nbp_vlan_init(struct net_bridge_port *port)
829{
830 return 0;
831}
832
Vlad Yasevich78851982013-02-13 12:00:14 +0000833static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000834{
835 return 0;
836}
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200837
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200838static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +0000839{
Vlad Yasevich3df6bf42014-10-03 11:29:17 -0400840 return 0;
Vlad Yasevich78851982013-02-13 12:00:14 +0000841}
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400842
Alexei Starovoitovd4f0e092014-05-18 10:30:28 -0700843static inline int br_vlan_enabled(struct net_bridge *br)
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400844{
845 return 0;
846}
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300847
848static inline int __br_vlan_filter_toggle(struct net_bridge *br,
849 unsigned long val)
850{
851 return -EOPNOTSUPP;
852}
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200853
854static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
855 u32 filter_mask)
856{
857 return 0;
858}
859
860static inline struct net_bridge_vlan_group *br_vlan_group(
861 const struct net_bridge *br)
862{
863 return NULL;
864}
865
866static inline struct net_bridge_vlan_group *nbp_vlan_group(
867 const struct net_bridge_port *p)
868{
869 return NULL;
870}
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200871
872static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
873 const struct net_bridge *br)
874{
875 return NULL;
876}
877
878static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
879 const struct net_bridge_port *p)
880{
881 return NULL;
882}
883
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000884#endif
885
Pablo Neira Ayuso1a4ba642015-03-10 10:27:18 +0100886struct nf_br_ops {
887 int (*br_dev_xmit_hook)(struct sk_buff *skb);
888};
889extern const struct nf_br_ops __rcu *nf_br_ops;
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891/* br_netfilter.c */
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200892#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
893int br_nf_core_init(void);
894void br_nf_core_fini(void);
Joe Perches348662a2013-10-18 13:48:22 -0700895void br_netfilter_rtable_init(struct net_bridge *);
Stephen Hemmingerc0909712006-05-25 15:59:33 -0700896#else
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200897static inline int br_nf_core_init(void) { return 0; }
898static inline void br_nf_core_fini(void) {}
Simon Wunderlich4adf0af2008-07-30 16:27:55 -0700899#define br_netfilter_rtable_init(x)
Stephen Hemmingerc0909712006-05-25 15:59:33 -0700900#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902/* br_stp.c */
Florian Fainelli775dd692014-09-30 16:13:19 -0700903void br_set_state(struct net_bridge_port *p, unsigned int state);
Joe Perches348662a2013-10-18 13:48:22 -0700904struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
905void br_init_port(struct net_bridge_port *p);
906void br_become_designated_port(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Joe Perches348662a2013-10-18 13:48:22 -0700908void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
909int br_set_forward_delay(struct net_bridge *br, unsigned long x);
910int br_set_hello_time(struct net_bridge *br, unsigned long x);
911int br_set_max_age(struct net_bridge *br, unsigned long x);
Scott Feldmanc62987b2015-10-08 19:23:19 -0700912int br_set_ageing_time(struct net_bridge *br, u32 ageing_time);
stephen hemminger14f98f22011-04-04 14:03:33 +0000913
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915/* br_stp_if.c */
Joe Perches348662a2013-10-18 13:48:22 -0700916void br_stp_enable_bridge(struct net_bridge *br);
917void br_stp_disable_bridge(struct net_bridge *br);
918void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
919void br_stp_enable_port(struct net_bridge_port *p);
920void br_stp_disable_port(struct net_bridge_port *p);
921bool br_stp_recalculate_bridge_id(struct net_bridge *br);
922void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
923void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
924int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
925int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
926ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928/* br_stp_bpdu.c */
Patrick McHardy7c85fbf2008-07-05 21:25:56 -0700929struct stp_proto;
Joe Perches348662a2013-10-18 13:48:22 -0700930void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
931 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933/* br_stp_timer.c */
Joe Perches348662a2013-10-18 13:48:22 -0700934void br_stp_timer_init(struct net_bridge *br);
935void br_stp_port_timer_init(struct net_bridge_port *p);
936unsigned long br_timer_value(const struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938/* br.c */
Igor Maraviće6373c42011-12-12 02:58:25 +0000939#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +0000940extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
941#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700943/* br_netlink.c */
stephen hemminger149ddd82012-06-26 05:48:45 +0000944extern struct rtnl_link_ops br_link_ops;
Joe Perches348662a2013-10-18 13:48:22 -0700945int br_netlink_init(void);
946void br_netlink_fini(void);
947void br_ifinfo_notify(int event, struct net_bridge_port *port);
Roopa Prabhuadd511b2015-01-29 22:40:12 -0800948int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
949int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
Joe Perches348662a2013-10-18 13:48:22 -0700950int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +0200951 u32 filter_mask, int nlflags);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953#ifdef CONFIG_SYSFS
954/* br_sysfs_if.c */
Emese Revfy52cf25d2010-01-19 02:58:23 +0100955extern const struct sysfs_ops brport_sysfs_ops;
Joe Perches348662a2013-10-18 13:48:22 -0700956int br_sysfs_addif(struct net_bridge_port *p);
957int br_sysfs_renameif(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959/* br_sysfs_br.c */
Joe Perches348662a2013-10-18 13:48:22 -0700960int br_sysfs_addbr(struct net_device *dev);
961void br_sysfs_delbr(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963#else
964
Lee Jones0cb2bbb2012-11-03 23:02:30 +0100965static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
966static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
967static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
968static inline void br_sysfs_delbr(struct net_device *dev) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969#endif /* CONFIG_SYSFS */
970
971#endif