blob: bf4a4d1cc3bba6d61bea9b435f23134aedf3ecc9 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Linux ethernet bridge
4 *
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9#ifndef _BR_PRIVATE_H
10#define _BR_PRIVATE_H
11
12#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/if_bridge.h>
Herbert Xu91d2c342010-06-10 16:12:50 +000014#include <linux/netpoll.h>
Eric Dumazet406818f2010-06-23 13:00:48 -070015#include <linux/u64_stats_sync.h>
Simon Wunderlich4adf0af2008-07-30 16:27:55 -070016#include <net/route.h>
Bernhard Thalerefb6de92015-05-30 15:30:16 +020017#include <net/ip6_fib.h>
Vlad Yasevich243a2e62013-02-13 12:00:09 +000018#include <linux/if_vlan.h>
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020019#include <linux/rhashtable.h>
Reshetova, Elena25127752017-07-04 15:53:05 +030020#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#define BR_HASH_BITS 8
23#define BR_HASH_SIZE (1 << BR_HASH_BITS)
24
25#define BR_HOLD_TIME (1*HZ)
26
27#define BR_PORT_BITS 10
28#define BR_MAX_PORTS (1<<BR_PORT_BITS)
29
Nikolay Aleksandrovd08c6bc2018-12-05 15:14:27 +020030#define BR_MULTICAST_DEFAULT_HASH_MAX 4096
31
Stephen Hemminger9cde0702007-03-21 14:22:44 -070032#define BR_VERSION "2.3"
33
stephen hemminger515853c2011-10-03 18:14:46 +000034/* Control of forwarding link local multicast */
35#define BR_GROUPFWD_DEFAULT 0
Bernhard Thaler784b58a2015-05-04 22:47:13 +020036/* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +030037enum {
38 BR_GROUPFWD_STP = BIT(0),
39 BR_GROUPFWD_MACPAUSE = BIT(1),
40 BR_GROUPFWD_LACP = BIT(2),
41};
42
43#define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \
44 BR_GROUPFWD_LACP)
Toshiaki Makitaf2808d22014-06-10 20:59:24 +090045/* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
46#define BR_GROUPFWD_8021AD 0xB801u
stephen hemminger515853c2011-10-03 18:14:46 +000047
Stephen Hemminger9cde0702007-03-21 14:22:44 -070048/* Path to usermode spanning tree program */
49#define BR_STP_PROG "/sbin/bridge-stp"
Stephen Hemminger8cbb512e2005-12-21 19:01:30 -080050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051typedef struct bridge_id bridge_id;
52typedef struct mac_addr mac_addr;
53typedef __u16 port_id;
54
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +030055struct bridge_id {
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 unsigned char prio[2];
Joe Perchese5a727f2014-02-23 00:05:25 -080057 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070058};
59
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +030060struct mac_addr {
Joe Perchese5a727f2014-02-23 00:05:25 -080061 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020064#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
65/* our own querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020066struct bridge_mcast_own_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020067 struct timer_list timer;
68 u32 startup_sent;
69};
70
71/* other querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020072struct bridge_mcast_other_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020073 struct timer_list timer;
74 unsigned long delay_time;
75};
Linus Lüssingdc4eb532014-06-07 18:26:27 +020076
77/* selected querier */
78struct bridge_mcast_querier {
79 struct br_ip addr;
Linus Lüssing2cd41432014-06-07 18:26:29 +020080 struct net_bridge_port __rcu *port;
Linus Lüssingdc4eb532014-06-07 18:26:27 +020081};
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +020082
83/* IGMP/MLD statistics */
84struct bridge_mcast_stats {
85 struct br_mcast_stats mstats;
86 struct u64_stats_sync syncp;
87};
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020088#endif
89
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +020090struct br_vlan_stats {
91 u64 rx_bytes;
92 u64 rx_packets;
93 u64 tx_bytes;
94 u64 tx_packets;
95 struct u64_stats_sync syncp;
96};
97
Roopa Prabhuefa53562017-01-31 22:59:54 -080098struct br_tunnel_info {
99 __be64 tunnel_id;
100 struct metadata_dst *tunnel_dst;
101};
102
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200103/* private vlan flags */
104enum {
105 BR_VLFLAG_PER_PORT_STATS = BIT(0),
Ido Schimmel27973792019-01-08 16:48:11 +0000106 BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1),
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200107};
108
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200109/**
110 * struct net_bridge_vlan - per-vlan entry
111 *
112 * @vnode: rhashtable member
113 * @vid: VLAN id
114 * @flags: bridge vlan flags
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200115 * @priv_flags: private (in-kernel) bridge vlan flags
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200116 * @stats: per-cpu VLAN statistics
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200117 * @br: if MASTER flag set, this points to a bridge struct
118 * @port: if MASTER flag unset, this points to a port struct
119 * @refcnt: if MASTER flag set, this is bumped for each port referencing it
120 * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
121 * for this VLAN entry
122 * @vlist: sorted list of VLAN entries
123 * @rcu: used for entry destruction
124 *
125 * This structure is shared between the global per-VLAN entries contained in
126 * the bridge rhashtable and the local per-port per-VLAN entries contained in
127 * the port's rhashtable. The union entries should be interpreted depending on
128 * the entry flags that are set.
129 */
130struct net_bridge_vlan {
131 struct rhash_head vnode;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800132 struct rhash_head tnode;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200133 u16 vid;
134 u16 flags;
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200135 u16 priv_flags;
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200136 struct br_vlan_stats __percpu *stats;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000137 union {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200138 struct net_bridge *br;
139 struct net_bridge_port *port;
140 };
141 union {
Reshetova, Elena25127752017-07-04 15:53:05 +0300142 refcount_t refcnt;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200143 struct net_bridge_vlan *brvlan;
144 };
Roopa Prabhuefa53562017-01-31 22:59:54 -0800145
146 struct br_tunnel_info tinfo;
147
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200148 struct list_head vlist;
149
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000150 struct rcu_head rcu;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200151};
152
153/**
154 * struct net_bridge_vlan_group
155 *
156 * @vlan_hash: VLAN entry rhashtable
157 * @vlan_list: sorted VLAN entry list
158 * @num_vlans: number of total VLAN entries
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200159 * @pvid: PVID VLAN id
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200160 *
161 * IMPORTANT: Be careful when checking if there're VLAN entries using list
162 * primitives because the bridge can have entries in its list which
163 * are just for global context but not for filtering, i.e. they have
164 * the master flag set but not the brentry flag. If you have to check
165 * if there're "real" entries in the bridge please test @num_vlans
166 */
167struct net_bridge_vlan_group {
168 struct rhashtable vlan_hash;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800169 struct rhashtable tunnel_hash;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200170 struct list_head vlan_list;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000171 u16 num_vlans;
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200172 u16 pvid;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000173};
174
Nikolay Aleksandrov6869c3b2019-10-29 13:45:53 +0200175/* bridge fdb flags */
176enum {
177 BR_FDB_LOCAL,
Nikolay Aleksandrov29e63ff2019-10-29 13:45:54 +0200178 BR_FDB_STATIC,
Nikolay Aleksandrove0458d92019-10-29 13:45:55 +0200179 BR_FDB_STICKY,
Nikolay Aleksandrovac3ca6a2019-10-29 13:45:56 +0200180 BR_FDB_ADDED_BY_USER,
Nikolay Aleksandrov6869c3b2019-10-29 13:45:53 +0200181};
182
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200183struct net_bridge_fdb_key {
184 mac_addr addr;
185 u16 vlan_id;
186};
187
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100188struct net_bridge_fdb_entry {
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200189 struct rhash_head rhnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 struct net_bridge_port *dst;
191
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200192 struct net_bridge_fdb_key key;
193 struct hlist_node fdb_node;
Nikolay Aleksandrov6869c3b2019-10-29 13:45:53 +0200194 unsigned long flags;
Nikolay Aleksandrovac3ca6a2019-10-29 13:45:56 +0200195 unsigned char added_by_external_learn:1,
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200196 offloaded:1;
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100197
198 /* write-heavy members should not affect lookups */
199 unsigned long updated ____cacheline_aligned_in_smp;
200 unsigned long used;
201
Nikolay Aleksandrovb22fbf22015-08-27 14:19:20 -0700202 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203};
204
Elad Raz9d06b6d2016-02-03 09:57:05 +0100205#define MDB_PG_FLAGS_PERMANENT BIT(0)
206#define MDB_PG_FLAGS_OFFLOAD BIT(1)
Nikolay Aleksandrov3247b272019-07-30 15:20:41 +0300207#define MDB_PG_FLAGS_FAST_LEAVE BIT(2)
Elad Raz9d06b6d2016-02-03 09:57:05 +0100208
Herbert Xueb1d1642010-02-27 19:41:45 +0000209struct net_bridge_port_group {
210 struct net_bridge_port *port;
Eric Dumazete8051682010-11-15 06:38:10 +0000211 struct net_bridge_port_group __rcu *next;
Herbert Xueb1d1642010-02-27 19:41:45 +0000212 struct hlist_node mglist;
213 struct rcu_head rcu;
214 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900215 struct br_ip addr;
Elad Raz9d06b6d2016-02-03 09:57:05 +0100216 unsigned char flags;
Felix Fietkau6db6f0e2017-01-21 21:01:32 +0100217 unsigned char eth_addr[ETH_ALEN];
Herbert Xueb1d1642010-02-27 19:41:45 +0000218};
219
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +0300220struct net_bridge_mdb_entry {
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200221 struct rhash_head rhnode;
Herbert Xueb1d1642010-02-27 19:41:45 +0000222 struct net_bridge *br;
Eric Dumazete8051682010-11-15 06:38:10 +0000223 struct net_bridge_port_group __rcu *ports;
Herbert Xueb1d1642010-02-27 19:41:45 +0000224 struct rcu_head rcu;
225 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900226 struct br_ip addr;
Andrew Lunnff0fd342017-11-09 23:10:57 +0100227 bool host_joined;
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200228 struct hlist_node mdb_node;
Herbert Xueb1d1642010-02-27 19:41:45 +0000229};
230
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100231struct net_bridge_port {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 struct net_bridge *br;
233 struct net_device *dev;
234 struct list_head list;
235
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100236 unsigned long flags;
237#ifdef CONFIG_BRIDGE_VLAN_FILTERING
238 struct net_bridge_vlan_group __rcu *vlgrp;
239#endif
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300240 struct net_bridge_port __rcu *backup_port;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 /* STP */
243 u8 priority;
244 u8 state;
245 u16 port_no;
246 unsigned char topology_change_ack;
247 unsigned char config_pending;
248 port_id port_id;
249 port_id designated_port;
250 bridge_id designated_root;
251 bridge_id designated_bridge;
252 u32 path_cost;
253 u32 designated_cost;
stephen hemminger0c031502011-07-22 07:47:06 +0000254 unsigned long designated_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 struct timer_list forward_delay_timer;
257 struct timer_list hold_timer;
258 struct timer_list message_age_timer;
259 struct kobject kobj;
260 struct rcu_head rcu;
Fischer, Anna3982d3d2009-08-13 06:55:16 +0000261
Herbert Xueb1d1642010-02-27 19:41:45 +0000262#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Linus Lüssing90010b32014-06-07 18:26:26 +0200263 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200264#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200265 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200266#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000267 unsigned char multicast_router;
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200268 struct bridge_mcast_stats __percpu *mcast_stats;
Herbert Xueb1d1642010-02-27 19:41:45 +0000269 struct timer_list multicast_router_timer;
Herbert Xueb1d1642010-02-27 19:41:45 +0000270 struct hlist_head mglist;
271 struct hlist_node rlist;
272#endif
Simon Arlotte0f43752010-05-10 09:31:11 +0000273
274#ifdef CONFIG_SYSFS
275 char sysfs_name[IFNAMSIZ];
276#endif
Herbert Xu91d2c342010-06-10 16:12:50 +0000277
278#ifdef CONFIG_NET_POLL_CONTROLLER
279 struct netpoll *np;
280#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200281#ifdef CONFIG_NET_SWITCHDEV
282 int offload_fwd_mark;
283#endif
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +0300284 u16 group_fwd_mask;
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300285 u16 backup_redirected_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286};
287
Tyler Hicks705e0de2018-07-20 21:56:54 +0000288#define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
289
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400290#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
Vlad Yasevichf3a6ddf2014-05-16 09:59:18 -0400291#define br_promisc_port(p) ((p)->flags & BR_PROMISC)
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400292
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000293static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
294{
Hong Zhiguo716ec052013-09-14 22:42:28 +0800295 return rcu_dereference(dev->rx_handler_data);
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000296}
297
Hong Zhiguo1fb17542013-09-14 22:42:27 +0800298static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000299{
Julian Wiedmann35f861e2019-03-29 14:38:19 +0100300 return netif_is_bridge_port(dev) ?
Eric Dumazetec1e5612010-11-15 06:38:14 +0000301 rtnl_dereference(dev->rx_handler_data) : NULL;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000302}
303
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200304static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
305{
Julian Wiedmann35f861e2019-03-29 14:38:19 +0100306 return netif_is_bridge_port(dev) ?
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200307 rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
308}
309
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300310enum net_bridge_opts {
311 BROPT_VLAN_ENABLED,
312 BROPT_VLAN_STATS_ENABLED,
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300313 BROPT_NF_CALL_IPTABLES,
314 BROPT_NF_CALL_IP6TABLES,
315 BROPT_NF_CALL_ARPTABLES,
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300316 BROPT_GROUP_ADDR_SET,
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300317 BROPT_MULTICAST_ENABLED,
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300318 BROPT_MULTICAST_QUERIER,
319 BROPT_MULTICAST_QUERY_USE_IFADDR,
320 BROPT_MULTICAST_STATS_ENABLED,
321 BROPT_HAS_IPV6_ADDR,
Nikolay Aleksandrovc69c2cd2018-09-26 17:01:05 +0300322 BROPT_NEIGH_SUPPRESS_ENABLED,
Nikolay Aleksandrov3341d912018-09-26 17:01:06 +0300323 BROPT_MTU_SET_BY_USER,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300324 BROPT_VLAN_STATS_PER_PORT,
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200325 BROPT_NO_LL_LEARN,
Mike Manning9c0ec2e2019-04-18 18:35:33 +0100326 BROPT_VLAN_BRIDGE_BINDING,
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300327};
328
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100329struct net_bridge {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 spinlock_t lock;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100331 spinlock_t hash_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 struct list_head port_list;
333 struct net_device *dev;
Li RongQing8f849852014-01-04 13:57:59 +0800334 struct pcpu_sw_netstats __percpu *stats;
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300335 unsigned long options;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100336 /* These fields are accessed on each packet */
337#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100338 __be16 vlan_proto;
339 u16 default_pvid;
340 struct net_bridge_vlan_group __rcu *vlgrp;
341#endif
342
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200343 struct rhashtable fdb_hash_tbl;
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200344#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Bernhard Thalerefb6de92015-05-30 15:30:16 +0200345 union {
346 struct rtable fake_rtable;
347 struct rt6_info fake_rt6_info;
348 };
Simon Wunderlich4adf0af2008-07-30 16:27:55 -0700349#endif
stephen hemminger515853c2011-10-03 18:14:46 +0000350 u16 group_fwd_mask;
Toshiaki Makitaf2808d22014-06-10 20:59:24 +0900351 u16 group_fwd_mask_required;
stephen hemminger515853c2011-10-03 18:14:46 +0000352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 /* STP */
354 bridge_id designated_root;
355 bridge_id bridge_id;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100356 unsigned char topology_change;
357 unsigned char topology_change_detected;
358 u16 root_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 unsigned long max_age;
360 unsigned long hello_time;
361 unsigned long forward_delay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 unsigned long ageing_time;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500363 unsigned long bridge_max_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 unsigned long bridge_hello_time;
365 unsigned long bridge_forward_delay;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500366 unsigned long bridge_ageing_time;
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300367 u32 root_path_cost;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800369 u8 group_addr[ETH_ALEN];
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700370
371 enum {
372 BR_NO_STP, /* no spanning tree */
373 BR_KERNEL_STP, /* old STP in kernel */
374 BR_USER_STP, /* new RSTP in userspace */
375 } stp_enabled;
376
Herbert Xueb1d1642010-02-27 19:41:45 +0000377#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Herbert Xueb1d1642010-02-27 19:41:45 +0000378
Herbert Xueb1d1642010-02-27 19:41:45 +0000379 u32 hash_max;
380
381 u32 multicast_last_member_count;
Herbert Xueb1d1642010-02-27 19:41:45 +0000382 u32 multicast_startup_query_count;
383
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100384 u8 multicast_igmp_version;
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300385 u8 multicast_router;
386#if IS_ENABLED(CONFIG_IPV6)
387 u8 multicast_mld_version;
388#endif
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300389 spinlock_t multicast_lock;
Herbert Xueb1d1642010-02-27 19:41:45 +0000390 unsigned long multicast_last_member_interval;
391 unsigned long multicast_membership_interval;
392 unsigned long multicast_querier_interval;
393 unsigned long multicast_query_interval;
394 unsigned long multicast_query_response_interval;
395 unsigned long multicast_startup_query_interval;
396
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200397 struct rhashtable mdb_hash_tbl;
398
399 struct hlist_head mdb_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000400 struct hlist_head router_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000401
402 struct timer_list multicast_router_timer;
Linus Lüssing90010b32014-06-07 18:26:26 +0200403 struct bridge_mcast_other_query ip4_other_query;
404 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200405 struct bridge_mcast_querier ip4_querier;
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200406 struct bridge_mcast_stats __percpu *mcast_stats;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200407#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200408 struct bridge_mcast_other_query ip6_other_query;
409 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200410 struct bridge_mcast_querier ip6_querier;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200411#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000412#endif
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 struct timer_list hello_timer;
415 struct timer_list tcn_timer;
416 struct timer_list topology_change_timer;
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100417 struct delayed_work gc_work;
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400418 struct kobject *ifobj;
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400419 u32 auto_cnt;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200420
421#ifdef CONFIG_NET_SWITCHDEV
422 int offload_fwd_mark;
423#endif
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200424 struct hlist_head fdb_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425};
426
Herbert Xu68b7c892010-02-27 19:41:40 +0000427struct br_input_skb_cb {
428 struct net_device *brdev;
Herbert Xu93fdd472014-10-05 12:00:22 +0800429
Pablo Neira Ayuso3c171f42019-05-29 13:25:37 +0200430 u16 frag_max_size;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000431#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Florian Westphalf12064d2019-04-11 16:36:40 +0200432 u8 igmp;
433 u8 mrouters_only:1;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000434#endif
Florian Westphalf12064d2019-04-11 16:36:40 +0200435 u8 proxyarp_replied:1;
436 u8 src_port_isolated:1;
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400437#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Florian Westphalf12064d2019-04-11 16:36:40 +0200438 u8 vlan_filtered:1;
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400439#endif
Florian Westphal223fd0a2019-04-11 16:36:42 +0200440#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
441 u8 br_netfilter_broute:1;
442#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200443
444#ifdef CONFIG_NET_SWITCHDEV
445 int offload_fwd_mark;
446#endif
Herbert Xu68b7c892010-02-27 19:41:40 +0000447};
448
449#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
450
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000451#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
452# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
453#else
454# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
455#endif
456
stephen hemminger28a16c92010-05-10 09:31:09 +0000457#define br_printk(level, br, format, args...) \
458 printk(level "%s: " format, (br)->dev->name, ##args)
459
460#define br_err(__br, format, args...) \
461 br_printk(KERN_ERR, __br, format, ##args)
462#define br_warn(__br, format, args...) \
463 br_printk(KERN_WARNING, __br, format, ##args)
464#define br_notice(__br, format, args...) \
465 br_printk(KERN_NOTICE, __br, format, ##args)
466#define br_info(__br, format, args...) \
467 br_printk(KERN_INFO, __br, format, ##args)
468
469#define br_debug(br, format, args...) \
470 pr_debug("%s: " format, (br)->dev->name, ##args)
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472/* called under bridge lock */
473static inline int br_is_root_bridge(const struct net_bridge *br)
474{
475 return !memcmp(&br->bridge_id, &br->designated_root, 8);
476}
477
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200478/* check if a VLAN entry is global */
479static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
480{
481 return v->flags & BRIDGE_VLAN_INFO_MASTER;
482}
483
484/* check if a VLAN entry is used by the bridge */
485static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
486{
487 return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
488}
489
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200490/* check if we should use the vlan entry, returns false if it's only context */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200491static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
492{
493 if (br_vlan_is_master(v)) {
494 if (br_vlan_is_brentry(v))
495 return true;
496 else
497 return false;
498 }
499
500 return true;
501}
502
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300503static inline int br_opt_get(const struct net_bridge *br,
504 enum net_bridge_opts opt)
505{
506 return test_bit(opt, &br->options);
507}
508
Nikolay Aleksandrova428afe2018-11-24 04:34:20 +0200509int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
510 struct netlink_ext_ack *extack);
511int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
512int br_boolopt_multi_toggle(struct net_bridge *br,
513 struct br_boolopt_multi *bm,
514 struct netlink_ext_ack *extack);
515void br_boolopt_multi_get(const struct net_bridge *br,
516 struct br_boolopt_multi *bm);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300517void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519/* br_device.c */
Joe Perches348662a2013-10-18 13:48:22 -0700520void br_dev_setup(struct net_device *dev);
521void br_dev_delete(struct net_device *dev, struct list_head *list);
522netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
stephen hemmingercfb478d2010-05-10 09:31:08 +0000523#ifdef CONFIG_NET_POLL_CONTROLLER
Herbert Xu91d2c342010-06-10 16:12:50 +0000524static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
525 struct sk_buff *skb)
526{
527 struct netpoll *np = p->np;
528
529 if (np)
530 netpoll_send_skb(np, skb);
531}
532
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700533int br_netpoll_enable(struct net_bridge_port *p);
Joe Perches348662a2013-10-18 13:48:22 -0700534void br_netpoll_disable(struct net_bridge_port *p);
Herbert Xu91d2c342010-06-10 16:12:50 +0000535#else
Herbert Xu9f70b0f2010-06-15 21:43:48 -0700536static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
Herbert Xu91d2c342010-06-10 16:12:50 +0000537 struct sk_buff *skb)
538{
539}
540
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700541static inline int br_netpoll_enable(struct net_bridge_port *p)
Herbert Xu91d2c342010-06-10 16:12:50 +0000542{
543 return 0;
544}
545
546static inline void br_netpoll_disable(struct net_bridge_port *p)
547{
548}
stephen hemmingercfb478d2010-05-10 09:31:08 +0000549#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551/* br_fdb.c */
Joe Perches348662a2013-10-18 13:48:22 -0700552int br_fdb_init(void);
553void br_fdb_fini(void);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200554int br_fdb_hash_init(struct net_bridge *br);
555void br_fdb_hash_fini(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700556void br_fdb_flush(struct net_bridge *br);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900557void br_fdb_find_delete_local(struct net_bridge *br,
558 const struct net_bridge_port *p,
559 const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700560void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
561void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100562void br_fdb_cleanup(struct work_struct *work);
Joe Perches348662a2013-10-18 13:48:22 -0700563void br_fdb_delete_by_port(struct net_bridge *br,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700564 const struct net_bridge_port *p, u16 vid, int do_all);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100565struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
566 const unsigned char *addr,
567 __u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700568int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
569int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
570 unsigned long off);
571int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
572 const unsigned char *addr, u16 vid);
573void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900574 const unsigned char *addr, u16 vid, bool added_by_user);
John Fastabend77162022012-04-15 06:43:56 +0000575
Joe Perches348662a2013-10-18 13:48:22 -0700576int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
Jiri Pirkof6f64242014-11-28 14:34:15 +0100577 struct net_device *dev, const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700578int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
Petr Machata87b09842019-01-16 23:06:50 +0000579 const unsigned char *addr, u16 vid, u16 nlh_flags,
580 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700581int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
Roopa Prabhud2976532016-08-30 21:56:45 -0700582 struct net_device *dev, struct net_device *fdev, int *idx);
Roopa Prabhu47674562018-12-15 22:35:09 -0800583int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
584 const unsigned char *addr, u16 vid, u32 portid, u32 seq,
585 struct netlink_ext_ack *extack);
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400586int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
587void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100588int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200589 const unsigned char *addr, u16 vid,
590 bool swdev_notify);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100591int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200592 const unsigned char *addr, u16 vid,
593 bool swdev_notify);
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200594void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
Ido Schimmele9ba0fb2018-10-17 08:53:29 +0000595 const unsigned char *addr, u16 vid, bool offloaded);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597/* br_forward.c */
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200598enum br_pkt_type {
599 BR_PKT_UNICAST,
600 BR_PKT_MULTICAST,
601 BR_PKT_BROADCAST
602};
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500603int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrovb35c5f62016-07-14 06:10:01 +0300604void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300605 bool local_rcv, bool local_orig);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500606int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300607void br_flood(struct net_bridge *br, struct sk_buff *skb,
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200608 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +0300610/* return true if both source port and dest port are isolated */
611static inline bool br_skb_isolated(const struct net_bridge_port *to,
612 const struct sk_buff *skb)
613{
614 return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
615 (to->flags & BR_ISOLATED);
616}
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618/* br_if.c */
Nikolay Aleksandrovfaa1cd82018-05-03 13:47:24 +0300619void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
Joe Perches348662a2013-10-18 13:48:22 -0700620int br_add_bridge(struct net *net, const char *name);
621int br_del_bridge(struct net *net, const char *name);
David Ahernca752be2017-10-04 17:48:50 -0700622int br_add_if(struct net_bridge *br, struct net_device *dev,
623 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700624int br_del_if(struct net_bridge *br, struct net_device *dev);
Nikolay Aleksandrov804b8542018-03-30 13:46:19 +0300625void br_mtu_auto_adjust(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700626netdev_features_t br_features_recompute(struct net_bridge *br,
627 netdev_features_t features);
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400628void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400629void br_manage_promisc(struct net_bridge *br);
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300630int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632/* br_input.c */
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500633int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Joe Perches348662a2013-10-18 13:48:22 -0700634rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Jiri Pirko859828c2013-12-05 16:27:37 +0100636static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
637{
638 return rcu_dereference(dev->rx_handler) == br_handle_frame;
639}
640
Petr Machata4d4fd362018-04-29 10:56:08 +0300641static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
642{
643 return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame;
644}
645
Jiri Pirko859828c2013-12-05 16:27:37 +0100646static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
647{
648 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
649}
650
Petr Machata4d4fd362018-04-29 10:56:08 +0300651static inline struct net_bridge_port *
652br_port_get_check_rtnl(const struct net_device *dev)
653{
654 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
655}
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657/* br_ioctl.c */
Joe Perches348662a2013-10-18 13:48:22 -0700658int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
659int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
660 void __user *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Herbert Xueb1d1642010-02-27 19:41:45 +0000662/* br_multicast.c */
663#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Joe Perches348662a2013-10-18 13:48:22 -0700664int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
David S. Miller394efd12013-11-04 13:48:30 -0500665 struct sk_buff *skb, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700666struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
667 struct sk_buff *skb, u16 vid);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200668int br_multicast_add_port(struct net_bridge_port *port);
Joe Perches348662a2013-10-18 13:48:22 -0700669void br_multicast_del_port(struct net_bridge_port *port);
670void br_multicast_enable_port(struct net_bridge_port *port);
671void br_multicast_disable_port(struct net_bridge_port *port);
672void br_multicast_init(struct net_bridge *br);
673void br_multicast_open(struct net_bridge *br);
674void br_multicast_stop(struct net_bridge *br);
Satish Ashoke10177a2015-07-15 07:16:51 -0700675void br_multicast_dev_del(struct net_bridge *br);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300676void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
677 struct sk_buff *skb, bool local_rcv, bool local_orig);
Joe Perches348662a2013-10-18 13:48:22 -0700678int br_multicast_set_router(struct net_bridge *br, unsigned long val);
679int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
680int br_multicast_toggle(struct net_bridge *br, unsigned long val);
681int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
682int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100683int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100684#if IS_ENABLED(CONFIG_IPV6)
685int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val);
686#endif
Joe Perches348662a2013-10-18 13:48:22 -0700687struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200688br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
Joe Perches348662a2013-10-18 13:48:22 -0700689struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200690br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
Joe Perches348662a2013-10-18 13:48:22 -0700691struct net_bridge_port_group *
692br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
693 struct net_bridge_port_group __rcu *next,
Felix Fietkau6db6f0e2017-01-21 21:01:32 +0100694 unsigned char flags, const unsigned char *src);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200695int br_mdb_hash_init(struct net_bridge *br);
696void br_mdb_hash_fini(struct net_bridge *br);
Elad Raz45ebcce2016-04-21 12:52:45 +0200697void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
698 struct br_ip *group, int type, u8 flags);
Satish Ashok949f1e32015-07-23 05:00:53 -0700699void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
700 int type);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200701void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700702 const struct sk_buff *skb, u8 type, u8 dir);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200703int br_multicast_init_stats(struct net_bridge *br);
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300704void br_multicast_uninit_stats(struct net_bridge *br);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200705void br_multicast_get_stats(const struct net_bridge *br,
706 const struct net_bridge_port *p,
707 struct br_mcast_stats *dest);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200708void br_mdb_init(void);
709void br_mdb_uninit(void);
Nikolay Aleksandrov1bc844e2019-08-17 14:22:13 +0300710void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify);
711void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000712
Cong Wangcfd56752012-12-11 22:23:08 +0000713#define mlock_dereference(X, br) \
714 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
715
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000716static inline bool br_multicast_is_router(struct net_bridge *br)
717{
718 return br->multicast_router == 2 ||
719 (br->multicast_router == 1 &&
720 timer_pending(&br->multicast_router_timer));
721}
Linus Lüssingb00589a2013-08-01 01:06:20 +0200722
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200723static inline bool
724__br_multicast_querier_exists(struct net_bridge *br,
daniel0888d5f2016-06-24 12:35:18 +0200725 struct bridge_mcast_other_query *querier,
726 const bool is_ipv6)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200727{
daniel0888d5f2016-06-24 12:35:18 +0200728 bool own_querier_enabled;
729
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300730 if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
731 if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR))
daniel0888d5f2016-06-24 12:35:18 +0200732 own_querier_enabled = false;
733 else
734 own_querier_enabled = true;
735 } else {
736 own_querier_enabled = false;
737 }
738
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200739 return time_is_before_jiffies(querier->delay_time) &&
daniel0888d5f2016-06-24 12:35:18 +0200740 (own_querier_enabled || timer_pending(&querier->timer));
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200741}
742
743static inline bool br_multicast_querier_exists(struct net_bridge *br,
744 struct ethhdr *eth)
745{
746 switch (eth->h_proto) {
747 case (htons(ETH_P_IP)):
daniel0888d5f2016-06-24 12:35:18 +0200748 return __br_multicast_querier_exists(br,
749 &br->ip4_other_query, false);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200750#if IS_ENABLED(CONFIG_IPV6)
751 case (htons(ETH_P_IPV6)):
daniel0888d5f2016-06-24 12:35:18 +0200752 return __br_multicast_querier_exists(br,
753 &br->ip6_other_query, true);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200754#endif
755 default:
756 return false;
757 }
Linus Lüssingb00589a2013-08-01 01:06:20 +0200758}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200759
760static inline int br_multicast_igmp_type(const struct sk_buff *skb)
761{
762 return BR_INPUT_SKB_CB(skb)->igmp;
763}
Herbert Xueb1d1642010-02-27 19:41:45 +0000764#else
765static inline int br_multicast_rcv(struct net_bridge *br,
766 struct net_bridge_port *port,
Vlad Yasevich06499092013-10-28 15:45:07 -0400767 struct sk_buff *skb,
768 u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000769{
770 return 0;
771}
772
773static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
Cong Wangfbca58a2013-03-07 03:05:33 +0000774 struct sk_buff *skb, u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000775{
776 return NULL;
777}
778
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200779static inline int br_multicast_add_port(struct net_bridge_port *port)
Herbert Xueb1d1642010-02-27 19:41:45 +0000780{
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200781 return 0;
Herbert Xueb1d1642010-02-27 19:41:45 +0000782}
783
784static inline void br_multicast_del_port(struct net_bridge_port *port)
785{
786}
787
788static inline void br_multicast_enable_port(struct net_bridge_port *port)
789{
790}
791
792static inline void br_multicast_disable_port(struct net_bridge_port *port)
793{
794}
795
796static inline void br_multicast_init(struct net_bridge *br)
797{
798}
799
800static inline void br_multicast_open(struct net_bridge *br)
801{
802}
803
804static inline void br_multicast_stop(struct net_bridge *br)
805{
806}
Herbert Xu5cb5e942010-02-27 19:41:46 +0000807
Nikolay Aleksandrova7ce45a2015-07-20 23:03:45 +0200808static inline void br_multicast_dev_del(struct net_bridge *br)
809{
810}
811
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300812static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
813 struct sk_buff *skb,
814 bool local_rcv, bool local_orig)
Herbert Xu5cb5e942010-02-27 19:41:46 +0000815{
816}
817
Herbert Xueb1d1642010-02-27 19:41:45 +0000818static inline bool br_multicast_is_router(struct net_bridge *br)
819{
Gustavo A. R. Silva03aaa9e2018-01-18 17:37:45 -0600820 return false;
Herbert Xueb1d1642010-02-27 19:41:45 +0000821}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300822
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200823static inline bool br_multicast_querier_exists(struct net_bridge *br,
824 struct ethhdr *eth)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200825{
826 return false;
827}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300828
Rami Rosenfdb184d2013-01-03 13:30:43 +0200829static inline void br_mdb_init(void)
830{
831}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300832
Rami Rosenfdb184d2013-01-03 13:30:43 +0200833static inline void br_mdb_uninit(void)
834{
835}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200836
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200837static inline int br_mdb_hash_init(struct net_bridge *br)
838{
839 return 0;
840}
841
842static inline void br_mdb_hash_fini(struct net_bridge *br)
843{
844}
845
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200846static inline void br_multicast_count(struct net_bridge *br,
847 const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700848 const struct sk_buff *skb,
849 u8 type, u8 dir)
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200850{
851}
852
853static inline int br_multicast_init_stats(struct net_bridge *br)
854{
855 return 0;
856}
857
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300858static inline void br_multicast_uninit_stats(struct net_bridge *br)
859{
860}
861
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200862static inline int br_multicast_igmp_type(const struct sk_buff *skb)
863{
864 return 0;
865}
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000866#endif
Herbert Xueb1d1642010-02-27 19:41:45 +0000867
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000868/* br_vlan.c */
869#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200870bool br_allowed_ingress(const struct net_bridge *br,
871 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
872 u16 *vid);
873bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700874 const struct sk_buff *skb);
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900875bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
Joe Perches348662a2013-10-18 13:48:22 -0700876struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800877 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200878 struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700879 struct sk_buff *skb);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300880int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +0000881 bool *changed, struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700882int br_vlan_delete(struct net_bridge *br, u16 vid);
883void br_vlan_flush(struct net_bridge *br);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200884struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900885void br_recalculate_fwd_mask(struct net_bridge *br);
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300886int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Joe Perches348662a2013-10-18 13:48:22 -0700887int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900888int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900889int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200890int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300891int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400892int br_vlan_init(struct net_bridge *br);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400893int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
Petr Machata169327d2018-12-12 17:02:50 +0000894int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
895 struct netlink_ext_ack *extack);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300896int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +0000897 bool *changed, struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700898int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
899void nbp_vlan_flush(struct net_bridge_port *port);
Petr Machata169327d2018-12-12 17:02:50 +0000900int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200901int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +0200902void br_vlan_get_stats(const struct net_bridge_vlan *v,
903 struct br_vlan_stats *stats);
Mike Manning9c0ec2e2019-04-18 18:35:33 +0100904void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
Nikolay Aleksandrov091adf92019-08-02 13:57:36 +0300905int br_vlan_bridge_event(struct net_device *dev, unsigned long event,
906 void *ptr);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000907
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200908static inline struct net_bridge_vlan_group *br_vlan_group(
909 const struct net_bridge *br)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000910{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200911 return rtnl_dereference(br->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000912}
913
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200914static inline struct net_bridge_vlan_group *nbp_vlan_group(
915 const struct net_bridge_port *p)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000916{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200917 return rtnl_dereference(p->vlgrp);
918}
919
920static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
921 const struct net_bridge *br)
922{
923 return rcu_dereference(br->vlgrp);
924}
925
926static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
927 const struct net_bridge_port *p)
928{
929 return rcu_dereference(p->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000930}
931
932/* Since bridge now depends on 8021Q module, but the time bridge sees the
933 * skb, the vlan tag will always be present if the frame was tagged.
934 */
935static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
936{
937 int err = 0;
938
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200939 if (skb_vlan_tag_present(skb)) {
Michał Mirosław5978f8a2018-11-09 00:18:03 +0100940 *vid = skb_vlan_tag_get_id(skb);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200941 } else {
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000942 *vid = 0;
943 err = -EINVAL;
944 }
945
946 return err;
947}
Vlad Yasevich78851982013-02-13 12:00:14 +0000948
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200949static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +0000950{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200951 if (!vg)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400952 return 0;
953
Vlad Yasevich78851982013-02-13 12:00:14 +0000954 smp_rmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200955 return vg->pvid;
Vlad Yasevich78851982013-02-13 12:00:14 +0000956}
957
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000958#else
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200959static inline bool br_allowed_ingress(const struct net_bridge *br,
960 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000961 struct sk_buff *skb,
962 u16 *vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000963{
964 return true;
965}
966
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200967static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000968 const struct sk_buff *skb)
969{
970 return true;
971}
972
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900973static inline bool br_should_learn(struct net_bridge_port *p,
974 struct sk_buff *skb, u16 *vid)
975{
976 return true;
977}
978
Vlad Yasevich78851982013-02-13 12:00:14 +0000979static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800980 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200981 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000982 struct sk_buff *skb)
983{
984 return skb;
985}
986
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300987static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +0000988 bool *changed, struct netlink_ext_ack *extack)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000989{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300990 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000991 return -EOPNOTSUPP;
992}
993
994static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
995{
996 return -EOPNOTSUPP;
997}
998
999static inline void br_vlan_flush(struct net_bridge *br)
1000{
1001}
1002
Toshiaki Makita204177f2014-06-10 20:59:25 +09001003static inline void br_recalculate_fwd_mask(struct net_bridge *br)
1004{
1005}
1006
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001007static inline int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +09001008{
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001009 return 0;
Toshiaki Makita8580e212014-06-10 20:59:23 +09001010}
1011
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001012static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +00001013 bool *changed, struct netlink_ext_ack *extack)
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001014{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001015 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001016 return -EOPNOTSUPP;
1017}
1018
1019static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1020{
1021 return -EOPNOTSUPP;
1022}
1023
1024static inline void nbp_vlan_flush(struct net_bridge_port *port)
1025{
1026}
1027
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001028static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1029 u16 vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001030{
1031 return NULL;
1032}
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +00001033
Petr Machata169327d2018-12-12 17:02:50 +00001034static inline int nbp_vlan_init(struct net_bridge_port *port,
1035 struct netlink_ext_ack *extack)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001036{
1037 return 0;
1038}
1039
Vlad Yasevich78851982013-02-13 12:00:14 +00001040static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001041{
1042 return 0;
1043}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001044
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001045static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +00001046{
Vlad Yasevich3df6bf42014-10-03 11:29:17 -04001047 return 0;
Vlad Yasevich78851982013-02-13 12:00:14 +00001048}
Vlad Yasevich2796d0c2014-05-16 09:59:20 -04001049
Nikolay Aleksandrova7854032015-08-07 19:40:45 +03001050static inline int __br_vlan_filter_toggle(struct net_bridge *br,
1051 unsigned long val)
1052{
1053 return -EOPNOTSUPP;
1054}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001055
1056static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1057 u32 filter_mask)
1058{
1059 return 0;
1060}
1061
1062static inline struct net_bridge_vlan_group *br_vlan_group(
1063 const struct net_bridge *br)
1064{
1065 return NULL;
1066}
1067
1068static inline struct net_bridge_vlan_group *nbp_vlan_group(
1069 const struct net_bridge_port *p)
1070{
1071 return NULL;
1072}
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001073
1074static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1075 const struct net_bridge *br)
1076{
1077 return NULL;
1078}
1079
1080static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1081 const struct net_bridge_port *p)
1082{
1083 return NULL;
1084}
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001085
1086static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1087 struct br_vlan_stats *stats)
1088{
1089}
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001090
1091static inline void br_vlan_port_event(struct net_bridge_port *p,
1092 unsigned long event)
1093{
1094}
1095
Nikolay Aleksandrov091adf92019-08-02 13:57:36 +03001096static inline int br_vlan_bridge_event(struct net_device *dev,
1097 unsigned long event, void *ptr)
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001098{
Nikolay Aleksandrov091adf92019-08-02 13:57:36 +03001099 return 0;
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001100}
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001101#endif
1102
Pablo Neira Ayuso1a4ba642015-03-10 10:27:18 +01001103struct nf_br_ops {
1104 int (*br_dev_xmit_hook)(struct sk_buff *skb);
1105};
1106extern const struct nf_br_ops __rcu *nf_br_ops;
1107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108/* br_netfilter.c */
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001109#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1110int br_nf_core_init(void);
1111void br_nf_core_fini(void);
Joe Perches348662a2013-10-18 13:48:22 -07001112void br_netfilter_rtable_init(struct net_bridge *);
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001113#else
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001114static inline int br_nf_core_init(void) { return 0; }
1115static inline void br_nf_core_fini(void) {}
Simon Wunderlich4adf0af2008-07-30 16:27:55 -07001116#define br_netfilter_rtable_init(x)
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001117#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119/* br_stp.c */
Florian Fainelli775dd692014-09-30 16:13:19 -07001120void br_set_state(struct net_bridge_port *p, unsigned int state);
Joe Perches348662a2013-10-18 13:48:22 -07001121struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1122void br_init_port(struct net_bridge_port *p);
1123void br_become_designated_port(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Joe Perches348662a2013-10-18 13:48:22 -07001125void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1126int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1127int br_set_hello_time(struct net_bridge *br, unsigned long x);
1128int br_set_max_age(struct net_bridge *br, unsigned long x);
Vivien Didelot82dd4332016-12-10 13:44:27 -05001129int __set_ageing_time(struct net_device *dev, unsigned long t);
Vivien Didelot9e0b27f2016-07-21 12:42:19 -04001130int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
stephen hemminger14f98f22011-04-04 14:03:33 +00001131
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133/* br_stp_if.c */
Joe Perches348662a2013-10-18 13:48:22 -07001134void br_stp_enable_bridge(struct net_bridge *br);
1135void br_stp_disable_bridge(struct net_bridge *br);
1136void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
1137void br_stp_enable_port(struct net_bridge_port *p);
1138void br_stp_disable_port(struct net_bridge_port *p);
1139bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1140void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1141void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1142int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1143int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1144ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146/* br_stp_bpdu.c */
Patrick McHardy7c85fbf2008-07-05 21:25:56 -07001147struct stp_proto;
Joe Perches348662a2013-10-18 13:48:22 -07001148void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1149 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151/* br_stp_timer.c */
Joe Perches348662a2013-10-18 13:48:22 -07001152void br_stp_timer_init(struct net_bridge *br);
1153void br_stp_port_timer_init(struct net_bridge_port *p);
1154unsigned long br_timer_value(const struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156/* br.c */
Igor Maraviće6373c42011-12-12 02:58:25 +00001157#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +00001158extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1159#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001161/* br_netlink.c */
stephen hemminger149ddd82012-06-26 05:48:45 +00001162extern struct rtnl_link_ops br_link_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001163int br_netlink_init(void);
1164void br_netlink_fini(void);
Nikolay Aleksandrov92899062017-11-01 12:18:13 +02001165void br_ifinfo_notify(int event, const struct net_bridge *br,
1166 const struct net_bridge_port *port);
Petr Machata2fd527b2018-12-12 17:02:48 +00001167int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1168 struct netlink_ext_ack *extack);
Roopa Prabhuadd511b2015-01-29 22:40:12 -08001169int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
Joe Perches348662a2013-10-18 13:48:22 -07001170int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02001171 u32 filter_mask, int nlflags);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173#ifdef CONFIG_SYSFS
1174/* br_sysfs_if.c */
Emese Revfy52cf25d2010-01-19 02:58:23 +01001175extern const struct sysfs_ops brport_sysfs_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001176int br_sysfs_addif(struct net_bridge_port *p);
1177int br_sysfs_renameif(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
1179/* br_sysfs_br.c */
Joe Perches348662a2013-10-18 13:48:22 -07001180int br_sysfs_addbr(struct net_device *dev);
1181void br_sysfs_delbr(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183#else
1184
Lee Jones0cb2bbb2012-11-03 23:02:30 +01001185static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1186static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1187static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1188static inline void br_sysfs_delbr(struct net_device *dev) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189#endif /* CONFIG_SYSFS */
1190
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001191/* br_switchdev.c */
1192#ifdef CONFIG_NET_SWITCHDEV
1193int nbp_switchdev_mark_set(struct net_bridge_port *p);
1194void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1195 struct sk_buff *skb);
1196bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1197 const struct sk_buff *skb);
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001198int br_switchdev_set_port_flag(struct net_bridge_port *p,
1199 unsigned long flags,
1200 unsigned long mask);
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001201void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
1202 int type);
Petr Machata169327d2018-12-12 17:02:50 +00001203int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1204 struct netlink_ext_ack *extack);
Petr Machatad66e4342018-05-30 02:56:03 +02001205int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001206
1207static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1208{
1209 skb->offload_fwd_mark = 0;
1210}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001211#else
1212static inline int nbp_switchdev_mark_set(struct net_bridge_port *p)
1213{
1214 return 0;
1215}
1216
1217static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1218 struct sk_buff *skb)
1219{
1220}
1221
1222static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1223 const struct sk_buff *skb)
1224{
1225 return true;
1226}
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001227
1228static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
1229 unsigned long flags,
1230 unsigned long mask)
1231{
1232 return 0;
1233}
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001234
Petr Machatad66e4342018-05-30 02:56:03 +02001235static inline int br_switchdev_port_vlan_add(struct net_device *dev,
Petr Machata169327d2018-12-12 17:02:50 +00001236 u16 vid, u16 flags,
1237 struct netlink_ext_ack *extack)
Petr Machatad66e4342018-05-30 02:56:03 +02001238{
1239 return -EOPNOTSUPP;
1240}
1241
1242static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
1243{
1244 return -EOPNOTSUPP;
1245}
1246
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001247static inline void
1248br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
1249{
1250}
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001251
1252static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1253{
1254}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001255#endif /* CONFIG_NET_SWITCHDEV */
1256
Roopa Prabhu057658c2017-10-06 22:12:38 -07001257/* br_arp_nd_proxy.c */
Roopa Prabhu821f1b22017-10-06 22:12:37 -07001258void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
Roopa Prabhu057658c2017-10-06 22:12:38 -07001259void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
1260 u16 vid, struct net_bridge_port *p);
Roopa Prabhued842fa2017-10-06 22:12:39 -07001261void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
1262 u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
1263struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264#endif