blob: a0ce0822921c6614e3033bb7cb1038c93fa2731b [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 Aleksandrov2594e9062015-09-25 19:00:11 +020023#include <linux/rhashtable.h>
Reshetova, Elena25127752017-07-04 15:53:05 +030024#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#define BR_HASH_BITS 8
27#define BR_HASH_SIZE (1 << BR_HASH_BITS)
28
29#define BR_HOLD_TIME (1*HZ)
30
31#define BR_PORT_BITS 10
32#define BR_MAX_PORTS (1<<BR_PORT_BITS)
33
Stephen Hemminger9cde0702007-03-21 14:22:44 -070034#define BR_VERSION "2.3"
35
stephen hemminger515853c2011-10-03 18:14:46 +000036/* Control of forwarding link local multicast */
37#define BR_GROUPFWD_DEFAULT 0
Bernhard Thaler784b58a2015-05-04 22:47:13 +020038/* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +030039enum {
40 BR_GROUPFWD_STP = BIT(0),
41 BR_GROUPFWD_MACPAUSE = BIT(1),
42 BR_GROUPFWD_LACP = BIT(2),
43};
44
45#define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \
46 BR_GROUPFWD_LACP)
Toshiaki Makitaf2808d22014-06-10 20:59:24 +090047/* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
48#define BR_GROUPFWD_8021AD 0xB801u
stephen hemminger515853c2011-10-03 18:14:46 +000049
Stephen Hemminger9cde0702007-03-21 14:22:44 -070050/* Path to usermode spanning tree program */
51#define BR_STP_PROG "/sbin/bridge-stp"
Stephen Hemminger8cbb512e2005-12-21 19:01:30 -080052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053typedef struct bridge_id bridge_id;
54typedef struct mac_addr mac_addr;
55typedef __u16 port_id;
56
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +030057struct bridge_id {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 unsigned char prio[2];
Joe Perchese5a727f2014-02-23 00:05:25 -080059 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +030062struct mac_addr {
Joe Perchese5a727f2014-02-23 00:05:25 -080063 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020066#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
67/* our own querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020068struct bridge_mcast_own_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020069 struct timer_list timer;
70 u32 startup_sent;
71};
72
73/* other querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020074struct bridge_mcast_other_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020075 struct timer_list timer;
76 unsigned long delay_time;
77};
Linus Lüssingdc4eb532014-06-07 18:26:27 +020078
79/* selected querier */
80struct bridge_mcast_querier {
81 struct br_ip addr;
Linus Lüssing2cd41432014-06-07 18:26:29 +020082 struct net_bridge_port __rcu *port;
Linus Lüssingdc4eb532014-06-07 18:26:27 +020083};
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +020084
85/* IGMP/MLD statistics */
86struct bridge_mcast_stats {
87 struct br_mcast_stats mstats;
88 struct u64_stats_sync syncp;
89};
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020090#endif
91
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +020092struct br_vlan_stats {
93 u64 rx_bytes;
94 u64 rx_packets;
95 u64 tx_bytes;
96 u64 tx_packets;
97 struct u64_stats_sync syncp;
98};
99
Roopa Prabhuefa53562017-01-31 22:59:54 -0800100struct br_tunnel_info {
101 __be64 tunnel_id;
102 struct metadata_dst *tunnel_dst;
103};
104
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200105/* private vlan flags */
106enum {
107 BR_VLFLAG_PER_PORT_STATS = BIT(0),
108};
109
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200110/**
111 * struct net_bridge_vlan - per-vlan entry
112 *
113 * @vnode: rhashtable member
114 * @vid: VLAN id
115 * @flags: bridge vlan flags
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200116 * @priv_flags: private (in-kernel) bridge vlan flags
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200117 * @stats: per-cpu VLAN statistics
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200118 * @br: if MASTER flag set, this points to a bridge struct
119 * @port: if MASTER flag unset, this points to a port struct
120 * @refcnt: if MASTER flag set, this is bumped for each port referencing it
121 * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
122 * for this VLAN entry
123 * @vlist: sorted list of VLAN entries
124 * @rcu: used for entry destruction
125 *
126 * This structure is shared between the global per-VLAN entries contained in
127 * the bridge rhashtable and the local per-port per-VLAN entries contained in
128 * the port's rhashtable. The union entries should be interpreted depending on
129 * the entry flags that are set.
130 */
131struct net_bridge_vlan {
132 struct rhash_head vnode;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800133 struct rhash_head tnode;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200134 u16 vid;
135 u16 flags;
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200136 u16 priv_flags;
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200137 struct br_vlan_stats __percpu *stats;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000138 union {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200139 struct net_bridge *br;
140 struct net_bridge_port *port;
141 };
142 union {
Reshetova, Elena25127752017-07-04 15:53:05 +0300143 refcount_t refcnt;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200144 struct net_bridge_vlan *brvlan;
145 };
Roopa Prabhuefa53562017-01-31 22:59:54 -0800146
147 struct br_tunnel_info tinfo;
148
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200149 struct list_head vlist;
150
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000151 struct rcu_head rcu;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200152};
153
154/**
155 * struct net_bridge_vlan_group
156 *
157 * @vlan_hash: VLAN entry rhashtable
158 * @vlan_list: sorted VLAN entry list
159 * @num_vlans: number of total VLAN entries
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200160 * @pvid: PVID VLAN id
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200161 *
162 * IMPORTANT: Be careful when checking if there're VLAN entries using list
163 * primitives because the bridge can have entries in its list which
164 * are just for global context but not for filtering, i.e. they have
165 * the master flag set but not the brentry flag. If you have to check
166 * if there're "real" entries in the bridge please test @num_vlans
167 */
168struct net_bridge_vlan_group {
169 struct rhashtable vlan_hash;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800170 struct rhashtable tunnel_hash;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200171 struct list_head vlan_list;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000172 u16 num_vlans;
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200173 u16 pvid;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000174};
175
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200176struct net_bridge_fdb_key {
177 mac_addr addr;
178 u16 vlan_id;
179};
180
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100181struct net_bridge_fdb_entry {
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200182 struct rhash_head rhnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 struct net_bridge_port *dst;
184
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200185 struct net_bridge_fdb_key key;
186 struct hlist_node fdb_node;
Jiri Pirko93859b12014-11-28 14:34:14 +0100187 unsigned char is_local:1,
188 is_static:1,
Nikolay Aleksandrov435f2e72018-09-11 09:39:53 +0300189 is_sticky:1,
Scott Feldmancf6b8e12014-11-28 14:34:21 +0100190 added_by_user:1,
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200191 added_by_external_learn:1,
192 offloaded:1;
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100193
194 /* write-heavy members should not affect lookups */
195 unsigned long updated ____cacheline_aligned_in_smp;
196 unsigned long used;
197
Nikolay Aleksandrovb22fbf22015-08-27 14:19:20 -0700198 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
Elad Raz9d06b6d2016-02-03 09:57:05 +0100201#define MDB_PG_FLAGS_PERMANENT BIT(0)
202#define MDB_PG_FLAGS_OFFLOAD BIT(1)
203
Herbert Xueb1d1642010-02-27 19:41:45 +0000204struct net_bridge_port_group {
205 struct net_bridge_port *port;
Eric Dumazete8051682010-11-15 06:38:10 +0000206 struct net_bridge_port_group __rcu *next;
Herbert Xueb1d1642010-02-27 19:41:45 +0000207 struct hlist_node mglist;
208 struct rcu_head rcu;
209 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900210 struct br_ip addr;
Elad Raz9d06b6d2016-02-03 09:57:05 +0100211 unsigned char flags;
Felix Fietkau6db6f0e2017-01-21 21:01:32 +0100212 unsigned char eth_addr[ETH_ALEN];
Herbert Xueb1d1642010-02-27 19:41:45 +0000213};
214
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +0300215struct net_bridge_mdb_entry {
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200216 struct rhash_head rhnode;
Herbert Xueb1d1642010-02-27 19:41:45 +0000217 struct net_bridge *br;
Eric Dumazete8051682010-11-15 06:38:10 +0000218 struct net_bridge_port_group __rcu *ports;
Herbert Xueb1d1642010-02-27 19:41:45 +0000219 struct rcu_head rcu;
220 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900221 struct br_ip addr;
Andrew Lunnff0fd342017-11-09 23:10:57 +0100222 bool host_joined;
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200223 struct hlist_node mdb_node;
Herbert Xueb1d1642010-02-27 19:41:45 +0000224};
225
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100226struct net_bridge_port {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 struct net_bridge *br;
228 struct net_device *dev;
229 struct list_head list;
230
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100231 unsigned long flags;
232#ifdef CONFIG_BRIDGE_VLAN_FILTERING
233 struct net_bridge_vlan_group __rcu *vlgrp;
234#endif
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300235 struct net_bridge_port __rcu *backup_port;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* STP */
238 u8 priority;
239 u8 state;
240 u16 port_no;
241 unsigned char topology_change_ack;
242 unsigned char config_pending;
243 port_id port_id;
244 port_id designated_port;
245 bridge_id designated_root;
246 bridge_id designated_bridge;
247 u32 path_cost;
248 u32 designated_cost;
stephen hemminger0c031502011-07-22 07:47:06 +0000249 unsigned long designated_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 struct timer_list forward_delay_timer;
252 struct timer_list hold_timer;
253 struct timer_list message_age_timer;
254 struct kobject kobj;
255 struct rcu_head rcu;
Fischer, Anna3982d3d2009-08-13 06:55:16 +0000256
Herbert Xueb1d1642010-02-27 19:41:45 +0000257#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Linus Lüssing90010b32014-06-07 18:26:26 +0200258 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200259#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200260 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200261#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000262 unsigned char multicast_router;
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200263 struct bridge_mcast_stats __percpu *mcast_stats;
Herbert Xueb1d1642010-02-27 19:41:45 +0000264 struct timer_list multicast_router_timer;
Herbert Xueb1d1642010-02-27 19:41:45 +0000265 struct hlist_head mglist;
266 struct hlist_node rlist;
267#endif
Simon Arlotte0f43752010-05-10 09:31:11 +0000268
269#ifdef CONFIG_SYSFS
270 char sysfs_name[IFNAMSIZ];
271#endif
Herbert Xu91d2c342010-06-10 16:12:50 +0000272
273#ifdef CONFIG_NET_POLL_CONTROLLER
274 struct netpoll *np;
275#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200276#ifdef CONFIG_NET_SWITCHDEV
277 int offload_fwd_mark;
278#endif
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +0300279 u16 group_fwd_mask;
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300280 u16 backup_redirected_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281};
282
Tyler Hicks705e0de2018-07-20 21:56:54 +0000283#define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
284
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400285#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
Vlad Yasevichf3a6ddf2014-05-16 09:59:18 -0400286#define br_promisc_port(p) ((p)->flags & BR_PROMISC)
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400287
Jiri Pirkof350a0a82010-06-15 06:50:45 +0000288#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
289
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000290static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
291{
Hong Zhiguo716ec052013-09-14 22:42:28 +0800292 return rcu_dereference(dev->rx_handler_data);
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000293}
294
Hong Zhiguo1fb17542013-09-14 22:42:27 +0800295static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000296{
Eric Dumazetec1e5612010-11-15 06:38:14 +0000297 return br_port_exists(dev) ?
298 rtnl_dereference(dev->rx_handler_data) : NULL;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000299}
300
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200301static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
302{
303 return br_port_exists(dev) ?
304 rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
305}
306
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300307enum net_bridge_opts {
308 BROPT_VLAN_ENABLED,
309 BROPT_VLAN_STATS_ENABLED,
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300310 BROPT_NF_CALL_IPTABLES,
311 BROPT_NF_CALL_IP6TABLES,
312 BROPT_NF_CALL_ARPTABLES,
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300313 BROPT_GROUP_ADDR_SET,
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300314 BROPT_MULTICAST_ENABLED,
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300315 BROPT_MULTICAST_QUERIER,
316 BROPT_MULTICAST_QUERY_USE_IFADDR,
317 BROPT_MULTICAST_STATS_ENABLED,
318 BROPT_HAS_IPV6_ADDR,
Nikolay Aleksandrovc69c2cd2018-09-26 17:01:05 +0300319 BROPT_NEIGH_SUPPRESS_ENABLED,
Nikolay Aleksandrov3341d912018-09-26 17:01:06 +0300320 BROPT_MTU_SET_BY_USER,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300321 BROPT_VLAN_STATS_PER_PORT,
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200322 BROPT_NO_LL_LEARN,
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300323};
324
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100325struct net_bridge {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 spinlock_t lock;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100327 spinlock_t hash_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 struct list_head port_list;
329 struct net_device *dev;
Li RongQing8f849852014-01-04 13:57:59 +0800330 struct pcpu_sw_netstats __percpu *stats;
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300331 unsigned long options;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100332 /* These fields are accessed on each packet */
333#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100334 __be16 vlan_proto;
335 u16 default_pvid;
336 struct net_bridge_vlan_group __rcu *vlgrp;
337#endif
338
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200339 struct rhashtable fdb_hash_tbl;
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200340#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Bernhard Thalerefb6de92015-05-30 15:30:16 +0200341 union {
342 struct rtable fake_rtable;
343 struct rt6_info fake_rt6_info;
344 };
Simon Wunderlich4adf0af2008-07-30 16:27:55 -0700345#endif
stephen hemminger515853c2011-10-03 18:14:46 +0000346 u16 group_fwd_mask;
Toshiaki Makitaf2808d22014-06-10 20:59:24 +0900347 u16 group_fwd_mask_required;
stephen hemminger515853c2011-10-03 18:14:46 +0000348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 /* STP */
350 bridge_id designated_root;
351 bridge_id bridge_id;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100352 unsigned char topology_change;
353 unsigned char topology_change_detected;
354 u16 root_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 unsigned long max_age;
356 unsigned long hello_time;
357 unsigned long forward_delay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 unsigned long ageing_time;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500359 unsigned long bridge_max_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 unsigned long bridge_hello_time;
361 unsigned long bridge_forward_delay;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500362 unsigned long bridge_ageing_time;
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300363 u32 root_path_cost;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800365 u8 group_addr[ETH_ALEN];
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700366
367 enum {
368 BR_NO_STP, /* no spanning tree */
369 BR_KERNEL_STP, /* old STP in kernel */
370 BR_USER_STP, /* new RSTP in userspace */
371 } stp_enabled;
372
Herbert Xueb1d1642010-02-27 19:41:45 +0000373#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Herbert Xueb1d1642010-02-27 19:41:45 +0000374
375 u32 hash_elasticity;
376 u32 hash_max;
377
378 u32 multicast_last_member_count;
Herbert Xueb1d1642010-02-27 19:41:45 +0000379 u32 multicast_startup_query_count;
380
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100381 u8 multicast_igmp_version;
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300382 u8 multicast_router;
383#if IS_ENABLED(CONFIG_IPV6)
384 u8 multicast_mld_version;
385#endif
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300386 spinlock_t multicast_lock;
Herbert Xueb1d1642010-02-27 19:41:45 +0000387 unsigned long multicast_last_member_interval;
388 unsigned long multicast_membership_interval;
389 unsigned long multicast_querier_interval;
390 unsigned long multicast_query_interval;
391 unsigned long multicast_query_response_interval;
392 unsigned long multicast_startup_query_interval;
393
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200394 struct rhashtable mdb_hash_tbl;
395
396 struct hlist_head mdb_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000397 struct hlist_head router_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000398
399 struct timer_list multicast_router_timer;
Linus Lüssing90010b32014-06-07 18:26:26 +0200400 struct bridge_mcast_other_query ip4_other_query;
401 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200402 struct bridge_mcast_querier ip4_querier;
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200403 struct bridge_mcast_stats __percpu *mcast_stats;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200404#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200405 struct bridge_mcast_other_query ip6_other_query;
406 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200407 struct bridge_mcast_querier ip6_querier;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200408#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000409#endif
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 struct timer_list hello_timer;
412 struct timer_list tcn_timer;
413 struct timer_list topology_change_timer;
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100414 struct delayed_work gc_work;
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400415 struct kobject *ifobj;
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400416 u32 auto_cnt;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200417
418#ifdef CONFIG_NET_SWITCHDEV
419 int offload_fwd_mark;
420#endif
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200421 struct hlist_head fdb_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422};
423
Herbert Xu68b7c892010-02-27 19:41:40 +0000424struct br_input_skb_cb {
425 struct net_device *brdev;
Herbert Xu93fdd472014-10-05 12:00:22 +0800426
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000427#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Herbert Xueb1d1642010-02-27 19:41:45 +0000428 int igmp;
429 int mrouters_only;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000430#endif
Herbert Xu93fdd472014-10-05 12:00:22 +0800431
Jouni Malinen842a9ae2015-03-04 12:54:21 +0200432 bool proxyarp_replied;
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +0300433 bool src_port_isolated;
Herbert Xu93fdd472014-10-05 12:00:22 +0800434
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400435#ifdef CONFIG_BRIDGE_VLAN_FILTERING
436 bool vlan_filtered;
437#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200438
439#ifdef CONFIG_NET_SWITCHDEV
440 int offload_fwd_mark;
441#endif
Herbert Xu68b7c892010-02-27 19:41:40 +0000442};
443
444#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
445
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000446#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
447# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
448#else
449# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
450#endif
451
stephen hemminger28a16c92010-05-10 09:31:09 +0000452#define br_printk(level, br, format, args...) \
453 printk(level "%s: " format, (br)->dev->name, ##args)
454
455#define br_err(__br, format, args...) \
456 br_printk(KERN_ERR, __br, format, ##args)
457#define br_warn(__br, format, args...) \
458 br_printk(KERN_WARNING, __br, format, ##args)
459#define br_notice(__br, format, args...) \
460 br_printk(KERN_NOTICE, __br, format, ##args)
461#define br_info(__br, format, args...) \
462 br_printk(KERN_INFO, __br, format, ##args)
463
464#define br_debug(br, format, args...) \
465 pr_debug("%s: " format, (br)->dev->name, ##args)
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467/* called under bridge lock */
468static inline int br_is_root_bridge(const struct net_bridge *br)
469{
470 return !memcmp(&br->bridge_id, &br->designated_root, 8);
471}
472
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200473/* check if a VLAN entry is global */
474static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
475{
476 return v->flags & BRIDGE_VLAN_INFO_MASTER;
477}
478
479/* check if a VLAN entry is used by the bridge */
480static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
481{
482 return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
483}
484
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200485/* check if we should use the vlan entry, returns false if it's only context */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200486static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
487{
488 if (br_vlan_is_master(v)) {
489 if (br_vlan_is_brentry(v))
490 return true;
491 else
492 return false;
493 }
494
495 return true;
496}
497
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300498static inline int br_opt_get(const struct net_bridge *br,
499 enum net_bridge_opts opt)
500{
501 return test_bit(opt, &br->options);
502}
503
Nikolay Aleksandrova428afe2018-11-24 04:34:20 +0200504int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
505 struct netlink_ext_ack *extack);
506int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
507int br_boolopt_multi_toggle(struct net_bridge *br,
508 struct br_boolopt_multi *bm,
509 struct netlink_ext_ack *extack);
510void br_boolopt_multi_get(const struct net_bridge *br,
511 struct br_boolopt_multi *bm);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300512void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514/* br_device.c */
Joe Perches348662a2013-10-18 13:48:22 -0700515void br_dev_setup(struct net_device *dev);
516void br_dev_delete(struct net_device *dev, struct list_head *list);
517netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
stephen hemmingercfb478d2010-05-10 09:31:08 +0000518#ifdef CONFIG_NET_POLL_CONTROLLER
Herbert Xu91d2c342010-06-10 16:12:50 +0000519static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
520 struct sk_buff *skb)
521{
522 struct netpoll *np = p->np;
523
524 if (np)
525 netpoll_send_skb(np, skb);
526}
527
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700528int br_netpoll_enable(struct net_bridge_port *p);
Joe Perches348662a2013-10-18 13:48:22 -0700529void br_netpoll_disable(struct net_bridge_port *p);
Herbert Xu91d2c342010-06-10 16:12:50 +0000530#else
Herbert Xu9f70b0f2010-06-15 21:43:48 -0700531static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
Herbert Xu91d2c342010-06-10 16:12:50 +0000532 struct sk_buff *skb)
533{
534}
535
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700536static inline int br_netpoll_enable(struct net_bridge_port *p)
Herbert Xu91d2c342010-06-10 16:12:50 +0000537{
538 return 0;
539}
540
541static inline void br_netpoll_disable(struct net_bridge_port *p)
542{
543}
stephen hemmingercfb478d2010-05-10 09:31:08 +0000544#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546/* br_fdb.c */
Joe Perches348662a2013-10-18 13:48:22 -0700547int br_fdb_init(void);
548void br_fdb_fini(void);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200549int br_fdb_hash_init(struct net_bridge *br);
550void br_fdb_hash_fini(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700551void br_fdb_flush(struct net_bridge *br);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900552void br_fdb_find_delete_local(struct net_bridge *br,
553 const struct net_bridge_port *p,
554 const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700555void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
556void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100557void br_fdb_cleanup(struct work_struct *work);
Joe Perches348662a2013-10-18 13:48:22 -0700558void br_fdb_delete_by_port(struct net_bridge *br,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700559 const struct net_bridge_port *p, u16 vid, int do_all);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100560struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
561 const unsigned char *addr,
562 __u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700563int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
564int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
565 unsigned long off);
566int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
567 const unsigned char *addr, u16 vid);
568void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900569 const unsigned char *addr, u16 vid, bool added_by_user);
John Fastabend77162022012-04-15 06:43:56 +0000570
Joe Perches348662a2013-10-18 13:48:22 -0700571int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
Jiri Pirkof6f64242014-11-28 14:34:15 +0100572 struct net_device *dev, const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700573int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100574 const unsigned char *addr, u16 vid, u16 nlh_flags);
Joe Perches348662a2013-10-18 13:48:22 -0700575int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
Roopa Prabhud2976532016-08-30 21:56:45 -0700576 struct net_device *dev, struct net_device *fdev, int *idx);
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400577int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
578void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100579int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200580 const unsigned char *addr, u16 vid,
581 bool swdev_notify);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100582int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200583 const unsigned char *addr, u16 vid,
584 bool swdev_notify);
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200585void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
Ido Schimmele9ba0fb2018-10-17 08:53:29 +0000586 const unsigned char *addr, u16 vid, bool offloaded);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588/* br_forward.c */
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200589enum br_pkt_type {
590 BR_PKT_UNICAST,
591 BR_PKT_MULTICAST,
592 BR_PKT_BROADCAST
593};
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500594int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrovb35c5f62016-07-14 06:10:01 +0300595void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300596 bool local_rcv, bool local_orig);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500597int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300598void br_flood(struct net_bridge *br, struct sk_buff *skb,
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200599 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +0300601/* return true if both source port and dest port are isolated */
602static inline bool br_skb_isolated(const struct net_bridge_port *to,
603 const struct sk_buff *skb)
604{
605 return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
606 (to->flags & BR_ISOLATED);
607}
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609/* br_if.c */
Nikolay Aleksandrovfaa1cd82018-05-03 13:47:24 +0300610void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
Joe Perches348662a2013-10-18 13:48:22 -0700611int br_add_bridge(struct net *net, const char *name);
612int br_del_bridge(struct net *net, const char *name);
David Ahernca752be2017-10-04 17:48:50 -0700613int br_add_if(struct net_bridge *br, struct net_device *dev,
614 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700615int br_del_if(struct net_bridge *br, struct net_device *dev);
Nikolay Aleksandrov804b8542018-03-30 13:46:19 +0300616void br_mtu_auto_adjust(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700617netdev_features_t br_features_recompute(struct net_bridge *br,
618 netdev_features_t features);
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400619void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400620void br_manage_promisc(struct net_bridge *br);
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300621int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623/* br_input.c */
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500624int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Joe Perches348662a2013-10-18 13:48:22 -0700625rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Jiri Pirko859828c2013-12-05 16:27:37 +0100627static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
628{
629 return rcu_dereference(dev->rx_handler) == br_handle_frame;
630}
631
Petr Machata4d4fd362018-04-29 10:56:08 +0300632static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
633{
634 return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame;
635}
636
Jiri Pirko859828c2013-12-05 16:27:37 +0100637static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
638{
639 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
640}
641
Petr Machata4d4fd362018-04-29 10:56:08 +0300642static inline struct net_bridge_port *
643br_port_get_check_rtnl(const struct net_device *dev)
644{
645 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
646}
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648/* br_ioctl.c */
Joe Perches348662a2013-10-18 13:48:22 -0700649int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
650int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
651 void __user *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Herbert Xueb1d1642010-02-27 19:41:45 +0000653/* br_multicast.c */
654#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Joe Perches348662a2013-10-18 13:48:22 -0700655int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
David S. Miller394efd12013-11-04 13:48:30 -0500656 struct sk_buff *skb, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700657struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
658 struct sk_buff *skb, u16 vid);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200659int br_multicast_add_port(struct net_bridge_port *port);
Joe Perches348662a2013-10-18 13:48:22 -0700660void br_multicast_del_port(struct net_bridge_port *port);
661void br_multicast_enable_port(struct net_bridge_port *port);
662void br_multicast_disable_port(struct net_bridge_port *port);
663void br_multicast_init(struct net_bridge *br);
664void br_multicast_open(struct net_bridge *br);
665void br_multicast_stop(struct net_bridge *br);
Satish Ashoke10177a2015-07-15 07:16:51 -0700666void br_multicast_dev_del(struct net_bridge *br);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300667void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
668 struct sk_buff *skb, bool local_rcv, bool local_orig);
Joe Perches348662a2013-10-18 13:48:22 -0700669int br_multicast_set_router(struct net_bridge *br, unsigned long val);
670int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
671int br_multicast_toggle(struct net_bridge *br, unsigned long val);
672int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
673int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100674int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100675#if IS_ENABLED(CONFIG_IPV6)
676int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val);
677#endif
Joe Perches348662a2013-10-18 13:48:22 -0700678struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200679br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
Joe Perches348662a2013-10-18 13:48:22 -0700680struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200681br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
Joe Perches348662a2013-10-18 13:48:22 -0700682void br_multicast_free_pg(struct rcu_head *head);
683struct net_bridge_port_group *
684br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
685 struct net_bridge_port_group __rcu *next,
Felix Fietkau6db6f0e2017-01-21 21:01:32 +0100686 unsigned char flags, const unsigned char *src);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200687int br_mdb_hash_init(struct net_bridge *br);
688void br_mdb_hash_fini(struct net_bridge *br);
Elad Raz45ebcce2016-04-21 12:52:45 +0200689void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
690 struct br_ip *group, int type, u8 flags);
Satish Ashok949f1e32015-07-23 05:00:53 -0700691void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
692 int type);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200693void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700694 const struct sk_buff *skb, u8 type, u8 dir);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200695int br_multicast_init_stats(struct net_bridge *br);
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300696void br_multicast_uninit_stats(struct net_bridge *br);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200697void br_multicast_get_stats(const struct net_bridge *br,
698 const struct net_bridge_port *p,
699 struct br_mcast_stats *dest);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200700void br_mdb_init(void);
701void br_mdb_uninit(void);
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000702
Cong Wangcfd56752012-12-11 22:23:08 +0000703#define mlock_dereference(X, br) \
704 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
705
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000706static inline bool br_multicast_is_router(struct net_bridge *br)
707{
708 return br->multicast_router == 2 ||
709 (br->multicast_router == 1 &&
710 timer_pending(&br->multicast_router_timer));
711}
Linus Lüssingb00589a2013-08-01 01:06:20 +0200712
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200713static inline bool
714__br_multicast_querier_exists(struct net_bridge *br,
daniel0888d5f2016-06-24 12:35:18 +0200715 struct bridge_mcast_other_query *querier,
716 const bool is_ipv6)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200717{
daniel0888d5f2016-06-24 12:35:18 +0200718 bool own_querier_enabled;
719
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300720 if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
721 if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR))
daniel0888d5f2016-06-24 12:35:18 +0200722 own_querier_enabled = false;
723 else
724 own_querier_enabled = true;
725 } else {
726 own_querier_enabled = false;
727 }
728
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200729 return time_is_before_jiffies(querier->delay_time) &&
daniel0888d5f2016-06-24 12:35:18 +0200730 (own_querier_enabled || timer_pending(&querier->timer));
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200731}
732
733static inline bool br_multicast_querier_exists(struct net_bridge *br,
734 struct ethhdr *eth)
735{
736 switch (eth->h_proto) {
737 case (htons(ETH_P_IP)):
daniel0888d5f2016-06-24 12:35:18 +0200738 return __br_multicast_querier_exists(br,
739 &br->ip4_other_query, false);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200740#if IS_ENABLED(CONFIG_IPV6)
741 case (htons(ETH_P_IPV6)):
daniel0888d5f2016-06-24 12:35:18 +0200742 return __br_multicast_querier_exists(br,
743 &br->ip6_other_query, true);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200744#endif
745 default:
746 return false;
747 }
Linus Lüssingb00589a2013-08-01 01:06:20 +0200748}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200749
750static inline int br_multicast_igmp_type(const struct sk_buff *skb)
751{
752 return BR_INPUT_SKB_CB(skb)->igmp;
753}
Herbert Xueb1d1642010-02-27 19:41:45 +0000754#else
755static inline int br_multicast_rcv(struct net_bridge *br,
756 struct net_bridge_port *port,
Vlad Yasevich06499092013-10-28 15:45:07 -0400757 struct sk_buff *skb,
758 u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000759{
760 return 0;
761}
762
763static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
Cong Wangfbca58a2013-03-07 03:05:33 +0000764 struct sk_buff *skb, u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000765{
766 return NULL;
767}
768
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200769static inline int br_multicast_add_port(struct net_bridge_port *port)
Herbert Xueb1d1642010-02-27 19:41:45 +0000770{
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200771 return 0;
Herbert Xueb1d1642010-02-27 19:41:45 +0000772}
773
774static inline void br_multicast_del_port(struct net_bridge_port *port)
775{
776}
777
778static inline void br_multicast_enable_port(struct net_bridge_port *port)
779{
780}
781
782static inline void br_multicast_disable_port(struct net_bridge_port *port)
783{
784}
785
786static inline void br_multicast_init(struct net_bridge *br)
787{
788}
789
790static inline void br_multicast_open(struct net_bridge *br)
791{
792}
793
794static inline void br_multicast_stop(struct net_bridge *br)
795{
796}
Herbert Xu5cb5e942010-02-27 19:41:46 +0000797
Nikolay Aleksandrova7ce45a2015-07-20 23:03:45 +0200798static inline void br_multicast_dev_del(struct net_bridge *br)
799{
800}
801
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300802static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
803 struct sk_buff *skb,
804 bool local_rcv, bool local_orig)
Herbert Xu5cb5e942010-02-27 19:41:46 +0000805{
806}
807
Herbert Xueb1d1642010-02-27 19:41:45 +0000808static inline bool br_multicast_is_router(struct net_bridge *br)
809{
Gustavo A. R. Silva03aaa9e2018-01-18 17:37:45 -0600810 return false;
Herbert Xueb1d1642010-02-27 19:41:45 +0000811}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300812
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200813static inline bool br_multicast_querier_exists(struct net_bridge *br,
814 struct ethhdr *eth)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200815{
816 return false;
817}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300818
Rami Rosenfdb184d2013-01-03 13:30:43 +0200819static inline void br_mdb_init(void)
820{
821}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300822
Rami Rosenfdb184d2013-01-03 13:30:43 +0200823static inline void br_mdb_uninit(void)
824{
825}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200826
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200827static inline int br_mdb_hash_init(struct net_bridge *br)
828{
829 return 0;
830}
831
832static inline void br_mdb_hash_fini(struct net_bridge *br)
833{
834}
835
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200836static inline void br_multicast_count(struct net_bridge *br,
837 const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700838 const struct sk_buff *skb,
839 u8 type, u8 dir)
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200840{
841}
842
843static inline int br_multicast_init_stats(struct net_bridge *br)
844{
845 return 0;
846}
847
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300848static inline void br_multicast_uninit_stats(struct net_bridge *br)
849{
850}
851
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200852static inline int br_multicast_igmp_type(const struct sk_buff *skb)
853{
854 return 0;
855}
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000856#endif
Herbert Xueb1d1642010-02-27 19:41:45 +0000857
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000858/* br_vlan.c */
859#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200860bool br_allowed_ingress(const struct net_bridge *br,
861 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
862 u16 *vid);
863bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700864 const struct sk_buff *skb);
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900865bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
Joe Perches348662a2013-10-18 13:48:22 -0700866struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800867 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200868 struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700869 struct sk_buff *skb);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300870int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
871 bool *changed);
Joe Perches348662a2013-10-18 13:48:22 -0700872int br_vlan_delete(struct net_bridge *br, u16 vid);
873void br_vlan_flush(struct net_bridge *br);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200874struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900875void br_recalculate_fwd_mask(struct net_bridge *br);
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300876int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Joe Perches348662a2013-10-18 13:48:22 -0700877int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900878int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900879int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200880int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300881int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400882int br_vlan_init(struct net_bridge *br);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400883int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov0f963b72015-10-04 14:23:47 +0200884int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300885int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
886 bool *changed);
Joe Perches348662a2013-10-18 13:48:22 -0700887int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
888void nbp_vlan_flush(struct net_bridge_port *port);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400889int nbp_vlan_init(struct net_bridge_port *port);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200890int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +0200891void br_vlan_get_stats(const struct net_bridge_vlan *v,
892 struct br_vlan_stats *stats);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000893
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200894static inline struct net_bridge_vlan_group *br_vlan_group(
895 const struct net_bridge *br)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000896{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200897 return rtnl_dereference(br->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000898}
899
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200900static inline struct net_bridge_vlan_group *nbp_vlan_group(
901 const struct net_bridge_port *p)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000902{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200903 return rtnl_dereference(p->vlgrp);
904}
905
906static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
907 const struct net_bridge *br)
908{
909 return rcu_dereference(br->vlgrp);
910}
911
912static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
913 const struct net_bridge_port *p)
914{
915 return rcu_dereference(p->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000916}
917
918/* Since bridge now depends on 8021Q module, but the time bridge sees the
919 * skb, the vlan tag will always be present if the frame was tagged.
920 */
921static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
922{
923 int err = 0;
924
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200925 if (skb_vlan_tag_present(skb)) {
Michał Mirosław5978f8a2018-11-09 00:18:03 +0100926 *vid = skb_vlan_tag_get_id(skb);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200927 } else {
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000928 *vid = 0;
929 err = -EINVAL;
930 }
931
932 return err;
933}
Vlad Yasevich78851982013-02-13 12:00:14 +0000934
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200935static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +0000936{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200937 if (!vg)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400938 return 0;
939
Vlad Yasevich78851982013-02-13 12:00:14 +0000940 smp_rmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200941 return vg->pvid;
Vlad Yasevich78851982013-02-13 12:00:14 +0000942}
943
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000944#else
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200945static inline bool br_allowed_ingress(const struct net_bridge *br,
946 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000947 struct sk_buff *skb,
948 u16 *vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000949{
950 return true;
951}
952
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200953static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000954 const struct sk_buff *skb)
955{
956 return true;
957}
958
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900959static inline bool br_should_learn(struct net_bridge_port *p,
960 struct sk_buff *skb, u16 *vid)
961{
962 return true;
963}
964
Vlad Yasevich78851982013-02-13 12:00:14 +0000965static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800966 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200967 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000968 struct sk_buff *skb)
969{
970 return skb;
971}
972
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300973static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
974 bool *changed)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000975{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300976 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000977 return -EOPNOTSUPP;
978}
979
980static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
981{
982 return -EOPNOTSUPP;
983}
984
985static inline void br_vlan_flush(struct net_bridge *br)
986{
987}
988
Toshiaki Makita204177f2014-06-10 20:59:25 +0900989static inline void br_recalculate_fwd_mask(struct net_bridge *br)
990{
991}
992
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400993static inline int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +0900994{
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400995 return 0;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900996}
997
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300998static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
999 bool *changed)
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001000{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001001 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001002 return -EOPNOTSUPP;
1003}
1004
1005static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1006{
1007 return -EOPNOTSUPP;
1008}
1009
1010static inline void nbp_vlan_flush(struct net_bridge_port *port)
1011{
1012}
1013
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001014static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1015 u16 vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001016{
1017 return NULL;
1018}
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +00001019
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001020static inline int nbp_vlan_init(struct net_bridge_port *port)
1021{
1022 return 0;
1023}
1024
Vlad Yasevich78851982013-02-13 12:00:14 +00001025static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001026{
1027 return 0;
1028}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001029
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001030static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +00001031{
Vlad Yasevich3df6bf42014-10-03 11:29:17 -04001032 return 0;
Vlad Yasevich78851982013-02-13 12:00:14 +00001033}
Vlad Yasevich2796d0c2014-05-16 09:59:20 -04001034
Nikolay Aleksandrova7854032015-08-07 19:40:45 +03001035static inline int __br_vlan_filter_toggle(struct net_bridge *br,
1036 unsigned long val)
1037{
1038 return -EOPNOTSUPP;
1039}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001040
1041static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1042 u32 filter_mask)
1043{
1044 return 0;
1045}
1046
1047static inline struct net_bridge_vlan_group *br_vlan_group(
1048 const struct net_bridge *br)
1049{
1050 return NULL;
1051}
1052
1053static inline struct net_bridge_vlan_group *nbp_vlan_group(
1054 const struct net_bridge_port *p)
1055{
1056 return NULL;
1057}
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001058
1059static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1060 const struct net_bridge *br)
1061{
1062 return NULL;
1063}
1064
1065static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1066 const struct net_bridge_port *p)
1067{
1068 return NULL;
1069}
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001070
1071static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1072 struct br_vlan_stats *stats)
1073{
1074}
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001075#endif
1076
Pablo Neira Ayuso1a4ba642015-03-10 10:27:18 +01001077struct nf_br_ops {
1078 int (*br_dev_xmit_hook)(struct sk_buff *skb);
1079};
1080extern const struct nf_br_ops __rcu *nf_br_ops;
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082/* br_netfilter.c */
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001083#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1084int br_nf_core_init(void);
1085void br_nf_core_fini(void);
Joe Perches348662a2013-10-18 13:48:22 -07001086void br_netfilter_rtable_init(struct net_bridge *);
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001087#else
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001088static inline int br_nf_core_init(void) { return 0; }
1089static inline void br_nf_core_fini(void) {}
Simon Wunderlich4adf0af2008-07-30 16:27:55 -07001090#define br_netfilter_rtable_init(x)
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001091#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093/* br_stp.c */
Florian Fainelli775dd692014-09-30 16:13:19 -07001094void br_set_state(struct net_bridge_port *p, unsigned int state);
Joe Perches348662a2013-10-18 13:48:22 -07001095struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1096void br_init_port(struct net_bridge_port *p);
1097void br_become_designated_port(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Joe Perches348662a2013-10-18 13:48:22 -07001099void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1100int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1101int br_set_hello_time(struct net_bridge *br, unsigned long x);
1102int br_set_max_age(struct net_bridge *br, unsigned long x);
Vivien Didelot82dd4332016-12-10 13:44:27 -05001103int __set_ageing_time(struct net_device *dev, unsigned long t);
Vivien Didelot9e0b27f2016-07-21 12:42:19 -04001104int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
stephen hemminger14f98f22011-04-04 14:03:33 +00001105
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107/* br_stp_if.c */
Joe Perches348662a2013-10-18 13:48:22 -07001108void br_stp_enable_bridge(struct net_bridge *br);
1109void br_stp_disable_bridge(struct net_bridge *br);
1110void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
1111void br_stp_enable_port(struct net_bridge_port *p);
1112void br_stp_disable_port(struct net_bridge_port *p);
1113bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1114void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1115void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1116int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1117int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1118ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120/* br_stp_bpdu.c */
Patrick McHardy7c85fbf2008-07-05 21:25:56 -07001121struct stp_proto;
Joe Perches348662a2013-10-18 13:48:22 -07001122void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1123 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125/* br_stp_timer.c */
Joe Perches348662a2013-10-18 13:48:22 -07001126void br_stp_timer_init(struct net_bridge *br);
1127void br_stp_port_timer_init(struct net_bridge_port *p);
1128unsigned long br_timer_value(const struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130/* br.c */
Igor Maraviće6373c42011-12-12 02:58:25 +00001131#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +00001132extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1133#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001135/* br_netlink.c */
stephen hemminger149ddd82012-06-26 05:48:45 +00001136extern struct rtnl_link_ops br_link_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001137int br_netlink_init(void);
1138void br_netlink_fini(void);
Nikolay Aleksandrov92899062017-11-01 12:18:13 +02001139void br_ifinfo_notify(int event, const struct net_bridge *br,
1140 const struct net_bridge_port *port);
Roopa Prabhuadd511b2015-01-29 22:40:12 -08001141int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
1142int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
Joe Perches348662a2013-10-18 13:48:22 -07001143int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02001144 u32 filter_mask, int nlflags);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146#ifdef CONFIG_SYSFS
1147/* br_sysfs_if.c */
Emese Revfy52cf25d2010-01-19 02:58:23 +01001148extern const struct sysfs_ops brport_sysfs_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001149int br_sysfs_addif(struct net_bridge_port *p);
1150int br_sysfs_renameif(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152/* br_sysfs_br.c */
Joe Perches348662a2013-10-18 13:48:22 -07001153int br_sysfs_addbr(struct net_device *dev);
1154void br_sysfs_delbr(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156#else
1157
Lee Jones0cb2bbb2012-11-03 23:02:30 +01001158static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1159static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1160static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1161static inline void br_sysfs_delbr(struct net_device *dev) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162#endif /* CONFIG_SYSFS */
1163
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001164/* br_switchdev.c */
1165#ifdef CONFIG_NET_SWITCHDEV
1166int nbp_switchdev_mark_set(struct net_bridge_port *p);
1167void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1168 struct sk_buff *skb);
1169bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1170 const struct sk_buff *skb);
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001171int br_switchdev_set_port_flag(struct net_bridge_port *p,
1172 unsigned long flags,
1173 unsigned long mask);
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001174void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
1175 int type);
Petr Machatad66e4342018-05-30 02:56:03 +02001176int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
1177int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001178
1179static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1180{
1181 skb->offload_fwd_mark = 0;
1182}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001183#else
1184static inline int nbp_switchdev_mark_set(struct net_bridge_port *p)
1185{
1186 return 0;
1187}
1188
1189static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1190 struct sk_buff *skb)
1191{
1192}
1193
1194static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1195 const struct sk_buff *skb)
1196{
1197 return true;
1198}
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001199
1200static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
1201 unsigned long flags,
1202 unsigned long mask)
1203{
1204 return 0;
1205}
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001206
Petr Machatad66e4342018-05-30 02:56:03 +02001207static inline int br_switchdev_port_vlan_add(struct net_device *dev,
1208 u16 vid, u16 flags)
1209{
1210 return -EOPNOTSUPP;
1211}
1212
1213static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
1214{
1215 return -EOPNOTSUPP;
1216}
1217
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001218static inline void
1219br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
1220{
1221}
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001222
1223static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1224{
1225}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001226#endif /* CONFIG_NET_SWITCHDEV */
1227
Roopa Prabhu057658c2017-10-06 22:12:38 -07001228/* br_arp_nd_proxy.c */
Roopa Prabhu821f1b22017-10-06 22:12:37 -07001229void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
Roopa Prabhu057658c2017-10-06 22:12:38 -07001230void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
1231 u16 vid, struct net_bridge_port *p);
Roopa Prabhued842fa2017-10-06 22:12:39 -07001232void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
1233 u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
1234struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235#endif