blob: c0efd697865abea651263fc5258715e50c151726 [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
Tobias Waldekranz85826612021-07-21 19:24:00 +030032#define BR_HWDOM_MAX BITS_PER_LONG
33
Stephen Hemminger9cde0702007-03-21 14:22:44 -070034#define BR_VERSION "2.3"
35
stephen hemminger515853c2011-10-03 18:14:46 +000036/* Control of forwarding link local multicast */
37#define BR_GROUPFWD_DEFAULT 0
Bernhard Thaler784b58a2015-05-04 22:47:13 +020038/* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +030039enum {
40 BR_GROUPFWD_STP = BIT(0),
41 BR_GROUPFWD_MACPAUSE = BIT(1),
42 BR_GROUPFWD_LACP = BIT(2),
43};
44
45#define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \
46 BR_GROUPFWD_LACP)
Toshiaki Makitaf2808d22014-06-10 20:59:24 +090047/* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
48#define BR_GROUPFWD_8021AD 0xB801u
stephen hemminger515853c2011-10-03 18:14:46 +000049
Stephen Hemminger9cde0702007-03-21 14:22:44 -070050/* Path to usermode spanning tree program */
51#define BR_STP_PROG "/sbin/bridge-stp"
Stephen Hemminger8cbb512e2005-12-21 19:01:30 -080052
Nikolay Aleksandrov31cbc39b2020-06-23 23:47:17 +030053#define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT)
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055typedef struct bridge_id bridge_id;
56typedef struct mac_addr mac_addr;
57typedef __u16 port_id;
58
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +030059struct bridge_id {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned char prio[2];
Joe Perchese5a727f2014-02-23 00:05:25 -080061 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +030064struct mac_addr {
Joe Perchese5a727f2014-02-23 00:05:25 -080065 unsigned char addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020068#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
69/* our own querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020070struct bridge_mcast_own_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020071 struct timer_list timer;
72 u32 startup_sent;
73};
74
75/* other querier */
Linus Lüssing90010b32014-06-07 18:26:26 +020076struct bridge_mcast_other_query {
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020077 struct timer_list timer;
78 unsigned long delay_time;
79};
Linus Lüssingdc4eb532014-06-07 18:26:27 +020080
81/* selected querier */
82struct bridge_mcast_querier {
83 struct br_ip addr;
Nikolay Aleksandrovbb18ef82021-08-13 17:59:57 +030084 int port_ifidx;
Thomas Gleixnerf936bb42021-09-28 16:10:49 +020085 seqcount_spinlock_t seq;
Linus Lüssingdc4eb532014-06-07 18:26:27 +020086};
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +020087
88/* IGMP/MLD statistics */
89struct bridge_mcast_stats {
90 struct br_mcast_stats mstats;
91 struct u64_stats_sync syncp;
92};
Linus Lüssingcc0fdd82013-08-30 17:28:17 +020093#endif
94
Nikolay Aleksandrov96322332021-07-19 20:06:23 +030095/* net_bridge_mcast_port must be always defined due to forwarding stubs */
96struct net_bridge_mcast_port {
97#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
98 struct net_bridge_port *port;
Nikolay Aleksandrov613d61d2021-07-19 20:06:26 +030099 struct net_bridge_vlan *vlan;
Nikolay Aleksandrov96322332021-07-19 20:06:23 +0300100
101 struct bridge_mcast_own_query ip4_own_query;
102 struct timer_list ip4_mc_router_timer;
103 struct hlist_node ip4_rlist;
104#if IS_ENABLED(CONFIG_IPV6)
105 struct bridge_mcast_own_query ip6_own_query;
106 struct timer_list ip6_mc_router_timer;
107 struct hlist_node ip6_rlist;
108#endif /* IS_ENABLED(CONFIG_IPV6) */
109 unsigned char multicast_router;
110#endif /* CONFIG_BRIDGE_IGMP_SNOOPING */
111};
112
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300113/* net_bridge_mcast must be always defined due to forwarding stubs */
114struct net_bridge_mcast {
115#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
116 struct net_bridge *br;
Nikolay Aleksandrov613d61d2021-07-19 20:06:26 +0300117 struct net_bridge_vlan *vlan;
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300118
119 u32 multicast_last_member_count;
120 u32 multicast_startup_query_count;
121
Nikolay Aleksandrov4d5b4e82021-08-10 18:29:28 +0300122 u8 multicast_querier;
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300123 u8 multicast_igmp_version;
124 u8 multicast_router;
125#if IS_ENABLED(CONFIG_IPV6)
126 u8 multicast_mld_version;
127#endif
128 unsigned long multicast_last_member_interval;
129 unsigned long multicast_membership_interval;
130 unsigned long multicast_querier_interval;
131 unsigned long multicast_query_interval;
132 unsigned long multicast_query_response_interval;
133 unsigned long multicast_startup_query_interval;
134 struct hlist_head ip4_mc_router_list;
135 struct timer_list ip4_mc_router_timer;
136 struct bridge_mcast_other_query ip4_other_query;
137 struct bridge_mcast_own_query ip4_own_query;
138 struct bridge_mcast_querier ip4_querier;
139#if IS_ENABLED(CONFIG_IPV6)
140 struct hlist_head ip6_mc_router_list;
141 struct timer_list ip6_mc_router_timer;
142 struct bridge_mcast_other_query ip6_other_query;
143 struct bridge_mcast_own_query ip6_own_query;
144 struct bridge_mcast_querier ip6_querier;
145#endif /* IS_ENABLED(CONFIG_IPV6) */
146#endif /* CONFIG_BRIDGE_IGMP_SNOOPING */
147};
148
Roopa Prabhuefa53562017-01-31 22:59:54 -0800149struct br_tunnel_info {
Nikolay Aleksandrov58e20712021-06-10 15:04:10 +0300150 __be64 tunnel_id;
151 struct metadata_dst __rcu *tunnel_dst;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800152};
153
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200154/* private vlan flags */
155enum {
156 BR_VLFLAG_PER_PORT_STATS = BIT(0),
Ido Schimmel27973792019-01-08 16:48:11 +0000157 BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1),
Nikolay Aleksandrov7b54aaa2021-07-19 20:06:27 +0300158 BR_VLFLAG_MCAST_ENABLED = BIT(2),
159 BR_VLFLAG_GLOBAL_MCAST_ENABLED = BIT(3),
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200160};
161
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200162/**
163 * struct net_bridge_vlan - per-vlan entry
164 *
165 * @vnode: rhashtable member
166 * @vid: VLAN id
167 * @flags: bridge vlan flags
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200168 * @priv_flags: private (in-kernel) bridge vlan flags
Nikolay Aleksandrova580c762020-01-24 13:40:22 +0200169 * @state: STP state (e.g. blocking, learning, forwarding)
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200170 * @stats: per-cpu VLAN statistics
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200171 * @br: if MASTER flag set, this points to a bridge struct
172 * @port: if MASTER flag unset, this points to a port struct
173 * @refcnt: if MASTER flag set, this is bumped for each port referencing it
174 * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
175 * for this VLAN entry
Nikolay Aleksandrov613d61d2021-07-19 20:06:26 +0300176 * @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context
177 * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast
178 * context
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200179 * @vlist: sorted list of VLAN entries
180 * @rcu: used for entry destruction
181 *
182 * This structure is shared between the global per-VLAN entries contained in
183 * the bridge rhashtable and the local per-port per-VLAN entries contained in
184 * the port's rhashtable. The union entries should be interpreted depending on
185 * the entry flags that are set.
186 */
187struct net_bridge_vlan {
188 struct rhash_head vnode;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800189 struct rhash_head tnode;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200190 u16 vid;
191 u16 flags;
Nikolay Aleksandrov9d332e69c2018-11-16 18:50:01 +0200192 u16 priv_flags;
Nikolay Aleksandrova580c762020-01-24 13:40:22 +0200193 u8 state;
Heiner Kallweit281cc282020-11-17 21:25:42 +0100194 struct pcpu_sw_netstats __percpu *stats;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000195 union {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200196 struct net_bridge *br;
197 struct net_bridge_port *port;
198 };
199 union {
Reshetova, Elena25127752017-07-04 15:53:05 +0300200 refcount_t refcnt;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200201 struct net_bridge_vlan *brvlan;
202 };
Roopa Prabhuefa53562017-01-31 22:59:54 -0800203
204 struct br_tunnel_info tinfo;
205
Nikolay Aleksandrov613d61d2021-07-19 20:06:26 +0300206 union {
207 struct net_bridge_mcast br_mcast_ctx;
208 struct net_bridge_mcast_port port_mcast_ctx;
209 };
210
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200211 struct list_head vlist;
212
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000213 struct rcu_head rcu;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200214};
215
216/**
217 * struct net_bridge_vlan_group
218 *
219 * @vlan_hash: VLAN entry rhashtable
220 * @vlan_list: sorted VLAN entry list
221 * @num_vlans: number of total VLAN entries
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200222 * @pvid: PVID VLAN id
Nikolay Aleksandrova580c762020-01-24 13:40:22 +0200223 * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200224 *
225 * IMPORTANT: Be careful when checking if there're VLAN entries using list
226 * primitives because the bridge can have entries in its list which
227 * are just for global context but not for filtering, i.e. they have
228 * the master flag set but not the brentry flag. If you have to check
229 * if there're "real" entries in the bridge please test @num_vlans
230 */
231struct net_bridge_vlan_group {
232 struct rhashtable vlan_hash;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800233 struct rhashtable tunnel_hash;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200234 struct list_head vlan_list;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000235 u16 num_vlans;
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200236 u16 pvid;
Nikolay Aleksandrova580c762020-01-24 13:40:22 +0200237 u8 pvid_state;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000238};
239
Nikolay Aleksandrov6869c3b2019-10-29 13:45:53 +0200240/* bridge fdb flags */
241enum {
242 BR_FDB_LOCAL,
Nikolay Aleksandrov29e63ff2019-10-29 13:45:54 +0200243 BR_FDB_STATIC,
Nikolay Aleksandrove0458d92019-10-29 13:45:55 +0200244 BR_FDB_STICKY,
Nikolay Aleksandrovac3ca6a2019-10-29 13:45:56 +0200245 BR_FDB_ADDED_BY_USER,
Nikolay Aleksandrovb5cd9f72019-10-29 13:45:57 +0200246 BR_FDB_ADDED_BY_EXT_LEARN,
Nikolay Aleksandrovd38c6e32019-10-29 13:45:58 +0200247 BR_FDB_OFFLOADED,
Nikolay Aleksandrov31cbc39b2020-06-23 23:47:17 +0300248 BR_FDB_NOTIFY,
249 BR_FDB_NOTIFY_INACTIVE
Nikolay Aleksandrov6869c3b2019-10-29 13:45:53 +0200250};
251
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200252struct net_bridge_fdb_key {
253 mac_addr addr;
254 u16 vlan_id;
255};
256
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100257struct net_bridge_fdb_entry {
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200258 struct rhash_head rhnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 struct net_bridge_port *dst;
260
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200261 struct net_bridge_fdb_key key;
262 struct hlist_node fdb_node;
Nikolay Aleksandrov6869c3b2019-10-29 13:45:53 +0200263 unsigned long flags;
Nikolay Aleksandrov1214628c2017-02-04 18:05:08 +0100264
265 /* write-heavy members should not affect lookups */
266 unsigned long updated ____cacheline_aligned_in_smp;
267 unsigned long used;
268
Nikolay Aleksandrovb22fbf22015-08-27 14:19:20 -0700269 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270};
271
Elad Raz9d06b6d2016-02-03 09:57:05 +0100272#define MDB_PG_FLAGS_PERMANENT BIT(0)
273#define MDB_PG_FLAGS_OFFLOAD BIT(1)
Nikolay Aleksandrov3247b272019-07-30 15:20:41 +0300274#define MDB_PG_FLAGS_FAST_LEAVE BIT(2)
Nikolay Aleksandrov8266a042020-09-22 10:30:24 +0300275#define MDB_PG_FLAGS_STAR_EXCL BIT(3)
Nikolay Aleksandrov9116ffb2020-09-22 10:30:25 +0300276#define MDB_PG_FLAGS_BLOCKED BIT(4)
Elad Raz9d06b6d2016-02-03 09:57:05 +0100277
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300278#define PG_SRC_ENT_LIMIT 32
279
280#define BR_SGRP_F_DELETE BIT(0)
281#define BR_SGRP_F_SEND BIT(1)
Nikolay Aleksandrovb0812362020-09-22 10:30:23 +0300282#define BR_SGRP_F_INSTALLED BIT(2)
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300283
Nikolay Aleksandrove12cec62020-09-07 12:56:19 +0300284struct net_bridge_mcast_gc {
285 struct hlist_node gc_node;
286 void (*destroy)(struct net_bridge_mcast_gc *gc);
287};
288
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300289struct net_bridge_group_src {
290 struct hlist_node node;
291
292 struct br_ip addr;
293 struct net_bridge_port_group *pg;
294 u8 flags;
Nikolay Aleksandrov438ef2d2020-09-07 12:56:09 +0300295 u8 src_query_rexmit_cnt;
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300296 struct timer_list timer;
297
298 struct net_bridge *br;
Nikolay Aleksandrove12cec62020-09-07 12:56:19 +0300299 struct net_bridge_mcast_gc mcast_gc;
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300300 struct rcu_head rcu;
301};
302
Nikolay Aleksandrov085b53c2020-09-22 10:30:22 +0300303struct net_bridge_port_group_sg_key {
Herbert Xueb1d1642010-02-27 19:41:45 +0000304 struct net_bridge_port *port;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900305 struct br_ip addr;
Nikolay Aleksandrov085b53c2020-09-22 10:30:22 +0300306};
307
308struct net_bridge_port_group {
309 struct net_bridge_port_group __rcu *next;
310 struct net_bridge_port_group_sg_key key;
Thomas Martitz206e73232020-06-25 14:26:03 +0200311 unsigned char eth_addr[ETH_ALEN] __aligned(2);
Elad Raz9d06b6d2016-02-03 09:57:05 +0100312 unsigned char flags;
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300313 unsigned char filter_mode;
Nikolay Aleksandrov42c11cc2020-09-07 12:56:10 +0300314 unsigned char grp_query_rexmit_cnt;
Nikolay Aleksandrov8f8cb772020-09-22 10:30:21 +0300315 unsigned char rt_protocol;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300316
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300317 struct hlist_head src_list;
318 unsigned int src_ents;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300319 struct timer_list timer;
Nikolay Aleksandrov42c11cc2020-09-07 12:56:10 +0300320 struct timer_list rexmit_timer;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300321 struct hlist_node mglist;
Nikolay Aleksandrov8f07b832021-01-20 16:51:54 +0200322 struct rb_root eht_set_tree;
323 struct rb_root eht_host_tree;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300324
Nikolay Aleksandrov085b53c2020-09-22 10:30:22 +0300325 struct rhash_head rhnode;
Nikolay Aleksandrove12cec62020-09-07 12:56:19 +0300326 struct net_bridge_mcast_gc mcast_gc;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300327 struct rcu_head rcu;
Herbert Xueb1d1642010-02-27 19:41:45 +0000328};
329
Nikolay Aleksandrov1c1cb6d2018-09-26 17:00:59 +0300330struct net_bridge_mdb_entry {
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200331 struct rhash_head rhnode;
Herbert Xueb1d1642010-02-27 19:41:45 +0000332 struct net_bridge *br;
Eric Dumazete8051682010-11-15 06:38:10 +0000333 struct net_bridge_port_group __rcu *ports;
YOSHIFUJI Hideaki8ef2a9a2010-04-18 12:42:07 +0900334 struct br_ip addr;
Andrew Lunnff0fd342017-11-09 23:10:57 +0100335 bool host_joined;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300336
337 struct timer_list timer;
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200338 struct hlist_node mdb_node;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300339
Nikolay Aleksandrove12cec62020-09-07 12:56:19 +0300340 struct net_bridge_mcast_gc mcast_gc;
Nikolay Aleksandrov6ec0d0e2020-09-07 12:56:05 +0300341 struct rcu_head rcu;
Herbert Xueb1d1642010-02-27 19:41:45 +0000342};
343
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100344struct net_bridge_port {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 struct net_bridge *br;
346 struct net_device *dev;
347 struct list_head list;
348
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100349 unsigned long flags;
350#ifdef CONFIG_BRIDGE_VLAN_FILTERING
351 struct net_bridge_vlan_group __rcu *vlgrp;
352#endif
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300353 struct net_bridge_port __rcu *backup_port;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /* STP */
356 u8 priority;
357 u8 state;
358 u16 port_no;
359 unsigned char topology_change_ack;
360 unsigned char config_pending;
361 port_id port_id;
362 port_id designated_port;
363 bridge_id designated_root;
364 bridge_id designated_bridge;
365 u32 path_cost;
366 u32 designated_cost;
stephen hemminger0c031502011-07-22 07:47:06 +0000367 unsigned long designated_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 struct timer_list forward_delay_timer;
370 struct timer_list hold_timer;
371 struct timer_list message_age_timer;
372 struct kobject kobj;
373 struct rcu_head rcu;
Fischer, Anna3982d3d2009-08-13 06:55:16 +0000374
Nikolay Aleksandrov96322332021-07-19 20:06:23 +0300375 struct net_bridge_mcast_port multicast_ctx;
376
Herbert Xueb1d1642010-02-27 19:41:45 +0000377#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Nikolay Aleksandrov96322332021-07-19 20:06:23 +0300378 struct bridge_mcast_stats __percpu *mcast_stats;
379
Nikolay Aleksandrov89268b02021-01-26 11:35:32 +0200380 u32 multicast_eht_hosts_limit;
381 u32 multicast_eht_hosts_cnt;
Herbert Xueb1d1642010-02-27 19:41:45 +0000382 struct hlist_head mglist;
Herbert Xueb1d1642010-02-27 19:41:45 +0000383#endif
Simon Arlotte0f43752010-05-10 09:31:11 +0000384
385#ifdef CONFIG_SYSFS
386 char sysfs_name[IFNAMSIZ];
387#endif
Herbert Xu91d2c342010-06-10 16:12:50 +0000388
389#ifdef CONFIG_NET_POLL_CONTROLLER
390 struct netpoll *np;
391#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200392#ifdef CONFIG_NET_SWITCHDEV
Tobias Waldekranzf7cf9722021-07-21 19:23:59 +0300393 /* Identifier used to group ports that share the same switchdev
394 * hardware domain.
395 */
396 int hwdom;
Vladimir Oltean2f5dc002021-07-21 19:24:01 +0300397 int offload_count;
398 struct netdev_phys_item_id ppid;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200399#endif
Nikolay Aleksandrov5af48b52017-09-27 16:12:44 +0300400 u16 group_fwd_mask;
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300401 u16 backup_redirected_cnt;
Vivien Didelotde179962019-12-11 20:07:10 -0500402
403 struct bridge_stp_xstats stp_xstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404};
405
Tyler Hicks705e0de2018-07-20 21:56:54 +0000406#define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
407
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400408#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
Vlad Yasevichf3a6ddf2014-05-16 09:59:18 -0400409#define br_promisc_port(p) ((p)->flags & BR_PROMISC)
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400410
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000411static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
412{
Hong Zhiguo716ec052013-09-14 22:42:28 +0800413 return rcu_dereference(dev->rx_handler_data);
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000414}
415
Hong Zhiguo1fb17542013-09-14 22:42:27 +0800416static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000417{
Julian Wiedmann35f861e2019-03-29 14:38:19 +0100418 return netif_is_bridge_port(dev) ?
Eric Dumazetec1e5612010-11-15 06:38:14 +0000419 rtnl_dereference(dev->rx_handler_data) : NULL;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000420}
421
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200422static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
423{
Julian Wiedmann35f861e2019-03-29 14:38:19 +0100424 return netif_is_bridge_port(dev) ?
Arkadi Sharshevsky0baa10f2017-06-08 08:44:12 +0200425 rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
426}
427
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300428enum net_bridge_opts {
429 BROPT_VLAN_ENABLED,
430 BROPT_VLAN_STATS_ENABLED,
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300431 BROPT_NF_CALL_IPTABLES,
432 BROPT_NF_CALL_IP6TABLES,
433 BROPT_NF_CALL_ARPTABLES,
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300434 BROPT_GROUP_ADDR_SET,
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300435 BROPT_MULTICAST_ENABLED,
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300436 BROPT_MULTICAST_QUERY_USE_IFADDR,
437 BROPT_MULTICAST_STATS_ENABLED,
438 BROPT_HAS_IPV6_ADDR,
Nikolay Aleksandrovc69c2cd2018-09-26 17:01:05 +0300439 BROPT_NEIGH_SUPPRESS_ENABLED,
Nikolay Aleksandrov3341d912018-09-26 17:01:06 +0300440 BROPT_MTU_SET_BY_USER,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300441 BROPT_VLAN_STATS_PER_PORT,
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200442 BROPT_NO_LL_LEARN,
Mike Manning9c0ec2e2019-04-18 18:35:33 +0100443 BROPT_VLAN_BRIDGE_BINDING,
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +0300444 BROPT_MCAST_VLAN_SNOOPING_ENABLED,
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300445};
446
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100447struct net_bridge {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 spinlock_t lock;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100449 spinlock_t hash_lock;
Henrik Bjoernlund90c628d2020-10-27 10:02:42 +0000450 struct hlist_head frame_type_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 struct net_device *dev;
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300452 unsigned long options;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100453 /* These fields are accessed on each packet */
454#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100455 __be16 vlan_proto;
456 u16 default_pvid;
457 struct net_bridge_vlan_group __rcu *vlgrp;
458#endif
459
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200460 struct rhashtable fdb_hash_tbl;
Henrik Bjoernlund90c628d2020-10-27 10:02:42 +0000461 struct list_head port_list;
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200462#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Bernhard Thalerefb6de92015-05-30 15:30:16 +0200463 union {
464 struct rtable fake_rtable;
465 struct rt6_info fake_rt6_info;
466 };
Simon Wunderlich4adf0af2008-07-30 16:27:55 -0700467#endif
stephen hemminger515853c2011-10-03 18:14:46 +0000468 u16 group_fwd_mask;
Toshiaki Makitaf2808d22014-06-10 20:59:24 +0900469 u16 group_fwd_mask_required;
stephen hemminger515853c2011-10-03 18:14:46 +0000470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 /* STP */
472 bridge_id designated_root;
473 bridge_id bridge_id;
Nikolay Aleksandrov1f90c7f2017-02-04 18:05:06 +0100474 unsigned char topology_change;
475 unsigned char topology_change_detected;
476 u16 root_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 unsigned long max_age;
478 unsigned long hello_time;
479 unsigned long forward_delay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 unsigned long ageing_time;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500481 unsigned long bridge_max_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 unsigned long bridge_hello_time;
483 unsigned long bridge_forward_delay;
Vivien Didelot34d8acd2016-12-10 13:44:29 -0500484 unsigned long bridge_ageing_time;
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300485 u32 root_path_cost;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800487 u8 group_addr[ETH_ALEN];
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700488
489 enum {
490 BR_NO_STP, /* no spanning tree */
491 BR_KERNEL_STP, /* old STP in kernel */
492 BR_USER_STP, /* new RSTP in userspace */
493 } stp_enabled;
494
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300495 struct net_bridge_mcast multicast_ctx;
496
Herbert Xueb1d1642010-02-27 19:41:45 +0000497#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300498 struct bridge_mcast_stats __percpu *mcast_stats;
Herbert Xueb1d1642010-02-27 19:41:45 +0000499
Herbert Xueb1d1642010-02-27 19:41:45 +0000500 u32 hash_max;
501
Nikolay Aleksandrov35750b02018-09-26 17:01:07 +0300502 spinlock_t multicast_lock;
Herbert Xueb1d1642010-02-27 19:41:45 +0000503
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200504 struct rhashtable mdb_hash_tbl;
Nikolay Aleksandrov085b53c2020-09-22 10:30:22 +0300505 struct rhashtable sg_port_tbl;
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200506
Nikolay Aleksandrove12cec62020-09-07 12:56:19 +0300507 struct hlist_head mcast_gc_list;
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200508 struct hlist_head mdb_list;
Herbert Xueb1d1642010-02-27 19:41:45 +0000509
Nikolay Aleksandrove12cec62020-09-07 12:56:19 +0300510 struct work_struct mcast_gc_work;
Herbert Xueb1d1642010-02-27 19:41:45 +0000511#endif
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 struct timer_list hello_timer;
514 struct timer_list tcn_timer;
515 struct timer_list topology_change_timer;
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100516 struct delayed_work gc_work;
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400517 struct kobject *ifobj;
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400518 u32 auto_cnt;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200519
520#ifdef CONFIG_NET_SWITCHDEV
Tobias Waldekranzf7cf9722021-07-21 19:23:59 +0300521 /* Counter used to make sure that hardware domains get unique
522 * identifiers in case a bridge spans multiple switchdev instances.
523 */
524 int last_hwdom;
Tobias Waldekranz85826612021-07-21 19:24:00 +0300525 /* Bit mask of hardware domain numbers in use */
526 unsigned long busy_hwdoms;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200527#endif
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200528 struct hlist_head fdb_list;
Horatiu Vultur4b8d7d42020-04-26 15:22:00 +0200529
530#if IS_ENABLED(CONFIG_BRIDGE_MRP)
Horatiu Vultur0169b822020-11-06 22:50:49 +0100531 struct hlist_head mrp_list;
Horatiu Vultur4b8d7d42020-04-26 15:22:00 +0200532#endif
Henrik Bjoernlundf323aa52020-10-27 10:02:43 +0000533#if IS_ENABLED(CONFIG_BRIDGE_CFM)
534 struct hlist_head mep_list;
535#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536};
537
Herbert Xu68b7c892010-02-27 19:41:40 +0000538struct br_input_skb_cb {
539 struct net_device *brdev;
Herbert Xu93fdd472014-10-05 12:00:22 +0800540
Pablo Neira Ayuso3c171f42019-05-29 13:25:37 +0200541 u16 frag_max_size;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000542#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Florian Westphalf12064d2019-04-11 16:36:40 +0200543 u8 igmp;
544 u8 mrouters_only:1;
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000545#endif
Florian Westphalf12064d2019-04-11 16:36:40 +0200546 u8 proxyarp_replied:1;
547 u8 src_port_isolated:1;
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400548#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Florian Westphalf12064d2019-04-11 16:36:40 +0200549 u8 vlan_filtered:1;
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400550#endif
Florian Westphal223fd0a2019-04-11 16:36:42 +0200551#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
552 u8 br_netfilter_broute:1;
553#endif
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200554
555#ifdef CONFIG_NET_SWITCHDEV
Tobias Waldekranz47211192021-07-22 18:55:38 +0300556 /* Set if TX data plane offloading is used towards at least one
557 * hardware domain.
558 */
559 u8 tx_fwd_offload:1;
Tobias Waldekranzf7cf9722021-07-21 19:23:59 +0300560 /* The switchdev hardware domain from which this packet was received.
561 * If skb->offload_fwd_mark was set, then this packet was already
562 * forwarded by hardware to the other ports in the source hardware
563 * domain, otherwise it wasn't.
564 */
565 int src_hwdom;
Tobias Waldekranz47211192021-07-22 18:55:38 +0300566 /* Bit mask of hardware domains towards this packet has already been
567 * transmitted using the TX data plane offload.
568 */
569 unsigned long fwd_hwdoms;
Ido Schimmel6bc506b2016-08-25 18:42:37 +0200570#endif
Herbert Xu68b7c892010-02-27 19:41:40 +0000571};
572
573#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
574
YOSHIFUJI Hideaki / 吉藤英明32dec5d2010-03-15 21:51:18 +0000575#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
576# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
577#else
578# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
579#endif
580
stephen hemminger28a16c92010-05-10 09:31:09 +0000581#define br_printk(level, br, format, args...) \
582 printk(level "%s: " format, (br)->dev->name, ##args)
583
584#define br_err(__br, format, args...) \
585 br_printk(KERN_ERR, __br, format, ##args)
586#define br_warn(__br, format, args...) \
587 br_printk(KERN_WARNING, __br, format, ##args)
588#define br_notice(__br, format, args...) \
589 br_printk(KERN_NOTICE, __br, format, ##args)
590#define br_info(__br, format, args...) \
591 br_printk(KERN_INFO, __br, format, ##args)
592
593#define br_debug(br, format, args...) \
594 pr_debug("%s: " format, (br)->dev->name, ##args)
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596/* called under bridge lock */
597static inline int br_is_root_bridge(const struct net_bridge *br)
598{
599 return !memcmp(&br->bridge_id, &br->designated_root, 8);
600}
601
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200602/* check if a VLAN entry is global */
603static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
604{
605 return v->flags & BRIDGE_VLAN_INFO_MASTER;
606}
607
608/* check if a VLAN entry is used by the bridge */
609static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
610{
611 return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
612}
613
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200614/* check if we should use the vlan entry, returns false if it's only context */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200615static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
616{
617 if (br_vlan_is_master(v)) {
618 if (br_vlan_is_brentry(v))
619 return true;
620 else
621 return false;
622 }
623
624 return true;
625}
626
Nikolay Aleksandrov5d1fcaf2019-11-04 11:36:51 +0200627static inline bool nbp_state_should_learn(const struct net_bridge_port *p)
628{
629 return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING;
630}
631
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200632static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack)
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200633{
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200634 bool ret = vid > 0 && vid < VLAN_VID_MASK;
635
636 if (!ret)
637 NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid");
638
639 return ret;
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200640}
641
642static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200643 const struct bridge_vlan_info *last,
644 struct netlink_ext_ack *extack)
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200645{
646 /* pvid flag is not allowed in ranges */
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200647 if (cur->flags & BRIDGE_VLAN_INFO_PVID) {
648 NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range");
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200649 return false;
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200650 }
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200651
652 /* when cur is the range end, check if:
653 * - it has range start flag
654 * - range ids are invalid (end is equal to or before start)
655 */
656 if (last) {
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200657 if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
658 NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one");
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200659 return false;
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200660 } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) {
661 NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing");
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200662 return false;
Nikolay Aleksandrov8f4cc942020-01-14 19:56:08 +0200663 } else if (cur->vid <= last->vid) {
664 NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
665 return false;
666 }
667 }
668
669 /* check for required range flags */
670 if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
671 BRIDGE_VLAN_INFO_RANGE_END))) {
672 NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing");
673 return false;
Nikolay Aleksandrov5a46fac2020-01-14 19:56:07 +0200674 }
675
676 return true;
677}
678
Nikolay Aleksandrov2796d842021-08-20 15:42:55 +0300679static inline u8 br_vlan_multicast_router(const struct net_bridge_vlan *v)
680{
681 u8 mcast_router = MDB_RTR_TYPE_DISABLED;
682
683#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
684 if (!br_vlan_is_master(v))
685 mcast_router = v->port_mcast_ctx.multicast_router;
686 else
687 mcast_router = v->br_mcast_ctx.multicast_router;
688#endif
689
690 return mcast_router;
691}
692
Nikolay Aleksandrovf5459232020-01-14 19:56:14 +0200693static inline int br_afspec_cmd_to_rtm(int cmd)
694{
695 switch (cmd) {
696 case RTM_SETLINK:
697 return RTM_NEWVLAN;
698 case RTM_DELLINK:
699 return RTM_DELVLAN;
700 }
701
702 return 0;
703}
704
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300705static inline int br_opt_get(const struct net_bridge *br,
706 enum net_bridge_opts opt)
707{
708 return test_bit(opt, &br->options);
709}
710
Nikolay Aleksandrova428afe2018-11-24 04:34:20 +0200711int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
712 struct netlink_ext_ack *extack);
713int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
714int br_boolopt_multi_toggle(struct net_bridge *br,
715 struct br_boolopt_multi *bm,
716 struct netlink_ext_ack *extack);
717void br_boolopt_multi_get(const struct net_bridge *br,
718 struct br_boolopt_multi *bm);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300719void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721/* br_device.c */
Joe Perches348662a2013-10-18 13:48:22 -0700722void br_dev_setup(struct net_device *dev);
723void br_dev_delete(struct net_device *dev, struct list_head *list);
724netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
stephen hemmingercfb478d2010-05-10 09:31:08 +0000725#ifdef CONFIG_NET_POLL_CONTROLLER
Herbert Xu91d2c342010-06-10 16:12:50 +0000726static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
727 struct sk_buff *skb)
728{
Eric Dumazetf78ed222020-05-07 09:32:21 -0700729 netpoll_send_skb(p->np, skb);
Herbert Xu91d2c342010-06-10 16:12:50 +0000730}
731
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700732int br_netpoll_enable(struct net_bridge_port *p);
Joe Perches348662a2013-10-18 13:48:22 -0700733void br_netpoll_disable(struct net_bridge_port *p);
Herbert Xu91d2c342010-06-10 16:12:50 +0000734#else
Herbert Xu9f70b0f2010-06-15 21:43:48 -0700735static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
Herbert Xu91d2c342010-06-10 16:12:50 +0000736 struct sk_buff *skb)
737{
738}
739
Eric W. Biedermana8779ec2014-03-27 15:36:38 -0700740static inline int br_netpoll_enable(struct net_bridge_port *p)
Herbert Xu91d2c342010-06-10 16:12:50 +0000741{
742 return 0;
743}
744
745static inline void br_netpoll_disable(struct net_bridge_port *p)
746{
747}
stephen hemmingercfb478d2010-05-10 09:31:08 +0000748#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750/* br_fdb.c */
Joe Perches348662a2013-10-18 13:48:22 -0700751int br_fdb_init(void);
752void br_fdb_fini(void);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200753int br_fdb_hash_init(struct net_bridge *br);
754void br_fdb_hash_fini(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700755void br_fdb_flush(struct net_bridge *br);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900756void br_fdb_find_delete_local(struct net_bridge *br,
757 const struct net_bridge_port *p,
758 const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700759void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
760void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100761void br_fdb_cleanup(struct work_struct *work);
Joe Perches348662a2013-10-18 13:48:22 -0700762void br_fdb_delete_by_port(struct net_bridge *br,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700763 const struct net_bridge_port *p, u16 vid, int do_all);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100764struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
765 const unsigned char *addr,
766 __u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700767int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
768int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
769 unsigned long off);
Vladimir Olteanf6814fd2021-10-26 17:27:39 +0300770int br_fdb_add_local(struct net_bridge *br, struct net_bridge_port *source,
771 const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700772void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Nikolay Aleksandrovbe0c5672019-11-01 14:46:37 +0200773 const unsigned char *addr, u16 vid, unsigned long flags);
John Fastabend77162022012-04-15 06:43:56 +0000774
Joe Perches348662a2013-10-18 13:48:22 -0700775int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
Jiri Pirkof6f64242014-11-28 14:34:15 +0100776 struct net_device *dev, const unsigned char *addr, u16 vid);
Joe Perches348662a2013-10-18 13:48:22 -0700777int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
Petr Machata87b09842019-01-16 23:06:50 +0000778 const unsigned char *addr, u16 vid, u16 nlh_flags,
779 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700780int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
Roopa Prabhud2976532016-08-30 21:56:45 -0700781 struct net_device *dev, struct net_device *fdev, int *idx);
Roopa Prabhu47674562018-12-15 22:35:09 -0800782int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
783 const unsigned char *addr, u16 vid, u32 portid, u32 seq,
784 struct netlink_ext_ack *extack);
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400785int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
786void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100787int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Nikolay Aleksandrov45a68782021-08-10 14:00:10 +0300788 const unsigned char *addr, u16 vid,
Petr Machata161d82d2018-05-03 14:43:53 +0200789 bool swdev_notify);
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100790int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Petr Machata161d82d2018-05-03 14:43:53 +0200791 const unsigned char *addr, u16 vid,
792 bool swdev_notify);
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200793void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
Ido Schimmele9ba0fb2018-10-17 08:53:29 +0000794 const unsigned char *addr, u16 vid, bool offloaded);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796/* br_forward.c */
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200797enum br_pkt_type {
798 BR_PKT_UNICAST,
799 BR_PKT_MULTICAST,
800 BR_PKT_BROADCAST
801};
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500802int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrovb35c5f62016-07-14 06:10:01 +0300803void br_forward(const struct net_bridge_port *to, struct sk_buff *skb,
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300804 bool local_rcv, bool local_orig);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500805int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +0300806void br_flood(struct net_bridge *br, struct sk_buff *skb,
Nikolay Aleksandrov8addd5e2016-08-31 15:36:51 +0200807 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +0300809/* return true if both source port and dest port are isolated */
810static inline bool br_skb_isolated(const struct net_bridge_port *to,
811 const struct sk_buff *skb)
812{
813 return BR_INPUT_SKB_CB(skb)->src_port_isolated &&
814 (to->flags & BR_ISOLATED);
815}
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817/* br_if.c */
Nikolay Aleksandrovfaa1cd82018-05-03 13:47:24 +0300818void br_port_carrier_check(struct net_bridge_port *p, bool *notified);
Joe Perches348662a2013-10-18 13:48:22 -0700819int br_add_bridge(struct net *net, const char *name);
820int br_del_bridge(struct net *net, const char *name);
David Ahernca752be2017-10-04 17:48:50 -0700821int br_add_if(struct net_bridge *br, struct net_device *dev,
822 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -0700823int br_del_if(struct net_bridge *br, struct net_device *dev);
Nikolay Aleksandrov804b8542018-03-30 13:46:19 +0300824void br_mtu_auto_adjust(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700825netdev_features_t br_features_recompute(struct net_bridge *br,
826 netdev_features_t features);
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400827void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400828void br_manage_promisc(struct net_bridge *br);
Nikolay Aleksandrov2756f682018-07-23 11:16:59 +0300829int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831/* br_input.c */
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500832int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
Vladimir Oltean9eb8eff2020-05-10 19:37:40 +0300833rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Henrik Bjoernlund90c628d2020-10-27 10:02:42 +0000835struct br_frame_type {
836 __be16 type;
837 int (*frame_handler)(struct net_bridge_port *port,
838 struct sk_buff *skb);
839 struct hlist_node list;
840};
841
842void br_add_frame(struct net_bridge *br, struct br_frame_type *ft);
843void br_del_frame(struct net_bridge *br, struct br_frame_type *ft);
844
Jiri Pirko859828c2013-12-05 16:27:37 +0100845static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
846{
Vladimir Oltean9eb8eff2020-05-10 19:37:40 +0300847 return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
Jiri Pirko859828c2013-12-05 16:27:37 +0100848}
849
Petr Machata4d4fd362018-04-29 10:56:08 +0300850static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
851{
Vladimir Oltean9eb8eff2020-05-10 19:37:40 +0300852 return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev);
Petr Machata4d4fd362018-04-29 10:56:08 +0300853}
854
Jiri Pirko859828c2013-12-05 16:27:37 +0100855static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
856{
857 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
858}
859
Petr Machata4d4fd362018-04-29 10:56:08 +0300860static inline struct net_bridge_port *
861br_port_get_check_rtnl(const struct net_device *dev)
862{
863 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL;
864}
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866/* br_ioctl.c */
Arnd Bergmann561d8352021-07-27 15:44:51 +0200867int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq,
868 void __user *data, int cmd);
Arnd Bergmannad2f99a2021-07-27 15:45:16 +0200869int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd,
870 struct ifreq *ifr, void __user *uarg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Herbert Xueb1d1642010-02-27 19:41:45 +0000872/* br_multicast.c */
873#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +0300874int br_multicast_rcv(struct net_bridge_mcast **brmctx,
875 struct net_bridge_mcast_port **pmctx,
876 struct net_bridge_vlan *vlan,
David S. Miller394efd12013-11-04 13:48:30 -0500877 struct sk_buff *skb, u16 vid);
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +0300878struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx,
Joe Perches348662a2013-10-18 13:48:22 -0700879 struct sk_buff *skb, u16 vid);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200880int br_multicast_add_port(struct net_bridge_port *port);
Joe Perches348662a2013-10-18 13:48:22 -0700881void br_multicast_del_port(struct net_bridge_port *port);
882void br_multicast_enable_port(struct net_bridge_port *port);
883void br_multicast_disable_port(struct net_bridge_port *port);
884void br_multicast_init(struct net_bridge *br);
Joseph Huang851d0a72020-12-04 18:56:28 -0500885void br_multicast_join_snoopers(struct net_bridge *br);
886void br_multicast_leave_snoopers(struct net_bridge *br);
Joe Perches348662a2013-10-18 13:48:22 -0700887void br_multicast_open(struct net_bridge *br);
888void br_multicast_stop(struct net_bridge *br);
Satish Ashoke10177a2015-07-15 07:16:51 -0700889void br_multicast_dev_del(struct net_bridge *br);
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +0300890void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb,
891 struct net_bridge_mcast *brmctx,
892 bool local_rcv, bool local_orig);
Nikolay Aleksandrova97df082021-08-10 18:29:31 +0300893int br_multicast_set_router(struct net_bridge_mcast *brmctx, unsigned long val);
Nikolay Aleksandrova53581d2021-08-20 15:42:54 +0300894int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx,
895 unsigned long val);
Nikolay Aleksandrov2796d842021-08-20 15:42:55 +0300896int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router);
Florian Fainelliae1ea842021-04-14 22:22:57 +0300897int br_multicast_toggle(struct net_bridge *br, unsigned long val,
898 struct netlink_ext_ack *extack);
Nikolay Aleksandrov62938182021-08-10 18:29:30 +0300899int br_multicast_set_querier(struct net_bridge_mcast *brmctx, unsigned long val);
Joe Perches348662a2013-10-18 13:48:22 -0700900int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +0300901int br_multicast_set_igmp_version(struct net_bridge_mcast *brmctx,
902 unsigned long val);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100903#if IS_ENABLED(CONFIG_IPV6)
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +0300904int br_multicast_set_mld_version(struct net_bridge_mcast *brmctx,
905 unsigned long val);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100906#endif
Joe Perches348662a2013-10-18 13:48:22 -0700907struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200908br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
Joe Perches348662a2013-10-18 13:48:22 -0700909struct net_bridge_mdb_entry *
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200910br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
Joe Perches348662a2013-10-18 13:48:22 -0700911struct net_bridge_port_group *
912br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
913 struct net_bridge_port_group __rcu *next,
Nikolay Aleksandrov8b671772020-09-07 12:56:07 +0300914 unsigned char flags, const unsigned char *src,
Nikolay Aleksandrov8f8cb772020-09-22 10:30:21 +0300915 u8 filter_mode, u8 rt_protocol);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200916int br_mdb_hash_init(struct net_bridge *br);
917void br_mdb_hash_fini(struct net_bridge *br);
Nikolay Aleksandrov81f19832020-09-07 12:56:12 +0300918void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp,
919 struct net_bridge_port_group *pg, int type);
Nikolay Aleksandrov1e9ca452021-07-19 20:06:33 +0300920void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx,
Satish Ashok949f1e32015-07-23 05:00:53 -0700921 int type);
Nikolay Aleksandrov681590b2020-09-07 12:56:06 +0300922void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
923 struct net_bridge_port_group *pg,
924 struct net_bridge_port_group __rcu **pp);
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +0300925void br_multicast_count(struct net_bridge *br,
926 const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -0700927 const struct sk_buff *skb, u8 type, u8 dir);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200928int br_multicast_init_stats(struct net_bridge *br);
Ido Schimmelb6fe0442017-04-10 14:59:27 +0300929void br_multicast_uninit_stats(struct net_bridge *br);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200930void br_multicast_get_stats(const struct net_bridge *br,
931 const struct net_bridge_port *p,
932 struct br_mcast_stats *dest);
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200933void br_mdb_init(void);
934void br_mdb_uninit(void);
Nikolay Aleksandrov58d913a2021-07-21 17:01:27 +0300935void br_multicast_host_join(const struct net_bridge_mcast *brmctx,
936 struct net_bridge_mdb_entry *mp, bool notify);
Nikolay Aleksandrov1bc844e2019-08-17 14:22:13 +0300937void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
Nikolay Aleksandrov8266a042020-09-22 10:30:24 +0300938void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg,
939 u8 filter_mode);
940void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp,
941 struct net_bridge_port_group *sg);
Nikolay Aleksandrov474ddb32021-01-20 16:51:58 +0200942struct net_bridge_group_src *
943br_multicast_find_group_src(struct net_bridge_port_group *pg, struct br_ip *ip);
Nikolay Aleksandrovd5a10222021-01-20 16:52:03 +0200944void br_multicast_del_group_src(struct net_bridge_group_src *src,
945 bool fastleave);
Nikolay Aleksandrov613d61d2021-07-19 20:06:26 +0300946void br_multicast_ctx_init(struct net_bridge *br,
947 struct net_bridge_vlan *vlan,
948 struct net_bridge_mcast *brmctx);
949void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx);
950void br_multicast_port_ctx_init(struct net_bridge_port *port,
951 struct net_bridge_vlan *vlan,
952 struct net_bridge_mcast_port *pmctx);
953void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx);
Nikolay Aleksandrov7b54aaa2021-07-19 20:06:27 +0300954void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on);
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +0300955int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on,
956 struct netlink_ext_ack *extack);
Nikolay Aleksandrov9dee5722021-07-19 20:06:37 +0300957bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on);
Sridhar Samudrala85b35262010-03-01 09:53:04 +0000958
Nikolay Aleksandrovdc002872021-08-10 18:29:33 +0300959int br_rports_fill_info(struct sk_buff *skb,
960 const struct net_bridge_mcast *brmctx);
Nikolay Aleksandrovc7fa1d92021-08-13 18:00:00 +0300961int br_multicast_dump_querier_state(struct sk_buff *skb,
962 const struct net_bridge_mcast *brmctx,
963 int nest_attr);
964size_t br_multicast_querier_state_size(void);
Nikolay Aleksandrov05d6f382021-08-16 17:57:05 +0300965size_t br_rports_size(const struct net_bridge_mcast *brmctx);
Vladimir Oltean4e51bf42021-07-21 19:24:03 +0300966
Nikolay Aleksandrov955062b2020-10-29 01:38:31 +0200967static inline bool br_group_is_l2(const struct br_ip *group)
968{
969 return group->proto == 0;
970}
971
Cong Wangcfd56752012-12-11 22:23:08 +0000972#define mlock_dereference(X, br) \
973 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
974
Linus Lüssing44ebb082021-05-13 15:20:44 +0200975static inline struct hlist_node *
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +0300976br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx,
977 struct sk_buff *skb)
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300978{
Linus Lüssinga3c02e72021-05-13 15:20:51 +0200979#if IS_ENABLED(CONFIG_IPV6)
980 if (skb->protocol == htons(ETH_P_IPV6))
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300981 return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list));
Linus Lüssinga3c02e72021-05-13 15:20:51 +0200982#endif
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300983 return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list));
Linus Lüssing44ebb082021-05-13 15:20:44 +0200984}
985
986static inline struct net_bridge_port *
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300987br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb)
988{
Nikolay Aleksandrov96322332021-07-19 20:06:23 +0300989 struct net_bridge_mcast_port *mctx;
990
Linus Lüssinga3c02e72021-05-13 15:20:51 +0200991#if IS_ENABLED(CONFIG_IPV6)
992 if (skb->protocol == htons(ETH_P_IPV6))
Nikolay Aleksandrov96322332021-07-19 20:06:23 +0300993 mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port,
994 ip6_rlist);
995 else
Linus Lüssinga3c02e72021-05-13 15:20:51 +0200996#endif
Nikolay Aleksandrov96322332021-07-19 20:06:23 +0300997 mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port,
998 ip4_rlist);
999
1000 if (mctx)
1001 return mctx->port;
1002 else
1003 return NULL;
Linus Lüssing44ebb082021-05-13 15:20:44 +02001004}
1005
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001006static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx)
Sridhar Samudrala85b35262010-03-01 09:53:04 +00001007{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001008 return timer_pending(&brmctx->ip4_mc_router_timer);
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001009}
1010
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001011static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx)
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001012{
1013#if IS_ENABLED(CONFIG_IPV6)
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001014 return timer_pending(&brmctx->ip6_mc_router_timer);
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001015#else
1016 return false;
1017#endif
1018}
1019
1020static inline bool
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001021br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb)
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001022{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001023 switch (brmctx->multicast_router) {
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001024 case MDB_RTR_TYPE_PERM:
1025 return true;
1026 case MDB_RTR_TYPE_TEMP_QUERY:
1027 if (skb) {
1028 if (skb->protocol == htons(ETH_P_IP))
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001029 return br_ip4_multicast_is_router(brmctx);
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001030 else if (skb->protocol == htons(ETH_P_IPV6))
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001031 return br_ip6_multicast_is_router(brmctx);
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001032 } else {
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +03001033 return br_ip4_multicast_is_router(brmctx) ||
1034 br_ip6_multicast_is_router(brmctx);
Linus Lüssing1a3065a2021-05-13 15:20:47 +02001035 }
1036 fallthrough;
1037 default:
1038 return false;
1039 }
Sridhar Samudrala85b35262010-03-01 09:53:04 +00001040}
Linus Lüssingb00589a2013-08-01 01:06:20 +02001041
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001042static inline bool
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001043__br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
1044 struct bridge_mcast_other_query *querier,
1045 const bool is_ipv6)
Linus Lüssingb00589a2013-08-01 01:06:20 +02001046{
daniel0888d5f2016-06-24 12:35:18 +02001047 bool own_querier_enabled;
1048
Nikolay Aleksandrov62938182021-08-10 18:29:30 +03001049 if (brmctx->multicast_querier) {
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001050 if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR))
daniel0888d5f2016-06-24 12:35:18 +02001051 own_querier_enabled = false;
1052 else
1053 own_querier_enabled = true;
1054 } else {
1055 own_querier_enabled = false;
1056 }
1057
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001058 return time_is_before_jiffies(querier->delay_time) &&
daniel0888d5f2016-06-24 12:35:18 +02001059 (own_querier_enabled || timer_pending(&querier->timer));
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001060}
1061
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001062static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
Nikolay Aleksandrov955062b2020-10-29 01:38:31 +02001063 struct ethhdr *eth,
1064 const struct net_bridge_mdb_entry *mdb)
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001065{
1066 switch (eth->h_proto) {
1067 case (htons(ETH_P_IP)):
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001068 return __br_multicast_querier_exists(brmctx,
1069 &brmctx->ip4_other_query, false);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001070#if IS_ENABLED(CONFIG_IPV6)
1071 case (htons(ETH_P_IPV6)):
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001072 return __br_multicast_querier_exists(brmctx,
1073 &brmctx->ip6_other_query, true);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001074#endif
1075 default:
Nikolay Aleksandrov955062b2020-10-29 01:38:31 +02001076 return !!mdb && br_group_is_l2(&mdb->addr);
Linus Lüssingcc0fdd82013-08-30 17:28:17 +02001077 }
Linus Lüssingb00589a2013-08-01 01:06:20 +02001078}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001079
Nikolay Aleksandrov88d4bd12020-09-22 10:30:19 +03001080static inline bool br_multicast_is_star_g(const struct br_ip *ip)
1081{
1082 switch (ip->proto) {
1083 case htons(ETH_P_IP):
1084 return ipv4_is_zeronet(ip->src.ip4);
1085#if IS_ENABLED(CONFIG_IPV6)
1086 case htons(ETH_P_IPV6):
1087 return ipv6_addr_any(&ip->src.ip6);
1088#endif
1089 default:
1090 return false;
1091 }
1092}
1093
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001094static inline bool
1095br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx,
1096 __be16 proto)
Nikolay Aleksandrov8266a042020-09-22 10:30:24 +03001097{
1098 switch (proto) {
1099 case htons(ETH_P_IP):
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001100 return !!(brmctx->multicast_igmp_version == 3);
Nikolay Aleksandrov8266a042020-09-22 10:30:24 +03001101#if IS_ENABLED(CONFIG_IPV6)
1102 case htons(ETH_P_IPV6):
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001103 return !!(brmctx->multicast_mld_version == 2);
Nikolay Aleksandrov8266a042020-09-22 10:30:24 +03001104#endif
1105 default:
1106 return false;
1107 }
1108}
1109
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001110static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1111{
1112 return BR_INPUT_SKB_CB(skb)->igmp;
1113}
Nikolay Aleksandrov42c11cc2020-09-07 12:56:10 +03001114
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001115static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx)
Nikolay Aleksandrov42c11cc2020-09-07 12:56:10 +03001116{
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001117 return brmctx->multicast_last_member_interval *
1118 brmctx->multicast_last_member_count;
Nikolay Aleksandrov42c11cc2020-09-07 12:56:10 +03001119}
Nikolay Aleksandrov04368622020-09-07 12:56:14 +03001120
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001121static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx)
Nikolay Aleksandrov04368622020-09-07 12:56:14 +03001122{
Nikolay Aleksandrovfac3cb82021-10-15 12:05:46 +03001123 return brmctx->multicast_membership_interval;
Nikolay Aleksandrov04368622020-09-07 12:56:14 +03001124}
Nikolay Aleksandrov7b54aaa2021-07-19 20:06:27 +03001125
1126static inline bool
1127br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx)
1128{
1129 return !!brmctx->vlan;
1130}
1131
1132static inline bool
1133br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx)
1134{
1135 return !!pmctx->vlan;
1136}
1137
1138static inline struct net_bridge_mcast *
1139br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx)
1140{
1141 if (!br_multicast_port_ctx_is_vlan(pmctx))
1142 return &pmctx->port->br->multicast_ctx;
1143 else
1144 return &pmctx->vlan->brvlan->br_mcast_ctx;
1145}
1146
1147static inline bool
1148br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx)
1149{
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001150 return br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) &&
1151 br_multicast_ctx_is_vlan(brmctx) &&
Nikolay Aleksandrov7b54aaa2021-07-19 20:06:27 +03001152 !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED);
1153}
1154
1155static inline bool
1156br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx)
1157{
1158 return br_multicast_ctx_is_vlan(brmctx) &&
1159 !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED);
1160}
1161
1162static inline bool
1163br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx)
1164{
1165 return br_multicast_port_ctx_is_vlan(pmctx) &&
1166 !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED);
1167}
Nikolay Aleksandrov4cdd0d12021-07-19 20:06:31 +03001168
1169static inline bool
1170br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx)
1171{
1172 return pmctx->port->state == BR_STATE_DISABLED ||
1173 (br_multicast_port_ctx_is_vlan(pmctx) &&
1174 (br_multicast_port_ctx_vlan_disabled(pmctx) ||
1175 pmctx->vlan->state == BR_STATE_DISABLED));
1176}
1177
1178static inline bool
1179br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx)
1180{
1181 return br_multicast_port_ctx_state_disabled(pmctx) ||
1182 pmctx->port->state == BR_STATE_BLOCKING ||
1183 (br_multicast_port_ctx_is_vlan(pmctx) &&
1184 pmctx->vlan->state == BR_STATE_BLOCKING);
1185}
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +03001186
1187static inline bool
Nikolay Aleksandrovdc002872021-08-10 18:29:33 +03001188br_rports_have_mc_router(const struct net_bridge_mcast *brmctx)
1189{
1190#if IS_ENABLED(CONFIG_IPV6)
1191 return !hlist_empty(&brmctx->ip4_mc_router_list) ||
1192 !hlist_empty(&brmctx->ip6_mc_router_list);
1193#else
1194 return !hlist_empty(&brmctx->ip4_mc_router_list);
1195#endif
1196}
1197
1198static inline bool
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +03001199br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1,
1200 const struct net_bridge_mcast *brmctx2)
1201{
1202 return brmctx1->multicast_igmp_version ==
1203 brmctx2->multicast_igmp_version &&
Nikolay Aleksandrov931ba872021-08-10 18:29:20 +03001204 brmctx1->multicast_last_member_count ==
1205 brmctx2->multicast_last_member_count &&
Nikolay Aleksandrov50725f62021-08-10 18:29:21 +03001206 brmctx1->multicast_startup_query_count ==
1207 brmctx2->multicast_startup_query_count &&
Nikolay Aleksandrov77f6aba2021-08-10 18:29:22 +03001208 brmctx1->multicast_last_member_interval ==
1209 brmctx2->multicast_last_member_interval &&
Nikolay Aleksandrov2da0aea2021-08-10 18:29:23 +03001210 brmctx1->multicast_membership_interval ==
1211 brmctx2->multicast_membership_interval &&
Nikolay Aleksandrovcd9269d2021-08-10 18:29:24 +03001212 brmctx1->multicast_querier_interval ==
1213 brmctx2->multicast_querier_interval &&
Nikolay Aleksandrovd6c08ab2021-08-10 18:29:25 +03001214 brmctx1->multicast_query_interval ==
1215 brmctx2->multicast_query_interval &&
Nikolay Aleksandrov42521452021-08-10 18:29:26 +03001216 brmctx1->multicast_query_response_interval ==
1217 brmctx2->multicast_query_response_interval &&
Nikolay Aleksandrov941121e2021-08-10 18:29:27 +03001218 brmctx1->multicast_startup_query_interval ==
1219 brmctx2->multicast_startup_query_interval &&
Nikolay Aleksandrov62938182021-08-10 18:29:30 +03001220 brmctx1->multicast_querier == brmctx2->multicast_querier &&
Nikolay Aleksandrova97df082021-08-10 18:29:31 +03001221 brmctx1->multicast_router == brmctx2->multicast_router &&
Nikolay Aleksandrovdc002872021-08-10 18:29:33 +03001222 !br_rports_have_mc_router(brmctx1) &&
1223 !br_rports_have_mc_router(brmctx2) &&
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +03001224#if IS_ENABLED(CONFIG_IPV6)
1225 brmctx1->multicast_mld_version ==
1226 brmctx2->multicast_mld_version &&
1227#endif
1228 true;
1229}
Nikolay Aleksandrovcb486ce2021-08-10 18:29:29 +03001230
1231static inline bool
1232br_multicast_ctx_matches_vlan_snooping(const struct net_bridge_mcast *brmctx)
1233{
1234 bool vlan_snooping_enabled;
1235
1236 vlan_snooping_enabled = !!br_opt_get(brmctx->br,
1237 BROPT_MCAST_VLAN_SNOOPING_ENABLED);
1238
1239 return !!(vlan_snooping_enabled == br_multicast_ctx_is_vlan(brmctx));
1240}
Herbert Xueb1d1642010-02-27 19:41:45 +00001241#else
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001242static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx,
1243 struct net_bridge_mcast_port **pmctx,
1244 struct net_bridge_vlan *vlan,
Vlad Yasevich06499092013-10-28 15:45:07 -04001245 struct sk_buff *skb,
1246 u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +00001247{
1248 return 0;
1249}
1250
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001251static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx,
Cong Wangfbca58a2013-03-07 03:05:33 +00001252 struct sk_buff *skb, u16 vid)
Herbert Xueb1d1642010-02-27 19:41:45 +00001253{
1254 return NULL;
1255}
1256
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001257static inline int br_multicast_add_port(struct net_bridge_port *port)
Herbert Xueb1d1642010-02-27 19:41:45 +00001258{
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001259 return 0;
Herbert Xueb1d1642010-02-27 19:41:45 +00001260}
1261
1262static inline void br_multicast_del_port(struct net_bridge_port *port)
1263{
1264}
1265
1266static inline void br_multicast_enable_port(struct net_bridge_port *port)
1267{
1268}
1269
1270static inline void br_multicast_disable_port(struct net_bridge_port *port)
1271{
1272}
1273
1274static inline void br_multicast_init(struct net_bridge *br)
1275{
1276}
1277
Joseph Huang851d0a72020-12-04 18:56:28 -05001278static inline void br_multicast_join_snoopers(struct net_bridge *br)
1279{
1280}
1281
1282static inline void br_multicast_leave_snoopers(struct net_bridge *br)
1283{
1284}
1285
Herbert Xueb1d1642010-02-27 19:41:45 +00001286static inline void br_multicast_open(struct net_bridge *br)
1287{
1288}
1289
1290static inline void br_multicast_stop(struct net_bridge *br)
1291{
1292}
Herbert Xu5cb5e942010-02-27 19:41:46 +00001293
Nikolay Aleksandrova7ce45a2015-07-20 23:03:45 +02001294static inline void br_multicast_dev_del(struct net_bridge *br)
1295{
1296}
1297
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +03001298static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
1299 struct sk_buff *skb,
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001300 struct net_bridge_mcast *brmctx,
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +03001301 bool local_rcv, bool local_orig)
Herbert Xu5cb5e942010-02-27 19:41:46 +00001302{
1303}
1304
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001305static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx,
Nikolay Aleksandrovbbc6f2c2021-05-14 10:32:33 +03001306 struct sk_buff *skb)
Herbert Xueb1d1642010-02-27 19:41:45 +00001307{
Gustavo A. R. Silva03aaa9e2018-01-18 17:37:45 -06001308 return false;
Herbert Xueb1d1642010-02-27 19:41:45 +00001309}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +03001310
Nikolay Aleksandrovadc47032021-07-19 20:06:25 +03001311static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx,
Vladimir Olteanc43fd362020-11-01 02:08:45 +02001312 struct ethhdr *eth,
1313 const struct net_bridge_mdb_entry *mdb)
Linus Lüssingb00589a2013-08-01 01:06:20 +02001314{
1315 return false;
1316}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +03001317
Rami Rosenfdb184d2013-01-03 13:30:43 +02001318static inline void br_mdb_init(void)
1319{
1320}
Nikolay Aleksandrov37b090e2016-07-14 06:10:02 +03001321
Rami Rosenfdb184d2013-01-03 13:30:43 +02001322static inline void br_mdb_uninit(void)
1323{
1324}
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001325
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +02001326static inline int br_mdb_hash_init(struct net_bridge *br)
1327{
1328 return 0;
1329}
1330
1331static inline void br_mdb_hash_fini(struct net_bridge *br)
1332{
1333}
1334
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001335static inline void br_multicast_count(struct net_bridge *br,
1336 const struct net_bridge_port *p,
Nikolay Aleksandrova65056e2016-07-06 12:12:21 -07001337 const struct sk_buff *skb,
1338 u8 type, u8 dir)
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001339{
1340}
1341
1342static inline int br_multicast_init_stats(struct net_bridge *br)
1343{
1344 return 0;
1345}
1346
Ido Schimmelb6fe0442017-04-10 14:59:27 +03001347static inline void br_multicast_uninit_stats(struct net_bridge *br)
1348{
1349}
1350
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +02001351static inline int br_multicast_igmp_type(const struct sk_buff *skb)
1352{
1353 return 0;
1354}
Nikolay Aleksandrov613d61d2021-07-19 20:06:26 +03001355
1356static inline void br_multicast_ctx_init(struct net_bridge *br,
1357 struct net_bridge_vlan *vlan,
1358 struct net_bridge_mcast *brmctx)
1359{
1360}
1361
1362static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx)
1363{
1364}
1365
1366static inline void br_multicast_port_ctx_init(struct net_bridge_port *port,
1367 struct net_bridge_vlan *vlan,
1368 struct net_bridge_mcast_port *pmctx)
1369{
1370}
1371
1372static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx)
1373{
1374}
Nikolay Aleksandrov7b54aaa2021-07-19 20:06:27 +03001375
1376static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan,
1377 bool on)
1378{
1379}
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001380
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001381static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br,
1382 bool on,
1383 struct netlink_ext_ack *extack)
1384{
1385 return -EOPNOTSUPP;
1386}
Nikolay Aleksandrov9dee5722021-07-19 20:06:37 +03001387
1388static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan,
1389 bool on)
1390{
1391 return false;
1392}
Vladimir Oltean4e51bf42021-07-21 19:24:03 +03001393
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +03001394static inline bool
1395br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1,
1396 const struct net_bridge_mcast *brmctx2)
1397{
1398 return true;
1399}
Sridhar Samudrala85b35262010-03-01 09:53:04 +00001400#endif
Herbert Xueb1d1642010-02-27 19:41:45 +00001401
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001402/* br_vlan.c */
1403#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001404bool br_allowed_ingress(const struct net_bridge *br,
1405 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001406 u16 *vid, u8 *state,
1407 struct net_bridge_vlan **vlan);
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001408bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -07001409 const struct sk_buff *skb);
Toshiaki Makitae0d79682014-05-26 15:15:53 +09001410bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
Joe Perches348662a2013-10-18 13:48:22 -07001411struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -08001412 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001413 struct net_bridge_vlan_group *vg,
Joe Perches348662a2013-10-18 13:48:22 -07001414 struct sk_buff *skb);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001415int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +00001416 bool *changed, struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -07001417int br_vlan_delete(struct net_bridge *br, u16 vid);
1418void br_vlan_flush(struct net_bridge *br);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001419struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +09001420void br_recalculate_fwd_mask(struct net_bridge *br);
Vladimir Oltean9e781402021-02-13 22:43:16 +02001421int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val,
1422 struct netlink_ext_ack *extack);
Vladimir Olteandcbdf132021-02-13 22:43:17 +02001423int __br_vlan_set_proto(struct net_bridge *br, __be16 proto,
1424 struct netlink_ext_ack *extack);
Vladimir Oltean9e781402021-02-13 22:43:16 +02001425int br_vlan_set_proto(struct net_bridge *br, unsigned long val,
1426 struct netlink_ext_ack *extack);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +02001427int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +03001428int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001429int br_vlan_init(struct net_bridge *br);
Vladimir Oltean9e781402021-02-13 22:43:16 +02001430int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val,
1431 struct netlink_ext_ack *extack);
Petr Machata169327d2018-12-12 17:02:50 +00001432int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
1433 struct netlink_ext_ack *extack);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001434int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +00001435 bool *changed, struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -07001436int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
1437void nbp_vlan_flush(struct net_bridge_port *port);
Petr Machata169327d2018-12-12 17:02:50 +00001438int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001439int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001440void br_vlan_get_stats(const struct net_bridge_vlan *v,
Heiner Kallweit281cc282020-11-17 21:25:42 +01001441 struct pcpu_sw_netstats *stats);
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001442void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
Nikolay Aleksandrov091adf92019-08-02 13:57:36 +03001443int br_vlan_bridge_event(struct net_device *dev, unsigned long event,
1444 void *ptr);
Nikolay Aleksandrov8dcea182020-01-14 19:56:09 +02001445void br_vlan_rtnl_init(void);
1446void br_vlan_rtnl_uninit(void);
Nikolay Aleksandrovcf5bddb2020-01-14 19:56:13 +02001447void br_vlan_notify(const struct net_bridge *br,
1448 const struct net_bridge_port *p,
1449 u16 vid, u16 vid_range,
1450 int cmd);
Nikolay Aleksandrova5d29ae2020-01-24 13:40:21 +02001451bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1452 const struct net_bridge_vlan *range_end);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001453
Felix Fietkaubcf27662021-03-24 02:30:35 +01001454void br_vlan_fill_forward_path_pvid(struct net_bridge *br,
1455 struct net_device_path_ctx *ctx,
1456 struct net_device_path *path);
1457int br_vlan_fill_forward_path_mode(struct net_bridge *br,
1458 struct net_bridge_port *dst,
1459 struct net_device_path *path);
1460
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001461static inline struct net_bridge_vlan_group *br_vlan_group(
1462 const struct net_bridge *br)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001463{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001464 return rtnl_dereference(br->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001465}
1466
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001467static inline struct net_bridge_vlan_group *nbp_vlan_group(
1468 const struct net_bridge_port *p)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001469{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001470 return rtnl_dereference(p->vlgrp);
1471}
1472
1473static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1474 const struct net_bridge *br)
1475{
1476 return rcu_dereference(br->vlgrp);
1477}
1478
1479static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1480 const struct net_bridge_port *p)
1481{
1482 return rcu_dereference(p->vlgrp);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001483}
1484
1485/* Since bridge now depends on 8021Q module, but the time bridge sees the
1486 * skb, the vlan tag will always be present if the frame was tagged.
1487 */
1488static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
1489{
1490 int err = 0;
1491
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001492 if (skb_vlan_tag_present(skb)) {
Michał Mirosław5978f8a2018-11-09 00:18:03 +01001493 *vid = skb_vlan_tag_get_id(skb);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001494 } else {
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001495 *vid = 0;
1496 err = -EINVAL;
1497 }
1498
1499 return err;
1500}
Vlad Yasevich78851982013-02-13 12:00:14 +00001501
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001502static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +00001503{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001504 if (!vg)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001505 return 0;
1506
Vlad Yasevich78851982013-02-13 12:00:14 +00001507 smp_rmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001508 return vg->pvid;
Vlad Yasevich78851982013-02-13 12:00:14 +00001509}
1510
Nikolay Aleksandrov8dcea182020-01-14 19:56:09 +02001511static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1512{
1513 return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags;
1514}
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001515#else
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001516static inline bool br_allowed_ingress(const struct net_bridge *br,
1517 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +00001518 struct sk_buff *skb,
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001519 u16 *vid, u8 *state,
1520 struct net_bridge_vlan **vlan)
1521
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001522{
Nikolay Aleksandrovf4b70022021-07-19 20:06:28 +03001523 *vlan = NULL;
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001524 return true;
1525}
1526
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001527static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +00001528 const struct sk_buff *skb)
1529{
1530 return true;
1531}
1532
Toshiaki Makitae0d79682014-05-26 15:15:53 +09001533static inline bool br_should_learn(struct net_bridge_port *p,
1534 struct sk_buff *skb, u16 *vid)
1535{
1536 return true;
1537}
1538
Vlad Yasevich78851982013-02-13 12:00:14 +00001539static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -08001540 const struct net_bridge_port *port,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001541 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +00001542 struct sk_buff *skb)
1543{
1544 return skb;
1545}
1546
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001547static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +00001548 bool *changed, struct netlink_ext_ack *extack)
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001549{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001550 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001551 return -EOPNOTSUPP;
1552}
1553
1554static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
1555{
1556 return -EOPNOTSUPP;
1557}
1558
1559static inline void br_vlan_flush(struct net_bridge *br)
1560{
1561}
1562
Toshiaki Makita204177f2014-06-10 20:59:25 +09001563static inline void br_recalculate_fwd_mask(struct net_bridge *br)
1564{
1565}
1566
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001567static inline int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +09001568{
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001569 return 0;
Toshiaki Makita8580e212014-06-10 20:59:23 +09001570}
1571
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001572static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
Petr Machata169327d2018-12-12 17:02:50 +00001573 bool *changed, struct netlink_ext_ack *extack)
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001574{
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001575 *changed = false;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001576 return -EOPNOTSUPP;
1577}
1578
1579static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1580{
1581 return -EOPNOTSUPP;
1582}
1583
1584static inline void nbp_vlan_flush(struct net_bridge_port *port)
1585{
1586}
1587
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001588static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
1589 u16 vid)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001590{
1591 return NULL;
1592}
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +00001593
Petr Machata169327d2018-12-12 17:02:50 +00001594static inline int nbp_vlan_init(struct net_bridge_port *port,
1595 struct netlink_ext_ack *extack)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001596{
1597 return 0;
1598}
1599
Vlad Yasevich78851982013-02-13 12:00:14 +00001600static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +00001601{
1602 return 0;
1603}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001604
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +02001605static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
Vlad Yasevich78851982013-02-13 12:00:14 +00001606{
Vlad Yasevich3df6bf42014-10-03 11:29:17 -04001607 return 0;
Vlad Yasevich78851982013-02-13 12:00:14 +00001608}
Vlad Yasevich2796d0c2014-05-16 09:59:20 -04001609
Vladimir Oltean7a572962021-02-13 22:43:15 +02001610static inline int br_vlan_filter_toggle(struct net_bridge *br,
Vladimir Olteanc97f47e2021-02-15 23:09:12 +02001611 unsigned long val,
1612 struct netlink_ext_ack *extack)
Nikolay Aleksandrova7854032015-08-07 19:40:45 +03001613{
1614 return -EOPNOTSUPP;
1615}
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001616
1617static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
1618 u32 filter_mask)
1619{
1620 return 0;
1621}
1622
Felix Fietkaubcf27662021-03-24 02:30:35 +01001623static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br,
1624 struct net_device_path_ctx *ctx,
1625 struct net_device_path *path)
1626{
1627}
1628
1629static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br,
1630 struct net_bridge_port *dst,
1631 struct net_device_path *path)
1632{
1633 return 0;
1634}
1635
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001636static inline struct net_bridge_vlan_group *br_vlan_group(
1637 const struct net_bridge *br)
1638{
1639 return NULL;
1640}
1641
1642static inline struct net_bridge_vlan_group *nbp_vlan_group(
1643 const struct net_bridge_port *p)
1644{
1645 return NULL;
1646}
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001647
1648static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
1649 const struct net_bridge *br)
1650{
1651 return NULL;
1652}
1653
1654static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
1655 const struct net_bridge_port *p)
1656{
1657 return NULL;
1658}
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001659
1660static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
Heiner Kallweit281cc282020-11-17 21:25:42 +01001661 struct pcpu_sw_netstats *stats)
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001662{
1663}
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001664
1665static inline void br_vlan_port_event(struct net_bridge_port *p,
1666 unsigned long event)
1667{
1668}
1669
Nikolay Aleksandrov091adf92019-08-02 13:57:36 +03001670static inline int br_vlan_bridge_event(struct net_device *dev,
1671 unsigned long event, void *ptr)
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001672{
Nikolay Aleksandrov091adf92019-08-02 13:57:36 +03001673 return 0;
Mike Manning9c0ec2e2019-04-18 18:35:33 +01001674}
Nikolay Aleksandrov8dcea182020-01-14 19:56:09 +02001675
1676static inline void br_vlan_rtnl_init(void)
1677{
1678}
1679
1680static inline void br_vlan_rtnl_uninit(void)
1681{
1682}
Nikolay Aleksandrovcf5bddb2020-01-14 19:56:13 +02001683
1684static inline void br_vlan_notify(const struct net_bridge *br,
1685 const struct net_bridge_port *p,
1686 u16 vid, u16 vid_range,
1687 int cmd)
1688{
1689}
Nikolay Aleksandrov528ae842020-07-13 10:55:46 +03001690
1691static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1692 const struct net_bridge_vlan *range_end)
1693{
1694 return true;
1695}
Vladimir Oltean4e51bf42021-07-21 19:24:03 +03001696
Vladimir Olteanc5f6e5e2021-10-27 19:21:15 +03001697static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1698{
1699 return 0;
1700}
1701
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001702#endif
1703
Nikolay Aleksandrov7a53e712020-01-24 13:40:20 +02001704/* br_vlan_options.c */
1705#ifdef CONFIG_BRIDGE_VLAN_FILTERING
Nikolay Aleksandrov99f7c5e2020-03-17 14:08:33 +02001706bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
1707 const struct net_bridge_vlan *range_end);
Nikolay Aleksandrov7a53e712020-01-24 13:40:20 +02001708bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
1709size_t br_vlan_opts_nl_size(void);
Nikolay Aleksandrova5d29ae2020-01-24 13:40:21 +02001710int br_vlan_process_options(const struct net_bridge *br,
1711 const struct net_bridge_port *p,
1712 struct net_bridge_vlan *range_start,
1713 struct net_bridge_vlan *range_end,
1714 struct nlattr **tb,
1715 struct netlink_ext_ack *extack);
Nikolay Aleksandrov47ecd2d2021-07-19 20:06:34 +03001716int br_vlan_rtm_process_global_options(struct net_device *dev,
1717 const struct nlattr *attr,
1718 int cmd,
1719 struct netlink_ext_ack *extack);
Nikolay Aleksandrov743a53d2021-07-19 20:06:35 +03001720bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr,
1721 const struct net_bridge_vlan *r_end);
1722bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
1723 const struct net_bridge_vlan *v_opts);
Nikolay Aleksandrova580c762020-01-24 13:40:22 +02001724
1725/* vlan state manipulation helpers using *_ONCE to annotate lock-free access */
1726static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v)
1727{
1728 return READ_ONCE(v->state);
1729}
1730
1731static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state)
1732{
1733 WRITE_ONCE(v->state, state);
1734}
1735
1736static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg)
1737{
1738 return READ_ONCE(vg->pvid_state);
1739}
1740
1741static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg,
1742 u8 state)
1743{
1744 WRITE_ONCE(vg->pvid_state, state);
1745}
1746
1747/* learn_allow is true at ingress and false at egress */
1748static inline bool br_vlan_state_allowed(u8 state, bool learn_allow)
1749{
1750 switch (state) {
1751 case BR_STATE_LEARNING:
1752 return learn_allow;
1753 case BR_STATE_FORWARDING:
1754 return true;
1755 default:
1756 return false;
1757 }
1758}
Nikolay Aleksandrov7a53e712020-01-24 13:40:20 +02001759#endif
1760
Pablo Neira Ayuso1a4ba642015-03-10 10:27:18 +01001761struct nf_br_ops {
1762 int (*br_dev_xmit_hook)(struct sk_buff *skb);
1763};
1764extern const struct nf_br_ops __rcu *nf_br_ops;
1765
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766/* br_netfilter.c */
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001767#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1768int br_nf_core_init(void);
1769void br_nf_core_fini(void);
Joe Perches348662a2013-10-18 13:48:22 -07001770void br_netfilter_rtable_init(struct net_bridge *);
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001771#else
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +02001772static inline int br_nf_core_init(void) { return 0; }
1773static inline void br_nf_core_fini(void) {}
Simon Wunderlich4adf0af2008-07-30 16:27:55 -07001774#define br_netfilter_rtable_init(x)
Stephen Hemmingerc0909712006-05-25 15:59:33 -07001775#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
1777/* br_stp.c */
Florian Fainelli775dd692014-09-30 16:13:19 -07001778void br_set_state(struct net_bridge_port *p, unsigned int state);
Joe Perches348662a2013-10-18 13:48:22 -07001779struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
1780void br_init_port(struct net_bridge_port *p);
1781void br_become_designated_port(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
Joe Perches348662a2013-10-18 13:48:22 -07001783void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
1784int br_set_forward_delay(struct net_bridge *br, unsigned long x);
1785int br_set_hello_time(struct net_bridge *br, unsigned long x);
1786int br_set_max_age(struct net_bridge *br, unsigned long x);
Vivien Didelot82dd4332016-12-10 13:44:27 -05001787int __set_ageing_time(struct net_device *dev, unsigned long t);
Vivien Didelot9e0b27f2016-07-21 12:42:19 -04001788int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
stephen hemminger14f98f22011-04-04 14:03:33 +00001789
1790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791/* br_stp_if.c */
Joe Perches348662a2013-10-18 13:48:22 -07001792void br_stp_enable_bridge(struct net_bridge *br);
1793void br_stp_disable_bridge(struct net_bridge *br);
Horatiu Vultur419dba8a2020-04-26 15:22:08 +02001794int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
1795 struct netlink_ext_ack *extack);
Joe Perches348662a2013-10-18 13:48:22 -07001796void br_stp_enable_port(struct net_bridge_port *p);
1797void br_stp_disable_port(struct net_bridge_port *p);
1798bool br_stp_recalculate_bridge_id(struct net_bridge *br);
1799void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
1800void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
1801int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
1802int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
1803ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805/* br_stp_bpdu.c */
Patrick McHardy7c85fbf2008-07-05 21:25:56 -07001806struct stp_proto;
Joe Perches348662a2013-10-18 13:48:22 -07001807void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
1808 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810/* br_stp_timer.c */
Joe Perches348662a2013-10-18 13:48:22 -07001811void br_stp_timer_init(struct net_bridge *br);
1812void br_stp_port_timer_init(struct net_bridge_port *p);
1813unsigned long br_timer_value(const struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
1815/* br.c */
Igor Maraviće6373c42011-12-12 02:58:25 +00001816#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +00001817extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
1818#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Horatiu Vultur65369932020-04-26 15:22:07 +02001820/* br_mrp.c */
1821#if IS_ENABLED(CONFIG_BRIDGE_MRP)
1822int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1823 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
Horatiu Vultur65369932020-04-26 15:22:07 +02001824bool br_mrp_enabled(struct net_bridge *br);
1825void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
Horatiu Vulturdf42ef222020-07-02 10:13:06 +02001826int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
Horatiu Vultur65369932020-04-26 15:22:07 +02001827#else
1828static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1829 struct nlattr *attr, int cmd,
1830 struct netlink_ext_ack *extack)
1831{
1832 return -EOPNOTSUPP;
1833}
1834
Horatiu Vultur65369932020-04-26 15:22:07 +02001835static inline bool br_mrp_enabled(struct net_bridge *br)
1836{
Jason Yan8741e182020-05-06 14:16:16 +08001837 return false;
Horatiu Vultur65369932020-04-26 15:22:07 +02001838}
1839
1840static inline void br_mrp_port_del(struct net_bridge *br,
1841 struct net_bridge_port *p)
1842{
1843}
Horatiu Vulturdf42ef222020-07-02 10:13:06 +02001844
1845static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
1846{
1847 return 0;
1848}
1849
Horatiu Vultur65369932020-04-26 15:22:07 +02001850#endif
1851
Henrik Bjoernlund2be665c2020-10-27 10:02:48 +00001852/* br_cfm.c */
Henrik Bjoernlund86a14b72020-10-27 10:02:45 +00001853#if IS_ENABLED(CONFIG_BRIDGE_CFM)
Henrik Bjoernlund2be665c2020-10-27 10:02:48 +00001854int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
1855 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1856bool br_cfm_created(struct net_bridge *br);
Henrik Bjoernlund86a14b72020-10-27 10:02:45 +00001857void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p);
Henrik Bjoernlund5e312fc2020-10-27 10:02:49 +00001858int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br);
Henrik Bjoernlundb6d04252020-10-27 10:02:51 +00001859int br_cfm_status_fill_info(struct sk_buff *skb,
1860 struct net_bridge *br,
1861 bool getlink);
1862int br_cfm_mep_count(struct net_bridge *br, u32 *count);
1863int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count);
Henrik Bjoernlund86a14b72020-10-27 10:02:45 +00001864#else
Henrik Bjoernlund2be665c2020-10-27 10:02:48 +00001865static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
1866 struct nlattr *attr, int cmd,
1867 struct netlink_ext_ack *extack)
1868{
1869 return -EOPNOTSUPP;
1870}
1871
1872static inline bool br_cfm_created(struct net_bridge *br)
1873{
1874 return false;
1875}
1876
Henrik Bjoernlund86a14b72020-10-27 10:02:45 +00001877static inline void br_cfm_port_del(struct net_bridge *br,
1878 struct net_bridge_port *p)
1879{
1880}
Henrik Bjoernlund5e312fc2020-10-27 10:02:49 +00001881
1882static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br)
1883{
1884 return -EOPNOTSUPP;
1885}
Henrik Bjoernlunde77824d2020-10-27 10:02:50 +00001886
Henrik Bjoernlundb6d04252020-10-27 10:02:51 +00001887static inline int br_cfm_status_fill_info(struct sk_buff *skb,
1888 struct net_bridge *br,
1889 bool getlink)
1890{
1891 return -EOPNOTSUPP;
1892}
1893
1894static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count)
1895{
Ivan Vecera829e0502021-10-28 17:58:35 +02001896 *count = 0;
Henrik Bjoernlundb6d04252020-10-27 10:02:51 +00001897 return -EOPNOTSUPP;
1898}
1899
1900static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count)
Henrik Bjoernlunde77824d2020-10-27 10:02:50 +00001901{
Ivan Vecera829e0502021-10-28 17:58:35 +02001902 *count = 0;
Henrik Bjoernlunde77824d2020-10-27 10:02:50 +00001903 return -EOPNOTSUPP;
1904}
Henrik Bjoernlund86a14b72020-10-27 10:02:45 +00001905#endif
1906
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001907/* br_netlink.c */
stephen hemminger149ddd82012-06-26 05:48:45 +00001908extern struct rtnl_link_ops br_link_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001909int br_netlink_init(void);
1910void br_netlink_fini(void);
Nikolay Aleksandrov92899062017-11-01 12:18:13 +02001911void br_ifinfo_notify(int event, const struct net_bridge *br,
1912 const struct net_bridge_port *port);
Henrik Bjoernlundb6d04252020-10-27 10:02:51 +00001913void br_info_notify(int event, const struct net_bridge *br,
1914 const struct net_bridge_port *port, u32 filter);
Petr Machata2fd527b2018-12-12 17:02:48 +00001915int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1916 struct netlink_ext_ack *extack);
Roopa Prabhuadd511b2015-01-29 22:40:12 -08001917int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
Joe Perches348662a2013-10-18 13:48:22 -07001918int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02001919 u32 filter_mask, int nlflags);
Nikolay Aleksandrovf26b2962020-01-14 19:56:10 +02001920int br_process_vlan_info(struct net_bridge *br,
1921 struct net_bridge_port *p, int cmd,
1922 struct bridge_vlan_info *vinfo_curr,
1923 struct bridge_vlan_info **vinfo_last,
1924 bool *changed,
1925 struct netlink_ext_ack *extack);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927#ifdef CONFIG_SYSFS
1928/* br_sysfs_if.c */
Emese Revfy52cf25d2010-01-19 02:58:23 +01001929extern const struct sysfs_ops brport_sysfs_ops;
Joe Perches348662a2013-10-18 13:48:22 -07001930int br_sysfs_addif(struct net_bridge_port *p);
1931int br_sysfs_renameif(struct net_bridge_port *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933/* br_sysfs_br.c */
Joe Perches348662a2013-10-18 13:48:22 -07001934int br_sysfs_addbr(struct net_device *dev);
1935void br_sysfs_delbr(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
1937#else
1938
Lee Jones0cb2bbb2012-11-03 23:02:30 +01001939static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
1940static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
1941static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
1942static inline void br_sysfs_delbr(struct net_device *dev) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943#endif /* CONFIG_SYSFS */
1944
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001945/* br_switchdev.c */
1946#ifdef CONFIG_NET_SWITCHDEV
Vladimir Oltean957e2232021-08-03 23:34:08 +03001947int br_switchdev_port_offload(struct net_bridge_port *p,
1948 struct net_device *dev, const void *ctx,
1949 struct notifier_block *atomic_nb,
1950 struct notifier_block *blocking_nb,
1951 bool tx_fwd_offload,
1952 struct netlink_ext_ack *extack);
1953
1954void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
1955 struct notifier_block *atomic_nb,
1956 struct notifier_block *blocking_nb);
1957
Tobias Waldekranz47211192021-07-22 18:55:38 +03001958bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb);
1959
Vladimir Olteanc5381152021-07-23 23:49:11 +03001960void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb);
1961
Tobias Waldekranz47211192021-07-22 18:55:38 +03001962void nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p,
1963 struct sk_buff *skb);
1964void nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p,
1965 struct sk_buff *skb);
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001966void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
1967 struct sk_buff *skb);
1968bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
1969 const struct sk_buff *skb);
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02001970int br_switchdev_set_port_flag(struct net_bridge_port *p,
1971 unsigned long flags,
Vladimir Oltean078bbb82021-02-12 17:15:53 +02001972 unsigned long mask,
1973 struct netlink_ext_ack *extack);
Tobias Waldekranz6eb38bf2021-06-29 17:06:45 +03001974void br_switchdev_fdb_notify(struct net_bridge *br,
1975 const struct net_bridge_fdb_entry *fdb, int type);
Vladimir Olteanae039352021-10-30 01:36:06 +03001976void br_switchdev_mdb_notify(struct net_device *dev,
1977 struct net_bridge_mdb_entry *mp,
1978 struct net_bridge_port_group *pg,
1979 int type);
Petr Machata169327d2018-12-12 17:02:50 +00001980int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1981 struct netlink_ext_ack *extack);
Petr Machatad66e4342018-05-30 02:56:03 +02001982int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
Tobias Waldekranz85826612021-07-21 19:24:00 +03001983void br_switchdev_init(struct net_bridge *br);
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03001984
1985static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
1986{
1987 skb->offload_fwd_mark = 0;
1988}
Ido Schimmel6bc506b2016-08-25 18:42:37 +02001989#else
Vladimir Oltean957e2232021-08-03 23:34:08 +03001990static inline int
1991br_switchdev_port_offload(struct net_bridge_port *p,
1992 struct net_device *dev, const void *ctx,
1993 struct notifier_block *atomic_nb,
1994 struct notifier_block *blocking_nb,
1995 bool tx_fwd_offload,
1996 struct netlink_ext_ack *extack)
1997{
1998 return -EOPNOTSUPP;
1999}
2000
2001static inline void
2002br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
2003 struct notifier_block *atomic_nb,
2004 struct notifier_block *blocking_nb)
2005{
2006}
2007
Tobias Waldekranz47211192021-07-22 18:55:38 +03002008static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb)
2009{
2010 return false;
2011}
2012
Vladimir Olteanc5381152021-07-23 23:49:11 +03002013static inline void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb)
2014{
2015}
2016
Tobias Waldekranz47211192021-07-22 18:55:38 +03002017static inline void
2018nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p,
2019 struct sk_buff *skb)
2020{
2021}
2022
2023static inline void
2024nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p,
2025 struct sk_buff *skb)
2026{
2027}
2028
Ido Schimmel6bc506b2016-08-25 18:42:37 +02002029static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p,
2030 struct sk_buff *skb)
2031{
2032}
2033
2034static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p,
2035 const struct sk_buff *skb)
2036{
2037 return true;
2038}
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02002039
2040static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
2041 unsigned long flags,
Vladimir Oltean078bbb82021-02-12 17:15:53 +02002042 unsigned long mask,
2043 struct netlink_ext_ack *extack)
Arkadi Sharshevsky39222852017-06-08 08:44:11 +02002044{
2045 return 0;
2046}
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02002047
Petr Machatad66e4342018-05-30 02:56:03 +02002048static inline int br_switchdev_port_vlan_add(struct net_device *dev,
Petr Machata169327d2018-12-12 17:02:50 +00002049 u16 vid, u16 flags,
2050 struct netlink_ext_ack *extack)
Petr Machatad66e4342018-05-30 02:56:03 +02002051{
2052 return -EOPNOTSUPP;
2053}
2054
2055static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
2056{
2057 return -EOPNOTSUPP;
2058}
2059
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02002060static inline void
Tobias Waldekranz6eb38bf2021-06-29 17:06:45 +03002061br_switchdev_fdb_notify(struct net_bridge *br,
2062 const struct net_bridge_fdb_entry *fdb, int type)
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +02002063{
2064}
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03002065
Vladimir Olteanae039352021-10-30 01:36:06 +03002066static inline void br_switchdev_mdb_notify(struct net_device *dev,
2067 struct net_bridge_mdb_entry *mp,
2068 struct net_bridge_port_group *pg,
2069 int type)
2070{
2071}
2072
Ido Schimmelf1c2edd2017-09-03 17:44:13 +03002073static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
2074{
2075}
Tobias Waldekranz85826612021-07-21 19:24:00 +03002076
Tobias Waldekranz85826612021-07-21 19:24:00 +03002077static inline void br_switchdev_init(struct net_bridge *br)
2078{
2079}
2080
Ido Schimmel6bc506b2016-08-25 18:42:37 +02002081#endif /* CONFIG_NET_SWITCHDEV */
2082
Roopa Prabhu057658c2017-10-06 22:12:38 -07002083/* br_arp_nd_proxy.c */
Roopa Prabhu821f1b22017-10-06 22:12:37 -07002084void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
Roopa Prabhu057658c2017-10-06 22:12:38 -07002085void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
2086 u16 vid, struct net_bridge_port *p);
Roopa Prabhued842fa2017-10-06 22:12:39 -07002087void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
2088 u16 vid, struct net_bridge_port *p, struct nd_msg *msg);
2089struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090#endif