blob: 159a0e2cb0f63fd7c645feb4c66ce169ef094fe2 [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 Aleksandroveb793582017-12-12 16:02:50 +0200175struct net_bridge_fdb_key {
176 mac_addr addr;
177 u16 vlan_id;
178};
179
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100180struct net_bridge_fdb_entry {
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200181 struct rhash_head rhnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 struct net_bridge_port *dst;
183
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200184 struct net_bridge_fdb_key key;
185 struct hlist_node fdb_node;
Jiri Pirko93859b12014-11-28 14:34:14 +0100186 unsigned char is_local:1,
187 is_static:1,
Nikolay Aleksandrov435f2e72018-09-11 09:39:53 +0300188 is_sticky:1,
Scott Feldmancf6b8e12014-11-28 14:34:21 +0100189 added_by_user:1,
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200190 added_by_external_learn:1,
191 offloaded:1;
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100192
193 /* write-heavy members should not affect lookups */
194 unsigned long updated ____cacheline_aligned_in_smp;
195 unsigned long used;
196
Nikolay Aleksandrovb22fbf22015-08-27 14:19:20 -0700197 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198};
199
Elad Raz9d06b6d2016-02-03 09:57:05 +0100200#define MDB_PG_FLAGS_PERMANENT BIT(0)
201#define MDB_PG_FLAGS_OFFLOAD BIT(1)
202
Herbert Xueb1d1642010-02-27 19:41:45 +0000203struct net_bridge_port_group {
204 struct net_bridge_port *port;
Eric Dumazete8051682010-11-15 06:38:10 +0000205 struct net_bridge_port_group __rcu *next;
Herbert Xueb1d1642010-02-27 19:41:45 +0000206 struct hlist_node mglist;
207 struct rcu_head rcu;
208 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900209 struct br_ip addr;
Elad Raz9d06b6d2016-02-03 09:57:05 +0100210 unsigned char flags;
Felix Fietkau6db6f0e2017-01-21 21:01:32 +0100211 unsigned char eth_addr[ETH_ALEN];
Herbert Xueb1d1642010-02-27 19:41:45 +0000212};
213
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +0300214struct net_bridge_mdb_entry {
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200215 struct rhash_head rhnode;
Herbert Xueb1d1642010-02-27 19:41:45 +0000216 struct net_bridge *br;
Eric Dumazete8051682010-11-15 06:38:10 +0000217 struct net_bridge_port_group __rcu *ports;
Herbert Xueb1d1642010-02-27 19:41:45 +0000218 struct rcu_head rcu;
219 struct timer_list timer;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900220 struct br_ip addr;
Andrew Lunnff0fd342017-11-09 23:10:57 +0100221 bool host_joined;
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200222 struct hlist_node mdb_node;
Herbert Xueb1d1642010-02-27 19:41:45 +0000223};
224
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100225struct net_bridge_port {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 struct net_bridge *br;
227 struct net_device *dev;
228 struct list_head list;
229
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100230 unsigned long flags;
231#ifdef CONFIG_BRIDGE_VLAN_FILTERING
232 struct net_bridge_vlan_group __rcu *vlgrp;
233#endif
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300234 struct net_bridge_port __rcu *backup_port;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 /* STP */
237 u8 priority;
238 u8 state;
239 u16 port_no;
240 unsigned char topology_change_ack;
241 unsigned char config_pending;
242 port_id port_id;
243 port_id designated_port;
244 bridge_id designated_root;
245 bridge_id designated_bridge;
246 u32 path_cost;
247 u32 designated_cost;
stephen hemminger0c031502011-07-22 07:47:06 +0000248 unsigned long designated_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 struct timer_list forward_delay_timer;
251 struct timer_list hold_timer;
252 struct timer_list message_age_timer;
253 struct kobject kobj;
254 struct rcu_head rcu;
Fischer, Anna3982d3d2009-08-13 06:55:16 +0000255
Herbert Xueb1d1642010-02-27 19:41:45 +0000256#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Linus Lüssing90010b32014-06-07 18:26:26 +0200257 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200258#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200259 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200260#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000261 unsigned char multicast_router;
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200262 struct bridge_mcast_stats __percpu *mcast_stats;
Herbert Xueb1d1642010-02-27 19:41:45 +0000263 struct timer_list multicast_router_timer;
Herbert Xueb1d1642010-02-27 19:41:45 +0000264 struct hlist_head mglist;
265 struct hlist_node rlist;
266#endif
Simon Arlotte0f43752010-05-10 09:31:11 +0000267
268#ifdef CONFIG_SYSFS
269 char sysfs_name[IFNAMSIZ];
270#endif
Herbert Xu91d2c342010-06-10 16:12:50 +0000271
272#ifdef CONFIG_NET_POLL_CONTROLLER
273 struct netpoll *np;
274#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200275#ifdef CONFIG_NET_SWITCHDEV
276 int offload_fwd_mark;
277#endif
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +0300278 u16 group_fwd_mask;
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300279 u16 backup_redirected_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280};
281
Tyler Hicks705e0de2018-07-20 21:56:54 +0000282#define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
283
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400284#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
Vlad Yasevichf3a6ddf2014-05-16 09:59:18 -0400285#define br_promisc_port(p) ((p)->flags & BR_PROMISC)
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400286
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000287static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
288{
Hong Zhiguo716ec052013-09-14 22:42:28 +0800289 return rcu_dereference(dev->rx_handler_data);
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000290}
291
Hong Zhiguo1fb17542013-09-14 22:42:27 +0800292static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000293{
Julian Wiedmann35f861e2019-03-29 14:38:19 +0100294 return netif_is_bridge_port(dev) ?
Eric Dumazetec1e5612010-11-15 06:38:14 +0000295 rtnl_dereference(dev->rx_handler_data) : NULL;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000296}
297
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200298static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
299{
Julian Wiedmann35f861e2019-03-29 14:38:19 +0100300 return netif_is_bridge_port(dev) ?
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200301 rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
302}
303
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300304enum net_bridge_opts {
305 BROPT_VLAN_ENABLED,
306 BROPT_VLAN_STATS_ENABLED,
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300307 BROPT_NF_CALL_IPTABLES,
308 BROPT_NF_CALL_IP6TABLES,
309 BROPT_NF_CALL_ARPTABLES,
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300310 BROPT_GROUP_ADDR_SET,
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300311 BROPT_MULTICAST_ENABLED,
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300312 BROPT_MULTICAST_QUERIER,
313 BROPT_MULTICAST_QUERY_USE_IFADDR,
314 BROPT_MULTICAST_STATS_ENABLED,
315 BROPT_HAS_IPV6_ADDR,
Nikolay Aleksandrovc69c2cd2018-09-26 17:01:05 +0300316 BROPT_NEIGH_SUPPRESS_ENABLED,
Nikolay Aleksandrov3341d912018-09-26 17:01:06 +0300317 BROPT_MTU_SET_BY_USER,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300318 BROPT_VLAN_STATS_PER_PORT,
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200319 BROPT_NO_LL_LEARN,
Mike Manning9c0ec2e2019-04-18 18:35:33 +0100320 BROPT_VLAN_BRIDGE_BINDING,
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300321};
322
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100323struct net_bridge {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 spinlock_t lock;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100325 spinlock_t hash_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 struct list_head port_list;
327 struct net_device *dev;
Li RongQing8f849852014-01-04 13:57:59 +0800328 struct pcpu_sw_netstats __percpu *stats;
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300329 unsigned long options;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100330 /* These fields are accessed on each packet */
331#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100332 __be16 vlan_proto;
333 u16 default_pvid;
334 struct net_bridge_vlan_group __rcu *vlgrp;
335#endif
336
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200337 struct rhashtable fdb_hash_tbl;
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200338#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Bernhard Thalerefb6de92015-05-30 15:30:16 +0200339 union {
340 struct rtable fake_rtable;
341 struct rt6_info fake_rt6_info;
342 };
Simon Wunderlich4adf0af2008-07-30 16:27:55 -0700343#endif
stephen hemminger515853c2011-10-03 18:14:46 +0000344 u16 group_fwd_mask;
Toshiaki Makitaf2808d22014-06-10 20:59:24 +0900345 u16 group_fwd_mask_required;
stephen hemminger515853c2011-10-03 18:14:46 +0000346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* STP */
348 bridge_id designated_root;
349 bridge_id bridge_id;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100350 unsigned char topology_change;
351 unsigned char topology_change_detected;
352 u16 root_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 unsigned long max_age;
354 unsigned long hello_time;
355 unsigned long forward_delay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 unsigned long ageing_time;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500357 unsigned long bridge_max_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 unsigned long bridge_hello_time;
359 unsigned long bridge_forward_delay;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500360 unsigned long bridge_ageing_time;
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300361 u32 root_path_cost;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800363 u8 group_addr[ETH_ALEN];
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700364
365 enum {
366 BR_NO_STP, /* no spanning tree */
367 BR_KERNEL_STP, /* old STP in kernel */
368 BR_USER_STP, /* new RSTP in userspace */
369 } stp_enabled;
370
Herbert Xueb1d1642010-02-27 19:41:45 +0000371#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Herbert Xueb1d1642010-02-27 19:41:45 +0000372
Herbert Xueb1d1642010-02-27 19:41:45 +0000373 u32 hash_max;
374
375 u32 multicast_last_member_count;
Herbert Xueb1d1642010-02-27 19:41:45 +0000376 u32 multicast_startup_query_count;
377
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100378 u8 multicast_igmp_version;
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300379 u8 multicast_router;
380#if IS_ENABLED(CONFIG_IPV6)
381 u8 multicast_mld_version;
382#endif
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300383 spinlock_t multicast_lock;
Herbert Xueb1d1642010-02-27 19:41:45 +0000384 unsigned long multicast_last_member_interval;
385 unsigned long multicast_membership_interval;
386 unsigned long multicast_querier_interval;
387 unsigned long multicast_query_interval;
388 unsigned long multicast_query_response_interval;
389 unsigned long multicast_startup_query_interval;
390
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200391 struct rhashtable mdb_hash_tbl;
392
393 struct hlist_head mdb_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000394 struct hlist_head router_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000395
396 struct timer_list multicast_router_timer;
Linus Lüssing90010b32014-06-07 18:26:26 +0200397 struct bridge_mcast_other_query ip4_other_query;
398 struct bridge_mcast_own_query ip4_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200399 struct bridge_mcast_querier ip4_querier;
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200400 struct bridge_mcast_stats __percpu *mcast_stats;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200401#if IS_ENABLED(CONFIG_IPV6)
Linus Lüssing90010b32014-06-07 18:26:26 +0200402 struct bridge_mcast_other_query ip6_other_query;
403 struct bridge_mcast_own_query ip6_own_query;
Linus Lüssingdc4eb532014-06-07 18:26:27 +0200404 struct bridge_mcast_querier ip6_querier;
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200405#endif /* IS_ENABLED(CONFIG_IPV6) */
Herbert Xueb1d1642010-02-27 19:41:45 +0000406#endif
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 struct timer_list hello_timer;
409 struct timer_list tcn_timer;
410 struct timer_list topology_change_timer;
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100411 struct delayed_work gc_work;
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400412 struct kobject *ifobj;
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400413 u32 auto_cnt;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200414
415#ifdef CONFIG_NET_SWITCHDEV
416 int offload_fwd_mark;
417#endif
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200418 struct hlist_head fdb_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419};
420
Herbert Xu68b7c892010-02-27 19:41:40 +0000421struct br_input_skb_cb {
422 struct net_device *brdev;
Herbert Xu93fdd472014-10-05 12:00:22 +0800423
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000424#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Florian Westphalf12064d2019-04-11 16:36:40 +0200425 u8 igmp;
426 u8 mrouters_only:1;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000427#endif
Florian Westphalf12064d2019-04-11 16:36:40 +0200428 u8 proxyarp_replied:1;
429 u8 src_port_isolated:1;
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400430#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Florian Westphalf12064d2019-04-11 16:36:40 +0200431 u8 vlan_filtered:1;
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400432#endif
Florian Westphal223fd0a2019-04-11 16:36:42 +0200433#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
434 u8 br_netfilter_broute:1;
435#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200436
437#ifdef CONFIG_NET_SWITCHDEV
438 int offload_fwd_mark;
439#endif
Herbert Xu68b7c892010-02-27 19:41:40 +0000440};
441
442#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
443
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000444#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
445# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
446#else
447# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
448#endif
449
stephen hemminger28a16c92010-05-10 09:31:09 +0000450#define br_printk(level, br, format, args...) \
451 printk(level "%s: " format, (br)->dev->name, ##args)
452
453#define br_err(__br, format, args...) \
454 br_printk(KERN_ERR, __br, format, ##args)
455#define br_warn(__br, format, args...) \
456 br_printk(KERN_WARNING, __br, format, ##args)
457#define br_notice(__br, format, args...) \
458 br_printk(KERN_NOTICE, __br, format, ##args)
459#define br_info(__br, format, args...) \
460 br_printk(KERN_INFO, __br, format, ##args)
461
462#define br_debug(br, format, args...) \
463 pr_debug("%s: " format, (br)->dev->name, ##args)
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/* called under bridge lock */
466static inline int br_is_root_bridge(const struct net_bridge *br)
467{
468 return !memcmp(&br->bridge_id, &br->designated_root, 8);
469}
470
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200471/* check if a VLAN entry is global */
472static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
473{
474 return v->flags & BRIDGE_VLAN_INFO_MASTER;
475}
476
477/* check if a VLAN entry is used by the bridge */
478static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
479{
480 return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
481}
482
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200483/* check if we should use the vlan entry, returns false if it's only context */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200484static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
485{
486 if (br_vlan_is_master(v)) {
487 if (br_vlan_is_brentry(v))
488 return true;
489 else
490 return false;
491 }
492
493 return true;
494}
495
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300496static inline int br_opt_get(const struct net_bridge *br,
497 enum net_bridge_opts opt)
498{
499 return test_bit(opt, &br->options);
500}
501
Nikolay Aleksandrova428afe2018-11-24 04:34:20 +0200502int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
503 struct netlink_ext_ack *extack);
504int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
505int br_boolopt_multi_toggle(struct net_bridge *br,
506 struct br_boolopt_multi *bm,
507 struct netlink_ext_ack *extack);
508void br_boolopt_multi_get(const struct net_bridge *br,
509 struct br_boolopt_multi *bm);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300510void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512/* br_device.c */
Joe Perches348662a2013-10-18 13:48:22 -0700513void br_dev_setup(struct net_device *dev);
514void br_dev_delete(struct net_device *dev, struct list_head *list);
515netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
stephen hemmingercfb478d2010-05-10 09:31:08 +0000516#ifdef CONFIG_NET_POLL_CONTROLLER
Herbert Xu91d2c342010-06-10 16:12:50 +0000517static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
518 struct sk_buff *skb)
519{
520 struct netpoll *np = p->np;
521
522 if (np)
523 netpoll_send_skb(np, skb);
524}
525
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700526int br_netpoll_enable(struct net_bridge_port *p);
Joe Perches348662a2013-10-18 13:48:22 -0700527void br_netpoll_disable(struct net_bridge_port *p);
Herbert Xu91d2c342010-06-10 16:12:50 +0000528#else
Herbert Xu9f70b0f2010-06-15 21:43:48 -0700529static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
Herbert Xu91d2c342010-06-10 16:12:50 +0000530 struct sk_buff *skb)
531{
532}
533
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700534static inline int br_netpoll_enable(struct net_bridge_port *p)
Herbert Xu91d2c342010-06-10 16:12:50 +0000535{
536 return 0;
537}
538
539static inline void br_netpoll_disable(struct net_bridge_port *p)
540{
541}
stephen hemmingercfb478d2010-05-10 09:31:08 +0000542#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544/* br_fdb.c */
Joe Perches348662a2013-10-18 13:48:22 -0700545int br_fdb_init(void);
546void br_fdb_fini(void);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200547int br_fdb_hash_init(struct net_bridge *br);
548void br_fdb_hash_fini(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700549void br_fdb_flush(struct net_bridge *br);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900550void br_fdb_find_delete_local(struct net_bridge *br,
551 const struct net_bridge_port *p,
552 const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700553void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
554void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100555void br_fdb_cleanup(struct work_struct *work);
Joe Perches348662a2013-10-18 13:48:22 -0700556void br_fdb_delete_by_port(struct net_bridge *br,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700557 const struct net_bridge_port *p, u16 vid, int do_all);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100558struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
559 const unsigned char *addr,
560 __u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700561int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
562int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
563 unsigned long off);
564int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
565 const unsigned char *addr, u16 vid);
566void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900567 const unsigned char *addr, u16 vid, bool added_by_user);
John Fastabend77162022012-04-15 06:43:56 +0000568
Joe Perches348662a2013-10-18 13:48:22 -0700569int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
Jiri Pirkof6f64242014-11-28 14:34:15 +0100570 struct net_device *dev, const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700571int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
Petr Machata87b09842019-01-16 23:06:50 +0000572 const unsigned char *addr, u16 vid, u16 nlh_flags,
573 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700574int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
Roopa Prabhud2976532016-08-30 21:56:45 -0700575 struct net_device *dev, struct net_device *fdev, int *idx);
Roopa Prabhu47674562018-12-15 22:35:09 -0800576int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
577 const unsigned char *addr, u16 vid, u32 portid, u32 seq,
578 struct netlink_ext_ack *extack);
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400579int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
580void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100581int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200582 const unsigned char *addr, u16 vid,
583 bool swdev_notify);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100584int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200585 const unsigned char *addr, u16 vid,
586 bool swdev_notify);
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200587void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
Ido Schimmele9ba0fb2018-10-17 08:53:29 +0000588 const unsigned char *addr, u16 vid, bool offloaded);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590/* br_forward.c */
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200591enum br_pkt_type {
592 BR_PKT_UNICAST,
593 BR_PKT_MULTICAST,
594 BR_PKT_BROADCAST
595};
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500596int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrovb35c5f62016-07-14 06:10:01 +0300597void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300598 bool local_rcv, bool local_orig);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500599int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300600void br_flood(struct net_bridge *br, struct sk_buff *skb,
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200601 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +0300603/* return true if both source port and dest port are isolated */
604static inline bool br_skb_isolated(const struct net_bridge_port *to,
605 const struct sk_buff *skb)
606{
607 return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
608 (to->flags & BR_ISOLATED);
609}
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611/* br_if.c */
Nikolay Aleksandrovfaa1cd82018-05-03 13:47:24 +0300612void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
Joe Perches348662a2013-10-18 13:48:22 -0700613int br_add_bridge(struct net *net, const char *name);
614int br_del_bridge(struct net *net, const char *name);
David Ahernca752be2017-10-04 17:48:50 -0700615int br_add_if(struct net_bridge *br, struct net_device *dev,
616 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700617int br_del_if(struct net_bridge *br, struct net_device *dev);
Nikolay Aleksandrov804b8542018-03-30 13:46:19 +0300618void br_mtu_auto_adjust(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700619netdev_features_t br_features_recompute(struct net_bridge *br,
620 netdev_features_t features);
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400621void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400622void br_manage_promisc(struct net_bridge *br);
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300623int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625/* br_input.c */
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500626int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Joe Perches348662a2013-10-18 13:48:22 -0700627rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Jiri Pirko859828c2013-12-05 16:27:37 +0100629static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
630{
631 return rcu_dereference(dev->rx_handler) == br_handle_frame;
632}
633
Petr Machata4d4fd362018-04-29 10:56:08 +0300634static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
635{
636 return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame;
637}
638
Jiri Pirko859828c2013-12-05 16:27:37 +0100639static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
640{
641 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
642}
643
Petr Machata4d4fd362018-04-29 10:56:08 +0300644static inline struct net_bridge_port *
645br_port_get_check_rtnl(const struct net_device *dev)
646{
647 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
648}
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650/* br_ioctl.c */
Joe Perches348662a2013-10-18 13:48:22 -0700651int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
652int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
653 void __user *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Herbert Xueb1d1642010-02-27 19:41:45 +0000655/* br_multicast.c */
656#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Joe Perches348662a2013-10-18 13:48:22 -0700657int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
David S. Miller394efd12013-11-04 13:48:30 -0500658 struct sk_buff *skb, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700659struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
660 struct sk_buff *skb, u16 vid);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200661int br_multicast_add_port(struct net_bridge_port *port);
Joe Perches348662a2013-10-18 13:48:22 -0700662void br_multicast_del_port(struct net_bridge_port *port);
663void br_multicast_enable_port(struct net_bridge_port *port);
664void br_multicast_disable_port(struct net_bridge_port *port);
665void br_multicast_init(struct net_bridge *br);
666void br_multicast_open(struct net_bridge *br);
667void br_multicast_stop(struct net_bridge *br);
Satish Ashoke10177a2015-07-15 07:16:51 -0700668void br_multicast_dev_del(struct net_bridge *br);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300669void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
670 struct sk_buff *skb, bool local_rcv, bool local_orig);
Joe Perches348662a2013-10-18 13:48:22 -0700671int br_multicast_set_router(struct net_bridge *br, unsigned long val);
672int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
673int br_multicast_toggle(struct net_bridge *br, unsigned long val);
674int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
675int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100676int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100677#if IS_ENABLED(CONFIG_IPV6)
678int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val);
679#endif
Joe Perches348662a2013-10-18 13:48:22 -0700680struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200681br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
Joe Perches348662a2013-10-18 13:48:22 -0700682struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200683br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
Joe Perches348662a2013-10-18 13:48:22 -0700684struct net_bridge_port_group *
685br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
686 struct net_bridge_port_group __rcu *next,
Felix Fietkau6db6f0e2017-01-21 21:01:32 +0100687 unsigned char flags, const unsigned char *src);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200688int br_mdb_hash_init(struct net_bridge *br);
689void br_mdb_hash_fini(struct net_bridge *br);
Elad Raz45ebcce2016-04-21 12:52:45 +0200690void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
691 struct br_ip *group, int type, u8 flags);
Satish Ashok949f1e32015-07-23 05:00:53 -0700692void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
693 int type);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200694void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700695 const struct sk_buff *skb, u8 type, u8 dir);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200696int br_multicast_init_stats(struct net_bridge *br);
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300697void br_multicast_uninit_stats(struct net_bridge *br);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200698void br_multicast_get_stats(const struct net_bridge *br,
699 const struct net_bridge_port *p,
700 struct br_mcast_stats *dest);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200701void br_mdb_init(void);
702void br_mdb_uninit(void);
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000703
Cong Wangcfd56752012-12-11 22:23:08 +0000704#define mlock_dereference(X, br) \
705 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
706
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000707static inline bool br_multicast_is_router(struct net_bridge *br)
708{
709 return br->multicast_router == 2 ||
710 (br->multicast_router == 1 &&
711 timer_pending(&br->multicast_router_timer));
712}
Linus Lüssingb00589a2013-08-01 01:06:20 +0200713
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200714static inline bool
715__br_multicast_querier_exists(struct net_bridge *br,
daniel0888d5f2016-06-24 12:35:18 +0200716 struct bridge_mcast_other_query *querier,
717 const bool is_ipv6)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200718{
daniel0888d5f2016-06-24 12:35:18 +0200719 bool own_querier_enabled;
720
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300721 if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
722 if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR))
daniel0888d5f2016-06-24 12:35:18 +0200723 own_querier_enabled = false;
724 else
725 own_querier_enabled = true;
726 } else {
727 own_querier_enabled = false;
728 }
729
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200730 return time_is_before_jiffies(querier->delay_time) &&
daniel0888d5f2016-06-24 12:35:18 +0200731 (own_querier_enabled || timer_pending(&querier->timer));
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200732}
733
734static inline bool br_multicast_querier_exists(struct net_bridge *br,
735 struct ethhdr *eth)
736{
737 switch (eth->h_proto) {
738 case (htons(ETH_P_IP)):
daniel0888d5f2016-06-24 12:35:18 +0200739 return __br_multicast_querier_exists(br,
740 &br->ip4_other_query, false);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200741#if IS_ENABLED(CONFIG_IPV6)
742 case (htons(ETH_P_IPV6)):
daniel0888d5f2016-06-24 12:35:18 +0200743 return __br_multicast_querier_exists(br,
744 &br->ip6_other_query, true);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200745#endif
746 default:
747 return false;
748 }
Linus Lüssingb00589a2013-08-01 01:06:20 +0200749}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200750
751static inline int br_multicast_igmp_type(const struct sk_buff *skb)
752{
753 return BR_INPUT_SKB_CB(skb)->igmp;
754}
Herbert Xueb1d1642010-02-27 19:41:45 +0000755#else
756static inline int br_multicast_rcv(struct net_bridge *br,
757 struct net_bridge_port *port,
Vlad Yasevich06499092013-10-28 15:45:07 -0400758 struct sk_buff *skb,
759 u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000760{
761 return 0;
762}
763
764static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
Cong Wangfbca58a2013-03-07 03:05:33 +0000765 struct sk_buff *skb, u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +0000766{
767 return NULL;
768}
769
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200770static inline int br_multicast_add_port(struct net_bridge_port *port)
Herbert Xueb1d1642010-02-27 19:41:45 +0000771{
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200772 return 0;
Herbert Xueb1d1642010-02-27 19:41:45 +0000773}
774
775static inline void br_multicast_del_port(struct net_bridge_port *port)
776{
777}
778
779static inline void br_multicast_enable_port(struct net_bridge_port *port)
780{
781}
782
783static inline void br_multicast_disable_port(struct net_bridge_port *port)
784{
785}
786
787static inline void br_multicast_init(struct net_bridge *br)
788{
789}
790
791static inline void br_multicast_open(struct net_bridge *br)
792{
793}
794
795static inline void br_multicast_stop(struct net_bridge *br)
796{
797}
Herbert Xu5cb5e942010-02-27 19:41:46 +0000798
Nikolay Aleksandrova7ce45a2015-07-20 23:03:45 +0200799static inline void br_multicast_dev_del(struct net_bridge *br)
800{
801}
802
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300803static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
804 struct sk_buff *skb,
805 bool local_rcv, bool local_orig)
Herbert Xu5cb5e942010-02-27 19:41:46 +0000806{
807}
808
Herbert Xueb1d1642010-02-27 19:41:45 +0000809static inline bool br_multicast_is_router(struct net_bridge *br)
810{
Gustavo A. R. Silva03aaa9e2018-01-18 17:37:45 -0600811 return false;
Herbert Xueb1d1642010-02-27 19:41:45 +0000812}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300813
Linus Lüssingcc0fdd82013-08-30 17:28:17 +0200814static inline bool br_multicast_querier_exists(struct net_bridge *br,
815 struct ethhdr *eth)
Linus Lüssingb00589a2013-08-01 01:06:20 +0200816{
817 return false;
818}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300819
Rami Rosenfdb184d2013-01-03 13:30:43 +0200820static inline void br_mdb_init(void)
821{
822}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300823
Rami Rosenfdb184d2013-01-03 13:30:43 +0200824static inline void br_mdb_uninit(void)
825{
826}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200827
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200828static inline int br_mdb_hash_init(struct net_bridge *br)
829{
830 return 0;
831}
832
833static inline void br_mdb_hash_fini(struct net_bridge *br)
834{
835}
836
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200837static inline void br_multicast_count(struct net_bridge *br,
838 const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700839 const struct sk_buff *skb,
840 u8 type, u8 dir)
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200841{
842}
843
844static inline int br_multicast_init_stats(struct net_bridge *br)
845{
846 return 0;
847}
848
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300849static inline void br_multicast_uninit_stats(struct net_bridge *br)
850{
851}
852
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200853static inline int br_multicast_igmp_type(const struct sk_buff *skb)
854{
855 return 0;
856}
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000857#endif
Herbert Xueb1d1642010-02-27 19:41:45 +0000858
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000859/* br_vlan.c */
860#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200861bool br_allowed_ingress(const struct net_bridge *br,
862 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
863 u16 *vid);
864bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700865 const struct sk_buff *skb);
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900866bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
Joe Perches348662a2013-10-18 13:48:22 -0700867struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800868 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200869 struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -0700870 struct sk_buff *skb);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300871int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +0000872 bool *changed, struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700873int br_vlan_delete(struct net_bridge *br, u16 vid);
874void br_vlan_flush(struct net_bridge *br);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200875struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900876void br_recalculate_fwd_mask(struct net_bridge *br);
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300877int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Joe Perches348662a2013-10-18 13:48:22 -0700878int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900879int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900880int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200881int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300882int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400883int br_vlan_init(struct net_bridge *br);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400884int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
Petr Machata169327d2018-12-12 17:02:50 +0000885int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
886 struct netlink_ext_ack *extack);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300887int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +0000888 bool *changed, struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700889int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
890void nbp_vlan_flush(struct net_bridge_port *port);
Petr Machata169327d2018-12-12 17:02:50 +0000891int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200892int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +0200893void br_vlan_get_stats(const struct net_bridge_vlan *v,
894 struct br_vlan_stats *stats);
Mike Manning9c0ec2e2019-04-18 18:35:33 +0100895void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
896void br_vlan_bridge_event(struct net_device *dev, unsigned long event,
897 void *ptr);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000898
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200899static inline struct net_bridge_vlan_group *br_vlan_group(
900 const struct net_bridge *br)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000901{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200902 return rtnl_dereference(br->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000903}
904
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200905static inline struct net_bridge_vlan_group *nbp_vlan_group(
906 const struct net_bridge_port *p)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000907{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200908 return rtnl_dereference(p->vlgrp);
909}
910
911static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
912 const struct net_bridge *br)
913{
914 return rcu_dereference(br->vlgrp);
915}
916
917static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
918 const struct net_bridge_port *p)
919{
920 return rcu_dereference(p->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000921}
922
923/* Since bridge now depends on 8021Q module, but the time bridge sees the
924 * skb, the vlan tag will always be present if the frame was tagged.
925 */
926static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
927{
928 int err = 0;
929
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200930 if (skb_vlan_tag_present(skb)) {
Michał Mirosław5978f8a2018-11-09 00:18:03 +0100931 *vid = skb_vlan_tag_get_id(skb);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200932 } else {
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000933 *vid = 0;
934 err = -EINVAL;
935 }
936
937 return err;
938}
Vlad Yasevich78851982013-02-13 12:00:14 +0000939
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200940static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +0000941{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200942 if (!vg)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400943 return 0;
944
Vlad Yasevich78851982013-02-13 12:00:14 +0000945 smp_rmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200946 return vg->pvid;
Vlad Yasevich78851982013-02-13 12:00:14 +0000947}
948
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000949#else
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200950static inline bool br_allowed_ingress(const struct net_bridge *br,
951 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000952 struct sk_buff *skb,
953 u16 *vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000954{
955 return true;
956}
957
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200958static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000959 const struct sk_buff *skb)
960{
961 return true;
962}
963
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900964static inline bool br_should_learn(struct net_bridge_port *p,
965 struct sk_buff *skb, u16 *vid)
966{
967 return true;
968}
969
Vlad Yasevich78851982013-02-13 12:00:14 +0000970static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800971 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200972 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000973 struct sk_buff *skb)
974{
975 return skb;
976}
977
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300978static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +0000979 bool *changed, struct netlink_ext_ack *extack)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000980{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300981 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000982 return -EOPNOTSUPP;
983}
984
985static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
986{
987 return -EOPNOTSUPP;
988}
989
990static inline void br_vlan_flush(struct net_bridge *br)
991{
992}
993
Toshiaki Makita204177f2014-06-10 20:59:25 +0900994static inline void br_recalculate_fwd_mask(struct net_bridge *br)
995{
996}
997
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400998static inline int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +0900999{
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001000 return 0;
Toshiaki Makita8580e212014-06-10 20:59:23 +09001001}
1002
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001003static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +00001004 bool *changed, struct netlink_ext_ack *extack)
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001005{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001006 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001007 return -EOPNOTSUPP;
1008}
1009
1010static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1011{
1012 return -EOPNOTSUPP;
1013}
1014
1015static inline void nbp_vlan_flush(struct net_bridge_port *port)
1016{
1017}
1018
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001019static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1020 u16 vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001021{
1022 return NULL;
1023}
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +00001024
Petr Machata169327d2018-12-12 17:02:50 +00001025static inline int nbp_vlan_init(struct net_bridge_port *port,
1026 struct netlink_ext_ack *extack)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001027{
1028 return 0;
1029}
1030
Vlad Yasevich78851982013-02-13 12:00:14 +00001031static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001032{
1033 return 0;
1034}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001035
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001036static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +00001037{
Vlad Yasevich3df6bf42014-10-03 11:29:17 -04001038 return 0;
Vlad Yasevich78851982013-02-13 12:00:14 +00001039}
Vlad Yasevich2796d0c2014-05-16 09:59:20 -04001040
Nikolay Aleksandrova7854032015-08-07 19:40:45 +03001041static inline int __br_vlan_filter_toggle(struct net_bridge *br,
1042 unsigned long val)
1043{
1044 return -EOPNOTSUPP;
1045}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001046
1047static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1048 u32 filter_mask)
1049{
1050 return 0;
1051}
1052
1053static inline struct net_bridge_vlan_group *br_vlan_group(
1054 const struct net_bridge *br)
1055{
1056 return NULL;
1057}
1058
1059static inline struct net_bridge_vlan_group *nbp_vlan_group(
1060 const struct net_bridge_port *p)
1061{
1062 return NULL;
1063}
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001064
1065static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1066 const struct net_bridge *br)
1067{
1068 return NULL;
1069}
1070
1071static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1072 const struct net_bridge_port *p)
1073{
1074 return NULL;
1075}
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001076
1077static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1078 struct br_vlan_stats *stats)
1079{
1080}
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001081
1082static inline void br_vlan_port_event(struct net_bridge_port *p,
1083 unsigned long event)
1084{
1085}
1086
1087static inline void br_vlan_bridge_event(struct net_device *dev,
1088 unsigned long event, void *ptr)
1089{
1090}
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001091#endif
1092
Pablo Neira Ayuso1a4ba642015-03-10 10:27:18 +01001093struct nf_br_ops {
1094 int (*br_dev_xmit_hook)(struct sk_buff *skb);
1095};
1096extern const struct nf_br_ops __rcu *nf_br_ops;
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098/* br_netfilter.c */
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001099#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1100int br_nf_core_init(void);
1101void br_nf_core_fini(void);
Joe Perches348662a2013-10-18 13:48:22 -07001102void br_netfilter_rtable_init(struct net_bridge *);
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001103#else
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001104static inline int br_nf_core_init(void) { return 0; }
1105static inline void br_nf_core_fini(void) {}
Simon Wunderlich4adf0af2008-07-30 16:27:55 -07001106#define br_netfilter_rtable_init(x)
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109/* br_stp.c */
Florian Fainelli775dd692014-09-30 16:13:19 -07001110void br_set_state(struct net_bridge_port *p, unsigned int state);
Joe Perches348662a2013-10-18 13:48:22 -07001111struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1112void br_init_port(struct net_bridge_port *p);
1113void br_become_designated_port(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Joe Perches348662a2013-10-18 13:48:22 -07001115void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1116int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1117int br_set_hello_time(struct net_bridge *br, unsigned long x);
1118int br_set_max_age(struct net_bridge *br, unsigned long x);
Vivien Didelot82dd4332016-12-10 13:44:27 -05001119int __set_ageing_time(struct net_device *dev, unsigned long t);
Vivien Didelot9e0b27f2016-07-21 12:42:19 -04001120int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
stephen hemminger14f98f22011-04-04 14:03:33 +00001121
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123/* br_stp_if.c */
Joe Perches348662a2013-10-18 13:48:22 -07001124void br_stp_enable_bridge(struct net_bridge *br);
1125void br_stp_disable_bridge(struct net_bridge *br);
1126void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
1127void br_stp_enable_port(struct net_bridge_port *p);
1128void br_stp_disable_port(struct net_bridge_port *p);
1129bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1130void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1131void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1132int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1133int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1134ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136/* br_stp_bpdu.c */
Patrick McHardy7c85fbf2008-07-05 21:25:56 -07001137struct stp_proto;
Joe Perches348662a2013-10-18 13:48:22 -07001138void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1139 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141/* br_stp_timer.c */
Joe Perches348662a2013-10-18 13:48:22 -07001142void br_stp_timer_init(struct net_bridge *br);
1143void br_stp_port_timer_init(struct net_bridge_port *p);
1144unsigned long br_timer_value(const struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146/* br.c */
Igor Maraviće6373c42011-12-12 02:58:25 +00001147#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +00001148extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1149#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001151/* br_netlink.c */
stephen hemminger149ddd82012-06-26 05:48:45 +00001152extern struct rtnl_link_ops br_link_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001153int br_netlink_init(void);
1154void br_netlink_fini(void);
Nikolay Aleksandrov92899062017-11-01 12:18:13 +02001155void br_ifinfo_notify(int event, const struct net_bridge *br,
1156 const struct net_bridge_port *port);
Petr Machata2fd527b2018-12-12 17:02:48 +00001157int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1158 struct netlink_ext_ack *extack);
Roopa Prabhuadd511b2015-01-29 22:40:12 -08001159int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
Joe Perches348662a2013-10-18 13:48:22 -07001160int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02001161 u32 filter_mask, int nlflags);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163#ifdef CONFIG_SYSFS
1164/* br_sysfs_if.c */
Emese Revfy52cf25d2010-01-19 02:58:23 +01001165extern const struct sysfs_ops brport_sysfs_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001166int br_sysfs_addif(struct net_bridge_port *p);
1167int br_sysfs_renameif(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169/* br_sysfs_br.c */
Joe Perches348662a2013-10-18 13:48:22 -07001170int br_sysfs_addbr(struct net_device *dev);
1171void br_sysfs_delbr(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173#else
1174
Lee Jones0cb2bbb2012-11-03 23:02:30 +01001175static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1176static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1177static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1178static inline void br_sysfs_delbr(struct net_device *dev) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179#endif /* CONFIG_SYSFS */
1180
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001181/* br_switchdev.c */
1182#ifdef CONFIG_NET_SWITCHDEV
1183int nbp_switchdev_mark_set(struct net_bridge_port *p);
1184void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1185 struct sk_buff *skb);
1186bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1187 const struct sk_buff *skb);
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001188int br_switchdev_set_port_flag(struct net_bridge_port *p,
1189 unsigned long flags,
1190 unsigned long mask);
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001191void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
1192 int type);
Petr Machata169327d2018-12-12 17:02:50 +00001193int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1194 struct netlink_ext_ack *extack);
Petr Machatad66e4342018-05-30 02:56:03 +02001195int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001196
1197static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1198{
1199 skb->offload_fwd_mark = 0;
1200}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001201#else
1202static inline int nbp_switchdev_mark_set(struct net_bridge_port *p)
1203{
1204 return 0;
1205}
1206
1207static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1208 struct sk_buff *skb)
1209{
1210}
1211
1212static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1213 const struct sk_buff *skb)
1214{
1215 return true;
1216}
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001217
1218static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
1219 unsigned long flags,
1220 unsigned long mask)
1221{
1222 return 0;
1223}
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001224
Petr Machatad66e4342018-05-30 02:56:03 +02001225static inline int br_switchdev_port_vlan_add(struct net_device *dev,
Petr Machata169327d2018-12-12 17:02:50 +00001226 u16 vid, u16 flags,
1227 struct netlink_ext_ack *extack)
Petr Machatad66e4342018-05-30 02:56:03 +02001228{
1229 return -EOPNOTSUPP;
1230}
1231
1232static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
1233{
1234 return -EOPNOTSUPP;
1235}
1236
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02001237static inline void
1238br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
1239{
1240}
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001241
1242static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1243{
1244}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001245#endif /* CONFIG_NET_SWITCHDEV */
1246
Roopa Prabhu057658c2017-10-06 22:12:38 -07001247/* br_arp_nd_proxy.c */
Roopa Prabhu821f1b22017-10-06 22:12:37 -07001248void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
Roopa Prabhu057658c2017-10-06 22:12:38 -07001249void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
1250 u16 vid, struct net_bridge_port *p);
Roopa Prabhued842fa2017-10-06 22:12:39 -07001251void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
1252 u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
1253struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254#endif