Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Linux ethernet bridge |
| 4 | * |
| 5 | * Authors: |
| 6 | * Lennert Buytenhek <buytenh@gnu.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _BR_PRIVATE_H |
| 10 | #define _BR_PRIVATE_H |
| 11 | |
| 12 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/if_bridge.h> |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 14 | #include <linux/netpoll.h> |
Eric Dumazet | 406818f | 2010-06-23 13:00:48 -0700 | [diff] [blame] | 15 | #include <linux/u64_stats_sync.h> |
Simon Wunderlich | 4adf0af | 2008-07-30 16:27:55 -0700 | [diff] [blame] | 16 | #include <net/route.h> |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 17 | #include <net/ip6_fib.h> |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 18 | #include <linux/if_vlan.h> |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 19 | #include <linux/rhashtable.h> |
Reshetova, Elena | 2512775 | 2017-07-04 15:53:05 +0300 | [diff] [blame] | 20 | #include <linux/refcount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #define BR_HASH_BITS 8 |
| 23 | #define BR_HASH_SIZE (1 << BR_HASH_BITS) |
| 24 | |
| 25 | #define BR_HOLD_TIME (1*HZ) |
| 26 | |
| 27 | #define BR_PORT_BITS 10 |
| 28 | #define BR_MAX_PORTS (1<<BR_PORT_BITS) |
| 29 | |
Nikolay Aleksandrov | d08c6bc | 2018-12-05 15:14:27 +0200 | [diff] [blame] | 30 | #define BR_MULTICAST_DEFAULT_HASH_MAX 4096 |
Nikolay Aleksandrov | 99b4061 | 2021-12-27 19:21:15 +0200 | [diff] [blame] | 31 | #define BR_MULTICAST_QUERY_INTVL_MIN msecs_to_jiffies(1000) |
Nikolay Aleksandrov | f83a112 | 2021-12-27 19:21:16 +0200 | [diff] [blame] | 32 | #define BR_MULTICAST_STARTUP_QUERY_INTVL_MIN BR_MULTICAST_QUERY_INTVL_MIN |
Nikolay Aleksandrov | d08c6bc | 2018-12-05 15:14:27 +0200 | [diff] [blame] | 33 | |
Tobias Waldekranz | 8582661 | 2021-07-21 19:24:00 +0300 | [diff] [blame] | 34 | #define BR_HWDOM_MAX BITS_PER_LONG |
| 35 | |
Stephen Hemminger | 9cde070 | 2007-03-21 14:22:44 -0700 | [diff] [blame] | 36 | #define BR_VERSION "2.3" |
| 37 | |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 38 | /* Control of forwarding link local multicast */ |
| 39 | #define BR_GROUPFWD_DEFAULT 0 |
Bernhard Thaler | 784b58a | 2015-05-04 22:47:13 +0200 | [diff] [blame] | 40 | /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */ |
Nikolay Aleksandrov | 5af48b5 | 2017-09-27 16:12:44 +0300 | [diff] [blame] | 41 | enum { |
| 42 | BR_GROUPFWD_STP = BIT(0), |
| 43 | BR_GROUPFWD_MACPAUSE = BIT(1), |
| 44 | BR_GROUPFWD_LACP = BIT(2), |
| 45 | }; |
| 46 | |
| 47 | #define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \ |
| 48 | BR_GROUPFWD_LACP) |
Toshiaki Makita | f2808d2 | 2014-06-10 20:59:24 +0900 | [diff] [blame] | 49 | /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */ |
| 50 | #define BR_GROUPFWD_8021AD 0xB801u |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 51 | |
Stephen Hemminger | 9cde070 | 2007-03-21 14:22:44 -0700 | [diff] [blame] | 52 | /* Path to usermode spanning tree program */ |
| 53 | #define BR_STP_PROG "/sbin/bridge-stp" |
Stephen Hemminger | 8cbb512e | 2005-12-21 19:01:30 -0800 | [diff] [blame] | 54 | |
Nikolay Aleksandrov | 31cbc39b | 2020-06-23 23:47:17 +0300 | [diff] [blame] | 55 | #define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT) |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | typedef struct bridge_id bridge_id; |
| 58 | typedef struct mac_addr mac_addr; |
| 59 | typedef __u16 port_id; |
| 60 | |
Nikolay Aleksandrov | 1c1cb6d | 2018-09-26 17:00:59 +0300 | [diff] [blame] | 61 | struct bridge_id { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | unsigned char prio[2]; |
Joe Perches | e5a727f | 2014-02-23 00:05:25 -0800 | [diff] [blame] | 63 | unsigned char addr[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Nikolay Aleksandrov | 1c1cb6d | 2018-09-26 17:00:59 +0300 | [diff] [blame] | 66 | struct mac_addr { |
Joe Perches | e5a727f | 2014-02-23 00:05:25 -0800 | [diff] [blame] | 67 | unsigned char addr[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 70 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 71 | /* our own querier */ |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 72 | struct bridge_mcast_own_query { |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 73 | struct timer_list timer; |
| 74 | u32 startup_sent; |
| 75 | }; |
| 76 | |
| 77 | /* other querier */ |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 78 | struct bridge_mcast_other_query { |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 79 | struct timer_list timer; |
| 80 | unsigned long delay_time; |
| 81 | }; |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 82 | |
| 83 | /* selected querier */ |
| 84 | struct bridge_mcast_querier { |
| 85 | struct br_ip addr; |
Nikolay Aleksandrov | bb18ef8 | 2021-08-13 17:59:57 +0300 | [diff] [blame] | 86 | int port_ifidx; |
Thomas Gleixner | f936bb4 | 2021-09-28 16:10:49 +0200 | [diff] [blame] | 87 | seqcount_spinlock_t seq; |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 88 | }; |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 89 | |
| 90 | /* IGMP/MLD statistics */ |
| 91 | struct bridge_mcast_stats { |
| 92 | struct br_mcast_stats mstats; |
| 93 | struct u64_stats_sync syncp; |
| 94 | }; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 95 | #endif |
| 96 | |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 97 | /* net_bridge_mcast_port must be always defined due to forwarding stubs */ |
| 98 | struct net_bridge_mcast_port { |
| 99 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 100 | struct net_bridge_port *port; |
Nikolay Aleksandrov | 613d61d | 2021-07-19 20:06:26 +0300 | [diff] [blame] | 101 | struct net_bridge_vlan *vlan; |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 102 | |
| 103 | struct bridge_mcast_own_query ip4_own_query; |
| 104 | struct timer_list ip4_mc_router_timer; |
| 105 | struct hlist_node ip4_rlist; |
| 106 | #if IS_ENABLED(CONFIG_IPV6) |
| 107 | struct bridge_mcast_own_query ip6_own_query; |
| 108 | struct timer_list ip6_mc_router_timer; |
| 109 | struct hlist_node ip6_rlist; |
| 110 | #endif /* IS_ENABLED(CONFIG_IPV6) */ |
| 111 | unsigned char multicast_router; |
| 112 | #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */ |
| 113 | }; |
| 114 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 115 | /* net_bridge_mcast must be always defined due to forwarding stubs */ |
| 116 | struct net_bridge_mcast { |
| 117 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 118 | struct net_bridge *br; |
Nikolay Aleksandrov | 613d61d | 2021-07-19 20:06:26 +0300 | [diff] [blame] | 119 | struct net_bridge_vlan *vlan; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 120 | |
| 121 | u32 multicast_last_member_count; |
| 122 | u32 multicast_startup_query_count; |
| 123 | |
Nikolay Aleksandrov | 4d5b4e8 | 2021-08-10 18:29:28 +0300 | [diff] [blame] | 124 | u8 multicast_querier; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 125 | u8 multicast_igmp_version; |
| 126 | u8 multicast_router; |
| 127 | #if IS_ENABLED(CONFIG_IPV6) |
| 128 | u8 multicast_mld_version; |
| 129 | #endif |
| 130 | unsigned long multicast_last_member_interval; |
| 131 | unsigned long multicast_membership_interval; |
| 132 | unsigned long multicast_querier_interval; |
| 133 | unsigned long multicast_query_interval; |
| 134 | unsigned long multicast_query_response_interval; |
| 135 | unsigned long multicast_startup_query_interval; |
| 136 | struct hlist_head ip4_mc_router_list; |
| 137 | struct timer_list ip4_mc_router_timer; |
| 138 | struct bridge_mcast_other_query ip4_other_query; |
| 139 | struct bridge_mcast_own_query ip4_own_query; |
| 140 | struct bridge_mcast_querier ip4_querier; |
| 141 | #if IS_ENABLED(CONFIG_IPV6) |
| 142 | struct hlist_head ip6_mc_router_list; |
| 143 | struct timer_list ip6_mc_router_timer; |
| 144 | struct bridge_mcast_other_query ip6_other_query; |
| 145 | struct bridge_mcast_own_query ip6_own_query; |
| 146 | struct bridge_mcast_querier ip6_querier; |
| 147 | #endif /* IS_ENABLED(CONFIG_IPV6) */ |
| 148 | #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */ |
| 149 | }; |
| 150 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 151 | struct br_tunnel_info { |
Nikolay Aleksandrov | 58e2071 | 2021-06-10 15:04:10 +0300 | [diff] [blame] | 152 | __be64 tunnel_id; |
| 153 | struct metadata_dst __rcu *tunnel_dst; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
Nikolay Aleksandrov | 9d332e69c | 2018-11-16 18:50:01 +0200 | [diff] [blame] | 156 | /* private vlan flags */ |
| 157 | enum { |
| 158 | BR_VLFLAG_PER_PORT_STATS = BIT(0), |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 159 | BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1), |
Nikolay Aleksandrov | 7b54aaa | 2021-07-19 20:06:27 +0300 | [diff] [blame] | 160 | BR_VLFLAG_MCAST_ENABLED = BIT(2), |
| 161 | BR_VLFLAG_GLOBAL_MCAST_ENABLED = BIT(3), |
Nikolay Aleksandrov | 9d332e69c | 2018-11-16 18:50:01 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 164 | /** |
| 165 | * struct net_bridge_vlan - per-vlan entry |
| 166 | * |
| 167 | * @vnode: rhashtable member |
| 168 | * @vid: VLAN id |
| 169 | * @flags: bridge vlan flags |
Nikolay Aleksandrov | 9d332e69c | 2018-11-16 18:50:01 +0200 | [diff] [blame] | 170 | * @priv_flags: private (in-kernel) bridge vlan flags |
Nikolay Aleksandrov | a580c76 | 2020-01-24 13:40:22 +0200 | [diff] [blame] | 171 | * @state: STP state (e.g. blocking, learning, forwarding) |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 172 | * @stats: per-cpu VLAN statistics |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 173 | * @br: if MASTER flag set, this points to a bridge struct |
| 174 | * @port: if MASTER flag unset, this points to a port struct |
| 175 | * @refcnt: if MASTER flag set, this is bumped for each port referencing it |
| 176 | * @brvlan: if MASTER flag unset, this points to the global per-VLAN context |
| 177 | * for this VLAN entry |
Nikolay Aleksandrov | 613d61d | 2021-07-19 20:06:26 +0300 | [diff] [blame] | 178 | * @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context |
| 179 | * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast |
| 180 | * context |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 181 | * @vlist: sorted list of VLAN entries |
| 182 | * @rcu: used for entry destruction |
| 183 | * |
| 184 | * This structure is shared between the global per-VLAN entries contained in |
| 185 | * the bridge rhashtable and the local per-port per-VLAN entries contained in |
| 186 | * the port's rhashtable. The union entries should be interpreted depending on |
| 187 | * the entry flags that are set. |
| 188 | */ |
| 189 | struct net_bridge_vlan { |
| 190 | struct rhash_head vnode; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 191 | struct rhash_head tnode; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 192 | u16 vid; |
| 193 | u16 flags; |
Nikolay Aleksandrov | 9d332e69c | 2018-11-16 18:50:01 +0200 | [diff] [blame] | 194 | u16 priv_flags; |
Nikolay Aleksandrov | a580c76 | 2020-01-24 13:40:22 +0200 | [diff] [blame] | 195 | u8 state; |
Heiner Kallweit | 281cc28 | 2020-11-17 21:25:42 +0100 | [diff] [blame] | 196 | struct pcpu_sw_netstats __percpu *stats; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 197 | union { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 198 | struct net_bridge *br; |
| 199 | struct net_bridge_port *port; |
| 200 | }; |
| 201 | union { |
Reshetova, Elena | 2512775 | 2017-07-04 15:53:05 +0300 | [diff] [blame] | 202 | refcount_t refcnt; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 203 | struct net_bridge_vlan *brvlan; |
| 204 | }; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 205 | |
| 206 | struct br_tunnel_info tinfo; |
| 207 | |
Nikolay Aleksandrov | 613d61d | 2021-07-19 20:06:26 +0300 | [diff] [blame] | 208 | union { |
| 209 | struct net_bridge_mcast br_mcast_ctx; |
| 210 | struct net_bridge_mcast_port port_mcast_ctx; |
| 211 | }; |
| 212 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 213 | struct list_head vlist; |
| 214 | |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 215 | struct rcu_head rcu; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | /** |
| 219 | * struct net_bridge_vlan_group |
| 220 | * |
| 221 | * @vlan_hash: VLAN entry rhashtable |
| 222 | * @vlan_list: sorted VLAN entry list |
| 223 | * @num_vlans: number of total VLAN entries |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 224 | * @pvid: PVID VLAN id |
Nikolay Aleksandrov | a580c76 | 2020-01-24 13:40:22 +0200 | [diff] [blame] | 225 | * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 226 | * |
| 227 | * IMPORTANT: Be careful when checking if there're VLAN entries using list |
| 228 | * primitives because the bridge can have entries in its list which |
| 229 | * are just for global context but not for filtering, i.e. they have |
| 230 | * the master flag set but not the brentry flag. If you have to check |
| 231 | * if there're "real" entries in the bridge please test @num_vlans |
| 232 | */ |
| 233 | struct net_bridge_vlan_group { |
| 234 | struct rhashtable vlan_hash; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 235 | struct rhashtable tunnel_hash; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 236 | struct list_head vlan_list; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 237 | u16 num_vlans; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 238 | u16 pvid; |
Nikolay Aleksandrov | a580c76 | 2020-01-24 13:40:22 +0200 | [diff] [blame] | 239 | u8 pvid_state; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 240 | }; |
| 241 | |
Nikolay Aleksandrov | 6869c3b | 2019-10-29 13:45:53 +0200 | [diff] [blame] | 242 | /* bridge fdb flags */ |
| 243 | enum { |
| 244 | BR_FDB_LOCAL, |
Nikolay Aleksandrov | 29e63ff | 2019-10-29 13:45:54 +0200 | [diff] [blame] | 245 | BR_FDB_STATIC, |
Nikolay Aleksandrov | e0458d9 | 2019-10-29 13:45:55 +0200 | [diff] [blame] | 246 | BR_FDB_STICKY, |
Nikolay Aleksandrov | ac3ca6a | 2019-10-29 13:45:56 +0200 | [diff] [blame] | 247 | BR_FDB_ADDED_BY_USER, |
Nikolay Aleksandrov | b5cd9f7 | 2019-10-29 13:45:57 +0200 | [diff] [blame] | 248 | BR_FDB_ADDED_BY_EXT_LEARN, |
Nikolay Aleksandrov | d38c6e3 | 2019-10-29 13:45:58 +0200 | [diff] [blame] | 249 | BR_FDB_OFFLOADED, |
Nikolay Aleksandrov | 31cbc39b | 2020-06-23 23:47:17 +0300 | [diff] [blame] | 250 | BR_FDB_NOTIFY, |
| 251 | BR_FDB_NOTIFY_INACTIVE |
Nikolay Aleksandrov | 6869c3b | 2019-10-29 13:45:53 +0200 | [diff] [blame] | 252 | }; |
| 253 | |
Nikolay Aleksandrov | eb79358 | 2017-12-12 16:02:50 +0200 | [diff] [blame] | 254 | struct net_bridge_fdb_key { |
| 255 | mac_addr addr; |
| 256 | u16 vlan_id; |
| 257 | }; |
| 258 | |
Nikolay Aleksandrov | 1214628c | 2017-02-04 18:05:08 +0100 | [diff] [blame] | 259 | struct net_bridge_fdb_entry { |
Nikolay Aleksandrov | eb79358 | 2017-12-12 16:02:50 +0200 | [diff] [blame] | 260 | struct rhash_head rhnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | struct net_bridge_port *dst; |
| 262 | |
Nikolay Aleksandrov | eb79358 | 2017-12-12 16:02:50 +0200 | [diff] [blame] | 263 | struct net_bridge_fdb_key key; |
| 264 | struct hlist_node fdb_node; |
Nikolay Aleksandrov | 6869c3b | 2019-10-29 13:45:53 +0200 | [diff] [blame] | 265 | unsigned long flags; |
Nikolay Aleksandrov | 1214628c | 2017-02-04 18:05:08 +0100 | [diff] [blame] | 266 | |
| 267 | /* write-heavy members should not affect lookups */ |
| 268 | unsigned long updated ____cacheline_aligned_in_smp; |
| 269 | unsigned long used; |
| 270 | |
Nikolay Aleksandrov | b22fbf2 | 2015-08-27 14:19:20 -0700 | [diff] [blame] | 271 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Elad Raz | 9d06b6d | 2016-02-03 09:57:05 +0100 | [diff] [blame] | 274 | #define MDB_PG_FLAGS_PERMANENT BIT(0) |
| 275 | #define MDB_PG_FLAGS_OFFLOAD BIT(1) |
Nikolay Aleksandrov | 3247b27 | 2019-07-30 15:20:41 +0300 | [diff] [blame] | 276 | #define MDB_PG_FLAGS_FAST_LEAVE BIT(2) |
Nikolay Aleksandrov | 8266a04 | 2020-09-22 10:30:24 +0300 | [diff] [blame] | 277 | #define MDB_PG_FLAGS_STAR_EXCL BIT(3) |
Nikolay Aleksandrov | 9116ffb | 2020-09-22 10:30:25 +0300 | [diff] [blame] | 278 | #define MDB_PG_FLAGS_BLOCKED BIT(4) |
Elad Raz | 9d06b6d | 2016-02-03 09:57:05 +0100 | [diff] [blame] | 279 | |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 280 | #define PG_SRC_ENT_LIMIT 32 |
| 281 | |
| 282 | #define BR_SGRP_F_DELETE BIT(0) |
| 283 | #define BR_SGRP_F_SEND BIT(1) |
Nikolay Aleksandrov | b081236 | 2020-09-22 10:30:23 +0300 | [diff] [blame] | 284 | #define BR_SGRP_F_INSTALLED BIT(2) |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 285 | |
Nikolay Aleksandrov | e12cec6 | 2020-09-07 12:56:19 +0300 | [diff] [blame] | 286 | struct net_bridge_mcast_gc { |
| 287 | struct hlist_node gc_node; |
| 288 | void (*destroy)(struct net_bridge_mcast_gc *gc); |
| 289 | }; |
| 290 | |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 291 | struct net_bridge_group_src { |
| 292 | struct hlist_node node; |
| 293 | |
| 294 | struct br_ip addr; |
| 295 | struct net_bridge_port_group *pg; |
| 296 | u8 flags; |
Nikolay Aleksandrov | 438ef2d | 2020-09-07 12:56:09 +0300 | [diff] [blame] | 297 | u8 src_query_rexmit_cnt; |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 298 | struct timer_list timer; |
| 299 | |
| 300 | struct net_bridge *br; |
Nikolay Aleksandrov | e12cec6 | 2020-09-07 12:56:19 +0300 | [diff] [blame] | 301 | struct net_bridge_mcast_gc mcast_gc; |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 302 | struct rcu_head rcu; |
| 303 | }; |
| 304 | |
Nikolay Aleksandrov | 085b53c | 2020-09-22 10:30:22 +0300 | [diff] [blame] | 305 | struct net_bridge_port_group_sg_key { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 306 | struct net_bridge_port *port; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 307 | struct br_ip addr; |
Nikolay Aleksandrov | 085b53c | 2020-09-22 10:30:22 +0300 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | struct net_bridge_port_group { |
| 311 | struct net_bridge_port_group __rcu *next; |
| 312 | struct net_bridge_port_group_sg_key key; |
Thomas Martitz | 206e7323 | 2020-06-25 14:26:03 +0200 | [diff] [blame] | 313 | unsigned char eth_addr[ETH_ALEN] __aligned(2); |
Elad Raz | 9d06b6d | 2016-02-03 09:57:05 +0100 | [diff] [blame] | 314 | unsigned char flags; |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 315 | unsigned char filter_mode; |
Nikolay Aleksandrov | 42c11cc | 2020-09-07 12:56:10 +0300 | [diff] [blame] | 316 | unsigned char grp_query_rexmit_cnt; |
Nikolay Aleksandrov | 8f8cb77 | 2020-09-22 10:30:21 +0300 | [diff] [blame] | 317 | unsigned char rt_protocol; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 318 | |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 319 | struct hlist_head src_list; |
| 320 | unsigned int src_ents; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 321 | struct timer_list timer; |
Nikolay Aleksandrov | 42c11cc | 2020-09-07 12:56:10 +0300 | [diff] [blame] | 322 | struct timer_list rexmit_timer; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 323 | struct hlist_node mglist; |
Nikolay Aleksandrov | 8f07b83 | 2021-01-20 16:51:54 +0200 | [diff] [blame] | 324 | struct rb_root eht_set_tree; |
| 325 | struct rb_root eht_host_tree; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 326 | |
Nikolay Aleksandrov | 085b53c | 2020-09-22 10:30:22 +0300 | [diff] [blame] | 327 | struct rhash_head rhnode; |
Nikolay Aleksandrov | e12cec6 | 2020-09-07 12:56:19 +0300 | [diff] [blame] | 328 | struct net_bridge_mcast_gc mcast_gc; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 329 | struct rcu_head rcu; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Nikolay Aleksandrov | 1c1cb6d | 2018-09-26 17:00:59 +0300 | [diff] [blame] | 332 | struct net_bridge_mdb_entry { |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 333 | struct rhash_head rhnode; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 334 | struct net_bridge *br; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 335 | struct net_bridge_port_group __rcu *ports; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 336 | struct br_ip addr; |
Andrew Lunn | ff0fd34 | 2017-11-09 23:10:57 +0100 | [diff] [blame] | 337 | bool host_joined; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 338 | |
| 339 | struct timer_list timer; |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 340 | struct hlist_node mdb_node; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 341 | |
Nikolay Aleksandrov | e12cec6 | 2020-09-07 12:56:19 +0300 | [diff] [blame] | 342 | struct net_bridge_mcast_gc mcast_gc; |
Nikolay Aleksandrov | 6ec0d0e | 2020-09-07 12:56:05 +0300 | [diff] [blame] | 343 | struct rcu_head rcu; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 344 | }; |
| 345 | |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 346 | struct net_bridge_port { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | struct net_bridge *br; |
| 348 | struct net_device *dev; |
Eric Dumazet | b2dcdc7 | 2021-12-06 17:30:29 -0800 | [diff] [blame] | 349 | netdevice_tracker dev_tracker; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | struct list_head list; |
| 351 | |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 352 | unsigned long flags; |
| 353 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 354 | struct net_bridge_vlan_group __rcu *vlgrp; |
| 355 | #endif |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 356 | struct net_bridge_port __rcu *backup_port; |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* STP */ |
| 359 | u8 priority; |
| 360 | u8 state; |
| 361 | u16 port_no; |
| 362 | unsigned char topology_change_ack; |
| 363 | unsigned char config_pending; |
| 364 | port_id port_id; |
| 365 | port_id designated_port; |
| 366 | bridge_id designated_root; |
| 367 | bridge_id designated_bridge; |
| 368 | u32 path_cost; |
| 369 | u32 designated_cost; |
stephen hemminger | 0c03150 | 2011-07-22 07:47:06 +0000 | [diff] [blame] | 370 | unsigned long designated_age; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | struct timer_list forward_delay_timer; |
| 373 | struct timer_list hold_timer; |
| 374 | struct timer_list message_age_timer; |
| 375 | struct kobject kobj; |
| 376 | struct rcu_head rcu; |
Fischer, Anna | 3982d3d | 2009-08-13 06:55:16 +0000 | [diff] [blame] | 377 | |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 378 | struct net_bridge_mcast_port multicast_ctx; |
| 379 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 380 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 381 | struct bridge_mcast_stats __percpu *mcast_stats; |
| 382 | |
Nikolay Aleksandrov | 89268b0 | 2021-01-26 11:35:32 +0200 | [diff] [blame] | 383 | u32 multicast_eht_hosts_limit; |
| 384 | u32 multicast_eht_hosts_cnt; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 385 | struct hlist_head mglist; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 386 | #endif |
Simon Arlott | e0f4375 | 2010-05-10 09:31:11 +0000 | [diff] [blame] | 387 | |
| 388 | #ifdef CONFIG_SYSFS |
| 389 | char sysfs_name[IFNAMSIZ]; |
| 390 | #endif |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 391 | |
| 392 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 393 | struct netpoll *np; |
| 394 | #endif |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 395 | #ifdef CONFIG_NET_SWITCHDEV |
Tobias Waldekranz | f7cf972 | 2021-07-21 19:23:59 +0300 | [diff] [blame] | 396 | /* Identifier used to group ports that share the same switchdev |
| 397 | * hardware domain. |
| 398 | */ |
| 399 | int hwdom; |
Vladimir Oltean | 2f5dc00 | 2021-07-21 19:24:01 +0300 | [diff] [blame] | 400 | int offload_count; |
| 401 | struct netdev_phys_item_id ppid; |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 402 | #endif |
Nikolay Aleksandrov | 5af48b5 | 2017-09-27 16:12:44 +0300 | [diff] [blame] | 403 | u16 group_fwd_mask; |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 404 | u16 backup_redirected_cnt; |
Vivien Didelot | de17996 | 2019-12-11 20:07:10 -0500 | [diff] [blame] | 405 | |
| 406 | struct bridge_stp_xstats stp_xstats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | }; |
| 408 | |
Tyler Hicks | 705e0de | 2018-07-20 21:56:54 +0000 | [diff] [blame] | 409 | #define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj) |
| 410 | |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 411 | #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK) |
Vlad Yasevich | f3a6ddf | 2014-05-16 09:59:18 -0400 | [diff] [blame] | 412 | #define br_promisc_port(p) ((p)->flags & BR_PROMISC) |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 413 | |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 414 | static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev) |
| 415 | { |
Hong Zhiguo | 716ec05 | 2013-09-14 22:42:28 +0800 | [diff] [blame] | 416 | return rcu_dereference(dev->rx_handler_data); |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Hong Zhiguo | 1fb1754 | 2013-09-14 22:42:27 +0800 | [diff] [blame] | 419 | static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev) |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 420 | { |
Julian Wiedmann | 35f861e | 2019-03-29 14:38:19 +0100 | [diff] [blame] | 421 | return netif_is_bridge_port(dev) ? |
Eric Dumazet | ec1e561 | 2010-11-15 06:38:14 +0000 | [diff] [blame] | 422 | rtnl_dereference(dev->rx_handler_data) : NULL; |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Arkadi Sharshevsky | 0baa10f | 2017-06-08 08:44:12 +0200 | [diff] [blame] | 425 | static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev) |
| 426 | { |
Julian Wiedmann | 35f861e | 2019-03-29 14:38:19 +0100 | [diff] [blame] | 427 | return netif_is_bridge_port(dev) ? |
Arkadi Sharshevsky | 0baa10f | 2017-06-08 08:44:12 +0200 | [diff] [blame] | 428 | rcu_dereference_rtnl(dev->rx_handler_data) : NULL; |
| 429 | } |
| 430 | |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 431 | enum net_bridge_opts { |
| 432 | BROPT_VLAN_ENABLED, |
| 433 | BROPT_VLAN_STATS_ENABLED, |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 434 | BROPT_NF_CALL_IPTABLES, |
| 435 | BROPT_NF_CALL_IP6TABLES, |
| 436 | BROPT_NF_CALL_ARPTABLES, |
Nikolay Aleksandrov | be3664a | 2018-09-26 17:01:02 +0300 | [diff] [blame] | 437 | BROPT_GROUP_ADDR_SET, |
Nikolay Aleksandrov | 13cefad | 2018-09-26 17:01:03 +0300 | [diff] [blame] | 438 | BROPT_MULTICAST_ENABLED, |
Nikolay Aleksandrov | 675779a | 2018-09-26 17:01:04 +0300 | [diff] [blame] | 439 | BROPT_MULTICAST_QUERY_USE_IFADDR, |
| 440 | BROPT_MULTICAST_STATS_ENABLED, |
| 441 | BROPT_HAS_IPV6_ADDR, |
Nikolay Aleksandrov | c69c2cd | 2018-09-26 17:01:05 +0300 | [diff] [blame] | 442 | BROPT_NEIGH_SUPPRESS_ENABLED, |
Nikolay Aleksandrov | 3341d91 | 2018-09-26 17:01:06 +0300 | [diff] [blame] | 443 | BROPT_MTU_SET_BY_USER, |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 444 | BROPT_VLAN_STATS_PER_PORT, |
Nikolay Aleksandrov | 70e4272 | 2018-11-24 04:34:21 +0200 | [diff] [blame] | 445 | BROPT_NO_LL_LEARN, |
Mike Manning | 9c0ec2e | 2019-04-18 18:35:33 +0100 | [diff] [blame] | 446 | BROPT_VLAN_BRIDGE_BINDING, |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 447 | BROPT_MCAST_VLAN_SNOOPING_ENABLED, |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 448 | }; |
| 449 | |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 450 | struct net_bridge { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | spinlock_t lock; |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 452 | spinlock_t hash_lock; |
Henrik Bjoernlund | 90c628d | 2020-10-27 10:02:42 +0000 | [diff] [blame] | 453 | struct hlist_head frame_type_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | struct net_device *dev; |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 455 | unsigned long options; |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 456 | /* These fields are accessed on each packet */ |
| 457 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 458 | __be16 vlan_proto; |
| 459 | u16 default_pvid; |
| 460 | struct net_bridge_vlan_group __rcu *vlgrp; |
| 461 | #endif |
| 462 | |
Nikolay Aleksandrov | eb79358 | 2017-12-12 16:02:50 +0200 | [diff] [blame] | 463 | struct rhashtable fdb_hash_tbl; |
Henrik Bjoernlund | 90c628d | 2020-10-27 10:02:42 +0000 | [diff] [blame] | 464 | struct list_head port_list; |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 465 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 466 | union { |
| 467 | struct rtable fake_rtable; |
| 468 | struct rt6_info fake_rt6_info; |
| 469 | }; |
Simon Wunderlich | 4adf0af | 2008-07-30 16:27:55 -0700 | [diff] [blame] | 470 | #endif |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 471 | u16 group_fwd_mask; |
Toshiaki Makita | f2808d2 | 2014-06-10 20:59:24 +0900 | [diff] [blame] | 472 | u16 group_fwd_mask_required; |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* STP */ |
| 475 | bridge_id designated_root; |
| 476 | bridge_id bridge_id; |
Nikolay Aleksandrov | 1f90c7f | 2017-02-04 18:05:06 +0100 | [diff] [blame] | 477 | unsigned char topology_change; |
| 478 | unsigned char topology_change_detected; |
| 479 | u16 root_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | unsigned long max_age; |
| 481 | unsigned long hello_time; |
| 482 | unsigned long forward_delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | unsigned long ageing_time; |
Vivien Didelot | 34d8acd | 2016-12-10 13:44:29 -0500 | [diff] [blame] | 484 | unsigned long bridge_max_age; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | unsigned long bridge_hello_time; |
| 486 | unsigned long bridge_forward_delay; |
Vivien Didelot | 34d8acd | 2016-12-10 13:44:29 -0500 | [diff] [blame] | 487 | unsigned long bridge_ageing_time; |
Nikolay Aleksandrov | 35750b0 | 2018-09-26 17:01:07 +0300 | [diff] [blame] | 488 | u32 root_path_cost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 490 | u8 group_addr[ETH_ALEN]; |
Stephen Hemminger | 9cde070 | 2007-03-21 14:22:44 -0700 | [diff] [blame] | 491 | |
| 492 | enum { |
| 493 | BR_NO_STP, /* no spanning tree */ |
| 494 | BR_KERNEL_STP, /* old STP in kernel */ |
| 495 | BR_USER_STP, /* new RSTP in userspace */ |
| 496 | } stp_enabled; |
| 497 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 498 | struct net_bridge_mcast multicast_ctx; |
| 499 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 500 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 501 | struct bridge_mcast_stats __percpu *mcast_stats; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 502 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 503 | u32 hash_max; |
| 504 | |
Nikolay Aleksandrov | 35750b0 | 2018-09-26 17:01:07 +0300 | [diff] [blame] | 505 | spinlock_t multicast_lock; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 506 | |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 507 | struct rhashtable mdb_hash_tbl; |
Nikolay Aleksandrov | 085b53c | 2020-09-22 10:30:22 +0300 | [diff] [blame] | 508 | struct rhashtable sg_port_tbl; |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 509 | |
Nikolay Aleksandrov | e12cec6 | 2020-09-07 12:56:19 +0300 | [diff] [blame] | 510 | struct hlist_head mcast_gc_list; |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 511 | struct hlist_head mdb_list; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 512 | |
Nikolay Aleksandrov | e12cec6 | 2020-09-07 12:56:19 +0300 | [diff] [blame] | 513 | struct work_struct mcast_gc_work; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 514 | #endif |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | struct timer_list hello_timer; |
| 517 | struct timer_list tcn_timer; |
| 518 | struct timer_list topology_change_timer; |
Nikolay Aleksandrov | f7cdee8 | 2017-02-04 18:05:07 +0100 | [diff] [blame] | 519 | struct delayed_work gc_work; |
Greg Kroah-Hartman | 43b98c4 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 520 | struct kobject *ifobj; |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 521 | u32 auto_cnt; |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 522 | |
| 523 | #ifdef CONFIG_NET_SWITCHDEV |
Tobias Waldekranz | f7cf972 | 2021-07-21 19:23:59 +0300 | [diff] [blame] | 524 | /* Counter used to make sure that hardware domains get unique |
| 525 | * identifiers in case a bridge spans multiple switchdev instances. |
| 526 | */ |
| 527 | int last_hwdom; |
Tobias Waldekranz | 8582661 | 2021-07-21 19:24:00 +0300 | [diff] [blame] | 528 | /* Bit mask of hardware domain numbers in use */ |
| 529 | unsigned long busy_hwdoms; |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 530 | #endif |
Nikolay Aleksandrov | eb79358 | 2017-12-12 16:02:50 +0200 | [diff] [blame] | 531 | struct hlist_head fdb_list; |
Horatiu Vultur | 4b8d7d4 | 2020-04-26 15:22:00 +0200 | [diff] [blame] | 532 | |
| 533 | #if IS_ENABLED(CONFIG_BRIDGE_MRP) |
Horatiu Vultur | 0169b82 | 2020-11-06 22:50:49 +0100 | [diff] [blame] | 534 | struct hlist_head mrp_list; |
Horatiu Vultur | 4b8d7d4 | 2020-04-26 15:22:00 +0200 | [diff] [blame] | 535 | #endif |
Henrik Bjoernlund | f323aa5 | 2020-10-27 10:02:43 +0000 | [diff] [blame] | 536 | #if IS_ENABLED(CONFIG_BRIDGE_CFM) |
| 537 | struct hlist_head mep_list; |
| 538 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | }; |
| 540 | |
Herbert Xu | 68b7c89 | 2010-02-27 19:41:40 +0000 | [diff] [blame] | 541 | struct br_input_skb_cb { |
| 542 | struct net_device *brdev; |
Herbert Xu | 93fdd47 | 2014-10-05 12:00:22 +0800 | [diff] [blame] | 543 | |
Pablo Neira Ayuso | 3c171f4 | 2019-05-29 13:25:37 +0200 | [diff] [blame] | 544 | u16 frag_max_size; |
YOSHIFUJI Hideaki / 吉藤英明 | 32dec5d | 2010-03-15 21:51:18 +0000 | [diff] [blame] | 545 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
Florian Westphal | f12064d | 2019-04-11 16:36:40 +0200 | [diff] [blame] | 546 | u8 igmp; |
| 547 | u8 mrouters_only:1; |
YOSHIFUJI Hideaki / 吉藤英明 | 32dec5d | 2010-03-15 21:51:18 +0000 | [diff] [blame] | 548 | #endif |
Florian Westphal | f12064d | 2019-04-11 16:36:40 +0200 | [diff] [blame] | 549 | u8 proxyarp_replied:1; |
| 550 | u8 src_port_isolated:1; |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 551 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
Florian Westphal | f12064d | 2019-04-11 16:36:40 +0200 | [diff] [blame] | 552 | u8 vlan_filtered:1; |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 553 | #endif |
Florian Westphal | 223fd0a | 2019-04-11 16:36:42 +0200 | [diff] [blame] | 554 | #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE |
| 555 | u8 br_netfilter_broute:1; |
| 556 | #endif |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 557 | |
| 558 | #ifdef CONFIG_NET_SWITCHDEV |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 559 | /* Set if TX data plane offloading is used towards at least one |
| 560 | * hardware domain. |
| 561 | */ |
| 562 | u8 tx_fwd_offload:1; |
Tobias Waldekranz | f7cf972 | 2021-07-21 19:23:59 +0300 | [diff] [blame] | 563 | /* The switchdev hardware domain from which this packet was received. |
| 564 | * If skb->offload_fwd_mark was set, then this packet was already |
| 565 | * forwarded by hardware to the other ports in the source hardware |
| 566 | * domain, otherwise it wasn't. |
| 567 | */ |
| 568 | int src_hwdom; |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 569 | /* Bit mask of hardware domains towards this packet has already been |
| 570 | * transmitted using the TX data plane offload. |
| 571 | */ |
| 572 | unsigned long fwd_hwdoms; |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 573 | #endif |
Herbert Xu | 68b7c89 | 2010-02-27 19:41:40 +0000 | [diff] [blame] | 574 | }; |
| 575 | |
| 576 | #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb) |
| 577 | |
YOSHIFUJI Hideaki / 吉藤英明 | 32dec5d | 2010-03-15 21:51:18 +0000 | [diff] [blame] | 578 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 579 | # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only) |
| 580 | #else |
| 581 | # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0) |
| 582 | #endif |
| 583 | |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 584 | #define br_printk(level, br, format, args...) \ |
| 585 | printk(level "%s: " format, (br)->dev->name, ##args) |
| 586 | |
| 587 | #define br_err(__br, format, args...) \ |
| 588 | br_printk(KERN_ERR, __br, format, ##args) |
| 589 | #define br_warn(__br, format, args...) \ |
| 590 | br_printk(KERN_WARNING, __br, format, ##args) |
| 591 | #define br_notice(__br, format, args...) \ |
| 592 | br_printk(KERN_NOTICE, __br, format, ##args) |
| 593 | #define br_info(__br, format, args...) \ |
| 594 | br_printk(KERN_INFO, __br, format, ##args) |
| 595 | |
| 596 | #define br_debug(br, format, args...) \ |
| 597 | pr_debug("%s: " format, (br)->dev->name, ##args) |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* called under bridge lock */ |
| 600 | static inline int br_is_root_bridge(const struct net_bridge *br) |
| 601 | { |
| 602 | return !memcmp(&br->bridge_id, &br->designated_root, 8); |
| 603 | } |
| 604 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 605 | /* check if a VLAN entry is global */ |
| 606 | static inline bool br_vlan_is_master(const struct net_bridge_vlan *v) |
| 607 | { |
| 608 | return v->flags & BRIDGE_VLAN_INFO_MASTER; |
| 609 | } |
| 610 | |
| 611 | /* check if a VLAN entry is used by the bridge */ |
| 612 | static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v) |
| 613 | { |
| 614 | return v->flags & BRIDGE_VLAN_INFO_BRENTRY; |
| 615 | } |
| 616 | |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 617 | /* check if we should use the vlan entry, returns false if it's only context */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 618 | static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) |
| 619 | { |
| 620 | if (br_vlan_is_master(v)) { |
| 621 | if (br_vlan_is_brentry(v)) |
| 622 | return true; |
| 623 | else |
| 624 | return false; |
| 625 | } |
| 626 | |
| 627 | return true; |
| 628 | } |
| 629 | |
Nikolay Aleksandrov | 5d1fcaf | 2019-11-04 11:36:51 +0200 | [diff] [blame] | 630 | static inline bool nbp_state_should_learn(const struct net_bridge_port *p) |
| 631 | { |
| 632 | return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING; |
| 633 | } |
| 634 | |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 635 | static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 636 | { |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 637 | bool ret = vid > 0 && vid < VLAN_VID_MASK; |
| 638 | |
| 639 | if (!ret) |
| 640 | NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid"); |
| 641 | |
| 642 | return ret; |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur, |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 646 | const struct bridge_vlan_info *last, |
| 647 | struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 648 | { |
| 649 | /* pvid flag is not allowed in ranges */ |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 650 | if (cur->flags & BRIDGE_VLAN_INFO_PVID) { |
| 651 | NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range"); |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 652 | return false; |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 653 | } |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 654 | |
| 655 | /* when cur is the range end, check if: |
| 656 | * - it has range start flag |
| 657 | * - range ids are invalid (end is equal to or before start) |
| 658 | */ |
| 659 | if (last) { |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 660 | if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { |
| 661 | NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one"); |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 662 | return false; |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 663 | } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) { |
| 664 | NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing"); |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 665 | return false; |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 666 | } else if (cur->vid <= last->vid) { |
| 667 | NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id"); |
| 668 | return false; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /* check for required range flags */ |
| 673 | if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN | |
| 674 | BRIDGE_VLAN_INFO_RANGE_END))) { |
| 675 | NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing"); |
| 676 | return false; |
Nikolay Aleksandrov | 5a46fac | 2020-01-14 19:56:07 +0200 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | return true; |
| 680 | } |
| 681 | |
Nikolay Aleksandrov | 2796d84 | 2021-08-20 15:42:55 +0300 | [diff] [blame] | 682 | static inline u8 br_vlan_multicast_router(const struct net_bridge_vlan *v) |
| 683 | { |
| 684 | u8 mcast_router = MDB_RTR_TYPE_DISABLED; |
| 685 | |
| 686 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 687 | if (!br_vlan_is_master(v)) |
| 688 | mcast_router = v->port_mcast_ctx.multicast_router; |
| 689 | else |
| 690 | mcast_router = v->br_mcast_ctx.multicast_router; |
| 691 | #endif |
| 692 | |
| 693 | return mcast_router; |
| 694 | } |
| 695 | |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 696 | static inline int br_afspec_cmd_to_rtm(int cmd) |
| 697 | { |
| 698 | switch (cmd) { |
| 699 | case RTM_SETLINK: |
| 700 | return RTM_NEWVLAN; |
| 701 | case RTM_DELLINK: |
| 702 | return RTM_DELVLAN; |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 708 | static inline int br_opt_get(const struct net_bridge *br, |
| 709 | enum net_bridge_opts opt) |
| 710 | { |
| 711 | return test_bit(opt, &br->options); |
| 712 | } |
| 713 | |
Nikolay Aleksandrov | a428afe | 2018-11-24 04:34:20 +0200 | [diff] [blame] | 714 | int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, |
| 715 | struct netlink_ext_ack *extack); |
| 716 | int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt); |
| 717 | int br_boolopt_multi_toggle(struct net_bridge *br, |
| 718 | struct br_boolopt_multi *bm, |
| 719 | struct netlink_ext_ack *extack); |
| 720 | void br_boolopt_multi_get(const struct net_bridge *br, |
| 721 | struct br_boolopt_multi *bm); |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 722 | void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on); |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | /* br_device.c */ |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 725 | void br_dev_setup(struct net_device *dev); |
| 726 | void br_dev_delete(struct net_device *dev, struct list_head *list); |
| 727 | netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev); |
stephen hemminger | cfb478d | 2010-05-10 09:31:08 +0000 | [diff] [blame] | 728 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 729 | static inline void br_netpoll_send_skb(const struct net_bridge_port *p, |
| 730 | struct sk_buff *skb) |
| 731 | { |
Eric Dumazet | f78ed22 | 2020-05-07 09:32:21 -0700 | [diff] [blame] | 732 | netpoll_send_skb(p->np, skb); |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Eric W. Biederman | a8779ec | 2014-03-27 15:36:38 -0700 | [diff] [blame] | 735 | int br_netpoll_enable(struct net_bridge_port *p); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 736 | void br_netpoll_disable(struct net_bridge_port *p); |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 737 | #else |
Herbert Xu | 9f70b0f | 2010-06-15 21:43:48 -0700 | [diff] [blame] | 738 | static inline void br_netpoll_send_skb(const struct net_bridge_port *p, |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 739 | struct sk_buff *skb) |
| 740 | { |
| 741 | } |
| 742 | |
Eric W. Biederman | a8779ec | 2014-03-27 15:36:38 -0700 | [diff] [blame] | 743 | static inline int br_netpoll_enable(struct net_bridge_port *p) |
Herbert Xu | 91d2c34 | 2010-06-10 16:12:50 +0000 | [diff] [blame] | 744 | { |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static inline void br_netpoll_disable(struct net_bridge_port *p) |
| 749 | { |
| 750 | } |
stephen hemminger | cfb478d | 2010-05-10 09:31:08 +0000 | [diff] [blame] | 751 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | /* br_fdb.c */ |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 754 | int br_fdb_init(void); |
| 755 | void br_fdb_fini(void); |
Nikolay Aleksandrov | eb79358 | 2017-12-12 16:02:50 +0200 | [diff] [blame] | 756 | int br_fdb_hash_init(struct net_bridge *br); |
| 757 | void br_fdb_hash_fini(struct net_bridge *br); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 758 | void br_fdb_flush(struct net_bridge *br); |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame] | 759 | void br_fdb_find_delete_local(struct net_bridge *br, |
| 760 | const struct net_bridge_port *p, |
| 761 | const unsigned char *addr, u16 vid); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 762 | void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr); |
| 763 | void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); |
Nikolay Aleksandrov | f7cdee8 | 2017-02-04 18:05:07 +0100 | [diff] [blame] | 764 | void br_fdb_cleanup(struct work_struct *work); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 765 | void br_fdb_delete_by_port(struct net_bridge *br, |
Nikolay Aleksandrov | 1ea2d02 | 2015-06-23 05:28:16 -0700 | [diff] [blame] | 766 | const struct net_bridge_port *p, u16 vid, int do_all); |
Nikolay Aleksandrov | bfd0aea | 2017-02-13 14:59:09 +0100 | [diff] [blame] | 767 | struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, |
| 768 | const unsigned char *addr, |
| 769 | __u16 vid); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 770 | int br_fdb_test_addr(struct net_device *dev, unsigned char *addr); |
| 771 | int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count, |
| 772 | unsigned long off); |
Vladimir Oltean | f6814fd | 2021-10-26 17:27:39 +0300 | [diff] [blame] | 773 | int br_fdb_add_local(struct net_bridge *br, struct net_bridge_port *source, |
| 774 | const unsigned char *addr, u16 vid); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 775 | void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, |
Nikolay Aleksandrov | be0c567 | 2019-11-01 14:46:37 +0200 | [diff] [blame] | 776 | const unsigned char *addr, u16 vid, unsigned long flags); |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 777 | |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 778 | int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 779 | struct net_device *dev, const unsigned char *addr, u16 vid); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 780 | int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, |
Petr Machata | 87b0984 | 2019-01-16 23:06:50 +0000 | [diff] [blame] | 781 | const unsigned char *addr, u16 vid, u16 nlh_flags, |
| 782 | struct netlink_ext_ack *extack); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 783 | int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, |
Roopa Prabhu | d297653 | 2016-08-30 21:56:45 -0700 | [diff] [blame] | 784 | struct net_device *dev, struct net_device *fdev, int *idx); |
Roopa Prabhu | 4767456 | 2018-12-15 22:35:09 -0800 | [diff] [blame] | 785 | int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev, |
| 786 | const unsigned char *addr, u16 vid, u32 portid, u32 seq, |
| 787 | struct netlink_ext_ack *extack); |
Vlad Yasevich | 8db24af | 2014-05-16 09:59:17 -0400 | [diff] [blame] | 788 | int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); |
| 789 | void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 790 | int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, |
Nikolay Aleksandrov | 45a6878 | 2021-08-10 14:00:10 +0300 | [diff] [blame] | 791 | const unsigned char *addr, u16 vid, |
Petr Machata | 161d82d | 2018-05-03 14:43:53 +0200 | [diff] [blame] | 792 | bool swdev_notify); |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 793 | int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, |
Petr Machata | 161d82d | 2018-05-03 14:43:53 +0200 | [diff] [blame] | 794 | const unsigned char *addr, u16 vid, |
| 795 | bool swdev_notify); |
Arkadi Sharshevsky | 9fe8bce | 2017-06-08 08:44:15 +0200 | [diff] [blame] | 796 | void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p, |
Ido Schimmel | e9ba0fb | 2018-10-17 08:53:29 +0000 | [diff] [blame] | 797 | const unsigned char *addr, u16 vid, bool offloaded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* br_forward.c */ |
Nikolay Aleksandrov | 8addd5e | 2016-08-31 15:36:51 +0200 | [diff] [blame] | 800 | enum br_pkt_type { |
| 801 | BR_PKT_UNICAST, |
| 802 | BR_PKT_MULTICAST, |
| 803 | BR_PKT_BROADCAST |
| 804 | }; |
Eric W. Biederman | 0c4b51f | 2015-09-15 20:04:18 -0500 | [diff] [blame] | 805 | int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb); |
Nikolay Aleksandrov | b35c5f6 | 2016-07-14 06:10:01 +0300 | [diff] [blame] | 806 | void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 807 | bool local_rcv, bool local_orig); |
Eric W. Biederman | 0c4b51f | 2015-09-15 20:04:18 -0500 | [diff] [blame] | 808 | int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 809 | void br_flood(struct net_bridge *br, struct sk_buff *skb, |
Nikolay Aleksandrov | 8addd5e | 2016-08-31 15:36:51 +0200 | [diff] [blame] | 810 | enum br_pkt_type pkt_type, bool local_rcv, bool local_orig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Nikolay Aleksandrov | 7d850ab | 2018-05-24 11:56:48 +0300 | [diff] [blame] | 812 | /* return true if both source port and dest port are isolated */ |
| 813 | static inline bool br_skb_isolated(const struct net_bridge_port *to, |
| 814 | const struct sk_buff *skb) |
| 815 | { |
| 816 | return BR_INPUT_SKB_CB(skb)->src_port_isolated && |
| 817 | (to->flags & BR_ISOLATED); |
| 818 | } |
| 819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | /* br_if.c */ |
Nikolay Aleksandrov | faa1cd8 | 2018-05-03 13:47:24 +0300 | [diff] [blame] | 821 | void br_port_carrier_check(struct net_bridge_port *p, bool *notified); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 822 | int br_add_bridge(struct net *net, const char *name); |
| 823 | int br_del_bridge(struct net *net, const char *name); |
David Ahern | ca752be | 2017-10-04 17:48:50 -0700 | [diff] [blame] | 824 | int br_add_if(struct net_bridge *br, struct net_device *dev, |
| 825 | struct netlink_ext_ack *extack); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 826 | int br_del_if(struct net_bridge *br, struct net_device *dev); |
Nikolay Aleksandrov | 804b854 | 2018-03-30 13:46:19 +0300 | [diff] [blame] | 827 | void br_mtu_auto_adjust(struct net_bridge *br); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 828 | netdev_features_t br_features_recompute(struct net_bridge *br, |
| 829 | netdev_features_t features); |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 830 | void br_port_flags_change(struct net_bridge_port *port, unsigned long mask); |
Vlad Yasevich | 2796d0c | 2014-05-16 09:59:20 -0400 | [diff] [blame] | 831 | void br_manage_promisc(struct net_bridge *br); |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 832 | int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | /* br_input.c */ |
Eric W. Biederman | 0c4b51f | 2015-09-15 20:04:18 -0500 | [diff] [blame] | 835 | int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); |
Vladimir Oltean | 9eb8eff | 2020-05-10 19:37:40 +0300 | [diff] [blame] | 836 | rx_handler_func_t *br_get_rx_handler(const struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Henrik Bjoernlund | 90c628d | 2020-10-27 10:02:42 +0000 | [diff] [blame] | 838 | struct br_frame_type { |
| 839 | __be16 type; |
| 840 | int (*frame_handler)(struct net_bridge_port *port, |
| 841 | struct sk_buff *skb); |
| 842 | struct hlist_node list; |
| 843 | }; |
| 844 | |
| 845 | void br_add_frame(struct net_bridge *br, struct br_frame_type *ft); |
| 846 | void br_del_frame(struct net_bridge *br, struct br_frame_type *ft); |
| 847 | |
Jiri Pirko | 859828c | 2013-12-05 16:27:37 +0100 | [diff] [blame] | 848 | static inline bool br_rx_handler_check_rcu(const struct net_device *dev) |
| 849 | { |
Vladimir Oltean | 9eb8eff | 2020-05-10 19:37:40 +0300 | [diff] [blame] | 850 | return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev); |
Jiri Pirko | 859828c | 2013-12-05 16:27:37 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 853 | static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) |
| 854 | { |
Vladimir Oltean | 9eb8eff | 2020-05-10 19:37:40 +0300 | [diff] [blame] | 855 | return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev); |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 856 | } |
| 857 | |
Jiri Pirko | 859828c | 2013-12-05 16:27:37 +0100 | [diff] [blame] | 858 | static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) |
| 859 | { |
| 860 | return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL; |
| 861 | } |
| 862 | |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 863 | static inline struct net_bridge_port * |
| 864 | br_port_get_check_rtnl(const struct net_device *dev) |
| 865 | { |
| 866 | return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL; |
| 867 | } |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | /* br_ioctl.c */ |
Arnd Bergmann | 561d835 | 2021-07-27 15:44:51 +0200 | [diff] [blame] | 870 | int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq, |
| 871 | void __user *data, int cmd); |
Arnd Bergmann | ad2f99a | 2021-07-27 15:45:16 +0200 | [diff] [blame] | 872 | int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd, |
| 873 | struct ifreq *ifr, void __user *uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 875 | /* br_multicast.c */ |
| 876 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 877 | int br_multicast_rcv(struct net_bridge_mcast **brmctx, |
| 878 | struct net_bridge_mcast_port **pmctx, |
| 879 | struct net_bridge_vlan *vlan, |
David S. Miller | 394efd1 | 2013-11-04 13:48:30 -0500 | [diff] [blame] | 880 | struct sk_buff *skb, u16 vid); |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 881 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx, |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 882 | struct sk_buff *skb, u16 vid); |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 883 | int br_multicast_add_port(struct net_bridge_port *port); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 884 | void br_multicast_del_port(struct net_bridge_port *port); |
| 885 | void br_multicast_enable_port(struct net_bridge_port *port); |
| 886 | void br_multicast_disable_port(struct net_bridge_port *port); |
| 887 | void br_multicast_init(struct net_bridge *br); |
Joseph Huang | 851d0a7 | 2020-12-04 18:56:28 -0500 | [diff] [blame] | 888 | void br_multicast_join_snoopers(struct net_bridge *br); |
| 889 | void br_multicast_leave_snoopers(struct net_bridge *br); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 890 | void br_multicast_open(struct net_bridge *br); |
| 891 | void br_multicast_stop(struct net_bridge *br); |
Satish Ashok | e10177a | 2015-07-15 07:16:51 -0700 | [diff] [blame] | 892 | void br_multicast_dev_del(struct net_bridge *br); |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 893 | void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb, |
| 894 | struct net_bridge_mcast *brmctx, |
| 895 | bool local_rcv, bool local_orig); |
Nikolay Aleksandrov | a97df08 | 2021-08-10 18:29:31 +0300 | [diff] [blame] | 896 | int br_multicast_set_router(struct net_bridge_mcast *brmctx, unsigned long val); |
Nikolay Aleksandrov | a53581d | 2021-08-20 15:42:54 +0300 | [diff] [blame] | 897 | int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx, |
| 898 | unsigned long val); |
Nikolay Aleksandrov | 2796d84 | 2021-08-20 15:42:55 +0300 | [diff] [blame] | 899 | int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router); |
Florian Fainelli | ae1ea84 | 2021-04-14 22:22:57 +0300 | [diff] [blame] | 900 | int br_multicast_toggle(struct net_bridge *br, unsigned long val, |
| 901 | struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | 6293818 | 2021-08-10 18:29:30 +0300 | [diff] [blame] | 902 | int br_multicast_set_querier(struct net_bridge_mcast *brmctx, unsigned long val); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 903 | int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val); |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 904 | int br_multicast_set_igmp_version(struct net_bridge_mcast *brmctx, |
| 905 | unsigned long val); |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 906 | #if IS_ENABLED(CONFIG_IPV6) |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 907 | int br_multicast_set_mld_version(struct net_bridge_mcast *brmctx, |
| 908 | unsigned long val); |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 909 | #endif |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 910 | struct net_bridge_mdb_entry * |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 911 | br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 912 | struct net_bridge_mdb_entry * |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 913 | br_multicast_new_group(struct net_bridge *br, struct br_ip *group); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 914 | struct net_bridge_port_group * |
| 915 | br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group, |
| 916 | struct net_bridge_port_group __rcu *next, |
Nikolay Aleksandrov | 8b67177 | 2020-09-07 12:56:07 +0300 | [diff] [blame] | 917 | unsigned char flags, const unsigned char *src, |
Nikolay Aleksandrov | 8f8cb77 | 2020-09-22 10:30:21 +0300 | [diff] [blame] | 918 | u8 filter_mode, u8 rt_protocol); |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 919 | int br_mdb_hash_init(struct net_bridge *br); |
| 920 | void br_mdb_hash_fini(struct net_bridge *br); |
Nikolay Aleksandrov | 81f1983 | 2020-09-07 12:56:12 +0300 | [diff] [blame] | 921 | void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp, |
| 922 | struct net_bridge_port_group *pg, int type); |
Nikolay Aleksandrov | 1e9ca45 | 2021-07-19 20:06:33 +0300 | [diff] [blame] | 923 | void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx, |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 924 | int type); |
Nikolay Aleksandrov | 681590b | 2020-09-07 12:56:06 +0300 | [diff] [blame] | 925 | void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, |
| 926 | struct net_bridge_port_group *pg, |
| 927 | struct net_bridge_port_group __rcu **pp); |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 928 | void br_multicast_count(struct net_bridge *br, |
| 929 | const struct net_bridge_port *p, |
Nikolay Aleksandrov | a65056e | 2016-07-06 12:12:21 -0700 | [diff] [blame] | 930 | const struct sk_buff *skb, u8 type, u8 dir); |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 931 | int br_multicast_init_stats(struct net_bridge *br); |
Ido Schimmel | b6fe044 | 2017-04-10 14:59:27 +0300 | [diff] [blame] | 932 | void br_multicast_uninit_stats(struct net_bridge *br); |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 933 | void br_multicast_get_stats(const struct net_bridge *br, |
| 934 | const struct net_bridge_port *p, |
| 935 | struct br_mcast_stats *dest); |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 936 | void br_mdb_init(void); |
| 937 | void br_mdb_uninit(void); |
Nikolay Aleksandrov | 58d913a | 2021-07-21 17:01:27 +0300 | [diff] [blame] | 938 | void br_multicast_host_join(const struct net_bridge_mcast *brmctx, |
| 939 | struct net_bridge_mdb_entry *mp, bool notify); |
Nikolay Aleksandrov | 1bc844e | 2019-08-17 14:22:13 +0300 | [diff] [blame] | 940 | void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify); |
Nikolay Aleksandrov | 8266a04 | 2020-09-22 10:30:24 +0300 | [diff] [blame] | 941 | void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg, |
| 942 | u8 filter_mode); |
| 943 | void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp, |
| 944 | struct net_bridge_port_group *sg); |
Nikolay Aleksandrov | 474ddb3 | 2021-01-20 16:51:58 +0200 | [diff] [blame] | 945 | struct net_bridge_group_src * |
| 946 | br_multicast_find_group_src(struct net_bridge_port_group *pg, struct br_ip *ip); |
Nikolay Aleksandrov | d5a1022 | 2021-01-20 16:52:03 +0200 | [diff] [blame] | 947 | void br_multicast_del_group_src(struct net_bridge_group_src *src, |
| 948 | bool fastleave); |
Nikolay Aleksandrov | 613d61d | 2021-07-19 20:06:26 +0300 | [diff] [blame] | 949 | void br_multicast_ctx_init(struct net_bridge *br, |
| 950 | struct net_bridge_vlan *vlan, |
| 951 | struct net_bridge_mcast *brmctx); |
| 952 | void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx); |
| 953 | void br_multicast_port_ctx_init(struct net_bridge_port *port, |
| 954 | struct net_bridge_vlan *vlan, |
| 955 | struct net_bridge_mcast_port *pmctx); |
| 956 | void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx); |
Nikolay Aleksandrov | 7b54aaa | 2021-07-19 20:06:27 +0300 | [diff] [blame] | 957 | void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on); |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 958 | int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on, |
| 959 | struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | 9dee572 | 2021-07-19 20:06:37 +0300 | [diff] [blame] | 960 | bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on); |
Sridhar Samudrala | 85b3526 | 2010-03-01 09:53:04 +0000 | [diff] [blame] | 961 | |
Nikolay Aleksandrov | dc00287 | 2021-08-10 18:29:33 +0300 | [diff] [blame] | 962 | int br_rports_fill_info(struct sk_buff *skb, |
| 963 | const struct net_bridge_mcast *brmctx); |
Nikolay Aleksandrov | c7fa1d9 | 2021-08-13 18:00:00 +0300 | [diff] [blame] | 964 | int br_multicast_dump_querier_state(struct sk_buff *skb, |
| 965 | const struct net_bridge_mcast *brmctx, |
| 966 | int nest_attr); |
| 967 | size_t br_multicast_querier_state_size(void); |
Nikolay Aleksandrov | 05d6f38 | 2021-08-16 17:57:05 +0300 | [diff] [blame] | 968 | size_t br_rports_size(const struct net_bridge_mcast *brmctx); |
Nikolay Aleksandrov | 99b4061 | 2021-12-27 19:21:15 +0200 | [diff] [blame] | 969 | void br_multicast_set_query_intvl(struct net_bridge_mcast *brmctx, |
| 970 | unsigned long val); |
Nikolay Aleksandrov | f83a112 | 2021-12-27 19:21:16 +0200 | [diff] [blame] | 971 | void br_multicast_set_startup_query_intvl(struct net_bridge_mcast *brmctx, |
| 972 | unsigned long val); |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 973 | |
Nikolay Aleksandrov | 955062b | 2020-10-29 01:38:31 +0200 | [diff] [blame] | 974 | static inline bool br_group_is_l2(const struct br_ip *group) |
| 975 | { |
| 976 | return group->proto == 0; |
| 977 | } |
| 978 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 979 | #define mlock_dereference(X, br) \ |
| 980 | rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) |
| 981 | |
Linus Lüssing | 44ebb08 | 2021-05-13 15:20:44 +0200 | [diff] [blame] | 982 | static inline struct hlist_node * |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 983 | br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx, |
| 984 | struct sk_buff *skb) |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 985 | { |
Linus Lüssing | a3c02e7 | 2021-05-13 15:20:51 +0200 | [diff] [blame] | 986 | #if IS_ENABLED(CONFIG_IPV6) |
| 987 | if (skb->protocol == htons(ETH_P_IPV6)) |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 988 | return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list)); |
Linus Lüssing | a3c02e7 | 2021-05-13 15:20:51 +0200 | [diff] [blame] | 989 | #endif |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 990 | return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list)); |
Linus Lüssing | 44ebb08 | 2021-05-13 15:20:44 +0200 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | static inline struct net_bridge_port * |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 994 | br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) |
| 995 | { |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 996 | struct net_bridge_mcast_port *mctx; |
| 997 | |
Linus Lüssing | a3c02e7 | 2021-05-13 15:20:51 +0200 | [diff] [blame] | 998 | #if IS_ENABLED(CONFIG_IPV6) |
| 999 | if (skb->protocol == htons(ETH_P_IPV6)) |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 1000 | mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, |
| 1001 | ip6_rlist); |
| 1002 | else |
Linus Lüssing | a3c02e7 | 2021-05-13 15:20:51 +0200 | [diff] [blame] | 1003 | #endif |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 1004 | mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, |
| 1005 | ip4_rlist); |
| 1006 | |
| 1007 | if (mctx) |
| 1008 | return mctx->port; |
| 1009 | else |
| 1010 | return NULL; |
Linus Lüssing | 44ebb08 | 2021-05-13 15:20:44 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1013 | static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx) |
Sridhar Samudrala | 85b3526 | 2010-03-01 09:53:04 +0000 | [diff] [blame] | 1014 | { |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1015 | return timer_pending(&brmctx->ip4_mc_router_timer); |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1018 | static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx) |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1019 | { |
| 1020 | #if IS_ENABLED(CONFIG_IPV6) |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1021 | return timer_pending(&brmctx->ip6_mc_router_timer); |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1022 | #else |
| 1023 | return false; |
| 1024 | #endif |
| 1025 | } |
| 1026 | |
| 1027 | static inline bool |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1028 | br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb) |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1029 | { |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1030 | switch (brmctx->multicast_router) { |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1031 | case MDB_RTR_TYPE_PERM: |
| 1032 | return true; |
| 1033 | case MDB_RTR_TYPE_TEMP_QUERY: |
| 1034 | if (skb) { |
| 1035 | if (skb->protocol == htons(ETH_P_IP)) |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1036 | return br_ip4_multicast_is_router(brmctx); |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1037 | else if (skb->protocol == htons(ETH_P_IPV6)) |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1038 | return br_ip6_multicast_is_router(brmctx); |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1039 | } else { |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1040 | return br_ip4_multicast_is_router(brmctx) || |
| 1041 | br_ip6_multicast_is_router(brmctx); |
Linus Lüssing | 1a3065a | 2021-05-13 15:20:47 +0200 | [diff] [blame] | 1042 | } |
| 1043 | fallthrough; |
| 1044 | default: |
| 1045 | return false; |
| 1046 | } |
Sridhar Samudrala | 85b3526 | 2010-03-01 09:53:04 +0000 | [diff] [blame] | 1047 | } |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1048 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1049 | static inline bool |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1050 | __br_multicast_querier_exists(struct net_bridge_mcast *brmctx, |
| 1051 | struct bridge_mcast_other_query *querier, |
| 1052 | const bool is_ipv6) |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1053 | { |
daniel | 0888d5f | 2016-06-24 12:35:18 +0200 | [diff] [blame] | 1054 | bool own_querier_enabled; |
| 1055 | |
Nikolay Aleksandrov | 6293818 | 2021-08-10 18:29:30 +0300 | [diff] [blame] | 1056 | if (brmctx->multicast_querier) { |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1057 | if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR)) |
daniel | 0888d5f | 2016-06-24 12:35:18 +0200 | [diff] [blame] | 1058 | own_querier_enabled = false; |
| 1059 | else |
| 1060 | own_querier_enabled = true; |
| 1061 | } else { |
| 1062 | own_querier_enabled = false; |
| 1063 | } |
| 1064 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1065 | return time_is_before_jiffies(querier->delay_time) && |
daniel | 0888d5f | 2016-06-24 12:35:18 +0200 | [diff] [blame] | 1066 | (own_querier_enabled || timer_pending(&querier->timer)); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1069 | static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, |
Nikolay Aleksandrov | 955062b | 2020-10-29 01:38:31 +0200 | [diff] [blame] | 1070 | struct ethhdr *eth, |
| 1071 | const struct net_bridge_mdb_entry *mdb) |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1072 | { |
| 1073 | switch (eth->h_proto) { |
| 1074 | case (htons(ETH_P_IP)): |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1075 | return __br_multicast_querier_exists(brmctx, |
| 1076 | &brmctx->ip4_other_query, false); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1077 | #if IS_ENABLED(CONFIG_IPV6) |
| 1078 | case (htons(ETH_P_IPV6)): |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1079 | return __br_multicast_querier_exists(brmctx, |
| 1080 | &brmctx->ip6_other_query, true); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1081 | #endif |
| 1082 | default: |
Nikolay Aleksandrov | 955062b | 2020-10-29 01:38:31 +0200 | [diff] [blame] | 1083 | return !!mdb && br_group_is_l2(&mdb->addr); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1084 | } |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1085 | } |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1086 | |
Nikolay Aleksandrov | 88d4bd1 | 2020-09-22 10:30:19 +0300 | [diff] [blame] | 1087 | static inline bool br_multicast_is_star_g(const struct br_ip *ip) |
| 1088 | { |
| 1089 | switch (ip->proto) { |
| 1090 | case htons(ETH_P_IP): |
| 1091 | return ipv4_is_zeronet(ip->src.ip4); |
| 1092 | #if IS_ENABLED(CONFIG_IPV6) |
| 1093 | case htons(ETH_P_IPV6): |
| 1094 | return ipv6_addr_any(&ip->src.ip6); |
| 1095 | #endif |
| 1096 | default: |
| 1097 | return false; |
| 1098 | } |
| 1099 | } |
| 1100 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1101 | static inline bool |
| 1102 | br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx, |
| 1103 | __be16 proto) |
Nikolay Aleksandrov | 8266a04 | 2020-09-22 10:30:24 +0300 | [diff] [blame] | 1104 | { |
| 1105 | switch (proto) { |
| 1106 | case htons(ETH_P_IP): |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1107 | return !!(brmctx->multicast_igmp_version == 3); |
Nikolay Aleksandrov | 8266a04 | 2020-09-22 10:30:24 +0300 | [diff] [blame] | 1108 | #if IS_ENABLED(CONFIG_IPV6) |
| 1109 | case htons(ETH_P_IPV6): |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1110 | return !!(brmctx->multicast_mld_version == 2); |
Nikolay Aleksandrov | 8266a04 | 2020-09-22 10:30:24 +0300 | [diff] [blame] | 1111 | #endif |
| 1112 | default: |
| 1113 | return false; |
| 1114 | } |
| 1115 | } |
| 1116 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1117 | static inline int br_multicast_igmp_type(const struct sk_buff *skb) |
| 1118 | { |
| 1119 | return BR_INPUT_SKB_CB(skb)->igmp; |
| 1120 | } |
Nikolay Aleksandrov | 42c11cc | 2020-09-07 12:56:10 +0300 | [diff] [blame] | 1121 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1122 | static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx) |
Nikolay Aleksandrov | 42c11cc | 2020-09-07 12:56:10 +0300 | [diff] [blame] | 1123 | { |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1124 | return brmctx->multicast_last_member_interval * |
| 1125 | brmctx->multicast_last_member_count; |
Nikolay Aleksandrov | 42c11cc | 2020-09-07 12:56:10 +0300 | [diff] [blame] | 1126 | } |
Nikolay Aleksandrov | 0436862 | 2020-09-07 12:56:14 +0300 | [diff] [blame] | 1127 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1128 | static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx) |
Nikolay Aleksandrov | 0436862 | 2020-09-07 12:56:14 +0300 | [diff] [blame] | 1129 | { |
Nikolay Aleksandrov | fac3cb8 | 2021-10-15 12:05:46 +0300 | [diff] [blame] | 1130 | return brmctx->multicast_membership_interval; |
Nikolay Aleksandrov | 0436862 | 2020-09-07 12:56:14 +0300 | [diff] [blame] | 1131 | } |
Nikolay Aleksandrov | 7b54aaa | 2021-07-19 20:06:27 +0300 | [diff] [blame] | 1132 | |
| 1133 | static inline bool |
| 1134 | br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx) |
| 1135 | { |
| 1136 | return !!brmctx->vlan; |
| 1137 | } |
| 1138 | |
| 1139 | static inline bool |
| 1140 | br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx) |
| 1141 | { |
| 1142 | return !!pmctx->vlan; |
| 1143 | } |
| 1144 | |
| 1145 | static inline struct net_bridge_mcast * |
| 1146 | br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx) |
| 1147 | { |
| 1148 | if (!br_multicast_port_ctx_is_vlan(pmctx)) |
| 1149 | return &pmctx->port->br->multicast_ctx; |
| 1150 | else |
| 1151 | return &pmctx->vlan->brvlan->br_mcast_ctx; |
| 1152 | } |
| 1153 | |
| 1154 | static inline bool |
| 1155 | br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx) |
| 1156 | { |
Nikolay Aleksandrov | 168fed9 | 2021-12-28 17:31:42 +0200 | [diff] [blame] | 1157 | return br_multicast_ctx_is_vlan(brmctx) && |
| 1158 | (!br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) || |
| 1159 | !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)); |
Nikolay Aleksandrov | 7b54aaa | 2021-07-19 20:06:27 +0300 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | static inline bool |
| 1163 | br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx) |
| 1164 | { |
| 1165 | return br_multicast_ctx_is_vlan(brmctx) && |
| 1166 | !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); |
| 1167 | } |
| 1168 | |
| 1169 | static inline bool |
| 1170 | br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx) |
| 1171 | { |
| 1172 | return br_multicast_port_ctx_is_vlan(pmctx) && |
| 1173 | !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); |
| 1174 | } |
Nikolay Aleksandrov | 4cdd0d1 | 2021-07-19 20:06:31 +0300 | [diff] [blame] | 1175 | |
| 1176 | static inline bool |
| 1177 | br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx) |
| 1178 | { |
| 1179 | return pmctx->port->state == BR_STATE_DISABLED || |
| 1180 | (br_multicast_port_ctx_is_vlan(pmctx) && |
| 1181 | (br_multicast_port_ctx_vlan_disabled(pmctx) || |
| 1182 | pmctx->vlan->state == BR_STATE_DISABLED)); |
| 1183 | } |
| 1184 | |
| 1185 | static inline bool |
| 1186 | br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx) |
| 1187 | { |
| 1188 | return br_multicast_port_ctx_state_disabled(pmctx) || |
| 1189 | pmctx->port->state == BR_STATE_BLOCKING || |
| 1190 | (br_multicast_port_ctx_is_vlan(pmctx) && |
| 1191 | pmctx->vlan->state == BR_STATE_BLOCKING); |
| 1192 | } |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 1193 | |
| 1194 | static inline bool |
Nikolay Aleksandrov | dc00287 | 2021-08-10 18:29:33 +0300 | [diff] [blame] | 1195 | br_rports_have_mc_router(const struct net_bridge_mcast *brmctx) |
| 1196 | { |
| 1197 | #if IS_ENABLED(CONFIG_IPV6) |
| 1198 | return !hlist_empty(&brmctx->ip4_mc_router_list) || |
| 1199 | !hlist_empty(&brmctx->ip6_mc_router_list); |
| 1200 | #else |
| 1201 | return !hlist_empty(&brmctx->ip4_mc_router_list); |
| 1202 | #endif |
| 1203 | } |
| 1204 | |
| 1205 | static inline bool |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 1206 | br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, |
| 1207 | const struct net_bridge_mcast *brmctx2) |
| 1208 | { |
| 1209 | return brmctx1->multicast_igmp_version == |
| 1210 | brmctx2->multicast_igmp_version && |
Nikolay Aleksandrov | 931ba87 | 2021-08-10 18:29:20 +0300 | [diff] [blame] | 1211 | brmctx1->multicast_last_member_count == |
| 1212 | brmctx2->multicast_last_member_count && |
Nikolay Aleksandrov | 50725f6 | 2021-08-10 18:29:21 +0300 | [diff] [blame] | 1213 | brmctx1->multicast_startup_query_count == |
| 1214 | brmctx2->multicast_startup_query_count && |
Nikolay Aleksandrov | 77f6aba | 2021-08-10 18:29:22 +0300 | [diff] [blame] | 1215 | brmctx1->multicast_last_member_interval == |
| 1216 | brmctx2->multicast_last_member_interval && |
Nikolay Aleksandrov | 2da0aea | 2021-08-10 18:29:23 +0300 | [diff] [blame] | 1217 | brmctx1->multicast_membership_interval == |
| 1218 | brmctx2->multicast_membership_interval && |
Nikolay Aleksandrov | cd9269d | 2021-08-10 18:29:24 +0300 | [diff] [blame] | 1219 | brmctx1->multicast_querier_interval == |
| 1220 | brmctx2->multicast_querier_interval && |
Nikolay Aleksandrov | d6c08ab | 2021-08-10 18:29:25 +0300 | [diff] [blame] | 1221 | brmctx1->multicast_query_interval == |
| 1222 | brmctx2->multicast_query_interval && |
Nikolay Aleksandrov | 4252145 | 2021-08-10 18:29:26 +0300 | [diff] [blame] | 1223 | brmctx1->multicast_query_response_interval == |
| 1224 | brmctx2->multicast_query_response_interval && |
Nikolay Aleksandrov | 941121e | 2021-08-10 18:29:27 +0300 | [diff] [blame] | 1225 | brmctx1->multicast_startup_query_interval == |
| 1226 | brmctx2->multicast_startup_query_interval && |
Nikolay Aleksandrov | 6293818 | 2021-08-10 18:29:30 +0300 | [diff] [blame] | 1227 | brmctx1->multicast_querier == brmctx2->multicast_querier && |
Nikolay Aleksandrov | a97df08 | 2021-08-10 18:29:31 +0300 | [diff] [blame] | 1228 | brmctx1->multicast_router == brmctx2->multicast_router && |
Nikolay Aleksandrov | dc00287 | 2021-08-10 18:29:33 +0300 | [diff] [blame] | 1229 | !br_rports_have_mc_router(brmctx1) && |
| 1230 | !br_rports_have_mc_router(brmctx2) && |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 1231 | #if IS_ENABLED(CONFIG_IPV6) |
| 1232 | brmctx1->multicast_mld_version == |
| 1233 | brmctx2->multicast_mld_version && |
| 1234 | #endif |
| 1235 | true; |
| 1236 | } |
Nikolay Aleksandrov | cb486ce | 2021-08-10 18:29:29 +0300 | [diff] [blame] | 1237 | |
| 1238 | static inline bool |
| 1239 | br_multicast_ctx_matches_vlan_snooping(const struct net_bridge_mcast *brmctx) |
| 1240 | { |
| 1241 | bool vlan_snooping_enabled; |
| 1242 | |
| 1243 | vlan_snooping_enabled = !!br_opt_get(brmctx->br, |
| 1244 | BROPT_MCAST_VLAN_SNOOPING_ENABLED); |
| 1245 | |
| 1246 | return !!(vlan_snooping_enabled == br_multicast_ctx_is_vlan(brmctx)); |
| 1247 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1248 | #else |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 1249 | static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx, |
| 1250 | struct net_bridge_mcast_port **pmctx, |
| 1251 | struct net_bridge_vlan *vlan, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1252 | struct sk_buff *skb, |
| 1253 | u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1254 | { |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1258 | static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx, |
Cong Wang | fbca58a | 2013-03-07 03:05:33 +0000 | [diff] [blame] | 1259 | struct sk_buff *skb, u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1260 | { |
| 1261 | return NULL; |
| 1262 | } |
| 1263 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1264 | static inline int br_multicast_add_port(struct net_bridge_port *port) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1265 | { |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1266 | return 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static inline void br_multicast_del_port(struct net_bridge_port *port) |
| 1270 | { |
| 1271 | } |
| 1272 | |
| 1273 | static inline void br_multicast_enable_port(struct net_bridge_port *port) |
| 1274 | { |
| 1275 | } |
| 1276 | |
| 1277 | static inline void br_multicast_disable_port(struct net_bridge_port *port) |
| 1278 | { |
| 1279 | } |
| 1280 | |
| 1281 | static inline void br_multicast_init(struct net_bridge *br) |
| 1282 | { |
| 1283 | } |
| 1284 | |
Joseph Huang | 851d0a7 | 2020-12-04 18:56:28 -0500 | [diff] [blame] | 1285 | static inline void br_multicast_join_snoopers(struct net_bridge *br) |
| 1286 | { |
| 1287 | } |
| 1288 | |
| 1289 | static inline void br_multicast_leave_snoopers(struct net_bridge *br) |
| 1290 | { |
| 1291 | } |
| 1292 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1293 | static inline void br_multicast_open(struct net_bridge *br) |
| 1294 | { |
| 1295 | } |
| 1296 | |
| 1297 | static inline void br_multicast_stop(struct net_bridge *br) |
| 1298 | { |
| 1299 | } |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 1300 | |
Nikolay Aleksandrov | a7ce45a | 2015-07-20 23:03:45 +0200 | [diff] [blame] | 1301 | static inline void br_multicast_dev_del(struct net_bridge *br) |
| 1302 | { |
| 1303 | } |
| 1304 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 1305 | static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst, |
| 1306 | struct sk_buff *skb, |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1307 | struct net_bridge_mcast *brmctx, |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 1308 | bool local_rcv, bool local_orig) |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 1309 | { |
| 1310 | } |
| 1311 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1312 | static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx, |
Nikolay Aleksandrov | bbc6f2c | 2021-05-14 10:32:33 +0300 | [diff] [blame] | 1313 | struct sk_buff *skb) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1314 | { |
Gustavo A. R. Silva | 03aaa9e | 2018-01-18 17:37:45 -0600 | [diff] [blame] | 1315 | return false; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1316 | } |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 1317 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 1318 | static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, |
Vladimir Oltean | c43fd36 | 2020-11-01 02:08:45 +0200 | [diff] [blame] | 1319 | struct ethhdr *eth, |
| 1320 | const struct net_bridge_mdb_entry *mdb) |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1321 | { |
| 1322 | return false; |
| 1323 | } |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 1324 | |
Rami Rosen | fdb184d | 2013-01-03 13:30:43 +0200 | [diff] [blame] | 1325 | static inline void br_mdb_init(void) |
| 1326 | { |
| 1327 | } |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 1328 | |
Rami Rosen | fdb184d | 2013-01-03 13:30:43 +0200 | [diff] [blame] | 1329 | static inline void br_mdb_uninit(void) |
| 1330 | { |
| 1331 | } |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1332 | |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 1333 | static inline int br_mdb_hash_init(struct net_bridge *br) |
| 1334 | { |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
| 1338 | static inline void br_mdb_hash_fini(struct net_bridge *br) |
| 1339 | { |
| 1340 | } |
| 1341 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1342 | static inline void br_multicast_count(struct net_bridge *br, |
| 1343 | const struct net_bridge_port *p, |
Nikolay Aleksandrov | a65056e | 2016-07-06 12:12:21 -0700 | [diff] [blame] | 1344 | const struct sk_buff *skb, |
| 1345 | u8 type, u8 dir) |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1346 | { |
| 1347 | } |
| 1348 | |
| 1349 | static inline int br_multicast_init_stats(struct net_bridge *br) |
| 1350 | { |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
Ido Schimmel | b6fe044 | 2017-04-10 14:59:27 +0300 | [diff] [blame] | 1354 | static inline void br_multicast_uninit_stats(struct net_bridge *br) |
| 1355 | { |
| 1356 | } |
| 1357 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1358 | static inline int br_multicast_igmp_type(const struct sk_buff *skb) |
| 1359 | { |
| 1360 | return 0; |
| 1361 | } |
Nikolay Aleksandrov | 613d61d | 2021-07-19 20:06:26 +0300 | [diff] [blame] | 1362 | |
| 1363 | static inline void br_multicast_ctx_init(struct net_bridge *br, |
| 1364 | struct net_bridge_vlan *vlan, |
| 1365 | struct net_bridge_mcast *brmctx) |
| 1366 | { |
| 1367 | } |
| 1368 | |
| 1369 | static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx) |
| 1370 | { |
| 1371 | } |
| 1372 | |
| 1373 | static inline void br_multicast_port_ctx_init(struct net_bridge_port *port, |
| 1374 | struct net_bridge_vlan *vlan, |
| 1375 | struct net_bridge_mcast_port *pmctx) |
| 1376 | { |
| 1377 | } |
| 1378 | |
| 1379 | static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx) |
| 1380 | { |
| 1381 | } |
Nikolay Aleksandrov | 7b54aaa | 2021-07-19 20:06:27 +0300 | [diff] [blame] | 1382 | |
| 1383 | static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, |
| 1384 | bool on) |
| 1385 | { |
| 1386 | } |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 1387 | |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 1388 | static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br, |
| 1389 | bool on, |
| 1390 | struct netlink_ext_ack *extack) |
| 1391 | { |
| 1392 | return -EOPNOTSUPP; |
| 1393 | } |
Nikolay Aleksandrov | 9dee572 | 2021-07-19 20:06:37 +0300 | [diff] [blame] | 1394 | |
| 1395 | static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, |
| 1396 | bool on) |
| 1397 | { |
| 1398 | return false; |
| 1399 | } |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 1400 | |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 1401 | static inline bool |
| 1402 | br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, |
| 1403 | const struct net_bridge_mcast *brmctx2) |
| 1404 | { |
| 1405 | return true; |
| 1406 | } |
Sridhar Samudrala | 85b3526 | 2010-03-01 09:53:04 +0000 | [diff] [blame] | 1407 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1408 | |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1409 | /* br_vlan.c */ |
| 1410 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1411 | bool br_allowed_ingress(const struct net_bridge *br, |
| 1412 | struct net_bridge_vlan_group *vg, struct sk_buff *skb, |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 1413 | u16 *vid, u8 *state, |
| 1414 | struct net_bridge_vlan **vlan); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1415 | bool br_allowed_egress(struct net_bridge_vlan_group *vg, |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1416 | const struct sk_buff *skb); |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 1417 | bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1418 | struct sk_buff *br_handle_vlan(struct net_bridge *br, |
Roopa Prabhu | 11538d0 | 2017-01-31 22:59:55 -0800 | [diff] [blame] | 1419 | const struct net_bridge_port *port, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1420 | struct net_bridge_vlan_group *vg, |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1421 | struct sk_buff *skb); |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1422 | int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1423 | bool *changed, struct netlink_ext_ack *extack); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1424 | int br_vlan_delete(struct net_bridge *br, u16 vid); |
| 1425 | void br_vlan_flush(struct net_bridge *br); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1426 | struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 1427 | void br_recalculate_fwd_mask(struct net_bridge *br); |
Vladimir Oltean | 9e78140 | 2021-02-13 22:43:16 +0200 | [diff] [blame] | 1428 | int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val, |
| 1429 | struct netlink_ext_ack *extack); |
Vladimir Oltean | dcbdf13 | 2021-02-13 22:43:17 +0200 | [diff] [blame] | 1430 | int __br_vlan_set_proto(struct net_bridge *br, __be16 proto, |
| 1431 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 9e78140 | 2021-02-13 22:43:16 +0200 | [diff] [blame] | 1432 | int br_vlan_set_proto(struct net_bridge *br, unsigned long val, |
| 1433 | struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 1434 | int br_vlan_set_stats(struct net_bridge *br, unsigned long val); |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 1435 | int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1436 | int br_vlan_init(struct net_bridge *br); |
Vladimir Oltean | 9e78140 | 2021-02-13 22:43:16 +0200 | [diff] [blame] | 1437 | int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val, |
| 1438 | struct netlink_ext_ack *extack); |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1439 | int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, |
| 1440 | struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1441 | int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1442 | bool *changed, struct netlink_ext_ack *extack); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1443 | int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); |
| 1444 | void nbp_vlan_flush(struct net_bridge_port *port); |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1445 | int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1446 | int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1447 | void br_vlan_get_stats(const struct net_bridge_vlan *v, |
Heiner Kallweit | 281cc28 | 2020-11-17 21:25:42 +0100 | [diff] [blame] | 1448 | struct pcpu_sw_netstats *stats); |
Mike Manning | 9c0ec2e | 2019-04-18 18:35:33 +0100 | [diff] [blame] | 1449 | void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); |
Nikolay Aleksandrov | 091adf9 | 2019-08-02 13:57:36 +0300 | [diff] [blame] | 1450 | int br_vlan_bridge_event(struct net_device *dev, unsigned long event, |
| 1451 | void *ptr); |
Nikolay Aleksandrov | 8dcea18 | 2020-01-14 19:56:09 +0200 | [diff] [blame] | 1452 | void br_vlan_rtnl_init(void); |
| 1453 | void br_vlan_rtnl_uninit(void); |
Nikolay Aleksandrov | cf5bddb | 2020-01-14 19:56:13 +0200 | [diff] [blame] | 1454 | void br_vlan_notify(const struct net_bridge *br, |
| 1455 | const struct net_bridge_port *p, |
| 1456 | u16 vid, u16 vid_range, |
| 1457 | int cmd); |
Nikolay Aleksandrov | a5d29ae | 2020-01-24 13:40:21 +0200 | [diff] [blame] | 1458 | bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, |
| 1459 | const struct net_bridge_vlan *range_end); |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1460 | |
Felix Fietkau | bcf2766 | 2021-03-24 02:30:35 +0100 | [diff] [blame] | 1461 | void br_vlan_fill_forward_path_pvid(struct net_bridge *br, |
| 1462 | struct net_device_path_ctx *ctx, |
| 1463 | struct net_device_path *path); |
| 1464 | int br_vlan_fill_forward_path_mode(struct net_bridge *br, |
| 1465 | struct net_bridge_port *dst, |
| 1466 | struct net_device_path *path); |
| 1467 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1468 | static inline struct net_bridge_vlan_group *br_vlan_group( |
| 1469 | const struct net_bridge *br) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1470 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1471 | return rtnl_dereference(br->vlgrp); |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1474 | static inline struct net_bridge_vlan_group *nbp_vlan_group( |
| 1475 | const struct net_bridge_port *p) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1476 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1477 | return rtnl_dereference(p->vlgrp); |
| 1478 | } |
| 1479 | |
| 1480 | static inline struct net_bridge_vlan_group *br_vlan_group_rcu( |
| 1481 | const struct net_bridge *br) |
| 1482 | { |
| 1483 | return rcu_dereference(br->vlgrp); |
| 1484 | } |
| 1485 | |
| 1486 | static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( |
| 1487 | const struct net_bridge_port *p) |
| 1488 | { |
| 1489 | return rcu_dereference(p->vlgrp); |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | /* Since bridge now depends on 8021Q module, but the time bridge sees the |
| 1493 | * skb, the vlan tag will always be present if the frame was tagged. |
| 1494 | */ |
| 1495 | static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) |
| 1496 | { |
| 1497 | int err = 0; |
| 1498 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1499 | if (skb_vlan_tag_present(skb)) { |
Michał Mirosław | 5978f8a | 2018-11-09 00:18:03 +0100 | [diff] [blame] | 1500 | *vid = skb_vlan_tag_get_id(skb); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1501 | } else { |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1502 | *vid = 0; |
| 1503 | err = -EINVAL; |
| 1504 | } |
| 1505 | |
| 1506 | return err; |
| 1507 | } |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1508 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1509 | static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1510 | { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1511 | if (!vg) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1512 | return 0; |
| 1513 | |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1514 | smp_rmb(); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1515 | return vg->pvid; |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
Nikolay Aleksandrov | 8dcea18 | 2020-01-14 19:56:09 +0200 | [diff] [blame] | 1518 | static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) |
| 1519 | { |
| 1520 | return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags; |
| 1521 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1522 | #else |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1523 | static inline bool br_allowed_ingress(const struct net_bridge *br, |
| 1524 | struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1525 | struct sk_buff *skb, |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 1526 | u16 *vid, u8 *state, |
| 1527 | struct net_bridge_vlan **vlan) |
| 1528 | |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1529 | { |
Nikolay Aleksandrov | f4b7002 | 2021-07-19 20:06:28 +0300 | [diff] [blame] | 1530 | *vlan = NULL; |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1531 | return true; |
| 1532 | } |
| 1533 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1534 | static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 1535 | const struct sk_buff *skb) |
| 1536 | { |
| 1537 | return true; |
| 1538 | } |
| 1539 | |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 1540 | static inline bool br_should_learn(struct net_bridge_port *p, |
| 1541 | struct sk_buff *skb, u16 *vid) |
| 1542 | { |
| 1543 | return true; |
| 1544 | } |
| 1545 | |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1546 | static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, |
Roopa Prabhu | 11538d0 | 2017-01-31 22:59:55 -0800 | [diff] [blame] | 1547 | const struct net_bridge_port *port, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1548 | struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1549 | struct sk_buff *skb) |
| 1550 | { |
| 1551 | return skb; |
| 1552 | } |
| 1553 | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1554 | static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1555 | bool *changed, struct netlink_ext_ack *extack) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1556 | { |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1557 | *changed = false; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1558 | return -EOPNOTSUPP; |
| 1559 | } |
| 1560 | |
| 1561 | static inline int br_vlan_delete(struct net_bridge *br, u16 vid) |
| 1562 | { |
| 1563 | return -EOPNOTSUPP; |
| 1564 | } |
| 1565 | |
| 1566 | static inline void br_vlan_flush(struct net_bridge *br) |
| 1567 | { |
| 1568 | } |
| 1569 | |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 1570 | static inline void br_recalculate_fwd_mask(struct net_bridge *br) |
| 1571 | { |
| 1572 | } |
| 1573 | |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1574 | static inline int br_vlan_init(struct net_bridge *br) |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 1575 | { |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1576 | return 0; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 1577 | } |
| 1578 | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1579 | static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1580 | bool *changed, struct netlink_ext_ack *extack) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1581 | { |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1582 | *changed = false; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1583 | return -EOPNOTSUPP; |
| 1584 | } |
| 1585 | |
| 1586 | static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) |
| 1587 | { |
| 1588 | return -EOPNOTSUPP; |
| 1589 | } |
| 1590 | |
| 1591 | static inline void nbp_vlan_flush(struct net_bridge_port *port) |
| 1592 | { |
| 1593 | } |
| 1594 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1595 | static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, |
| 1596 | u16 vid) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1597 | { |
| 1598 | return NULL; |
| 1599 | } |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 1600 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1601 | static inline int nbp_vlan_init(struct net_bridge_port *port, |
| 1602 | struct netlink_ext_ack *extack) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1603 | { |
| 1604 | return 0; |
| 1605 | } |
| 1606 | |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1607 | static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 1608 | { |
| 1609 | return 0; |
| 1610 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1611 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 1612 | static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1613 | { |
Vlad Yasevich | 3df6bf4 | 2014-10-03 11:29:17 -0400 | [diff] [blame] | 1614 | return 0; |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 1615 | } |
Vlad Yasevich | 2796d0c | 2014-05-16 09:59:20 -0400 | [diff] [blame] | 1616 | |
Vladimir Oltean | 7a57296 | 2021-02-13 22:43:15 +0200 | [diff] [blame] | 1617 | static inline int br_vlan_filter_toggle(struct net_bridge *br, |
Vladimir Oltean | c97f47e | 2021-02-15 23:09:12 +0200 | [diff] [blame] | 1618 | unsigned long val, |
| 1619 | struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 1620 | { |
| 1621 | return -EOPNOTSUPP; |
| 1622 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1623 | |
| 1624 | static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, |
| 1625 | u32 filter_mask) |
| 1626 | { |
| 1627 | return 0; |
| 1628 | } |
| 1629 | |
Felix Fietkau | bcf2766 | 2021-03-24 02:30:35 +0100 | [diff] [blame] | 1630 | static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br, |
| 1631 | struct net_device_path_ctx *ctx, |
| 1632 | struct net_device_path *path) |
| 1633 | { |
| 1634 | } |
| 1635 | |
| 1636 | static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br, |
| 1637 | struct net_bridge_port *dst, |
| 1638 | struct net_device_path *path) |
| 1639 | { |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1643 | static inline struct net_bridge_vlan_group *br_vlan_group( |
| 1644 | const struct net_bridge *br) |
| 1645 | { |
| 1646 | return NULL; |
| 1647 | } |
| 1648 | |
| 1649 | static inline struct net_bridge_vlan_group *nbp_vlan_group( |
| 1650 | const struct net_bridge_port *p) |
| 1651 | { |
| 1652 | return NULL; |
| 1653 | } |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1654 | |
| 1655 | static inline struct net_bridge_vlan_group *br_vlan_group_rcu( |
| 1656 | const struct net_bridge *br) |
| 1657 | { |
| 1658 | return NULL; |
| 1659 | } |
| 1660 | |
| 1661 | static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( |
| 1662 | const struct net_bridge_port *p) |
| 1663 | { |
| 1664 | return NULL; |
| 1665 | } |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1666 | |
| 1667 | static inline void br_vlan_get_stats(const struct net_bridge_vlan *v, |
Heiner Kallweit | 281cc28 | 2020-11-17 21:25:42 +0100 | [diff] [blame] | 1668 | struct pcpu_sw_netstats *stats) |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1669 | { |
| 1670 | } |
Mike Manning | 9c0ec2e | 2019-04-18 18:35:33 +0100 | [diff] [blame] | 1671 | |
| 1672 | static inline void br_vlan_port_event(struct net_bridge_port *p, |
| 1673 | unsigned long event) |
| 1674 | { |
| 1675 | } |
| 1676 | |
Nikolay Aleksandrov | 091adf9 | 2019-08-02 13:57:36 +0300 | [diff] [blame] | 1677 | static inline int br_vlan_bridge_event(struct net_device *dev, |
| 1678 | unsigned long event, void *ptr) |
Mike Manning | 9c0ec2e | 2019-04-18 18:35:33 +0100 | [diff] [blame] | 1679 | { |
Nikolay Aleksandrov | 091adf9 | 2019-08-02 13:57:36 +0300 | [diff] [blame] | 1680 | return 0; |
Mike Manning | 9c0ec2e | 2019-04-18 18:35:33 +0100 | [diff] [blame] | 1681 | } |
Nikolay Aleksandrov | 8dcea18 | 2020-01-14 19:56:09 +0200 | [diff] [blame] | 1682 | |
| 1683 | static inline void br_vlan_rtnl_init(void) |
| 1684 | { |
| 1685 | } |
| 1686 | |
| 1687 | static inline void br_vlan_rtnl_uninit(void) |
| 1688 | { |
| 1689 | } |
Nikolay Aleksandrov | cf5bddb | 2020-01-14 19:56:13 +0200 | [diff] [blame] | 1690 | |
| 1691 | static inline void br_vlan_notify(const struct net_bridge *br, |
| 1692 | const struct net_bridge_port *p, |
| 1693 | u16 vid, u16 vid_range, |
| 1694 | int cmd) |
| 1695 | { |
| 1696 | } |
Nikolay Aleksandrov | 528ae84 | 2020-07-13 10:55:46 +0300 | [diff] [blame] | 1697 | |
| 1698 | static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, |
| 1699 | const struct net_bridge_vlan *range_end) |
| 1700 | { |
| 1701 | return true; |
| 1702 | } |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 1703 | |
Vladimir Oltean | c5f6e5e | 2021-10-27 19:21:15 +0300 | [diff] [blame] | 1704 | static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) |
| 1705 | { |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1709 | #endif |
| 1710 | |
Nikolay Aleksandrov | 7a53e71 | 2020-01-24 13:40:20 +0200 | [diff] [blame] | 1711 | /* br_vlan_options.c */ |
| 1712 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
Nikolay Aleksandrov | 99f7c5e | 2020-03-17 14:08:33 +0200 | [diff] [blame] | 1713 | bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr, |
| 1714 | const struct net_bridge_vlan *range_end); |
Nikolay Aleksandrov | 7a53e71 | 2020-01-24 13:40:20 +0200 | [diff] [blame] | 1715 | bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v); |
| 1716 | size_t br_vlan_opts_nl_size(void); |
Nikolay Aleksandrov | a5d29ae | 2020-01-24 13:40:21 +0200 | [diff] [blame] | 1717 | int br_vlan_process_options(const struct net_bridge *br, |
| 1718 | const struct net_bridge_port *p, |
| 1719 | struct net_bridge_vlan *range_start, |
| 1720 | struct net_bridge_vlan *range_end, |
| 1721 | struct nlattr **tb, |
| 1722 | struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | 47ecd2d | 2021-07-19 20:06:34 +0300 | [diff] [blame] | 1723 | int br_vlan_rtm_process_global_options(struct net_device *dev, |
| 1724 | const struct nlattr *attr, |
| 1725 | int cmd, |
| 1726 | struct netlink_ext_ack *extack); |
Nikolay Aleksandrov | 743a53d | 2021-07-19 20:06:35 +0300 | [diff] [blame] | 1727 | bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, |
| 1728 | const struct net_bridge_vlan *r_end); |
| 1729 | bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range, |
| 1730 | const struct net_bridge_vlan *v_opts); |
Nikolay Aleksandrov | a580c76 | 2020-01-24 13:40:22 +0200 | [diff] [blame] | 1731 | |
| 1732 | /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */ |
| 1733 | static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) |
| 1734 | { |
| 1735 | return READ_ONCE(v->state); |
| 1736 | } |
| 1737 | |
| 1738 | static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) |
| 1739 | { |
| 1740 | WRITE_ONCE(v->state, state); |
| 1741 | } |
| 1742 | |
| 1743 | static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) |
| 1744 | { |
| 1745 | return READ_ONCE(vg->pvid_state); |
| 1746 | } |
| 1747 | |
| 1748 | static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, |
| 1749 | u8 state) |
| 1750 | { |
| 1751 | WRITE_ONCE(vg->pvid_state, state); |
| 1752 | } |
| 1753 | |
| 1754 | /* learn_allow is true at ingress and false at egress */ |
| 1755 | static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) |
| 1756 | { |
| 1757 | switch (state) { |
| 1758 | case BR_STATE_LEARNING: |
| 1759 | return learn_allow; |
| 1760 | case BR_STATE_FORWARDING: |
| 1761 | return true; |
| 1762 | default: |
| 1763 | return false; |
| 1764 | } |
| 1765 | } |
Nikolay Aleksandrov | 7a53e71 | 2020-01-24 13:40:20 +0200 | [diff] [blame] | 1766 | #endif |
| 1767 | |
Pablo Neira Ayuso | 1a4ba64 | 2015-03-10 10:27:18 +0100 | [diff] [blame] | 1768 | struct nf_br_ops { |
| 1769 | int (*br_dev_xmit_hook)(struct sk_buff *skb); |
| 1770 | }; |
| 1771 | extern const struct nf_br_ops __rcu *nf_br_ops; |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | /* br_netfilter.c */ |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1774 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 1775 | int br_nf_core_init(void); |
| 1776 | void br_nf_core_fini(void); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1777 | void br_netfilter_rtable_init(struct net_bridge *); |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 1778 | #else |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1779 | static inline int br_nf_core_init(void) { return 0; } |
| 1780 | static inline void br_nf_core_fini(void) {} |
Simon Wunderlich | 4adf0af | 2008-07-30 16:27:55 -0700 | [diff] [blame] | 1781 | #define br_netfilter_rtable_init(x) |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 1782 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | |
| 1784 | /* br_stp.c */ |
Florian Fainelli | 775dd69 | 2014-09-30 16:13:19 -0700 | [diff] [blame] | 1785 | void br_set_state(struct net_bridge_port *p, unsigned int state); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1786 | struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no); |
| 1787 | void br_init_port(struct net_bridge_port *p); |
| 1788 | void br_become_designated_port(struct net_bridge_port *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1790 | void __br_set_forward_delay(struct net_bridge *br, unsigned long t); |
| 1791 | int br_set_forward_delay(struct net_bridge *br, unsigned long x); |
| 1792 | int br_set_hello_time(struct net_bridge *br, unsigned long x); |
| 1793 | int br_set_max_age(struct net_bridge *br, unsigned long x); |
Vivien Didelot | 82dd433 | 2016-12-10 13:44:27 -0500 | [diff] [blame] | 1794 | int __set_ageing_time(struct net_device *dev, unsigned long t); |
Vivien Didelot | 9e0b27f | 2016-07-21 12:42:19 -0400 | [diff] [blame] | 1795 | int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time); |
stephen hemminger | 14f98f2 | 2011-04-04 14:03:33 +0000 | [diff] [blame] | 1796 | |
| 1797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | /* br_stp_if.c */ |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1799 | void br_stp_enable_bridge(struct net_bridge *br); |
| 1800 | void br_stp_disable_bridge(struct net_bridge *br); |
Horatiu Vultur | 419dba8a | 2020-04-26 15:22:08 +0200 | [diff] [blame] | 1801 | int br_stp_set_enabled(struct net_bridge *br, unsigned long val, |
| 1802 | struct netlink_ext_ack *extack); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1803 | void br_stp_enable_port(struct net_bridge_port *p); |
| 1804 | void br_stp_disable_port(struct net_bridge_port *p); |
| 1805 | bool br_stp_recalculate_bridge_id(struct net_bridge *br); |
| 1806 | void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a); |
| 1807 | void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio); |
| 1808 | int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio); |
| 1809 | int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost); |
| 1810 | ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
| 1812 | /* br_stp_bpdu.c */ |
Patrick McHardy | 7c85fbf | 2008-07-05 21:25:56 -0700 | [diff] [blame] | 1813 | struct stp_proto; |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1814 | void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, |
| 1815 | struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | |
| 1817 | /* br_stp_timer.c */ |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1818 | void br_stp_timer_init(struct net_bridge *br); |
| 1819 | void br_stp_port_timer_init(struct net_bridge_port *p); |
| 1820 | unsigned long br_timer_value(const struct timer_list *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | |
| 1822 | /* br.c */ |
Igor Maravić | e6373c4 | 2011-12-12 02:58:25 +0000 | [diff] [blame] | 1823 | #if IS_ENABLED(CONFIG_ATM_LANE) |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 1824 | extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); |
| 1825 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 1827 | /* br_mrp.c */ |
| 1828 | #if IS_ENABLED(CONFIG_BRIDGE_MRP) |
| 1829 | int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, |
| 1830 | struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 1831 | bool br_mrp_enabled(struct net_bridge *br); |
| 1832 | void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p); |
Horatiu Vultur | df42ef22 | 2020-07-02 10:13:06 +0200 | [diff] [blame] | 1833 | int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br); |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 1834 | #else |
| 1835 | static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, |
| 1836 | struct nlattr *attr, int cmd, |
| 1837 | struct netlink_ext_ack *extack) |
| 1838 | { |
| 1839 | return -EOPNOTSUPP; |
| 1840 | } |
| 1841 | |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 1842 | static inline bool br_mrp_enabled(struct net_bridge *br) |
| 1843 | { |
Jason Yan | 8741e18 | 2020-05-06 14:16:16 +0800 | [diff] [blame] | 1844 | return false; |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | static inline void br_mrp_port_del(struct net_bridge *br, |
| 1848 | struct net_bridge_port *p) |
| 1849 | { |
| 1850 | } |
Horatiu Vultur | df42ef22 | 2020-07-02 10:13:06 +0200 | [diff] [blame] | 1851 | |
| 1852 | static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br) |
| 1853 | { |
| 1854 | return 0; |
| 1855 | } |
| 1856 | |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 1857 | #endif |
| 1858 | |
Henrik Bjoernlund | 2be665c | 2020-10-27 10:02:48 +0000 | [diff] [blame] | 1859 | /* br_cfm.c */ |
Henrik Bjoernlund | 86a14b7 | 2020-10-27 10:02:45 +0000 | [diff] [blame] | 1860 | #if IS_ENABLED(CONFIG_BRIDGE_CFM) |
Henrik Bjoernlund | 2be665c | 2020-10-27 10:02:48 +0000 | [diff] [blame] | 1861 | int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, |
| 1862 | struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); |
| 1863 | bool br_cfm_created(struct net_bridge *br); |
Henrik Bjoernlund | 86a14b7 | 2020-10-27 10:02:45 +0000 | [diff] [blame] | 1864 | void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p); |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 1865 | int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br); |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 1866 | int br_cfm_status_fill_info(struct sk_buff *skb, |
| 1867 | struct net_bridge *br, |
| 1868 | bool getlink); |
| 1869 | int br_cfm_mep_count(struct net_bridge *br, u32 *count); |
| 1870 | int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count); |
Henrik Bjoernlund | 86a14b7 | 2020-10-27 10:02:45 +0000 | [diff] [blame] | 1871 | #else |
Henrik Bjoernlund | 2be665c | 2020-10-27 10:02:48 +0000 | [diff] [blame] | 1872 | static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, |
| 1873 | struct nlattr *attr, int cmd, |
| 1874 | struct netlink_ext_ack *extack) |
| 1875 | { |
| 1876 | return -EOPNOTSUPP; |
| 1877 | } |
| 1878 | |
| 1879 | static inline bool br_cfm_created(struct net_bridge *br) |
| 1880 | { |
| 1881 | return false; |
| 1882 | } |
| 1883 | |
Henrik Bjoernlund | 86a14b7 | 2020-10-27 10:02:45 +0000 | [diff] [blame] | 1884 | static inline void br_cfm_port_del(struct net_bridge *br, |
| 1885 | struct net_bridge_port *p) |
| 1886 | { |
| 1887 | } |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 1888 | |
| 1889 | static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br) |
| 1890 | { |
| 1891 | return -EOPNOTSUPP; |
| 1892 | } |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 1893 | |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 1894 | static inline int br_cfm_status_fill_info(struct sk_buff *skb, |
| 1895 | struct net_bridge *br, |
| 1896 | bool getlink) |
| 1897 | { |
| 1898 | return -EOPNOTSUPP; |
| 1899 | } |
| 1900 | |
| 1901 | static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count) |
| 1902 | { |
Ivan Vecera | 829e050 | 2021-10-28 17:58:35 +0200 | [diff] [blame] | 1903 | *count = 0; |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 1904 | return -EOPNOTSUPP; |
| 1905 | } |
| 1906 | |
| 1907 | static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count) |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 1908 | { |
Ivan Vecera | 829e050 | 2021-10-28 17:58:35 +0200 | [diff] [blame] | 1909 | *count = 0; |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 1910 | return -EOPNOTSUPP; |
| 1911 | } |
Henrik Bjoernlund | 86a14b7 | 2020-10-27 10:02:45 +0000 | [diff] [blame] | 1912 | #endif |
| 1913 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1914 | /* br_netlink.c */ |
stephen hemminger | 149ddd8 | 2012-06-26 05:48:45 +0000 | [diff] [blame] | 1915 | extern struct rtnl_link_ops br_link_ops; |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1916 | int br_netlink_init(void); |
| 1917 | void br_netlink_fini(void); |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 1918 | void br_ifinfo_notify(int event, const struct net_bridge *br, |
| 1919 | const struct net_bridge_port *port); |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 1920 | void br_info_notify(int event, const struct net_bridge *br, |
| 1921 | const struct net_bridge_port *port, u32 filter); |
Petr Machata | 2fd527b | 2018-12-12 17:02:48 +0000 | [diff] [blame] | 1922 | int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags, |
| 1923 | struct netlink_ext_ack *extack); |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 1924 | int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1925 | int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 1926 | u32 filter_mask, int nlflags); |
Nikolay Aleksandrov | f26b296 | 2020-01-14 19:56:10 +0200 | [diff] [blame] | 1927 | int br_process_vlan_info(struct net_bridge *br, |
| 1928 | struct net_bridge_port *p, int cmd, |
| 1929 | struct bridge_vlan_info *vinfo_curr, |
| 1930 | struct bridge_vlan_info **vinfo_last, |
| 1931 | bool *changed, |
| 1932 | struct netlink_ext_ack *extack); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | #ifdef CONFIG_SYSFS |
| 1935 | /* br_sysfs_if.c */ |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 1936 | extern const struct sysfs_ops brport_sysfs_ops; |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1937 | int br_sysfs_addif(struct net_bridge_port *p); |
| 1938 | int br_sysfs_renameif(struct net_bridge_port *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | |
| 1940 | /* br_sysfs_br.c */ |
Joe Perches | 348662a | 2013-10-18 13:48:22 -0700 | [diff] [blame] | 1941 | int br_sysfs_addbr(struct net_device *dev); |
| 1942 | void br_sysfs_delbr(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
| 1944 | #else |
| 1945 | |
Lee Jones | 0cb2bbb | 2012-11-03 23:02:30 +0100 | [diff] [blame] | 1946 | static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; } |
| 1947 | static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; } |
| 1948 | static inline int br_sysfs_addbr(struct net_device *dev) { return 0; } |
| 1949 | static inline void br_sysfs_delbr(struct net_device *dev) { return; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | #endif /* CONFIG_SYSFS */ |
| 1951 | |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 1952 | /* br_switchdev.c */ |
| 1953 | #ifdef CONFIG_NET_SWITCHDEV |
Vladimir Oltean | 957e223 | 2021-08-03 23:34:08 +0300 | [diff] [blame] | 1954 | int br_switchdev_port_offload(struct net_bridge_port *p, |
| 1955 | struct net_device *dev, const void *ctx, |
| 1956 | struct notifier_block *atomic_nb, |
| 1957 | struct notifier_block *blocking_nb, |
| 1958 | bool tx_fwd_offload, |
| 1959 | struct netlink_ext_ack *extack); |
| 1960 | |
| 1961 | void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, |
| 1962 | struct notifier_block *atomic_nb, |
| 1963 | struct notifier_block *blocking_nb); |
| 1964 | |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 1965 | bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb); |
| 1966 | |
Vladimir Oltean | c538115 | 2021-07-23 23:49:11 +0300 | [diff] [blame] | 1967 | void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb); |
| 1968 | |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 1969 | void nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, |
| 1970 | struct sk_buff *skb); |
| 1971 | void nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, |
| 1972 | struct sk_buff *skb); |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 1973 | void nbp_switchdev_frame_mark(const struct net_bridge_port *p, |
| 1974 | struct sk_buff *skb); |
| 1975 | bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, |
| 1976 | const struct sk_buff *skb); |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 1977 | int br_switchdev_set_port_flag(struct net_bridge_port *p, |
| 1978 | unsigned long flags, |
Vladimir Oltean | 078bbb8 | 2021-02-12 17:15:53 +0200 | [diff] [blame] | 1979 | unsigned long mask, |
| 1980 | struct netlink_ext_ack *extack); |
Tobias Waldekranz | 6eb38bf | 2021-06-29 17:06:45 +0300 | [diff] [blame] | 1981 | void br_switchdev_fdb_notify(struct net_bridge *br, |
| 1982 | const struct net_bridge_fdb_entry *fdb, int type); |
Vladimir Oltean | ae03935 | 2021-10-30 01:36:06 +0300 | [diff] [blame] | 1983 | void br_switchdev_mdb_notify(struct net_device *dev, |
| 1984 | struct net_bridge_mdb_entry *mp, |
| 1985 | struct net_bridge_port_group *pg, |
| 1986 | int type); |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1987 | int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, |
| 1988 | struct netlink_ext_ack *extack); |
Petr Machata | d66e434 | 2018-05-30 02:56:03 +0200 | [diff] [blame] | 1989 | int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); |
Tobias Waldekranz | 8582661 | 2021-07-21 19:24:00 +0300 | [diff] [blame] | 1990 | void br_switchdev_init(struct net_bridge *br); |
Ido Schimmel | f1c2edd | 2017-09-03 17:44:13 +0300 | [diff] [blame] | 1991 | |
| 1992 | static inline void br_switchdev_frame_unmark(struct sk_buff *skb) |
| 1993 | { |
| 1994 | skb->offload_fwd_mark = 0; |
| 1995 | } |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 1996 | #else |
Vladimir Oltean | 957e223 | 2021-08-03 23:34:08 +0300 | [diff] [blame] | 1997 | static inline int |
| 1998 | br_switchdev_port_offload(struct net_bridge_port *p, |
| 1999 | struct net_device *dev, const void *ctx, |
| 2000 | struct notifier_block *atomic_nb, |
| 2001 | struct notifier_block *blocking_nb, |
| 2002 | bool tx_fwd_offload, |
| 2003 | struct netlink_ext_ack *extack) |
| 2004 | { |
| 2005 | return -EOPNOTSUPP; |
| 2006 | } |
| 2007 | |
| 2008 | static inline void |
| 2009 | br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, |
| 2010 | struct notifier_block *atomic_nb, |
| 2011 | struct notifier_block *blocking_nb) |
| 2012 | { |
| 2013 | } |
| 2014 | |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 2015 | static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb) |
| 2016 | { |
| 2017 | return false; |
| 2018 | } |
| 2019 | |
Vladimir Oltean | c538115 | 2021-07-23 23:49:11 +0300 | [diff] [blame] | 2020 | static inline void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb) |
| 2021 | { |
| 2022 | } |
| 2023 | |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 2024 | static inline void |
| 2025 | nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, |
| 2026 | struct sk_buff *skb) |
| 2027 | { |
| 2028 | } |
| 2029 | |
| 2030 | static inline void |
| 2031 | nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, |
| 2032 | struct sk_buff *skb) |
| 2033 | { |
| 2034 | } |
| 2035 | |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 2036 | static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, |
| 2037 | struct sk_buff *skb) |
| 2038 | { |
| 2039 | } |
| 2040 | |
| 2041 | static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, |
| 2042 | const struct sk_buff *skb) |
| 2043 | { |
| 2044 | return true; |
| 2045 | } |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 2046 | |
| 2047 | static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, |
| 2048 | unsigned long flags, |
Vladimir Oltean | 078bbb8 | 2021-02-12 17:15:53 +0200 | [diff] [blame] | 2049 | unsigned long mask, |
| 2050 | struct netlink_ext_ack *extack) |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 2051 | { |
| 2052 | return 0; |
| 2053 | } |
Arkadi Sharshevsky | 6b26b51 | 2017-06-08 08:44:14 +0200 | [diff] [blame] | 2054 | |
Petr Machata | d66e434 | 2018-05-30 02:56:03 +0200 | [diff] [blame] | 2055 | static inline int br_switchdev_port_vlan_add(struct net_device *dev, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 2056 | u16 vid, u16 flags, |
| 2057 | struct netlink_ext_ack *extack) |
Petr Machata | d66e434 | 2018-05-30 02:56:03 +0200 | [diff] [blame] | 2058 | { |
| 2059 | return -EOPNOTSUPP; |
| 2060 | } |
| 2061 | |
| 2062 | static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) |
| 2063 | { |
| 2064 | return -EOPNOTSUPP; |
| 2065 | } |
| 2066 | |
Arkadi Sharshevsky | 6b26b51 | 2017-06-08 08:44:14 +0200 | [diff] [blame] | 2067 | static inline void |
Tobias Waldekranz | 6eb38bf | 2021-06-29 17:06:45 +0300 | [diff] [blame] | 2068 | br_switchdev_fdb_notify(struct net_bridge *br, |
| 2069 | const struct net_bridge_fdb_entry *fdb, int type) |
Arkadi Sharshevsky | 6b26b51 | 2017-06-08 08:44:14 +0200 | [diff] [blame] | 2070 | { |
| 2071 | } |
Ido Schimmel | f1c2edd | 2017-09-03 17:44:13 +0300 | [diff] [blame] | 2072 | |
Vladimir Oltean | ae03935 | 2021-10-30 01:36:06 +0300 | [diff] [blame] | 2073 | static inline void br_switchdev_mdb_notify(struct net_device *dev, |
| 2074 | struct net_bridge_mdb_entry *mp, |
| 2075 | struct net_bridge_port_group *pg, |
| 2076 | int type) |
| 2077 | { |
| 2078 | } |
| 2079 | |
Ido Schimmel | f1c2edd | 2017-09-03 17:44:13 +0300 | [diff] [blame] | 2080 | static inline void br_switchdev_frame_unmark(struct sk_buff *skb) |
| 2081 | { |
| 2082 | } |
Tobias Waldekranz | 8582661 | 2021-07-21 19:24:00 +0300 | [diff] [blame] | 2083 | |
Tobias Waldekranz | 8582661 | 2021-07-21 19:24:00 +0300 | [diff] [blame] | 2084 | static inline void br_switchdev_init(struct net_bridge *br) |
| 2085 | { |
| 2086 | } |
| 2087 | |
Ido Schimmel | 6bc506b | 2016-08-25 18:42:37 +0200 | [diff] [blame] | 2088 | #endif /* CONFIG_NET_SWITCHDEV */ |
| 2089 | |
Roopa Prabhu | 057658c | 2017-10-06 22:12:38 -0700 | [diff] [blame] | 2090 | /* br_arp_nd_proxy.c */ |
Roopa Prabhu | 821f1b2 | 2017-10-06 22:12:37 -0700 | [diff] [blame] | 2091 | void br_recalculate_neigh_suppress_enabled(struct net_bridge *br); |
Roopa Prabhu | 057658c | 2017-10-06 22:12:38 -0700 | [diff] [blame] | 2092 | void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, |
| 2093 | u16 vid, struct net_bridge_port *p); |
Roopa Prabhu | ed842fa | 2017-10-06 22:12:39 -0700 | [diff] [blame] | 2094 | void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, |
| 2095 | u16 vid, struct net_bridge_port *p, struct nd_msg *msg); |
| 2096 | struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | #endif |