| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
|---|
| 2 | /* | 
|---|
| 3 | *	Linux ethernet bridge | 
|---|
| 4 | * | 
|---|
| 5 | *	Authors: | 
|---|
| 6 | *	Lennert Buytenhek		<buytenh@gnu.org> | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef _BR_PRIVATE_H | 
|---|
| 10 | #define _BR_PRIVATE_H | 
|---|
| 11 |  | 
|---|
| 12 | #include <linux/netdevice.h> | 
|---|
| 13 | #include <linux/if_bridge.h> | 
|---|
| 14 | #include <linux/netpoll.h> | 
|---|
| 15 | #include <linux/u64_stats_sync.h> | 
|---|
| 16 | #include <net/route.h> | 
|---|
| 17 | #include <net/ip6_fib.h> | 
|---|
| 18 | #include <net/pkt_cls.h> | 
|---|
| 19 | #include <linux/if_vlan.h> | 
|---|
| 20 | #include <linux/rhashtable.h> | 
|---|
| 21 | #include <linux/refcount.h> | 
|---|
| 22 |  | 
|---|
| 23 | #define BR_HASH_BITS 8 | 
|---|
| 24 | #define BR_HASH_SIZE (1 << BR_HASH_BITS) | 
|---|
| 25 |  | 
|---|
| 26 | #define BR_HOLD_TIME (1*HZ) | 
|---|
| 27 |  | 
|---|
| 28 | #define BR_PORT_BITS	10 | 
|---|
| 29 | #define BR_MAX_PORTS	(1<<BR_PORT_BITS) | 
|---|
| 30 |  | 
|---|
| 31 | #define BR_MULTICAST_DEFAULT_HASH_MAX 4096 | 
|---|
| 32 | #define BR_MULTICAST_QUERY_INTVL_MIN msecs_to_jiffies(1000) | 
|---|
| 33 | #define BR_MULTICAST_STARTUP_QUERY_INTVL_MIN BR_MULTICAST_QUERY_INTVL_MIN | 
|---|
| 34 | #define BR_MULTICAST_QUERY_INTVL_MAX msecs_to_jiffies(86400000) /* 24 hours */ | 
|---|
| 35 | #define BR_MULTICAST_STARTUP_QUERY_INTVL_MAX BR_MULTICAST_QUERY_INTVL_MAX | 
|---|
| 36 |  | 
|---|
| 37 | #define BR_HWDOM_MAX BITS_PER_LONG | 
|---|
| 38 |  | 
|---|
| 39 | #define BR_VERSION	"2.3" | 
|---|
| 40 |  | 
|---|
| 41 | /* Control of forwarding link local multicast */ | 
|---|
| 42 | #define BR_GROUPFWD_DEFAULT	0 | 
|---|
| 43 | /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */ | 
|---|
| 44 | enum { | 
|---|
| 45 | BR_GROUPFWD_STP		= BIT(0), | 
|---|
| 46 | BR_GROUPFWD_MACPAUSE	= BIT(1), | 
|---|
| 47 | BR_GROUPFWD_LACP	= BIT(2), | 
|---|
| 48 | }; | 
|---|
| 49 |  | 
|---|
| 50 | #define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \ | 
|---|
| 51 | BR_GROUPFWD_LACP) | 
|---|
| 52 | /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */ | 
|---|
| 53 | #define BR_GROUPFWD_8021AD	0xB801u | 
|---|
| 54 |  | 
|---|
| 55 | /* Path to usermode spanning tree program */ | 
|---|
| 56 | #define BR_STP_PROG	"/sbin/bridge-stp" | 
|---|
| 57 |  | 
|---|
| 58 | #define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT) | 
|---|
| 59 |  | 
|---|
| 60 | typedef struct bridge_id bridge_id; | 
|---|
| 61 | typedef struct mac_addr mac_addr; | 
|---|
| 62 | typedef __u16 port_id; | 
|---|
| 63 |  | 
|---|
| 64 | struct bridge_id { | 
|---|
| 65 | unsigned char	prio[2]; | 
|---|
| 66 | unsigned char	addr[ETH_ALEN]; | 
|---|
| 67 | }; | 
|---|
| 68 |  | 
|---|
| 69 | struct mac_addr { | 
|---|
| 70 | unsigned char	addr[ETH_ALEN]; | 
|---|
| 71 | }; | 
|---|
| 72 |  | 
|---|
| 73 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 74 | /* our own querier */ | 
|---|
| 75 | struct bridge_mcast_own_query { | 
|---|
| 76 | struct timer_list	timer; | 
|---|
| 77 | u32			startup_sent; | 
|---|
| 78 | }; | 
|---|
| 79 |  | 
|---|
| 80 | /* other querier */ | 
|---|
| 81 | struct bridge_mcast_other_query { | 
|---|
| 82 | struct timer_list		timer; | 
|---|
| 83 | struct timer_list		delay_timer; | 
|---|
| 84 | }; | 
|---|
| 85 |  | 
|---|
| 86 | /* selected querier */ | 
|---|
| 87 | struct bridge_mcast_querier { | 
|---|
| 88 | struct br_ip addr; | 
|---|
| 89 | int port_ifidx; | 
|---|
| 90 | seqcount_spinlock_t seq; | 
|---|
| 91 | }; | 
|---|
| 92 |  | 
|---|
| 93 | /* IGMP/MLD statistics */ | 
|---|
| 94 | struct bridge_mcast_stats { | 
|---|
| 95 | struct br_mcast_stats mstats; | 
|---|
| 96 | struct u64_stats_sync syncp; | 
|---|
| 97 | }; | 
|---|
| 98 |  | 
|---|
| 99 | struct br_mdb_src_entry { | 
|---|
| 100 | struct br_ip			addr; | 
|---|
| 101 | }; | 
|---|
| 102 |  | 
|---|
| 103 | struct br_mdb_config { | 
|---|
| 104 | struct net_bridge		*br; | 
|---|
| 105 | struct net_bridge_port		*p; | 
|---|
| 106 | struct br_mdb_entry		*entry; | 
|---|
| 107 | struct br_ip			group; | 
|---|
| 108 | bool				src_entry; | 
|---|
| 109 | u8				filter_mode; | 
|---|
| 110 | u16				nlflags; | 
|---|
| 111 | struct br_mdb_src_entry		*src_entries; | 
|---|
| 112 | int				num_src_entries; | 
|---|
| 113 | u8				rt_protocol; | 
|---|
| 114 | }; | 
|---|
| 115 | #endif | 
|---|
| 116 |  | 
|---|
| 117 | /* net_bridge_mcast_port must be always defined due to forwarding stubs */ | 
|---|
| 118 | struct net_bridge_mcast_port { | 
|---|
| 119 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 120 | struct net_bridge_port		*port; | 
|---|
| 121 | struct net_bridge_vlan		*vlan; | 
|---|
| 122 |  | 
|---|
| 123 | struct bridge_mcast_own_query	ip4_own_query; | 
|---|
| 124 | struct timer_list		ip4_mc_router_timer; | 
|---|
| 125 | struct hlist_node		ip4_rlist; | 
|---|
| 126 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 127 | struct bridge_mcast_own_query	ip6_own_query; | 
|---|
| 128 | struct timer_list		ip6_mc_router_timer; | 
|---|
| 129 | struct hlist_node		ip6_rlist; | 
|---|
| 130 | #endif /* IS_ENABLED(CONFIG_IPV6) */ | 
|---|
| 131 | unsigned char			multicast_router; | 
|---|
| 132 | u32				mdb_n_entries; | 
|---|
| 133 | u32				mdb_max_entries; | 
|---|
| 134 | #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */ | 
|---|
| 135 | }; | 
|---|
| 136 |  | 
|---|
| 137 | /* net_bridge_mcast must be always defined due to forwarding stubs */ | 
|---|
| 138 | struct net_bridge_mcast { | 
|---|
| 139 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 140 | struct net_bridge		*br; | 
|---|
| 141 | struct net_bridge_vlan		*vlan; | 
|---|
| 142 |  | 
|---|
| 143 | u32				multicast_last_member_count; | 
|---|
| 144 | u32				multicast_startup_query_count; | 
|---|
| 145 |  | 
|---|
| 146 | u8				multicast_querier; | 
|---|
| 147 | u8				multicast_igmp_version; | 
|---|
| 148 | u8				multicast_router; | 
|---|
| 149 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 150 | u8				multicast_mld_version; | 
|---|
| 151 | #endif | 
|---|
| 152 | unsigned long			multicast_last_member_interval; | 
|---|
| 153 | unsigned long			multicast_membership_interval; | 
|---|
| 154 | unsigned long			multicast_querier_interval; | 
|---|
| 155 | unsigned long			multicast_query_interval; | 
|---|
| 156 | unsigned long			multicast_query_response_interval; | 
|---|
| 157 | unsigned long			multicast_startup_query_interval; | 
|---|
| 158 | struct hlist_head		ip4_mc_router_list; | 
|---|
| 159 | struct timer_list		ip4_mc_router_timer; | 
|---|
| 160 | struct bridge_mcast_other_query	ip4_other_query; | 
|---|
| 161 | struct bridge_mcast_own_query	ip4_own_query; | 
|---|
| 162 | struct bridge_mcast_querier	ip4_querier; | 
|---|
| 163 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 164 | struct hlist_head		ip6_mc_router_list; | 
|---|
| 165 | struct timer_list		ip6_mc_router_timer; | 
|---|
| 166 | struct bridge_mcast_other_query	ip6_other_query; | 
|---|
| 167 | struct bridge_mcast_own_query	ip6_own_query; | 
|---|
| 168 | struct bridge_mcast_querier	ip6_querier; | 
|---|
| 169 | #endif /* IS_ENABLED(CONFIG_IPV6) */ | 
|---|
| 170 | #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */ | 
|---|
| 171 | }; | 
|---|
| 172 |  | 
|---|
| 173 | struct br_tunnel_info { | 
|---|
| 174 | __be64				tunnel_id; | 
|---|
| 175 | struct metadata_dst __rcu	*tunnel_dst; | 
|---|
| 176 | }; | 
|---|
| 177 |  | 
|---|
| 178 | /* private vlan flags */ | 
|---|
| 179 | enum { | 
|---|
| 180 | BR_VLFLAG_PER_PORT_STATS = BIT(0), | 
|---|
| 181 | BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1), | 
|---|
| 182 | BR_VLFLAG_MCAST_ENABLED = BIT(2), | 
|---|
| 183 | BR_VLFLAG_GLOBAL_MCAST_ENABLED = BIT(3), | 
|---|
| 184 | BR_VLFLAG_NEIGH_SUPPRESS_ENABLED = BIT(4), | 
|---|
| 185 | }; | 
|---|
| 186 |  | 
|---|
| 187 | /** | 
|---|
| 188 | * struct net_bridge_vlan - per-vlan entry | 
|---|
| 189 | * | 
|---|
| 190 | * @vnode: rhashtable member | 
|---|
| 191 | * @tnode: rhashtable member | 
|---|
| 192 | * @vid: VLAN id | 
|---|
| 193 | * @flags: bridge vlan flags | 
|---|
| 194 | * @priv_flags: private (in-kernel) bridge vlan flags | 
|---|
| 195 | * @state: STP state (e.g. blocking, learning, forwarding) | 
|---|
| 196 | * @stats: per-cpu VLAN statistics | 
|---|
| 197 | * @br: if MASTER flag set, this points to a bridge struct | 
|---|
| 198 | * @port: if MASTER flag unset, this points to a port struct | 
|---|
| 199 | * @refcnt: if MASTER flag set, this is bumped for each port referencing it | 
|---|
| 200 | * @brvlan: if MASTER flag unset, this points to the global per-VLAN context | 
|---|
| 201 | *          for this VLAN entry | 
|---|
| 202 | * @tinfo: bridge tunnel info | 
|---|
| 203 | * @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context | 
|---|
| 204 | * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast | 
|---|
| 205 | *                  context | 
|---|
| 206 | * @msti: if MASTER flag set, this holds the VLANs MST instance | 
|---|
| 207 | * @vlist: sorted list of VLAN entries | 
|---|
| 208 | * @rcu: used for entry destruction | 
|---|
| 209 | * | 
|---|
| 210 | * This structure is shared between the global per-VLAN entries contained in | 
|---|
| 211 | * the bridge rhashtable and the local per-port per-VLAN entries contained in | 
|---|
| 212 | * the port's rhashtable. The union entries should be interpreted depending on | 
|---|
| 213 | * the entry flags that are set. | 
|---|
| 214 | */ | 
|---|
| 215 | struct net_bridge_vlan { | 
|---|
| 216 | struct rhash_head		vnode; | 
|---|
| 217 | struct rhash_head		tnode; | 
|---|
| 218 | u16				vid; | 
|---|
| 219 | u16				flags; | 
|---|
| 220 | u16				priv_flags; | 
|---|
| 221 | u8				state; | 
|---|
| 222 | struct pcpu_sw_netstats __percpu *stats; | 
|---|
| 223 | union { | 
|---|
| 224 | struct net_bridge	*br; | 
|---|
| 225 | struct net_bridge_port	*port; | 
|---|
| 226 | }; | 
|---|
| 227 | union { | 
|---|
| 228 | refcount_t		refcnt; | 
|---|
| 229 | struct net_bridge_vlan	*brvlan; | 
|---|
| 230 | }; | 
|---|
| 231 |  | 
|---|
| 232 | struct br_tunnel_info		tinfo; | 
|---|
| 233 |  | 
|---|
| 234 | union { | 
|---|
| 235 | struct net_bridge_mcast		br_mcast_ctx; | 
|---|
| 236 | struct net_bridge_mcast_port	port_mcast_ctx; | 
|---|
| 237 | }; | 
|---|
| 238 |  | 
|---|
| 239 | u16				msti; | 
|---|
| 240 |  | 
|---|
| 241 | struct list_head		vlist; | 
|---|
| 242 |  | 
|---|
| 243 | struct rcu_head			rcu; | 
|---|
| 244 | }; | 
|---|
| 245 |  | 
|---|
| 246 | /** | 
|---|
| 247 | * struct net_bridge_vlan_group | 
|---|
| 248 | * | 
|---|
| 249 | * @vlan_hash: VLAN entry rhashtable | 
|---|
| 250 | * @vlan_list: sorted VLAN entry list | 
|---|
| 251 | * @num_vlans: number of total VLAN entries | 
|---|
| 252 | * @pvid: PVID VLAN id | 
|---|
| 253 | * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking) | 
|---|
| 254 | * | 
|---|
| 255 | * IMPORTANT: Be careful when checking if there're VLAN entries using list | 
|---|
| 256 | *            primitives because the bridge can have entries in its list which | 
|---|
| 257 | *            are just for global context but not for filtering, i.e. they have | 
|---|
| 258 | *            the master flag set but not the brentry flag. If you have to check | 
|---|
| 259 | *            if there're "real" entries in the bridge please test @num_vlans | 
|---|
| 260 | */ | 
|---|
| 261 | struct net_bridge_vlan_group { | 
|---|
| 262 | struct rhashtable		vlan_hash; | 
|---|
| 263 | struct rhashtable		tunnel_hash; | 
|---|
| 264 | struct list_head		vlan_list; | 
|---|
| 265 | u16				num_vlans; | 
|---|
| 266 | u16				pvid; | 
|---|
| 267 | u8				pvid_state; | 
|---|
| 268 | }; | 
|---|
| 269 |  | 
|---|
| 270 | /* bridge fdb flags */ | 
|---|
| 271 | enum { | 
|---|
| 272 | BR_FDB_LOCAL, | 
|---|
| 273 | BR_FDB_STATIC, | 
|---|
| 274 | BR_FDB_STICKY, | 
|---|
| 275 | BR_FDB_ADDED_BY_USER, | 
|---|
| 276 | BR_FDB_ADDED_BY_EXT_LEARN, | 
|---|
| 277 | BR_FDB_OFFLOADED, | 
|---|
| 278 | BR_FDB_NOTIFY, | 
|---|
| 279 | BR_FDB_NOTIFY_INACTIVE, | 
|---|
| 280 | BR_FDB_LOCKED, | 
|---|
| 281 | BR_FDB_DYNAMIC_LEARNED, | 
|---|
| 282 | }; | 
|---|
| 283 |  | 
|---|
| 284 | struct net_bridge_fdb_key { | 
|---|
| 285 | mac_addr addr; | 
|---|
| 286 | u16 vlan_id; | 
|---|
| 287 | }; | 
|---|
| 288 |  | 
|---|
| 289 | struct net_bridge_fdb_entry { | 
|---|
| 290 | struct rhash_head		rhnode; | 
|---|
| 291 | struct net_bridge_port		*dst; | 
|---|
| 292 |  | 
|---|
| 293 | struct net_bridge_fdb_key	key; | 
|---|
| 294 | struct hlist_node		fdb_node; | 
|---|
| 295 | unsigned long			flags; | 
|---|
| 296 |  | 
|---|
| 297 | /* write-heavy members should not affect lookups */ | 
|---|
| 298 | unsigned long			updated ____cacheline_aligned_in_smp; | 
|---|
| 299 | unsigned long			used; | 
|---|
| 300 |  | 
|---|
| 301 | struct rcu_head			rcu; | 
|---|
| 302 | }; | 
|---|
| 303 |  | 
|---|
| 304 | struct net_bridge_fdb_flush_desc { | 
|---|
| 305 | unsigned long			flags; | 
|---|
| 306 | unsigned long			flags_mask; | 
|---|
| 307 | int				port_ifindex; | 
|---|
| 308 | u16				vlan_id; | 
|---|
| 309 | }; | 
|---|
| 310 |  | 
|---|
| 311 | #define MDB_PG_FLAGS_PERMANENT		BIT(0) | 
|---|
| 312 | #define MDB_PG_FLAGS_OFFLOAD		BIT(1) | 
|---|
| 313 | #define MDB_PG_FLAGS_FAST_LEAVE		BIT(2) | 
|---|
| 314 | #define MDB_PG_FLAGS_STAR_EXCL		BIT(3) | 
|---|
| 315 | #define MDB_PG_FLAGS_BLOCKED		BIT(4) | 
|---|
| 316 | #define MDB_PG_FLAGS_OFFLOAD_FAILED	BIT(5) | 
|---|
| 317 |  | 
|---|
| 318 | #define PG_SRC_ENT_LIMIT	32 | 
|---|
| 319 |  | 
|---|
| 320 | #define BR_SGRP_F_DELETE	BIT(0) | 
|---|
| 321 | #define BR_SGRP_F_SEND		BIT(1) | 
|---|
| 322 | #define BR_SGRP_F_INSTALLED	BIT(2) | 
|---|
| 323 | #define BR_SGRP_F_USER_ADDED	BIT(3) | 
|---|
| 324 |  | 
|---|
| 325 | struct net_bridge_mcast_gc { | 
|---|
| 326 | struct hlist_node		gc_node; | 
|---|
| 327 | void				(*destroy)(struct net_bridge_mcast_gc *gc); | 
|---|
| 328 | }; | 
|---|
| 329 |  | 
|---|
| 330 | struct net_bridge_group_src { | 
|---|
| 331 | struct hlist_node		node; | 
|---|
| 332 |  | 
|---|
| 333 | struct br_ip			addr; | 
|---|
| 334 | struct net_bridge_port_group	*pg; | 
|---|
| 335 | u8				flags; | 
|---|
| 336 | u8				src_query_rexmit_cnt; | 
|---|
| 337 | struct timer_list		timer; | 
|---|
| 338 |  | 
|---|
| 339 | struct net_bridge		*br; | 
|---|
| 340 | struct net_bridge_mcast_gc	mcast_gc; | 
|---|
| 341 | struct rcu_head			rcu; | 
|---|
| 342 | }; | 
|---|
| 343 |  | 
|---|
| 344 | struct net_bridge_port_group_sg_key { | 
|---|
| 345 | struct net_bridge_port		*port; | 
|---|
| 346 | struct br_ip			addr; | 
|---|
| 347 | }; | 
|---|
| 348 |  | 
|---|
| 349 | struct net_bridge_port_group { | 
|---|
| 350 | struct net_bridge_port_group __rcu *next; | 
|---|
| 351 | struct net_bridge_port_group_sg_key key; | 
|---|
| 352 | unsigned char			eth_addr[ETH_ALEN] __aligned(2); | 
|---|
| 353 | unsigned char			flags; | 
|---|
| 354 | unsigned char			filter_mode; | 
|---|
| 355 | unsigned char			grp_query_rexmit_cnt; | 
|---|
| 356 | unsigned char			rt_protocol; | 
|---|
| 357 |  | 
|---|
| 358 | struct hlist_head		src_list; | 
|---|
| 359 | unsigned int			src_ents; | 
|---|
| 360 | struct timer_list		timer; | 
|---|
| 361 | struct timer_list		rexmit_timer; | 
|---|
| 362 | struct hlist_node		mglist; | 
|---|
| 363 | struct rb_root			eht_set_tree; | 
|---|
| 364 | struct rb_root			eht_host_tree; | 
|---|
| 365 |  | 
|---|
| 366 | struct rhash_head		rhnode; | 
|---|
| 367 | struct net_bridge_mcast_gc	mcast_gc; | 
|---|
| 368 | struct rcu_head			rcu; | 
|---|
| 369 | }; | 
|---|
| 370 |  | 
|---|
| 371 | struct net_bridge_mdb_entry { | 
|---|
| 372 | struct rhash_head		rhnode; | 
|---|
| 373 | struct net_bridge		*br; | 
|---|
| 374 | struct net_bridge_port_group __rcu *ports; | 
|---|
| 375 | struct br_ip			addr; | 
|---|
| 376 | bool				host_joined; | 
|---|
| 377 |  | 
|---|
| 378 | struct timer_list		timer; | 
|---|
| 379 | struct hlist_node		mdb_node; | 
|---|
| 380 |  | 
|---|
| 381 | struct net_bridge_mcast_gc	mcast_gc; | 
|---|
| 382 | struct rcu_head			rcu; | 
|---|
| 383 | }; | 
|---|
| 384 |  | 
|---|
| 385 | struct net_bridge_port { | 
|---|
| 386 | struct net_bridge		*br; | 
|---|
| 387 | struct net_device		*dev; | 
|---|
| 388 | netdevice_tracker		dev_tracker; | 
|---|
| 389 | struct list_head		list; | 
|---|
| 390 |  | 
|---|
| 391 | unsigned long			flags; | 
|---|
| 392 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | 
|---|
| 393 | struct net_bridge_vlan_group	__rcu *vlgrp; | 
|---|
| 394 | #endif | 
|---|
| 395 | struct net_bridge_port		__rcu *backup_port; | 
|---|
| 396 | u32				backup_nhid; | 
|---|
| 397 |  | 
|---|
| 398 | /* STP */ | 
|---|
| 399 | u8				priority; | 
|---|
| 400 | u8				state; | 
|---|
| 401 | u16				port_no; | 
|---|
| 402 | unsigned char			topology_change_ack; | 
|---|
| 403 | unsigned char			config_pending; | 
|---|
| 404 | port_id				port_id; | 
|---|
| 405 | port_id				designated_port; | 
|---|
| 406 | bridge_id			designated_root; | 
|---|
| 407 | bridge_id			designated_bridge; | 
|---|
| 408 | u32				path_cost; | 
|---|
| 409 | u32				designated_cost; | 
|---|
| 410 | unsigned long			designated_age; | 
|---|
| 411 |  | 
|---|
| 412 | struct timer_list		forward_delay_timer; | 
|---|
| 413 | struct timer_list		hold_timer; | 
|---|
| 414 | struct timer_list		message_age_timer; | 
|---|
| 415 | struct kobject			kobj; | 
|---|
| 416 | struct rcu_head			rcu; | 
|---|
| 417 |  | 
|---|
| 418 | struct net_bridge_mcast_port	multicast_ctx; | 
|---|
| 419 |  | 
|---|
| 420 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 421 | struct bridge_mcast_stats	__percpu *mcast_stats; | 
|---|
| 422 |  | 
|---|
| 423 | u32				multicast_eht_hosts_limit; | 
|---|
| 424 | u32				multicast_eht_hosts_cnt; | 
|---|
| 425 | struct hlist_head		mglist; | 
|---|
| 426 | #endif | 
|---|
| 427 |  | 
|---|
| 428 | #ifdef CONFIG_SYSFS | 
|---|
| 429 | char				sysfs_name[IFNAMSIZ]; | 
|---|
| 430 | #endif | 
|---|
| 431 |  | 
|---|
| 432 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
|---|
| 433 | struct netpoll			*np; | 
|---|
| 434 | #endif | 
|---|
| 435 | #ifdef CONFIG_NET_SWITCHDEV | 
|---|
| 436 | /* Identifier used to group ports that share the same switchdev | 
|---|
| 437 | * hardware domain. | 
|---|
| 438 | */ | 
|---|
| 439 | int				hwdom; | 
|---|
| 440 | int				offload_count; | 
|---|
| 441 | struct netdev_phys_item_id	ppid; | 
|---|
| 442 | #endif | 
|---|
| 443 | u16				group_fwd_mask; | 
|---|
| 444 | u16				backup_redirected_cnt; | 
|---|
| 445 |  | 
|---|
| 446 | struct bridge_stp_xstats	stp_xstats; | 
|---|
| 447 | }; | 
|---|
| 448 |  | 
|---|
| 449 | #define kobj_to_brport(obj)	container_of(obj, struct net_bridge_port, kobj) | 
|---|
| 450 |  | 
|---|
| 451 | #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK) | 
|---|
| 452 | #define br_promisc_port(p) ((p)->flags & BR_PROMISC) | 
|---|
| 453 |  | 
|---|
| 454 | static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev) | 
|---|
| 455 | { | 
|---|
| 456 | return rcu_dereference(dev->rx_handler_data); | 
|---|
| 457 | } | 
|---|
| 458 |  | 
|---|
| 459 | static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev) | 
|---|
| 460 | { | 
|---|
| 461 | return netif_is_bridge_port(dev) ? | 
|---|
| 462 | rtnl_dereference(dev->rx_handler_data) : NULL; | 
|---|
| 463 | } | 
|---|
| 464 |  | 
|---|
| 465 | static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev) | 
|---|
| 466 | { | 
|---|
| 467 | return netif_is_bridge_port(dev) ? | 
|---|
| 468 | rcu_dereference_rtnl(dev->rx_handler_data) : NULL; | 
|---|
| 469 | } | 
|---|
| 470 |  | 
|---|
| 471 | enum net_bridge_opts { | 
|---|
| 472 | BROPT_VLAN_ENABLED, | 
|---|
| 473 | BROPT_VLAN_STATS_ENABLED, | 
|---|
| 474 | BROPT_NF_CALL_IPTABLES, | 
|---|
| 475 | BROPT_NF_CALL_IP6TABLES, | 
|---|
| 476 | BROPT_NF_CALL_ARPTABLES, | 
|---|
| 477 | BROPT_GROUP_ADDR_SET, | 
|---|
| 478 | BROPT_MULTICAST_ENABLED, | 
|---|
| 479 | BROPT_MULTICAST_QUERY_USE_IFADDR, | 
|---|
| 480 | BROPT_MULTICAST_STATS_ENABLED, | 
|---|
| 481 | BROPT_HAS_IPV6_ADDR, | 
|---|
| 482 | BROPT_NEIGH_SUPPRESS_ENABLED, | 
|---|
| 483 | BROPT_MTU_SET_BY_USER, | 
|---|
| 484 | BROPT_VLAN_STATS_PER_PORT, | 
|---|
| 485 | BROPT_NO_LL_LEARN, | 
|---|
| 486 | BROPT_VLAN_BRIDGE_BINDING, | 
|---|
| 487 | BROPT_MCAST_VLAN_SNOOPING_ENABLED, | 
|---|
| 488 | BROPT_MST_ENABLED, | 
|---|
| 489 | BROPT_MDB_OFFLOAD_FAIL_NOTIFICATION, | 
|---|
| 490 | BROPT_FDB_LOCAL_VLAN_0, | 
|---|
| 491 | }; | 
|---|
| 492 |  | 
|---|
| 493 | struct net_bridge { | 
|---|
| 494 | spinlock_t			lock; | 
|---|
| 495 | spinlock_t			hash_lock; | 
|---|
| 496 | struct hlist_head		frame_type_list; | 
|---|
| 497 | struct net_device		*dev; | 
|---|
| 498 | unsigned long			options; | 
|---|
| 499 | /* These fields are accessed on each packet */ | 
|---|
| 500 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | 
|---|
| 501 | __be16				vlan_proto; | 
|---|
| 502 | u16				default_pvid; | 
|---|
| 503 | struct net_bridge_vlan_group	__rcu *vlgrp; | 
|---|
| 504 | #endif | 
|---|
| 505 |  | 
|---|
| 506 | struct rhashtable		fdb_hash_tbl; | 
|---|
| 507 | struct list_head		port_list; | 
|---|
| 508 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) | 
|---|
| 509 | union { | 
|---|
| 510 | struct rtable		fake_rtable; | 
|---|
| 511 | struct rt6_info		fake_rt6_info; | 
|---|
| 512 | }; | 
|---|
| 513 | u32				metrics[RTAX_MAX]; | 
|---|
| 514 | #endif | 
|---|
| 515 | u16				group_fwd_mask; | 
|---|
| 516 | u16				group_fwd_mask_required; | 
|---|
| 517 |  | 
|---|
| 518 | /* STP */ | 
|---|
| 519 | bridge_id			designated_root; | 
|---|
| 520 | bridge_id			bridge_id; | 
|---|
| 521 | unsigned char			topology_change; | 
|---|
| 522 | unsigned char			topology_change_detected; | 
|---|
| 523 | u16				root_port; | 
|---|
| 524 | unsigned long			max_age; | 
|---|
| 525 | unsigned long			hello_time; | 
|---|
| 526 | unsigned long			forward_delay; | 
|---|
| 527 | unsigned long			ageing_time; | 
|---|
| 528 | unsigned long			bridge_max_age; | 
|---|
| 529 | unsigned long			bridge_hello_time; | 
|---|
| 530 | unsigned long			bridge_forward_delay; | 
|---|
| 531 | unsigned long			bridge_ageing_time; | 
|---|
| 532 | u32				root_path_cost; | 
|---|
| 533 |  | 
|---|
| 534 | u8				group_addr[ETH_ALEN]; | 
|---|
| 535 |  | 
|---|
| 536 | enum { | 
|---|
| 537 | BR_NO_STP, 		/* no spanning tree */ | 
|---|
| 538 | BR_KERNEL_STP,		/* old STP in kernel */ | 
|---|
| 539 | BR_USER_STP,		/* new RSTP in userspace */ | 
|---|
| 540 | } stp_enabled; | 
|---|
| 541 |  | 
|---|
| 542 | struct net_bridge_mcast		multicast_ctx; | 
|---|
| 543 |  | 
|---|
| 544 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 545 | struct bridge_mcast_stats	__percpu *mcast_stats; | 
|---|
| 546 |  | 
|---|
| 547 | u32				hash_max; | 
|---|
| 548 |  | 
|---|
| 549 | spinlock_t			multicast_lock; | 
|---|
| 550 |  | 
|---|
| 551 | struct rhashtable		mdb_hash_tbl; | 
|---|
| 552 | struct rhashtable		sg_port_tbl; | 
|---|
| 553 |  | 
|---|
| 554 | struct hlist_head		mcast_gc_list; | 
|---|
| 555 | struct hlist_head		mdb_list; | 
|---|
| 556 |  | 
|---|
| 557 | struct work_struct		mcast_gc_work; | 
|---|
| 558 | #endif | 
|---|
| 559 |  | 
|---|
| 560 | struct timer_list		hello_timer; | 
|---|
| 561 | struct timer_list		tcn_timer; | 
|---|
| 562 | struct timer_list		topology_change_timer; | 
|---|
| 563 | struct delayed_work		gc_work; | 
|---|
| 564 | struct kobject			*ifobj; | 
|---|
| 565 | u32				auto_cnt; | 
|---|
| 566 |  | 
|---|
| 567 | atomic_t			fdb_n_learned; | 
|---|
| 568 | u32				fdb_max_learned; | 
|---|
| 569 |  | 
|---|
| 570 | #ifdef CONFIG_NET_SWITCHDEV | 
|---|
| 571 | /* Counter used to make sure that hardware domains get unique | 
|---|
| 572 | * identifiers in case a bridge spans multiple switchdev instances. | 
|---|
| 573 | */ | 
|---|
| 574 | int				last_hwdom; | 
|---|
| 575 | /* Bit mask of hardware domain numbers in use */ | 
|---|
| 576 | unsigned long			busy_hwdoms; | 
|---|
| 577 | #endif | 
|---|
| 578 | struct hlist_head		fdb_list; | 
|---|
| 579 |  | 
|---|
| 580 | #if IS_ENABLED(CONFIG_BRIDGE_MRP) | 
|---|
| 581 | struct hlist_head		mrp_list; | 
|---|
| 582 | #endif | 
|---|
| 583 | #if IS_ENABLED(CONFIG_BRIDGE_CFM) | 
|---|
| 584 | struct hlist_head		mep_list; | 
|---|
| 585 | #endif | 
|---|
| 586 | }; | 
|---|
| 587 |  | 
|---|
| 588 | struct br_input_skb_cb { | 
|---|
| 589 | struct net_device *brdev; | 
|---|
| 590 |  | 
|---|
| 591 | u16 frag_max_size; | 
|---|
| 592 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 593 | u8 igmp; | 
|---|
| 594 | u8 mrouters_only:1; | 
|---|
| 595 | #endif | 
|---|
| 596 | u8 proxyarp_replied:1; | 
|---|
| 597 | u8 src_port_isolated:1; | 
|---|
| 598 | u8 promisc:1; | 
|---|
| 599 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | 
|---|
| 600 | u8 vlan_filtered:1; | 
|---|
| 601 | #endif | 
|---|
| 602 | #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE | 
|---|
| 603 | u8 br_netfilter_broute:1; | 
|---|
| 604 | #endif | 
|---|
| 605 |  | 
|---|
| 606 | #ifdef CONFIG_NET_SWITCHDEV | 
|---|
| 607 | /* Set if TX data plane offloading is used towards at least one | 
|---|
| 608 | * hardware domain. | 
|---|
| 609 | */ | 
|---|
| 610 | u8 tx_fwd_offload:1; | 
|---|
| 611 | /* The switchdev hardware domain from which this packet was received. | 
|---|
| 612 | * If skb->offload_fwd_mark was set, then this packet was already | 
|---|
| 613 | * forwarded by hardware to the other ports in the source hardware | 
|---|
| 614 | * domain, otherwise it wasn't. | 
|---|
| 615 | */ | 
|---|
| 616 | int src_hwdom; | 
|---|
| 617 | /* Bit mask of hardware domains towards this packet has already been | 
|---|
| 618 | * transmitted using the TX data plane offload. | 
|---|
| 619 | */ | 
|---|
| 620 | unsigned long fwd_hwdoms; | 
|---|
| 621 | #endif | 
|---|
| 622 |  | 
|---|
| 623 | u32 backup_nhid; | 
|---|
| 624 | }; | 
|---|
| 625 |  | 
|---|
| 626 | #define BR_INPUT_SKB_CB(__skb)	((struct br_input_skb_cb *)(__skb)->cb) | 
|---|
| 627 |  | 
|---|
| 628 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 629 | # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(BR_INPUT_SKB_CB(__skb)->mrouters_only) | 
|---|
| 630 | #else | 
|---|
| 631 | # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb)	(0) | 
|---|
| 632 | #endif | 
|---|
| 633 |  | 
|---|
| 634 | #define br_printk(level, br, format, args...)	\ | 
|---|
| 635 | printk(level "%s: " format, (br)->dev->name, ##args) | 
|---|
| 636 |  | 
|---|
| 637 | #define br_err(__br, format, args...)			\ | 
|---|
| 638 | br_printk(KERN_ERR, __br, format, ##args) | 
|---|
| 639 | #define br_warn(__br, format, args...)			\ | 
|---|
| 640 | br_printk(KERN_WARNING, __br, format, ##args) | 
|---|
| 641 | #define br_notice(__br, format, args...)		\ | 
|---|
| 642 | br_printk(KERN_NOTICE, __br, format, ##args) | 
|---|
| 643 | #define br_info(__br, format, args...)			\ | 
|---|
| 644 | br_printk(KERN_INFO, __br, format, ##args) | 
|---|
| 645 |  | 
|---|
| 646 | #define br_debug(br, format, args...)			\ | 
|---|
| 647 | pr_debug("%s: " format,  (br)->dev->name, ##args) | 
|---|
| 648 |  | 
|---|
| 649 | /* called under bridge lock */ | 
|---|
| 650 | static inline int br_is_root_bridge(const struct net_bridge *br) | 
|---|
| 651 | { | 
|---|
| 652 | return !memcmp(&br->bridge_id, &br->designated_root, 8); | 
|---|
| 653 | } | 
|---|
| 654 |  | 
|---|
| 655 | /* check if a VLAN entry is global */ | 
|---|
| 656 | static inline bool br_vlan_is_master(const struct net_bridge_vlan *v) | 
|---|
| 657 | { | 
|---|
| 658 | return v->flags & BRIDGE_VLAN_INFO_MASTER; | 
|---|
| 659 | } | 
|---|
| 660 |  | 
|---|
| 661 | /* check if a VLAN entry is used by the bridge */ | 
|---|
| 662 | static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v) | 
|---|
| 663 | { | 
|---|
| 664 | return v->flags & BRIDGE_VLAN_INFO_BRENTRY; | 
|---|
| 665 | } | 
|---|
| 666 |  | 
|---|
| 667 | /* check if we should use the vlan entry, returns false if it's only context */ | 
|---|
| 668 | static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) | 
|---|
| 669 | { | 
|---|
| 670 | if (br_vlan_is_master(v)) { | 
|---|
| 671 | if (br_vlan_is_brentry(v)) | 
|---|
| 672 | return true; | 
|---|
| 673 | else | 
|---|
| 674 | return false; | 
|---|
| 675 | } | 
|---|
| 676 |  | 
|---|
| 677 | return true; | 
|---|
| 678 | } | 
|---|
| 679 |  | 
|---|
| 680 | static inline bool nbp_state_should_learn(const struct net_bridge_port *p) | 
|---|
| 681 | { | 
|---|
| 682 | return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING; | 
|---|
| 683 | } | 
|---|
| 684 |  | 
|---|
| 685 | static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack) | 
|---|
| 686 | { | 
|---|
| 687 | bool ret = vid > 0 && vid < VLAN_VID_MASK; | 
|---|
| 688 |  | 
|---|
| 689 | if (!ret) | 
|---|
| 690 | NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid"); | 
|---|
| 691 |  | 
|---|
| 692 | return ret; | 
|---|
| 693 | } | 
|---|
| 694 |  | 
|---|
| 695 | static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur, | 
|---|
| 696 | const struct bridge_vlan_info *last, | 
|---|
| 697 | struct netlink_ext_ack *extack) | 
|---|
| 698 | { | 
|---|
| 699 | /* pvid flag is not allowed in ranges */ | 
|---|
| 700 | if (cur->flags & BRIDGE_VLAN_INFO_PVID) { | 
|---|
| 701 | NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range"); | 
|---|
| 702 | return false; | 
|---|
| 703 | } | 
|---|
| 704 |  | 
|---|
| 705 | /* when cur is the range end, check if: | 
|---|
| 706 | *  - it has range start flag | 
|---|
| 707 | *  - range ids are invalid (end is equal to or before start) | 
|---|
| 708 | */ | 
|---|
| 709 | if (last) { | 
|---|
| 710 | if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { | 
|---|
| 711 | NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one"); | 
|---|
| 712 | return false; | 
|---|
| 713 | } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) { | 
|---|
| 714 | NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing"); | 
|---|
| 715 | return false; | 
|---|
| 716 | } else if (cur->vid <= last->vid) { | 
|---|
| 717 | NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id"); | 
|---|
| 718 | return false; | 
|---|
| 719 | } | 
|---|
| 720 | } | 
|---|
| 721 |  | 
|---|
| 722 | /* check for required range flags */ | 
|---|
| 723 | if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN | | 
|---|
| 724 | BRIDGE_VLAN_INFO_RANGE_END))) { | 
|---|
| 725 | NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing"); | 
|---|
| 726 | return false; | 
|---|
| 727 | } | 
|---|
| 728 |  | 
|---|
| 729 | return true; | 
|---|
| 730 | } | 
|---|
| 731 |  | 
|---|
| 732 | static inline u8 br_vlan_multicast_router(const struct net_bridge_vlan *v) | 
|---|
| 733 | { | 
|---|
| 734 | u8 mcast_router = MDB_RTR_TYPE_DISABLED; | 
|---|
| 735 |  | 
|---|
| 736 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 737 | if (!br_vlan_is_master(v)) | 
|---|
| 738 | mcast_router = v->port_mcast_ctx.multicast_router; | 
|---|
| 739 | else | 
|---|
| 740 | mcast_router = v->br_mcast_ctx.multicast_router; | 
|---|
| 741 | #endif | 
|---|
| 742 |  | 
|---|
| 743 | return mcast_router; | 
|---|
| 744 | } | 
|---|
| 745 |  | 
|---|
| 746 | static inline int br_afspec_cmd_to_rtm(int cmd) | 
|---|
| 747 | { | 
|---|
| 748 | switch (cmd) { | 
|---|
| 749 | case RTM_SETLINK: | 
|---|
| 750 | return RTM_NEWVLAN; | 
|---|
| 751 | case RTM_DELLINK: | 
|---|
| 752 | return RTM_DELVLAN; | 
|---|
| 753 | } | 
|---|
| 754 |  | 
|---|
| 755 | return 0; | 
|---|
| 756 | } | 
|---|
| 757 |  | 
|---|
| 758 | static inline int br_opt_get(const struct net_bridge *br, | 
|---|
| 759 | enum net_bridge_opts opt) | 
|---|
| 760 | { | 
|---|
| 761 | return test_bit(opt, &br->options); | 
|---|
| 762 | } | 
|---|
| 763 |  | 
|---|
| 764 | int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, | 
|---|
| 765 | struct netlink_ext_ack *extack); | 
|---|
| 766 | int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt); | 
|---|
| 767 | int br_boolopt_multi_toggle(struct net_bridge *br, | 
|---|
| 768 | struct br_boolopt_multi *bm, | 
|---|
| 769 | struct netlink_ext_ack *extack); | 
|---|
| 770 | void br_boolopt_multi_get(const struct net_bridge *br, | 
|---|
| 771 | struct br_boolopt_multi *bm); | 
|---|
| 772 | void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on); | 
|---|
| 773 |  | 
|---|
| 774 | #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT) | 
|---|
| 775 | static inline void br_tc_skb_miss_set(struct sk_buff *skb, bool miss) | 
|---|
| 776 | { | 
|---|
| 777 | struct tc_skb_ext *ext; | 
|---|
| 778 |  | 
|---|
| 779 | if (!tc_skb_ext_tc_enabled()) | 
|---|
| 780 | return; | 
|---|
| 781 |  | 
|---|
| 782 | ext = skb_ext_find(skb, TC_SKB_EXT); | 
|---|
| 783 | if (ext) { | 
|---|
| 784 | ext->l2_miss = miss; | 
|---|
| 785 | return; | 
|---|
| 786 | } | 
|---|
| 787 | if (!miss) | 
|---|
| 788 | return; | 
|---|
| 789 | ext = tc_skb_ext_alloc(skb); | 
|---|
| 790 | if (!ext) | 
|---|
| 791 | return; | 
|---|
| 792 | ext->l2_miss = true; | 
|---|
| 793 | } | 
|---|
| 794 | #else | 
|---|
| 795 | static inline void br_tc_skb_miss_set(struct sk_buff *skb, bool miss) | 
|---|
| 796 | { | 
|---|
| 797 | } | 
|---|
| 798 | #endif | 
|---|
| 799 |  | 
|---|
| 800 | /* br_device.c */ | 
|---|
| 801 | void br_dev_setup(struct net_device *dev); | 
|---|
| 802 | void br_dev_delete(struct net_device *dev, struct list_head *list); | 
|---|
| 803 | netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev); | 
|---|
| 804 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
|---|
| 805 | static inline void br_netpoll_send_skb(const struct net_bridge_port *p, | 
|---|
| 806 | struct sk_buff *skb) | 
|---|
| 807 | { | 
|---|
| 808 | netpoll_send_skb(np: p->np, skb); | 
|---|
| 809 | } | 
|---|
| 810 |  | 
|---|
| 811 | int br_netpoll_enable(struct net_bridge_port *p); | 
|---|
| 812 | void br_netpoll_disable(struct net_bridge_port *p); | 
|---|
| 813 | #else | 
|---|
| 814 | static inline void br_netpoll_send_skb(const struct net_bridge_port *p, | 
|---|
| 815 | struct sk_buff *skb) | 
|---|
| 816 | { | 
|---|
| 817 | } | 
|---|
| 818 |  | 
|---|
| 819 | static inline int br_netpoll_enable(struct net_bridge_port *p) | 
|---|
| 820 | { | 
|---|
| 821 | return 0; | 
|---|
| 822 | } | 
|---|
| 823 |  | 
|---|
| 824 | static inline void br_netpoll_disable(struct net_bridge_port *p) | 
|---|
| 825 | { | 
|---|
| 826 | } | 
|---|
| 827 | #endif | 
|---|
| 828 |  | 
|---|
| 829 | /* br_fdb.c */ | 
|---|
| 830 | #define FDB_FLUSH_IGNORED_NDM_FLAGS (NTF_MASTER | NTF_SELF) | 
|---|
| 831 | #define FDB_FLUSH_ALLOWED_NDM_STATES (NUD_PERMANENT | NUD_NOARP) | 
|---|
| 832 | #define FDB_FLUSH_ALLOWED_NDM_FLAGS (NTF_USE | NTF_EXT_LEARNED | \ | 
|---|
| 833 | NTF_STICKY | NTF_OFFLOADED) | 
|---|
| 834 |  | 
|---|
| 835 | int br_fdb_init(void); | 
|---|
| 836 | void br_fdb_fini(void); | 
|---|
| 837 | int br_fdb_hash_init(struct net_bridge *br); | 
|---|
| 838 | void br_fdb_hash_fini(struct net_bridge *br); | 
|---|
| 839 | void br_fdb_flush(struct net_bridge *br, | 
|---|
| 840 | const struct net_bridge_fdb_flush_desc *desc); | 
|---|
| 841 | void br_fdb_find_delete_local(struct net_bridge *br, | 
|---|
| 842 | const struct net_bridge_port *p, | 
|---|
| 843 | const unsigned char *addr, u16 vid); | 
|---|
| 844 | void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr); | 
|---|
| 845 | void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); | 
|---|
| 846 | void br_fdb_cleanup(struct work_struct *work); | 
|---|
| 847 | int br_fdb_toggle_local_vlan_0(struct net_bridge *br, bool on, | 
|---|
| 848 | struct netlink_ext_ack *extack); | 
|---|
| 849 | void br_fdb_delete_by_port(struct net_bridge *br, | 
|---|
| 850 | const struct net_bridge_port *p, u16 vid, int do_all); | 
|---|
| 851 | struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, | 
|---|
| 852 | const unsigned char *addr, | 
|---|
| 853 | __u16 vid); | 
|---|
| 854 | int br_fdb_test_addr(struct net_device *dev, unsigned char *addr); | 
|---|
| 855 | int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count, | 
|---|
| 856 | unsigned long off); | 
|---|
| 857 | int br_fdb_add_local(struct net_bridge *br, struct net_bridge_port *source, | 
|---|
| 858 | const unsigned char *addr, u16 vid); | 
|---|
| 859 | void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, | 
|---|
| 860 | const unsigned char *addr, u16 vid, unsigned long flags); | 
|---|
| 861 |  | 
|---|
| 862 | int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], | 
|---|
| 863 | struct net_device *dev, const unsigned char *addr, u16 vid, | 
|---|
| 864 | bool *notified, struct netlink_ext_ack *extack); | 
|---|
| 865 | int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev, | 
|---|
| 866 | struct netlink_ext_ack *extack); | 
|---|
| 867 | int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, | 
|---|
| 868 | const unsigned char *addr, u16 vid, u16 nlh_flags, | 
|---|
| 869 | bool *notified, struct netlink_ext_ack *extack); | 
|---|
| 870 | int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, | 
|---|
| 871 | struct net_device *dev, struct net_device *fdev, int *idx); | 
|---|
| 872 | int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev, | 
|---|
| 873 | const unsigned char *addr, u16 vid, u32 portid, u32 seq, | 
|---|
| 874 | struct netlink_ext_ack *extack); | 
|---|
| 875 | int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); | 
|---|
| 876 | void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); | 
|---|
| 877 | int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 878 | const unsigned char *addr, u16 vid, | 
|---|
| 879 | bool locked, bool swdev_notify); | 
|---|
| 880 | int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 881 | const unsigned char *addr, u16 vid, | 
|---|
| 882 | bool swdev_notify); | 
|---|
| 883 | void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 884 | const unsigned char *addr, u16 vid, bool offloaded); | 
|---|
| 885 |  | 
|---|
| 886 | /* br_forward.c */ | 
|---|
| 887 | enum br_pkt_type { | 
|---|
| 888 | BR_PKT_UNICAST, | 
|---|
| 889 | BR_PKT_MULTICAST, | 
|---|
| 890 | BR_PKT_BROADCAST | 
|---|
| 891 | }; | 
|---|
| 892 | int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb); | 
|---|
| 893 | void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, | 
|---|
| 894 | bool local_rcv, bool local_orig); | 
|---|
| 895 | int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); | 
|---|
| 896 | void br_flood(struct net_bridge *br, struct sk_buff *skb, | 
|---|
| 897 | enum br_pkt_type pkt_type, bool local_rcv, bool local_orig, | 
|---|
| 898 | u16 vid); | 
|---|
| 899 |  | 
|---|
| 900 | /* return true if both source port and dest port are isolated */ | 
|---|
| 901 | static inline bool br_skb_isolated(const struct net_bridge_port *to, | 
|---|
| 902 | const struct sk_buff *skb) | 
|---|
| 903 | { | 
|---|
| 904 | return BR_INPUT_SKB_CB(skb)->src_port_isolated && | 
|---|
| 905 | (to->flags & BR_ISOLATED); | 
|---|
| 906 | } | 
|---|
| 907 |  | 
|---|
| 908 | /* br_if.c */ | 
|---|
| 909 | void br_port_carrier_check(struct net_bridge_port *p, bool *notified); | 
|---|
| 910 | int br_add_bridge(struct net *net, const char *name); | 
|---|
| 911 | int br_del_bridge(struct net *net, const char *name); | 
|---|
| 912 | int br_add_if(struct net_bridge *br, struct net_device *dev, | 
|---|
| 913 | struct netlink_ext_ack *extack); | 
|---|
| 914 | int br_del_if(struct net_bridge *br, struct net_device *dev); | 
|---|
| 915 | void br_mtu_auto_adjust(struct net_bridge *br); | 
|---|
| 916 | netdev_features_t br_features_recompute(struct net_bridge *br, | 
|---|
| 917 | netdev_features_t features); | 
|---|
| 918 | void br_port_flags_change(struct net_bridge_port *port, unsigned long mask); | 
|---|
| 919 | void br_manage_promisc(struct net_bridge *br); | 
|---|
| 920 | int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); | 
|---|
| 921 |  | 
|---|
| 922 | /* br_input.c */ | 
|---|
| 923 | int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); | 
|---|
| 924 | rx_handler_func_t *br_get_rx_handler(const struct net_device *dev); | 
|---|
| 925 |  | 
|---|
| 926 | struct br_frame_type { | 
|---|
| 927 | __be16			type; | 
|---|
| 928 | int			(*frame_handler)(struct net_bridge_port *port, | 
|---|
| 929 | struct sk_buff *skb); | 
|---|
| 930 | struct hlist_node	list; | 
|---|
| 931 | }; | 
|---|
| 932 |  | 
|---|
| 933 | void br_add_frame(struct net_bridge *br, struct br_frame_type *ft); | 
|---|
| 934 | void br_del_frame(struct net_bridge *br, struct br_frame_type *ft); | 
|---|
| 935 |  | 
|---|
| 936 | static inline bool br_rx_handler_check_rcu(const struct net_device *dev) | 
|---|
| 937 | { | 
|---|
| 938 | return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev); | 
|---|
| 939 | } | 
|---|
| 940 |  | 
|---|
| 941 | static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) | 
|---|
| 942 | { | 
|---|
| 943 | return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev); | 
|---|
| 944 | } | 
|---|
| 945 |  | 
|---|
| 946 | static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) | 
|---|
| 947 | { | 
|---|
| 948 | return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL; | 
|---|
| 949 | } | 
|---|
| 950 |  | 
|---|
| 951 | static inline struct net_bridge_port * | 
|---|
| 952 | br_port_get_check_rtnl(const struct net_device *dev) | 
|---|
| 953 | { | 
|---|
| 954 | return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL; | 
|---|
| 955 | } | 
|---|
| 956 |  | 
|---|
| 957 | /* br_ioctl.c */ | 
|---|
| 958 | int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq, | 
|---|
| 959 | void __user *data, int cmd); | 
|---|
| 960 | int br_ioctl_stub(struct net *net, unsigned int cmd, void __user *uarg); | 
|---|
| 961 |  | 
|---|
| 962 | /* br_multicast.c */ | 
|---|
| 963 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | 
|---|
| 964 | int br_multicast_rcv(struct net_bridge_mcast **brmctx, | 
|---|
| 965 | struct net_bridge_mcast_port **pmctx, | 
|---|
| 966 | struct net_bridge_vlan *vlan, | 
|---|
| 967 | struct sk_buff *skb, u16 vid); | 
|---|
| 968 | struct net_bridge_mdb_entry * | 
|---|
| 969 | br_mdb_entry_skb_get(struct net_bridge_mcast *brmctx, struct sk_buff *skb, | 
|---|
| 970 | u16 vid); | 
|---|
| 971 | int br_multicast_add_port(struct net_bridge_port *port); | 
|---|
| 972 | void br_multicast_del_port(struct net_bridge_port *port); | 
|---|
| 973 | void br_multicast_enable_port(struct net_bridge_port *port); | 
|---|
| 974 | void br_multicast_disable_port(struct net_bridge_port *port); | 
|---|
| 975 | void br_multicast_init(struct net_bridge *br); | 
|---|
| 976 | void br_multicast_join_snoopers(struct net_bridge *br); | 
|---|
| 977 | void br_multicast_leave_snoopers(struct net_bridge *br); | 
|---|
| 978 | void br_multicast_open(struct net_bridge *br); | 
|---|
| 979 | void br_multicast_stop(struct net_bridge *br); | 
|---|
| 980 | void br_multicast_dev_del(struct net_bridge *br); | 
|---|
| 981 | void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb, | 
|---|
| 982 | struct net_bridge_mcast *brmctx, | 
|---|
| 983 | bool local_rcv, bool local_orig); | 
|---|
| 984 | int br_multicast_set_router(struct net_bridge_mcast *brmctx, unsigned long val); | 
|---|
| 985 | int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx, | 
|---|
| 986 | unsigned long val); | 
|---|
| 987 | int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router); | 
|---|
| 988 | int br_multicast_toggle(struct net_bridge *br, unsigned long val, | 
|---|
| 989 | struct netlink_ext_ack *extack); | 
|---|
| 990 | int br_multicast_set_querier(struct net_bridge_mcast *brmctx, unsigned long val); | 
|---|
| 991 | int br_multicast_set_igmp_version(struct net_bridge_mcast *brmctx, | 
|---|
| 992 | unsigned long val); | 
|---|
| 993 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 994 | int br_multicast_set_mld_version(struct net_bridge_mcast *brmctx, | 
|---|
| 995 | unsigned long val); | 
|---|
| 996 | #endif | 
|---|
| 997 | struct net_bridge_mdb_entry * | 
|---|
| 998 | br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst); | 
|---|
| 999 | struct net_bridge_mdb_entry * | 
|---|
| 1000 | br_multicast_new_group(struct net_bridge *br, struct br_ip *group); | 
|---|
| 1001 | struct net_bridge_port_group * | 
|---|
| 1002 | br_multicast_new_port_group(struct net_bridge_port *port, | 
|---|
| 1003 | const struct br_ip *group, | 
|---|
| 1004 | struct net_bridge_port_group __rcu *next, | 
|---|
| 1005 | unsigned char flags, const unsigned char *src, | 
|---|
| 1006 | u8 filter_mode, u8 rt_protocol, | 
|---|
| 1007 | struct netlink_ext_ack *extack); | 
|---|
| 1008 | void br_multicast_del_port_group(struct net_bridge_port_group *p); | 
|---|
| 1009 | int br_mdb_hash_init(struct net_bridge *br); | 
|---|
| 1010 | void br_mdb_hash_fini(struct net_bridge *br); | 
|---|
| 1011 | void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp, | 
|---|
| 1012 | struct net_bridge_port_group *pg, int type); | 
|---|
| 1013 | void br_mdb_flag_change_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp, | 
|---|
| 1014 | struct net_bridge_port_group *pg); | 
|---|
| 1015 | void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx, | 
|---|
| 1016 | int type); | 
|---|
| 1017 | void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | 
|---|
| 1018 | struct net_bridge_port_group *pg, | 
|---|
| 1019 | struct net_bridge_port_group __rcu **pp); | 
|---|
| 1020 | void br_multicast_count(struct net_bridge *br, | 
|---|
| 1021 | const struct net_bridge_port *p, | 
|---|
| 1022 | const struct sk_buff *skb, u8 type, u8 dir); | 
|---|
| 1023 | int br_multicast_init_stats(struct net_bridge *br); | 
|---|
| 1024 | void br_multicast_uninit_stats(struct net_bridge *br); | 
|---|
| 1025 | void br_multicast_get_stats(const struct net_bridge *br, | 
|---|
| 1026 | const struct net_bridge_port *p, | 
|---|
| 1027 | struct br_mcast_stats *dest); | 
|---|
| 1028 | u32 br_multicast_ngroups_get(const struct net_bridge_mcast_port *pmctx); | 
|---|
| 1029 | void br_multicast_ngroups_set_max(struct net_bridge_mcast_port *pmctx, u32 max); | 
|---|
| 1030 | u32 br_multicast_ngroups_get_max(const struct net_bridge_mcast_port *pmctx); | 
|---|
| 1031 | int br_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, | 
|---|
| 1032 | struct netlink_ext_ack *extack); | 
|---|
| 1033 | int br_mdb_del(struct net_device *dev, struct nlattr *tb[], | 
|---|
| 1034 | struct netlink_ext_ack *extack); | 
|---|
| 1035 | int br_mdb_del_bulk(struct net_device *dev, struct nlattr *tb[], | 
|---|
| 1036 | struct netlink_ext_ack *extack); | 
|---|
| 1037 | int br_mdb_dump(struct net_device *dev, struct sk_buff *skb, | 
|---|
| 1038 | struct netlink_callback *cb); | 
|---|
| 1039 | int br_mdb_get(struct net_device *dev, struct nlattr *tb[], u32 portid, u32 seq, | 
|---|
| 1040 | struct netlink_ext_ack *extack); | 
|---|
| 1041 | void br_multicast_host_join(const struct net_bridge_mcast *brmctx, | 
|---|
| 1042 | struct net_bridge_mdb_entry *mp, bool notify); | 
|---|
| 1043 | void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify); | 
|---|
| 1044 | void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg, | 
|---|
| 1045 | u8 filter_mode); | 
|---|
| 1046 | void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp, | 
|---|
| 1047 | struct net_bridge_port_group *sg); | 
|---|
| 1048 | struct net_bridge_group_src * | 
|---|
| 1049 | br_multicast_find_group_src(struct net_bridge_port_group *pg, struct br_ip *ip); | 
|---|
| 1050 | struct net_bridge_group_src * | 
|---|
| 1051 | br_multicast_new_group_src(struct net_bridge_port_group *pg, | 
|---|
| 1052 | struct br_ip *src_ip); | 
|---|
| 1053 | void __br_multicast_del_group_src(struct net_bridge_group_src *src); | 
|---|
| 1054 | void br_multicast_del_group_src(struct net_bridge_group_src *src, | 
|---|
| 1055 | bool fastleave); | 
|---|
| 1056 | void br_multicast_ctx_init(struct net_bridge *br, | 
|---|
| 1057 | struct net_bridge_vlan *vlan, | 
|---|
| 1058 | struct net_bridge_mcast *brmctx); | 
|---|
| 1059 | void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx); | 
|---|
| 1060 | void br_multicast_port_ctx_init(struct net_bridge_port *port, | 
|---|
| 1061 | struct net_bridge_vlan *vlan, | 
|---|
| 1062 | struct net_bridge_mcast_port *pmctx); | 
|---|
| 1063 | void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx); | 
|---|
| 1064 | void br_multicast_update_vlan_mcast_ctx(struct net_bridge_vlan *v, u8 state); | 
|---|
| 1065 | void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on); | 
|---|
| 1066 | int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on, | 
|---|
| 1067 | struct netlink_ext_ack *extack); | 
|---|
| 1068 | bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on); | 
|---|
| 1069 |  | 
|---|
| 1070 | int br_rports_fill_info(struct sk_buff *skb, | 
|---|
| 1071 | const struct net_bridge_mcast *brmctx); | 
|---|
| 1072 | int br_multicast_dump_querier_state(struct sk_buff *skb, | 
|---|
| 1073 | const struct net_bridge_mcast *brmctx, | 
|---|
| 1074 | int nest_attr); | 
|---|
| 1075 | size_t br_multicast_querier_state_size(void); | 
|---|
| 1076 | size_t br_rports_size(const struct net_bridge_mcast *brmctx); | 
|---|
| 1077 | void br_multicast_set_query_intvl(struct net_bridge_mcast *brmctx, | 
|---|
| 1078 | unsigned long val); | 
|---|
| 1079 | void br_multicast_set_startup_query_intvl(struct net_bridge_mcast *brmctx, | 
|---|
| 1080 | unsigned long val); | 
|---|
| 1081 |  | 
|---|
| 1082 | static inline bool br_group_is_l2(const struct br_ip *group) | 
|---|
| 1083 | { | 
|---|
| 1084 | return group->proto == 0; | 
|---|
| 1085 | } | 
|---|
| 1086 |  | 
|---|
| 1087 | #define mlock_dereference(X, br) \ | 
|---|
| 1088 | rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) | 
|---|
| 1089 |  | 
|---|
| 1090 | static inline struct hlist_node * | 
|---|
| 1091 | br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx, | 
|---|
| 1092 | struct sk_buff *skb) | 
|---|
| 1093 | { | 
|---|
| 1094 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1095 | if (skb->protocol == htons(ETH_P_IPV6)) | 
|---|
| 1096 | return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list)); | 
|---|
| 1097 | #endif | 
|---|
| 1098 | return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list)); | 
|---|
| 1099 | } | 
|---|
| 1100 |  | 
|---|
| 1101 | static inline struct net_bridge_port * | 
|---|
| 1102 | br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) | 
|---|
| 1103 | { | 
|---|
| 1104 | struct net_bridge_mcast_port *mctx; | 
|---|
| 1105 |  | 
|---|
| 1106 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1107 | if (skb->protocol == htons(ETH_P_IPV6)) | 
|---|
| 1108 | mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, | 
|---|
| 1109 | ip6_rlist); | 
|---|
| 1110 | else | 
|---|
| 1111 | #endif | 
|---|
| 1112 | mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, | 
|---|
| 1113 | ip4_rlist); | 
|---|
| 1114 |  | 
|---|
| 1115 | if (mctx) | 
|---|
| 1116 | return mctx->port; | 
|---|
| 1117 | else | 
|---|
| 1118 | return NULL; | 
|---|
| 1119 | } | 
|---|
| 1120 |  | 
|---|
| 1121 | static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx) | 
|---|
| 1122 | { | 
|---|
| 1123 | return timer_pending(&brmctx->ip4_mc_router_timer); | 
|---|
| 1124 | } | 
|---|
| 1125 |  | 
|---|
| 1126 | static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx) | 
|---|
| 1127 | { | 
|---|
| 1128 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1129 | return timer_pending(&brmctx->ip6_mc_router_timer); | 
|---|
| 1130 | #else | 
|---|
| 1131 | return false; | 
|---|
| 1132 | #endif | 
|---|
| 1133 | } | 
|---|
| 1134 |  | 
|---|
| 1135 | static inline bool | 
|---|
| 1136 | br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb) | 
|---|
| 1137 | { | 
|---|
| 1138 | switch (brmctx->multicast_router) { | 
|---|
| 1139 | case MDB_RTR_TYPE_PERM: | 
|---|
| 1140 | return true; | 
|---|
| 1141 | case MDB_RTR_TYPE_TEMP_QUERY: | 
|---|
| 1142 | if (skb) { | 
|---|
| 1143 | if (skb->protocol == htons(ETH_P_IP)) | 
|---|
| 1144 | return br_ip4_multicast_is_router(brmctx); | 
|---|
| 1145 | else if (skb->protocol == htons(ETH_P_IPV6)) | 
|---|
| 1146 | return br_ip6_multicast_is_router(brmctx); | 
|---|
| 1147 | } else { | 
|---|
| 1148 | return br_ip4_multicast_is_router(brmctx) || | 
|---|
| 1149 | br_ip6_multicast_is_router(brmctx); | 
|---|
| 1150 | } | 
|---|
| 1151 | fallthrough; | 
|---|
| 1152 | default: | 
|---|
| 1153 | return false; | 
|---|
| 1154 | } | 
|---|
| 1155 | } | 
|---|
| 1156 |  | 
|---|
| 1157 | static inline bool | 
|---|
| 1158 | __br_multicast_querier_exists(struct net_bridge_mcast *brmctx, | 
|---|
| 1159 | struct bridge_mcast_other_query *querier, | 
|---|
| 1160 | const bool is_ipv6) | 
|---|
| 1161 | { | 
|---|
| 1162 | bool own_querier_enabled; | 
|---|
| 1163 |  | 
|---|
| 1164 | if (brmctx->multicast_querier) { | 
|---|
| 1165 | if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR)) | 
|---|
| 1166 | own_querier_enabled = false; | 
|---|
| 1167 | else | 
|---|
| 1168 | own_querier_enabled = true; | 
|---|
| 1169 | } else { | 
|---|
| 1170 | own_querier_enabled = false; | 
|---|
| 1171 | } | 
|---|
| 1172 |  | 
|---|
| 1173 | return !timer_pending(&querier->delay_timer) && | 
|---|
| 1174 | (own_querier_enabled || timer_pending(&querier->timer)); | 
|---|
| 1175 | } | 
|---|
| 1176 |  | 
|---|
| 1177 | static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, | 
|---|
| 1178 | struct ethhdr *eth, | 
|---|
| 1179 | const struct net_bridge_mdb_entry *mdb) | 
|---|
| 1180 | { | 
|---|
| 1181 | switch (eth->h_proto) { | 
|---|
| 1182 | case (htons(ETH_P_IP)): | 
|---|
| 1183 | return __br_multicast_querier_exists(brmctx, | 
|---|
| 1184 | &brmctx->ip4_other_query, false); | 
|---|
| 1185 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1186 | case (htons(ETH_P_IPV6)): | 
|---|
| 1187 | return __br_multicast_querier_exists(brmctx, | 
|---|
| 1188 | &brmctx->ip6_other_query, true); | 
|---|
| 1189 | #endif | 
|---|
| 1190 | default: | 
|---|
| 1191 | return !!mdb && br_group_is_l2(&mdb->addr); | 
|---|
| 1192 | } | 
|---|
| 1193 | } | 
|---|
| 1194 |  | 
|---|
| 1195 | static inline bool br_multicast_is_star_g(const struct br_ip *ip) | 
|---|
| 1196 | { | 
|---|
| 1197 | switch (ip->proto) { | 
|---|
| 1198 | case htons(ETH_P_IP): | 
|---|
| 1199 | return ipv4_is_zeronet(ip->src.ip4); | 
|---|
| 1200 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1201 | case htons(ETH_P_IPV6): | 
|---|
| 1202 | return ipv6_addr_any(&ip->src.ip6); | 
|---|
| 1203 | #endif | 
|---|
| 1204 | default: | 
|---|
| 1205 | return false; | 
|---|
| 1206 | } | 
|---|
| 1207 | } | 
|---|
| 1208 |  | 
|---|
| 1209 | static inline bool | 
|---|
| 1210 | br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx, | 
|---|
| 1211 | __be16 proto) | 
|---|
| 1212 | { | 
|---|
| 1213 | switch (proto) { | 
|---|
| 1214 | case htons(ETH_P_IP): | 
|---|
| 1215 | return !!(brmctx->multicast_igmp_version == 3); | 
|---|
| 1216 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1217 | case htons(ETH_P_IPV6): | 
|---|
| 1218 | return !!(brmctx->multicast_mld_version == 2); | 
|---|
| 1219 | #endif | 
|---|
| 1220 | default: | 
|---|
| 1221 | return false; | 
|---|
| 1222 | } | 
|---|
| 1223 | } | 
|---|
| 1224 |  | 
|---|
| 1225 | static inline int br_multicast_igmp_type(const struct sk_buff *skb) | 
|---|
| 1226 | { | 
|---|
| 1227 | return BR_INPUT_SKB_CB(skb)->igmp; | 
|---|
| 1228 | } | 
|---|
| 1229 |  | 
|---|
| 1230 | static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx) | 
|---|
| 1231 | { | 
|---|
| 1232 | return brmctx->multicast_last_member_interval * | 
|---|
| 1233 | brmctx->multicast_last_member_count; | 
|---|
| 1234 | } | 
|---|
| 1235 |  | 
|---|
| 1236 | static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx) | 
|---|
| 1237 | { | 
|---|
| 1238 | return brmctx->multicast_membership_interval; | 
|---|
| 1239 | } | 
|---|
| 1240 |  | 
|---|
| 1241 | static inline bool | 
|---|
| 1242 | br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx) | 
|---|
| 1243 | { | 
|---|
| 1244 | return !!brmctx->vlan; | 
|---|
| 1245 | } | 
|---|
| 1246 |  | 
|---|
| 1247 | static inline bool | 
|---|
| 1248 | br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx) | 
|---|
| 1249 | { | 
|---|
| 1250 | return !!pmctx->vlan; | 
|---|
| 1251 | } | 
|---|
| 1252 |  | 
|---|
| 1253 | static inline struct net_bridge_mcast * | 
|---|
| 1254 | br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx) | 
|---|
| 1255 | { | 
|---|
| 1256 | if (!br_multicast_port_ctx_is_vlan(pmctx)) | 
|---|
| 1257 | return &pmctx->port->br->multicast_ctx; | 
|---|
| 1258 | else | 
|---|
| 1259 | return &pmctx->vlan->brvlan->br_mcast_ctx; | 
|---|
| 1260 | } | 
|---|
| 1261 |  | 
|---|
| 1262 | static inline bool | 
|---|
| 1263 | br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx) | 
|---|
| 1264 | { | 
|---|
| 1265 | return br_multicast_ctx_is_vlan(brmctx) && | 
|---|
| 1266 | (!br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) || | 
|---|
| 1267 | !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)); | 
|---|
| 1268 | } | 
|---|
| 1269 |  | 
|---|
| 1270 | static inline bool | 
|---|
| 1271 | br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx) | 
|---|
| 1272 | { | 
|---|
| 1273 | return br_multicast_ctx_is_vlan(brmctx) && | 
|---|
| 1274 | !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); | 
|---|
| 1275 | } | 
|---|
| 1276 |  | 
|---|
| 1277 | static inline bool | 
|---|
| 1278 | br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx) | 
|---|
| 1279 | { | 
|---|
| 1280 | return br_multicast_port_ctx_is_vlan(pmctx) && | 
|---|
| 1281 | !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); | 
|---|
| 1282 | } | 
|---|
| 1283 |  | 
|---|
| 1284 | static inline bool | 
|---|
| 1285 | br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx) | 
|---|
| 1286 | { | 
|---|
| 1287 | return pmctx->port->state == BR_STATE_DISABLED || | 
|---|
| 1288 | (br_multicast_port_ctx_is_vlan(pmctx) && | 
|---|
| 1289 | (br_multicast_port_ctx_vlan_disabled(pmctx) || | 
|---|
| 1290 | pmctx->vlan->state == BR_STATE_DISABLED)); | 
|---|
| 1291 | } | 
|---|
| 1292 |  | 
|---|
| 1293 | static inline bool | 
|---|
| 1294 | br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx) | 
|---|
| 1295 | { | 
|---|
| 1296 | return br_multicast_port_ctx_state_disabled(pmctx) || | 
|---|
| 1297 | pmctx->port->state == BR_STATE_BLOCKING || | 
|---|
| 1298 | (br_multicast_port_ctx_is_vlan(pmctx) && | 
|---|
| 1299 | pmctx->vlan->state == BR_STATE_BLOCKING); | 
|---|
| 1300 | } | 
|---|
| 1301 |  | 
|---|
| 1302 | static inline bool | 
|---|
| 1303 | br_rports_have_mc_router(const struct net_bridge_mcast *brmctx) | 
|---|
| 1304 | { | 
|---|
| 1305 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1306 | return !hlist_empty(&brmctx->ip4_mc_router_list) || | 
|---|
| 1307 | !hlist_empty(&brmctx->ip6_mc_router_list); | 
|---|
| 1308 | #else | 
|---|
| 1309 | return !hlist_empty(&brmctx->ip4_mc_router_list); | 
|---|
| 1310 | #endif | 
|---|
| 1311 | } | 
|---|
| 1312 |  | 
|---|
| 1313 | static inline bool | 
|---|
| 1314 | br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, | 
|---|
| 1315 | const struct net_bridge_mcast *brmctx2) | 
|---|
| 1316 | { | 
|---|
| 1317 | return brmctx1->multicast_igmp_version == | 
|---|
| 1318 | brmctx2->multicast_igmp_version && | 
|---|
| 1319 | brmctx1->multicast_last_member_count == | 
|---|
| 1320 | brmctx2->multicast_last_member_count && | 
|---|
| 1321 | brmctx1->multicast_startup_query_count == | 
|---|
| 1322 | brmctx2->multicast_startup_query_count && | 
|---|
| 1323 | brmctx1->multicast_last_member_interval == | 
|---|
| 1324 | brmctx2->multicast_last_member_interval && | 
|---|
| 1325 | brmctx1->multicast_membership_interval == | 
|---|
| 1326 | brmctx2->multicast_membership_interval && | 
|---|
| 1327 | brmctx1->multicast_querier_interval == | 
|---|
| 1328 | brmctx2->multicast_querier_interval && | 
|---|
| 1329 | brmctx1->multicast_query_interval == | 
|---|
| 1330 | brmctx2->multicast_query_interval && | 
|---|
| 1331 | brmctx1->multicast_query_response_interval == | 
|---|
| 1332 | brmctx2->multicast_query_response_interval && | 
|---|
| 1333 | brmctx1->multicast_startup_query_interval == | 
|---|
| 1334 | brmctx2->multicast_startup_query_interval && | 
|---|
| 1335 | brmctx1->multicast_querier == brmctx2->multicast_querier && | 
|---|
| 1336 | brmctx1->multicast_router == brmctx2->multicast_router && | 
|---|
| 1337 | !br_rports_have_mc_router(brmctx1) && | 
|---|
| 1338 | !br_rports_have_mc_router(brmctx2) && | 
|---|
| 1339 | #if IS_ENABLED(CONFIG_IPV6) | 
|---|
| 1340 | brmctx1->multicast_mld_version == | 
|---|
| 1341 | brmctx2->multicast_mld_version && | 
|---|
| 1342 | #endif | 
|---|
| 1343 | true; | 
|---|
| 1344 | } | 
|---|
| 1345 |  | 
|---|
| 1346 | static inline bool | 
|---|
| 1347 | br_multicast_ctx_matches_vlan_snooping(const struct net_bridge_mcast *brmctx) | 
|---|
| 1348 | { | 
|---|
| 1349 | bool vlan_snooping_enabled; | 
|---|
| 1350 |  | 
|---|
| 1351 | vlan_snooping_enabled = !!br_opt_get(brmctx->br, | 
|---|
| 1352 | BROPT_MCAST_VLAN_SNOOPING_ENABLED); | 
|---|
| 1353 |  | 
|---|
| 1354 | return !!(vlan_snooping_enabled == br_multicast_ctx_is_vlan(brmctx)); | 
|---|
| 1355 | } | 
|---|
| 1356 |  | 
|---|
| 1357 | static inline void | 
|---|
| 1358 | br_multicast_set_pg_offload_flags(struct net_bridge_port_group *p, | 
|---|
| 1359 | bool offloaded) | 
|---|
| 1360 | { | 
|---|
| 1361 | p->flags &= ~(MDB_PG_FLAGS_OFFLOAD | MDB_PG_FLAGS_OFFLOAD_FAILED); | 
|---|
| 1362 | p->flags |= (offloaded ? MDB_PG_FLAGS_OFFLOAD : | 
|---|
| 1363 | MDB_PG_FLAGS_OFFLOAD_FAILED); | 
|---|
| 1364 | } | 
|---|
| 1365 |  | 
|---|
| 1366 | static inline bool | 
|---|
| 1367 | br_mdb_should_notify(const struct net_bridge *br, u8 changed_flags) | 
|---|
| 1368 | { | 
|---|
| 1369 | return br_opt_get(br, BROPT_MDB_OFFLOAD_FAIL_NOTIFICATION) && | 
|---|
| 1370 | (changed_flags & MDB_PG_FLAGS_OFFLOAD_FAILED); | 
|---|
| 1371 | } | 
|---|
| 1372 | #else | 
|---|
| 1373 | static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx, | 
|---|
| 1374 | struct net_bridge_mcast_port **pmctx, | 
|---|
| 1375 | struct net_bridge_vlan *vlan, | 
|---|
| 1376 | struct sk_buff *skb, | 
|---|
| 1377 | u16 vid) | 
|---|
| 1378 | { | 
|---|
| 1379 | return 0; | 
|---|
| 1380 | } | 
|---|
| 1381 |  | 
|---|
| 1382 | static inline struct net_bridge_mdb_entry * | 
|---|
| 1383 | br_mdb_entry_skb_get(struct net_bridge_mcast *brmctx, struct sk_buff *skb, | 
|---|
| 1384 | u16 vid) | 
|---|
| 1385 | { | 
|---|
| 1386 | return NULL; | 
|---|
| 1387 | } | 
|---|
| 1388 |  | 
|---|
| 1389 | static inline int br_multicast_add_port(struct net_bridge_port *port) | 
|---|
| 1390 | { | 
|---|
| 1391 | return 0; | 
|---|
| 1392 | } | 
|---|
| 1393 |  | 
|---|
| 1394 | static inline void br_multicast_del_port(struct net_bridge_port *port) | 
|---|
| 1395 | { | 
|---|
| 1396 | } | 
|---|
| 1397 |  | 
|---|
| 1398 | static inline void br_multicast_enable_port(struct net_bridge_port *port) | 
|---|
| 1399 | { | 
|---|
| 1400 | } | 
|---|
| 1401 |  | 
|---|
| 1402 | static inline void br_multicast_disable_port(struct net_bridge_port *port) | 
|---|
| 1403 | { | 
|---|
| 1404 | } | 
|---|
| 1405 |  | 
|---|
| 1406 | static inline void br_multicast_init(struct net_bridge *br) | 
|---|
| 1407 | { | 
|---|
| 1408 | } | 
|---|
| 1409 |  | 
|---|
| 1410 | static inline void br_multicast_join_snoopers(struct net_bridge *br) | 
|---|
| 1411 | { | 
|---|
| 1412 | } | 
|---|
| 1413 |  | 
|---|
| 1414 | static inline void br_multicast_leave_snoopers(struct net_bridge *br) | 
|---|
| 1415 | { | 
|---|
| 1416 | } | 
|---|
| 1417 |  | 
|---|
| 1418 | static inline void br_multicast_open(struct net_bridge *br) | 
|---|
| 1419 | { | 
|---|
| 1420 | } | 
|---|
| 1421 |  | 
|---|
| 1422 | static inline void br_multicast_stop(struct net_bridge *br) | 
|---|
| 1423 | { | 
|---|
| 1424 | } | 
|---|
| 1425 |  | 
|---|
| 1426 | static inline void br_multicast_dev_del(struct net_bridge *br) | 
|---|
| 1427 | { | 
|---|
| 1428 | } | 
|---|
| 1429 |  | 
|---|
| 1430 | static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst, | 
|---|
| 1431 | struct sk_buff *skb, | 
|---|
| 1432 | struct net_bridge_mcast *brmctx, | 
|---|
| 1433 | bool local_rcv, bool local_orig) | 
|---|
| 1434 | { | 
|---|
| 1435 | } | 
|---|
| 1436 |  | 
|---|
| 1437 | static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx, | 
|---|
| 1438 | struct sk_buff *skb) | 
|---|
| 1439 | { | 
|---|
| 1440 | return false; | 
|---|
| 1441 | } | 
|---|
| 1442 |  | 
|---|
| 1443 | static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, | 
|---|
| 1444 | struct ethhdr *eth, | 
|---|
| 1445 | const struct net_bridge_mdb_entry *mdb) | 
|---|
| 1446 | { | 
|---|
| 1447 | return false; | 
|---|
| 1448 | } | 
|---|
| 1449 |  | 
|---|
| 1450 | static inline int br_mdb_add(struct net_device *dev, struct nlattr *tb[], | 
|---|
| 1451 | u16 nlmsg_flags, struct netlink_ext_ack *extack) | 
|---|
| 1452 | { | 
|---|
| 1453 | return -EOPNOTSUPP; | 
|---|
| 1454 | } | 
|---|
| 1455 |  | 
|---|
| 1456 | static inline int br_mdb_del(struct net_device *dev, struct nlattr *tb[], | 
|---|
| 1457 | struct netlink_ext_ack *extack) | 
|---|
| 1458 | { | 
|---|
| 1459 | return -EOPNOTSUPP; | 
|---|
| 1460 | } | 
|---|
| 1461 |  | 
|---|
| 1462 | static inline int br_mdb_del_bulk(struct net_device *dev, struct nlattr *tb[], | 
|---|
| 1463 | struct netlink_ext_ack *extack) | 
|---|
| 1464 | { | 
|---|
| 1465 | return -EOPNOTSUPP; | 
|---|
| 1466 | } | 
|---|
| 1467 |  | 
|---|
| 1468 | static inline int br_mdb_dump(struct net_device *dev, struct sk_buff *skb, | 
|---|
| 1469 | struct netlink_callback *cb) | 
|---|
| 1470 | { | 
|---|
| 1471 | return 0; | 
|---|
| 1472 | } | 
|---|
| 1473 |  | 
|---|
| 1474 | static inline int br_mdb_get(struct net_device *dev, struct nlattr *tb[], | 
|---|
| 1475 | u32 portid, u32 seq, | 
|---|
| 1476 | struct netlink_ext_ack *extack) | 
|---|
| 1477 | { | 
|---|
| 1478 | return -EOPNOTSUPP; | 
|---|
| 1479 | } | 
|---|
| 1480 |  | 
|---|
| 1481 | static inline int br_mdb_hash_init(struct net_bridge *br) | 
|---|
| 1482 | { | 
|---|
| 1483 | return 0; | 
|---|
| 1484 | } | 
|---|
| 1485 |  | 
|---|
| 1486 | static inline void br_mdb_hash_fini(struct net_bridge *br) | 
|---|
| 1487 | { | 
|---|
| 1488 | } | 
|---|
| 1489 |  | 
|---|
| 1490 | static inline void br_multicast_count(struct net_bridge *br, | 
|---|
| 1491 | const struct net_bridge_port *p, | 
|---|
| 1492 | const struct sk_buff *skb, | 
|---|
| 1493 | u8 type, u8 dir) | 
|---|
| 1494 | { | 
|---|
| 1495 | } | 
|---|
| 1496 |  | 
|---|
| 1497 | static inline int br_multicast_init_stats(struct net_bridge *br) | 
|---|
| 1498 | { | 
|---|
| 1499 | return 0; | 
|---|
| 1500 | } | 
|---|
| 1501 |  | 
|---|
| 1502 | static inline void br_multicast_uninit_stats(struct net_bridge *br) | 
|---|
| 1503 | { | 
|---|
| 1504 | } | 
|---|
| 1505 |  | 
|---|
| 1506 | static inline int br_multicast_igmp_type(const struct sk_buff *skb) | 
|---|
| 1507 | { | 
|---|
| 1508 | return 0; | 
|---|
| 1509 | } | 
|---|
| 1510 |  | 
|---|
| 1511 | static inline void br_multicast_ctx_init(struct net_bridge *br, | 
|---|
| 1512 | struct net_bridge_vlan *vlan, | 
|---|
| 1513 | struct net_bridge_mcast *brmctx) | 
|---|
| 1514 | { | 
|---|
| 1515 | } | 
|---|
| 1516 |  | 
|---|
| 1517 | static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx) | 
|---|
| 1518 | { | 
|---|
| 1519 | } | 
|---|
| 1520 |  | 
|---|
| 1521 | static inline void br_multicast_port_ctx_init(struct net_bridge_port *port, | 
|---|
| 1522 | struct net_bridge_vlan *vlan, | 
|---|
| 1523 | struct net_bridge_mcast_port *pmctx) | 
|---|
| 1524 | { | 
|---|
| 1525 | } | 
|---|
| 1526 |  | 
|---|
| 1527 | static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx) | 
|---|
| 1528 | { | 
|---|
| 1529 | } | 
|---|
| 1530 |  | 
|---|
| 1531 | static inline void br_multicast_update_vlan_mcast_ctx(struct net_bridge_vlan *v, | 
|---|
| 1532 | u8 state) | 
|---|
| 1533 | { | 
|---|
| 1534 | } | 
|---|
| 1535 |  | 
|---|
| 1536 | static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, | 
|---|
| 1537 | bool on) | 
|---|
| 1538 | { | 
|---|
| 1539 | } | 
|---|
| 1540 |  | 
|---|
| 1541 | static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br, | 
|---|
| 1542 | bool on, | 
|---|
| 1543 | struct netlink_ext_ack *extack) | 
|---|
| 1544 | { | 
|---|
| 1545 | return -EOPNOTSUPP; | 
|---|
| 1546 | } | 
|---|
| 1547 |  | 
|---|
| 1548 | static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, | 
|---|
| 1549 | bool on) | 
|---|
| 1550 | { | 
|---|
| 1551 | return false; | 
|---|
| 1552 | } | 
|---|
| 1553 |  | 
|---|
| 1554 | static inline bool | 
|---|
| 1555 | br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, | 
|---|
| 1556 | const struct net_bridge_mcast *brmctx2) | 
|---|
| 1557 | { | 
|---|
| 1558 | return true; | 
|---|
| 1559 | } | 
|---|
| 1560 | #endif | 
|---|
| 1561 |  | 
|---|
| 1562 | /* br_vlan.c */ | 
|---|
| 1563 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | 
|---|
| 1564 | bool br_allowed_ingress(const struct net_bridge *br, | 
|---|
| 1565 | struct net_bridge_vlan_group *vg, struct sk_buff *skb, | 
|---|
| 1566 | u16 *vid, u8 *state, | 
|---|
| 1567 | struct net_bridge_vlan **vlan); | 
|---|
| 1568 | bool br_allowed_egress(struct net_bridge_vlan_group *vg, | 
|---|
| 1569 | const struct sk_buff *skb); | 
|---|
| 1570 | bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); | 
|---|
| 1571 | struct sk_buff *br_handle_vlan(struct net_bridge *br, | 
|---|
| 1572 | const struct net_bridge_port *port, | 
|---|
| 1573 | struct net_bridge_vlan_group *vg, | 
|---|
| 1574 | struct sk_buff *skb); | 
|---|
| 1575 | int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, | 
|---|
| 1576 | bool *changed, struct netlink_ext_ack *extack); | 
|---|
| 1577 | int br_vlan_delete(struct net_bridge *br, u16 vid); | 
|---|
| 1578 | void br_vlan_flush(struct net_bridge *br); | 
|---|
| 1579 | struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid); | 
|---|
| 1580 | void br_recalculate_fwd_mask(struct net_bridge *br); | 
|---|
| 1581 | int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val, | 
|---|
| 1582 | struct netlink_ext_ack *extack); | 
|---|
| 1583 | int __br_vlan_set_proto(struct net_bridge *br, __be16 proto, | 
|---|
| 1584 | struct netlink_ext_ack *extack); | 
|---|
| 1585 | int br_vlan_set_proto(struct net_bridge *br, unsigned long val, | 
|---|
| 1586 | struct netlink_ext_ack *extack); | 
|---|
| 1587 | int br_vlan_set_stats(struct net_bridge *br, unsigned long val); | 
|---|
| 1588 | int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val); | 
|---|
| 1589 | int br_vlan_init(struct net_bridge *br); | 
|---|
| 1590 | int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val, | 
|---|
| 1591 | struct netlink_ext_ack *extack); | 
|---|
| 1592 | int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, | 
|---|
| 1593 | struct netlink_ext_ack *extack); | 
|---|
| 1594 | int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, | 
|---|
| 1595 | bool *changed, struct netlink_ext_ack *extack); | 
|---|
| 1596 | int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); | 
|---|
| 1597 | void nbp_vlan_flush(struct net_bridge_port *port); | 
|---|
| 1598 | int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); | 
|---|
| 1599 | int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); | 
|---|
| 1600 | void br_vlan_get_stats(const struct net_bridge_vlan *v, | 
|---|
| 1601 | struct pcpu_sw_netstats *stats); | 
|---|
| 1602 | void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); | 
|---|
| 1603 | int br_vlan_bridge_event(struct net_device *dev, unsigned long event, | 
|---|
| 1604 | void *ptr); | 
|---|
| 1605 | void br_vlan_vlan_upper_event(struct net_device *br_dev, | 
|---|
| 1606 | struct net_device *vlan_dev, | 
|---|
| 1607 | unsigned long event); | 
|---|
| 1608 | int br_vlan_rtnl_init(void); | 
|---|
| 1609 | void br_vlan_rtnl_uninit(void); | 
|---|
| 1610 | void br_vlan_notify(const struct net_bridge *br, | 
|---|
| 1611 | const struct net_bridge_port *p, | 
|---|
| 1612 | u16 vid, u16 vid_range, | 
|---|
| 1613 | int cmd); | 
|---|
| 1614 | bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, | 
|---|
| 1615 | const struct net_bridge_vlan *range_end); | 
|---|
| 1616 |  | 
|---|
| 1617 | void br_vlan_fill_forward_path_pvid(struct net_bridge *br, | 
|---|
| 1618 | struct net_device_path_ctx *ctx, | 
|---|
| 1619 | struct net_device_path *path); | 
|---|
| 1620 | int br_vlan_fill_forward_path_mode(struct net_bridge *br, | 
|---|
| 1621 | struct net_bridge_port *dst, | 
|---|
| 1622 | struct net_device_path *path); | 
|---|
| 1623 |  | 
|---|
| 1624 | static inline struct net_bridge_vlan_group *br_vlan_group( | 
|---|
| 1625 | const struct net_bridge *br) | 
|---|
| 1626 | { | 
|---|
| 1627 | return rtnl_dereference(br->vlgrp); | 
|---|
| 1628 | } | 
|---|
| 1629 |  | 
|---|
| 1630 | static inline struct net_bridge_vlan_group *nbp_vlan_group( | 
|---|
| 1631 | const struct net_bridge_port *p) | 
|---|
| 1632 | { | 
|---|
| 1633 | return rtnl_dereference(p->vlgrp); | 
|---|
| 1634 | } | 
|---|
| 1635 |  | 
|---|
| 1636 | static inline struct net_bridge_vlan_group *br_vlan_group_rcu( | 
|---|
| 1637 | const struct net_bridge *br) | 
|---|
| 1638 | { | 
|---|
| 1639 | return rcu_dereference(br->vlgrp); | 
|---|
| 1640 | } | 
|---|
| 1641 |  | 
|---|
| 1642 | static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( | 
|---|
| 1643 | const struct net_bridge_port *p) | 
|---|
| 1644 | { | 
|---|
| 1645 | return rcu_dereference(p->vlgrp); | 
|---|
| 1646 | } | 
|---|
| 1647 |  | 
|---|
| 1648 | /* Since bridge now depends on 8021Q module, but the time bridge sees the | 
|---|
| 1649 | * skb, the vlan tag will always be present if the frame was tagged. | 
|---|
| 1650 | */ | 
|---|
| 1651 | static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) | 
|---|
| 1652 | { | 
|---|
| 1653 | int err = 0; | 
|---|
| 1654 |  | 
|---|
| 1655 | if (skb_vlan_tag_present(skb)) { | 
|---|
| 1656 | *vid = skb_vlan_tag_get_id(skb); | 
|---|
| 1657 | } else { | 
|---|
| 1658 | *vid = 0; | 
|---|
| 1659 | err = -EINVAL; | 
|---|
| 1660 | } | 
|---|
| 1661 |  | 
|---|
| 1662 | return err; | 
|---|
| 1663 | } | 
|---|
| 1664 |  | 
|---|
| 1665 | static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) | 
|---|
| 1666 | { | 
|---|
| 1667 | if (!vg) | 
|---|
| 1668 | return 0; | 
|---|
| 1669 |  | 
|---|
| 1670 | smp_rmb(); | 
|---|
| 1671 | return vg->pvid; | 
|---|
| 1672 | } | 
|---|
| 1673 |  | 
|---|
| 1674 | static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) | 
|---|
| 1675 | { | 
|---|
| 1676 | return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags; | 
|---|
| 1677 | } | 
|---|
| 1678 | #else | 
|---|
| 1679 | static inline bool br_allowed_ingress(const struct net_bridge *br, | 
|---|
| 1680 | struct net_bridge_vlan_group *vg, | 
|---|
| 1681 | struct sk_buff *skb, | 
|---|
| 1682 | u16 *vid, u8 *state, | 
|---|
| 1683 | struct net_bridge_vlan **vlan) | 
|---|
| 1684 |  | 
|---|
| 1685 | { | 
|---|
| 1686 | *vlan = NULL; | 
|---|
| 1687 | return true; | 
|---|
| 1688 | } | 
|---|
| 1689 |  | 
|---|
| 1690 | static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, | 
|---|
| 1691 | const struct sk_buff *skb) | 
|---|
| 1692 | { | 
|---|
| 1693 | return true; | 
|---|
| 1694 | } | 
|---|
| 1695 |  | 
|---|
| 1696 | static inline bool br_should_learn(struct net_bridge_port *p, | 
|---|
| 1697 | struct sk_buff *skb, u16 *vid) | 
|---|
| 1698 | { | 
|---|
| 1699 | return true; | 
|---|
| 1700 | } | 
|---|
| 1701 |  | 
|---|
| 1702 | static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, | 
|---|
| 1703 | const struct net_bridge_port *port, | 
|---|
| 1704 | struct net_bridge_vlan_group *vg, | 
|---|
| 1705 | struct sk_buff *skb) | 
|---|
| 1706 | { | 
|---|
| 1707 | return skb; | 
|---|
| 1708 | } | 
|---|
| 1709 |  | 
|---|
| 1710 | static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, | 
|---|
| 1711 | bool *changed, struct netlink_ext_ack *extack) | 
|---|
| 1712 | { | 
|---|
| 1713 | *changed = false; | 
|---|
| 1714 | return -EOPNOTSUPP; | 
|---|
| 1715 | } | 
|---|
| 1716 |  | 
|---|
| 1717 | static inline int br_vlan_delete(struct net_bridge *br, u16 vid) | 
|---|
| 1718 | { | 
|---|
| 1719 | return -EOPNOTSUPP; | 
|---|
| 1720 | } | 
|---|
| 1721 |  | 
|---|
| 1722 | static inline void br_vlan_flush(struct net_bridge *br) | 
|---|
| 1723 | { | 
|---|
| 1724 | } | 
|---|
| 1725 |  | 
|---|
| 1726 | static inline void br_recalculate_fwd_mask(struct net_bridge *br) | 
|---|
| 1727 | { | 
|---|
| 1728 | } | 
|---|
| 1729 |  | 
|---|
| 1730 | static inline int br_vlan_init(struct net_bridge *br) | 
|---|
| 1731 | { | 
|---|
| 1732 | return 0; | 
|---|
| 1733 | } | 
|---|
| 1734 |  | 
|---|
| 1735 | static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, | 
|---|
| 1736 | bool *changed, struct netlink_ext_ack *extack) | 
|---|
| 1737 | { | 
|---|
| 1738 | *changed = false; | 
|---|
| 1739 | return -EOPNOTSUPP; | 
|---|
| 1740 | } | 
|---|
| 1741 |  | 
|---|
| 1742 | static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) | 
|---|
| 1743 | { | 
|---|
| 1744 | return -EOPNOTSUPP; | 
|---|
| 1745 | } | 
|---|
| 1746 |  | 
|---|
| 1747 | static inline void nbp_vlan_flush(struct net_bridge_port *port) | 
|---|
| 1748 | { | 
|---|
| 1749 | } | 
|---|
| 1750 |  | 
|---|
| 1751 | static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, | 
|---|
| 1752 | u16 vid) | 
|---|
| 1753 | { | 
|---|
| 1754 | return NULL; | 
|---|
| 1755 | } | 
|---|
| 1756 |  | 
|---|
| 1757 | static inline int nbp_vlan_init(struct net_bridge_port *port, | 
|---|
| 1758 | struct netlink_ext_ack *extack) | 
|---|
| 1759 | { | 
|---|
| 1760 | return 0; | 
|---|
| 1761 | } | 
|---|
| 1762 |  | 
|---|
| 1763 | static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag) | 
|---|
| 1764 | { | 
|---|
| 1765 | return 0; | 
|---|
| 1766 | } | 
|---|
| 1767 |  | 
|---|
| 1768 | static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) | 
|---|
| 1769 | { | 
|---|
| 1770 | return 0; | 
|---|
| 1771 | } | 
|---|
| 1772 |  | 
|---|
| 1773 | static inline int br_vlan_filter_toggle(struct net_bridge *br, | 
|---|
| 1774 | unsigned long val, | 
|---|
| 1775 | struct netlink_ext_ack *extack) | 
|---|
| 1776 | { | 
|---|
| 1777 | return -EOPNOTSUPP; | 
|---|
| 1778 | } | 
|---|
| 1779 |  | 
|---|
| 1780 | static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, | 
|---|
| 1781 | u32 filter_mask) | 
|---|
| 1782 | { | 
|---|
| 1783 | return 0; | 
|---|
| 1784 | } | 
|---|
| 1785 |  | 
|---|
| 1786 | static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br, | 
|---|
| 1787 | struct net_device_path_ctx *ctx, | 
|---|
| 1788 | struct net_device_path *path) | 
|---|
| 1789 | { | 
|---|
| 1790 | } | 
|---|
| 1791 |  | 
|---|
| 1792 | static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br, | 
|---|
| 1793 | struct net_bridge_port *dst, | 
|---|
| 1794 | struct net_device_path *path) | 
|---|
| 1795 | { | 
|---|
| 1796 | return 0; | 
|---|
| 1797 | } | 
|---|
| 1798 |  | 
|---|
| 1799 | static inline struct net_bridge_vlan_group *br_vlan_group( | 
|---|
| 1800 | const struct net_bridge *br) | 
|---|
| 1801 | { | 
|---|
| 1802 | return NULL; | 
|---|
| 1803 | } | 
|---|
| 1804 |  | 
|---|
| 1805 | static inline struct net_bridge_vlan_group *nbp_vlan_group( | 
|---|
| 1806 | const struct net_bridge_port *p) | 
|---|
| 1807 | { | 
|---|
| 1808 | return NULL; | 
|---|
| 1809 | } | 
|---|
| 1810 |  | 
|---|
| 1811 | static inline struct net_bridge_vlan_group *br_vlan_group_rcu( | 
|---|
| 1812 | const struct net_bridge *br) | 
|---|
| 1813 | { | 
|---|
| 1814 | return NULL; | 
|---|
| 1815 | } | 
|---|
| 1816 |  | 
|---|
| 1817 | static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( | 
|---|
| 1818 | const struct net_bridge_port *p) | 
|---|
| 1819 | { | 
|---|
| 1820 | return NULL; | 
|---|
| 1821 | } | 
|---|
| 1822 |  | 
|---|
| 1823 | static inline void br_vlan_get_stats(const struct net_bridge_vlan *v, | 
|---|
| 1824 | struct pcpu_sw_netstats *stats) | 
|---|
| 1825 | { | 
|---|
| 1826 | } | 
|---|
| 1827 |  | 
|---|
| 1828 | static inline void br_vlan_port_event(struct net_bridge_port *p, | 
|---|
| 1829 | unsigned long event) | 
|---|
| 1830 | { | 
|---|
| 1831 | } | 
|---|
| 1832 |  | 
|---|
| 1833 | static inline int br_vlan_bridge_event(struct net_device *dev, | 
|---|
| 1834 | unsigned long event, void *ptr) | 
|---|
| 1835 | { | 
|---|
| 1836 | return 0; | 
|---|
| 1837 | } | 
|---|
| 1838 |  | 
|---|
| 1839 | static inline void br_vlan_vlan_upper_event(struct net_device *br_dev, | 
|---|
| 1840 | struct net_device *vlan_dev, | 
|---|
| 1841 | unsigned long event) | 
|---|
| 1842 | { | 
|---|
| 1843 | } | 
|---|
| 1844 |  | 
|---|
| 1845 | static inline int br_vlan_rtnl_init(void) | 
|---|
| 1846 | { | 
|---|
| 1847 | return 0; | 
|---|
| 1848 | } | 
|---|
| 1849 |  | 
|---|
| 1850 | static inline void br_vlan_rtnl_uninit(void) | 
|---|
| 1851 | { | 
|---|
| 1852 | } | 
|---|
| 1853 |  | 
|---|
| 1854 | static inline void br_vlan_notify(const struct net_bridge *br, | 
|---|
| 1855 | const struct net_bridge_port *p, | 
|---|
| 1856 | u16 vid, u16 vid_range, | 
|---|
| 1857 | int cmd) | 
|---|
| 1858 | { | 
|---|
| 1859 | } | 
|---|
| 1860 |  | 
|---|
| 1861 | static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, | 
|---|
| 1862 | const struct net_bridge_vlan *range_end) | 
|---|
| 1863 | { | 
|---|
| 1864 | return true; | 
|---|
| 1865 | } | 
|---|
| 1866 |  | 
|---|
| 1867 | static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) | 
|---|
| 1868 | { | 
|---|
| 1869 | return 0; | 
|---|
| 1870 | } | 
|---|
| 1871 |  | 
|---|
| 1872 | #endif | 
|---|
| 1873 |  | 
|---|
| 1874 | /* br_vlan_options.c */ | 
|---|
| 1875 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | 
|---|
| 1876 | bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr, | 
|---|
| 1877 | const struct net_bridge_vlan *range_end); | 
|---|
| 1878 | bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v, | 
|---|
| 1879 | const struct net_bridge_port *p); | 
|---|
| 1880 | size_t br_vlan_opts_nl_size(void); | 
|---|
| 1881 | int br_vlan_process_options(const struct net_bridge *br, | 
|---|
| 1882 | const struct net_bridge_port *p, | 
|---|
| 1883 | struct net_bridge_vlan *range_start, | 
|---|
| 1884 | struct net_bridge_vlan *range_end, | 
|---|
| 1885 | struct nlattr **tb, | 
|---|
| 1886 | struct netlink_ext_ack *extack); | 
|---|
| 1887 | int br_vlan_rtm_process_global_options(struct net_device *dev, | 
|---|
| 1888 | const struct nlattr *attr, | 
|---|
| 1889 | int cmd, | 
|---|
| 1890 | struct netlink_ext_ack *extack); | 
|---|
| 1891 | bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, | 
|---|
| 1892 | const struct net_bridge_vlan *r_end); | 
|---|
| 1893 | bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range, | 
|---|
| 1894 | const struct net_bridge_vlan *v_opts); | 
|---|
| 1895 |  | 
|---|
| 1896 | /* vlan state manipulation helpers using *_ONCE to annotate lock-free access, | 
|---|
| 1897 | * while br_vlan_set_state() may access data protected by multicast_lock. | 
|---|
| 1898 | */ | 
|---|
| 1899 | static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) | 
|---|
| 1900 | { | 
|---|
| 1901 | return READ_ONCE(v->state); | 
|---|
| 1902 | } | 
|---|
| 1903 |  | 
|---|
| 1904 | static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) | 
|---|
| 1905 | { | 
|---|
| 1906 | WRITE_ONCE(v->state, state); | 
|---|
| 1907 | br_multicast_update_vlan_mcast_ctx(v, state); | 
|---|
| 1908 | } | 
|---|
| 1909 |  | 
|---|
| 1910 | static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) | 
|---|
| 1911 | { | 
|---|
| 1912 | return READ_ONCE(vg->pvid_state); | 
|---|
| 1913 | } | 
|---|
| 1914 |  | 
|---|
| 1915 | static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, | 
|---|
| 1916 | u8 state) | 
|---|
| 1917 | { | 
|---|
| 1918 | WRITE_ONCE(vg->pvid_state, state); | 
|---|
| 1919 | } | 
|---|
| 1920 |  | 
|---|
| 1921 | /* learn_allow is true at ingress and false at egress */ | 
|---|
| 1922 | static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) | 
|---|
| 1923 | { | 
|---|
| 1924 | switch (state) { | 
|---|
| 1925 | case BR_STATE_LEARNING: | 
|---|
| 1926 | return learn_allow; | 
|---|
| 1927 | case BR_STATE_FORWARDING: | 
|---|
| 1928 | return true; | 
|---|
| 1929 | default: | 
|---|
| 1930 | return false; | 
|---|
| 1931 | } | 
|---|
| 1932 | } | 
|---|
| 1933 | #endif | 
|---|
| 1934 |  | 
|---|
| 1935 | /* br_mst.c */ | 
|---|
| 1936 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | 
|---|
| 1937 | DECLARE_STATIC_KEY_FALSE(br_mst_used); | 
|---|
| 1938 | static inline bool br_mst_is_enabled(struct net_bridge *br) | 
|---|
| 1939 | { | 
|---|
| 1940 | return static_branch_unlikely(&br_mst_used) && | 
|---|
| 1941 | br_opt_get(br, BROPT_MST_ENABLED); | 
|---|
| 1942 | } | 
|---|
| 1943 |  | 
|---|
| 1944 | int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, | 
|---|
| 1945 | struct netlink_ext_ack *extack); | 
|---|
| 1946 | int br_mst_vlan_set_msti(struct net_bridge_vlan *v, u16 msti); | 
|---|
| 1947 | void br_mst_vlan_init_state(struct net_bridge_vlan *v); | 
|---|
| 1948 | int br_mst_set_enabled(struct net_bridge *br, bool on, | 
|---|
| 1949 | struct netlink_ext_ack *extack); | 
|---|
| 1950 | size_t br_mst_info_size(const struct net_bridge_vlan_group *vg); | 
|---|
| 1951 | int br_mst_fill_info(struct sk_buff *skb, | 
|---|
| 1952 | const struct net_bridge_vlan_group *vg); | 
|---|
| 1953 | int br_mst_process(struct net_bridge_port *p, const struct nlattr *mst_attr, | 
|---|
| 1954 | struct netlink_ext_ack *extack); | 
|---|
| 1955 | #else | 
|---|
| 1956 | static inline bool br_mst_is_enabled(struct net_bridge *br) | 
|---|
| 1957 | { | 
|---|
| 1958 | return false; | 
|---|
| 1959 | } | 
|---|
| 1960 |  | 
|---|
| 1961 | static inline int br_mst_set_state(struct net_bridge_port *p, u16 msti, | 
|---|
| 1962 | u8 state, struct netlink_ext_ack *extack) | 
|---|
| 1963 | { | 
|---|
| 1964 | return -EOPNOTSUPP; | 
|---|
| 1965 | } | 
|---|
| 1966 |  | 
|---|
| 1967 | static inline int br_mst_set_enabled(struct net_bridge *br, bool on, | 
|---|
| 1968 | struct netlink_ext_ack *extack) | 
|---|
| 1969 | { | 
|---|
| 1970 | return -EOPNOTSUPP; | 
|---|
| 1971 | } | 
|---|
| 1972 |  | 
|---|
| 1973 | static inline size_t br_mst_info_size(const struct net_bridge_vlan_group *vg) | 
|---|
| 1974 | { | 
|---|
| 1975 | return 0; | 
|---|
| 1976 | } | 
|---|
| 1977 |  | 
|---|
| 1978 | static inline int br_mst_fill_info(struct sk_buff *skb, | 
|---|
| 1979 | const struct net_bridge_vlan_group *vg) | 
|---|
| 1980 | { | 
|---|
| 1981 | return -EOPNOTSUPP; | 
|---|
| 1982 | } | 
|---|
| 1983 |  | 
|---|
| 1984 | static inline int br_mst_process(struct net_bridge_port *p, | 
|---|
| 1985 | const struct nlattr *mst_attr, | 
|---|
| 1986 | struct netlink_ext_ack *extack) | 
|---|
| 1987 | { | 
|---|
| 1988 | return -EOPNOTSUPP; | 
|---|
| 1989 | } | 
|---|
| 1990 | #endif | 
|---|
| 1991 |  | 
|---|
| 1992 | struct nf_br_ops { | 
|---|
| 1993 | int (*br_dev_xmit_hook)(struct sk_buff *skb); | 
|---|
| 1994 | }; | 
|---|
| 1995 | extern const struct nf_br_ops __rcu *nf_br_ops; | 
|---|
| 1996 |  | 
|---|
| 1997 | /* br_netfilter.c */ | 
|---|
| 1998 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) | 
|---|
| 1999 | int br_nf_core_init(void); | 
|---|
| 2000 | void br_nf_core_fini(void); | 
|---|
| 2001 | void br_netfilter_rtable_init(struct net_bridge *); | 
|---|
| 2002 | #else | 
|---|
| 2003 | static inline int br_nf_core_init(void) { return 0; } | 
|---|
| 2004 | static inline void br_nf_core_fini(void) {} | 
|---|
| 2005 | #define br_netfilter_rtable_init(x) | 
|---|
| 2006 | #endif | 
|---|
| 2007 |  | 
|---|
| 2008 | /* br_stp.c */ | 
|---|
| 2009 | void br_set_state(struct net_bridge_port *p, unsigned int state); | 
|---|
| 2010 | struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no); | 
|---|
| 2011 | void br_init_port(struct net_bridge_port *p); | 
|---|
| 2012 | void br_become_designated_port(struct net_bridge_port *p); | 
|---|
| 2013 |  | 
|---|
| 2014 | void __br_set_forward_delay(struct net_bridge *br, unsigned long t); | 
|---|
| 2015 | int br_set_forward_delay(struct net_bridge *br, unsigned long x); | 
|---|
| 2016 | int br_set_hello_time(struct net_bridge *br, unsigned long x); | 
|---|
| 2017 | int br_set_max_age(struct net_bridge *br, unsigned long x); | 
|---|
| 2018 | int __set_ageing_time(struct net_device *dev, unsigned long t); | 
|---|
| 2019 | int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time); | 
|---|
| 2020 |  | 
|---|
| 2021 |  | 
|---|
| 2022 | /* br_stp_if.c */ | 
|---|
| 2023 | void br_stp_enable_bridge(struct net_bridge *br); | 
|---|
| 2024 | void br_stp_disable_bridge(struct net_bridge *br); | 
|---|
| 2025 | int br_stp_set_enabled(struct net_bridge *br, unsigned long val, | 
|---|
| 2026 | struct netlink_ext_ack *extack); | 
|---|
| 2027 | void br_stp_enable_port(struct net_bridge_port *p); | 
|---|
| 2028 | void br_stp_disable_port(struct net_bridge_port *p); | 
|---|
| 2029 | bool br_stp_recalculate_bridge_id(struct net_bridge *br); | 
|---|
| 2030 | void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a); | 
|---|
| 2031 | void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio); | 
|---|
| 2032 | int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio); | 
|---|
| 2033 | int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost); | 
|---|
| 2034 | ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); | 
|---|
| 2035 |  | 
|---|
| 2036 | /* br_stp_bpdu.c */ | 
|---|
| 2037 | struct stp_proto; | 
|---|
| 2038 | void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, | 
|---|
| 2039 | struct net_device *dev); | 
|---|
| 2040 |  | 
|---|
| 2041 | /* br_stp_timer.c */ | 
|---|
| 2042 | void br_stp_timer_init(struct net_bridge *br); | 
|---|
| 2043 | void br_stp_port_timer_init(struct net_bridge_port *p); | 
|---|
| 2044 | unsigned long br_timer_value(const struct timer_list *timer); | 
|---|
| 2045 |  | 
|---|
| 2046 | /* br.c */ | 
|---|
| 2047 | #if IS_ENABLED(CONFIG_ATM_LANE) | 
|---|
| 2048 | extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); | 
|---|
| 2049 | #endif | 
|---|
| 2050 |  | 
|---|
| 2051 | /* br_mrp.c */ | 
|---|
| 2052 | #if IS_ENABLED(CONFIG_BRIDGE_MRP) | 
|---|
| 2053 | int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 2054 | struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); | 
|---|
| 2055 | bool br_mrp_enabled(struct net_bridge *br); | 
|---|
| 2056 | void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p); | 
|---|
| 2057 | int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br); | 
|---|
| 2058 | #else | 
|---|
| 2059 | static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 2060 | struct nlattr *attr, int cmd, | 
|---|
| 2061 | struct netlink_ext_ack *extack) | 
|---|
| 2062 | { | 
|---|
| 2063 | return -EOPNOTSUPP; | 
|---|
| 2064 | } | 
|---|
| 2065 |  | 
|---|
| 2066 | static inline bool br_mrp_enabled(struct net_bridge *br) | 
|---|
| 2067 | { | 
|---|
| 2068 | return false; | 
|---|
| 2069 | } | 
|---|
| 2070 |  | 
|---|
| 2071 | static inline void br_mrp_port_del(struct net_bridge *br, | 
|---|
| 2072 | struct net_bridge_port *p) | 
|---|
| 2073 | { | 
|---|
| 2074 | } | 
|---|
| 2075 |  | 
|---|
| 2076 | static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br) | 
|---|
| 2077 | { | 
|---|
| 2078 | return 0; | 
|---|
| 2079 | } | 
|---|
| 2080 |  | 
|---|
| 2081 | #endif | 
|---|
| 2082 |  | 
|---|
| 2083 | /* br_cfm.c */ | 
|---|
| 2084 | #if IS_ENABLED(CONFIG_BRIDGE_CFM) | 
|---|
| 2085 | int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 2086 | struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); | 
|---|
| 2087 | bool br_cfm_created(struct net_bridge *br); | 
|---|
| 2088 | void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p); | 
|---|
| 2089 | int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br); | 
|---|
| 2090 | int br_cfm_status_fill_info(struct sk_buff *skb, | 
|---|
| 2091 | struct net_bridge *br, | 
|---|
| 2092 | bool getlink); | 
|---|
| 2093 | int br_cfm_mep_count(struct net_bridge *br, u32 *count); | 
|---|
| 2094 | int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count); | 
|---|
| 2095 | #else | 
|---|
| 2096 | static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, | 
|---|
| 2097 | struct nlattr *attr, int cmd, | 
|---|
| 2098 | struct netlink_ext_ack *extack) | 
|---|
| 2099 | { | 
|---|
| 2100 | return -EOPNOTSUPP; | 
|---|
| 2101 | } | 
|---|
| 2102 |  | 
|---|
| 2103 | static inline bool br_cfm_created(struct net_bridge *br) | 
|---|
| 2104 | { | 
|---|
| 2105 | return false; | 
|---|
| 2106 | } | 
|---|
| 2107 |  | 
|---|
| 2108 | static inline void br_cfm_port_del(struct net_bridge *br, | 
|---|
| 2109 | struct net_bridge_port *p) | 
|---|
| 2110 | { | 
|---|
| 2111 | } | 
|---|
| 2112 |  | 
|---|
| 2113 | static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br) | 
|---|
| 2114 | { | 
|---|
| 2115 | return -EOPNOTSUPP; | 
|---|
| 2116 | } | 
|---|
| 2117 |  | 
|---|
| 2118 | static inline int br_cfm_status_fill_info(struct sk_buff *skb, | 
|---|
| 2119 | struct net_bridge *br, | 
|---|
| 2120 | bool getlink) | 
|---|
| 2121 | { | 
|---|
| 2122 | return -EOPNOTSUPP; | 
|---|
| 2123 | } | 
|---|
| 2124 |  | 
|---|
| 2125 | static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count) | 
|---|
| 2126 | { | 
|---|
| 2127 | *count = 0; | 
|---|
| 2128 | return -EOPNOTSUPP; | 
|---|
| 2129 | } | 
|---|
| 2130 |  | 
|---|
| 2131 | static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count) | 
|---|
| 2132 | { | 
|---|
| 2133 | *count = 0; | 
|---|
| 2134 | return -EOPNOTSUPP; | 
|---|
| 2135 | } | 
|---|
| 2136 | #endif | 
|---|
| 2137 |  | 
|---|
| 2138 | /* br_netlink.c */ | 
|---|
| 2139 | extern struct rtnl_link_ops br_link_ops; | 
|---|
| 2140 | int br_netlink_init(void); | 
|---|
| 2141 | void br_netlink_fini(void); | 
|---|
| 2142 | void br_ifinfo_notify(int event, const struct net_bridge *br, | 
|---|
| 2143 | const struct net_bridge_port *port); | 
|---|
| 2144 | void br_info_notify(int event, const struct net_bridge *br, | 
|---|
| 2145 | const struct net_bridge_port *port, u32 filter); | 
|---|
| 2146 | int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags, | 
|---|
| 2147 | struct netlink_ext_ack *extack); | 
|---|
| 2148 | int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); | 
|---|
| 2149 | int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, | 
|---|
| 2150 | u32 filter_mask, int nlflags); | 
|---|
| 2151 | int br_process_vlan_info(struct net_bridge *br, | 
|---|
| 2152 | struct net_bridge_port *p, int cmd, | 
|---|
| 2153 | struct bridge_vlan_info *vinfo_curr, | 
|---|
| 2154 | struct bridge_vlan_info **vinfo_last, | 
|---|
| 2155 | bool *changed, | 
|---|
| 2156 | struct netlink_ext_ack *extack); | 
|---|
| 2157 |  | 
|---|
| 2158 | #ifdef CONFIG_SYSFS | 
|---|
| 2159 | /* br_sysfs_if.c */ | 
|---|
| 2160 | extern const struct sysfs_ops brport_sysfs_ops; | 
|---|
| 2161 | int br_sysfs_addif(struct net_bridge_port *p); | 
|---|
| 2162 | int br_sysfs_renameif(struct net_bridge_port *p); | 
|---|
| 2163 |  | 
|---|
| 2164 | /* br_sysfs_br.c */ | 
|---|
| 2165 | int br_sysfs_addbr(struct net_device *dev); | 
|---|
| 2166 | void br_sysfs_delbr(struct net_device *dev); | 
|---|
| 2167 |  | 
|---|
| 2168 | #else | 
|---|
| 2169 |  | 
|---|
| 2170 | static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; } | 
|---|
| 2171 | static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; } | 
|---|
| 2172 | static inline int br_sysfs_addbr(struct net_device *dev) { return 0; } | 
|---|
| 2173 | static inline void br_sysfs_delbr(struct net_device *dev) { return; } | 
|---|
| 2174 | #endif /* CONFIG_SYSFS */ | 
|---|
| 2175 |  | 
|---|
| 2176 | /* br_switchdev.c */ | 
|---|
| 2177 | #ifdef CONFIG_NET_SWITCHDEV | 
|---|
| 2178 | int br_switchdev_port_offload(struct net_bridge_port *p, | 
|---|
| 2179 | struct net_device *dev, const void *ctx, | 
|---|
| 2180 | struct notifier_block *atomic_nb, | 
|---|
| 2181 | struct notifier_block *blocking_nb, | 
|---|
| 2182 | bool tx_fwd_offload, | 
|---|
| 2183 | struct netlink_ext_ack *extack); | 
|---|
| 2184 |  | 
|---|
| 2185 | void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, | 
|---|
| 2186 | struct notifier_block *atomic_nb, | 
|---|
| 2187 | struct notifier_block *blocking_nb); | 
|---|
| 2188 |  | 
|---|
| 2189 | int br_switchdev_port_replay(struct net_bridge_port *p, | 
|---|
| 2190 | struct net_device *dev, const void *ctx, | 
|---|
| 2191 | struct notifier_block *atomic_nb, | 
|---|
| 2192 | struct notifier_block *blocking_nb, | 
|---|
| 2193 | struct netlink_ext_ack *extack); | 
|---|
| 2194 |  | 
|---|
| 2195 | bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb); | 
|---|
| 2196 |  | 
|---|
| 2197 | void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb); | 
|---|
| 2198 |  | 
|---|
| 2199 | void nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, | 
|---|
| 2200 | struct sk_buff *skb); | 
|---|
| 2201 | void nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, | 
|---|
| 2202 | struct sk_buff *skb); | 
|---|
| 2203 | void nbp_switchdev_frame_mark(const struct net_bridge_port *p, | 
|---|
| 2204 | struct sk_buff *skb); | 
|---|
| 2205 | bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, | 
|---|
| 2206 | const struct sk_buff *skb); | 
|---|
| 2207 | int br_switchdev_set_port_flag(struct net_bridge_port *p, | 
|---|
| 2208 | unsigned long flags, | 
|---|
| 2209 | unsigned long mask, | 
|---|
| 2210 | struct netlink_ext_ack *extack); | 
|---|
| 2211 | void br_switchdev_fdb_notify(struct net_bridge *br, | 
|---|
| 2212 | const struct net_bridge_fdb_entry *fdb, int type); | 
|---|
| 2213 | void br_switchdev_mdb_notify(struct net_device *dev, | 
|---|
| 2214 | struct net_bridge_mdb_entry *mp, | 
|---|
| 2215 | struct net_bridge_port_group *pg, | 
|---|
| 2216 | int type); | 
|---|
| 2217 | int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, | 
|---|
| 2218 | bool changed, struct netlink_ext_ack *extack); | 
|---|
| 2219 | int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); | 
|---|
| 2220 | void br_switchdev_init(struct net_bridge *br); | 
|---|
| 2221 |  | 
|---|
| 2222 | static inline void br_switchdev_frame_unmark(struct sk_buff *skb) | 
|---|
| 2223 | { | 
|---|
| 2224 | skb->offload_fwd_mark = 0; | 
|---|
| 2225 | } | 
|---|
| 2226 | #else | 
|---|
| 2227 | static inline int | 
|---|
| 2228 | br_switchdev_port_offload(struct net_bridge_port *p, | 
|---|
| 2229 | struct net_device *dev, const void *ctx, | 
|---|
| 2230 | struct notifier_block *atomic_nb, | 
|---|
| 2231 | struct notifier_block *blocking_nb, | 
|---|
| 2232 | bool tx_fwd_offload, | 
|---|
| 2233 | struct netlink_ext_ack *extack) | 
|---|
| 2234 | { | 
|---|
| 2235 | return -EOPNOTSUPP; | 
|---|
| 2236 | } | 
|---|
| 2237 |  | 
|---|
| 2238 | static inline void | 
|---|
| 2239 | br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, | 
|---|
| 2240 | struct notifier_block *atomic_nb, | 
|---|
| 2241 | struct notifier_block *blocking_nb) | 
|---|
| 2242 | { | 
|---|
| 2243 | } | 
|---|
| 2244 |  | 
|---|
| 2245 | static inline int | 
|---|
| 2246 | br_switchdev_port_replay(struct net_bridge_port *p, | 
|---|
| 2247 | struct net_device *dev, const void *ctx, | 
|---|
| 2248 | struct notifier_block *atomic_nb, | 
|---|
| 2249 | struct notifier_block *blocking_nb, | 
|---|
| 2250 | struct netlink_ext_ack *extack) | 
|---|
| 2251 | { | 
|---|
| 2252 | return -EOPNOTSUPP; | 
|---|
| 2253 | } | 
|---|
| 2254 |  | 
|---|
| 2255 | static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb) | 
|---|
| 2256 | { | 
|---|
| 2257 | return false; | 
|---|
| 2258 | } | 
|---|
| 2259 |  | 
|---|
| 2260 | static inline void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb) | 
|---|
| 2261 | { | 
|---|
| 2262 | } | 
|---|
| 2263 |  | 
|---|
| 2264 | static inline void | 
|---|
| 2265 | nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, | 
|---|
| 2266 | struct sk_buff *skb) | 
|---|
| 2267 | { | 
|---|
| 2268 | } | 
|---|
| 2269 |  | 
|---|
| 2270 | static inline void | 
|---|
| 2271 | nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, | 
|---|
| 2272 | struct sk_buff *skb) | 
|---|
| 2273 | { | 
|---|
| 2274 | } | 
|---|
| 2275 |  | 
|---|
| 2276 | static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, | 
|---|
| 2277 | struct sk_buff *skb) | 
|---|
| 2278 | { | 
|---|
| 2279 | } | 
|---|
| 2280 |  | 
|---|
| 2281 | static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, | 
|---|
| 2282 | const struct sk_buff *skb) | 
|---|
| 2283 | { | 
|---|
| 2284 | return true; | 
|---|
| 2285 | } | 
|---|
| 2286 |  | 
|---|
| 2287 | static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, | 
|---|
| 2288 | unsigned long flags, | 
|---|
| 2289 | unsigned long mask, | 
|---|
| 2290 | struct netlink_ext_ack *extack) | 
|---|
| 2291 | { | 
|---|
| 2292 | return 0; | 
|---|
| 2293 | } | 
|---|
| 2294 |  | 
|---|
| 2295 | static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, | 
|---|
| 2296 | u16 flags, bool changed, | 
|---|
| 2297 | struct netlink_ext_ack *extack) | 
|---|
| 2298 | { | 
|---|
| 2299 | return -EOPNOTSUPP; | 
|---|
| 2300 | } | 
|---|
| 2301 |  | 
|---|
| 2302 | static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) | 
|---|
| 2303 | { | 
|---|
| 2304 | return -EOPNOTSUPP; | 
|---|
| 2305 | } | 
|---|
| 2306 |  | 
|---|
| 2307 | static inline void | 
|---|
| 2308 | br_switchdev_fdb_notify(struct net_bridge *br, | 
|---|
| 2309 | const struct net_bridge_fdb_entry *fdb, int type) | 
|---|
| 2310 | { | 
|---|
| 2311 | } | 
|---|
| 2312 |  | 
|---|
| 2313 | static inline void br_switchdev_mdb_notify(struct net_device *dev, | 
|---|
| 2314 | struct net_bridge_mdb_entry *mp, | 
|---|
| 2315 | struct net_bridge_port_group *pg, | 
|---|
| 2316 | int type) | 
|---|
| 2317 | { | 
|---|
| 2318 | } | 
|---|
| 2319 |  | 
|---|
| 2320 | static inline void br_switchdev_frame_unmark(struct sk_buff *skb) | 
|---|
| 2321 | { | 
|---|
| 2322 | } | 
|---|
| 2323 |  | 
|---|
| 2324 | static inline void br_switchdev_init(struct net_bridge *br) | 
|---|
| 2325 | { | 
|---|
| 2326 | } | 
|---|
| 2327 |  | 
|---|
| 2328 | #endif /* CONFIG_NET_SWITCHDEV */ | 
|---|
| 2329 |  | 
|---|
| 2330 | /* br_arp_nd_proxy.c */ | 
|---|
| 2331 | void br_recalculate_neigh_suppress_enabled(struct net_bridge *br); | 
|---|
| 2332 | void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, | 
|---|
| 2333 | u16 vid, struct net_bridge_port *p); | 
|---|
| 2334 | void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, | 
|---|
| 2335 | u16 vid, struct net_bridge_port *p, struct nd_msg *msg); | 
|---|
| 2336 | struct nd_msg *br_is_nd_neigh_msg(const struct sk_buff *skb, struct nd_msg *m); | 
|---|
| 2337 | bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, u16 vid); | 
|---|
| 2338 | #endif | 
|---|
| 2339 |  | 
|---|