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 | * Forwarding decision |
| 4 | * Linux ethernet bridge |
| 5 | * |
| 6 | * Authors: |
| 7 | * Lennert Buytenhek <buytenh@gnu.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 10 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/netdevice.h> |
WANG Cong | c06ee96 | 2010-05-06 00:48:24 -0700 | [diff] [blame] | 14 | #include <linux/netpoll.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/skbuff.h> |
Stephen Hemminger | 85ca719 | 2006-04-26 02:39:19 -0700 | [diff] [blame] | 16 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/netfilter_bridge.h> |
| 18 | #include "br_private.h" |
| 19 | |
tanxiaojun | 1a81a2e | 2013-12-16 21:32:46 +0800 | [diff] [blame] | 20 | /* Don't forward packets to originating port or forwarding disabled */ |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 21 | static inline int should_deliver(const struct net_bridge_port *p, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | const struct sk_buff *skb) |
| 23 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 24 | struct net_bridge_vlan_group *vg; |
| 25 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 26 | vg = nbp_vlan_group_rcu(p); |
tanxiaojun | a97bfc1 | 2013-12-19 13:28:11 +0800 | [diff] [blame] | 27 | return ((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) && |
Nikolay Aleksandrov | ac0e932 | 2020-01-24 13:40:19 +0200 | [diff] [blame] | 28 | p->state == BR_STATE_FORWARDING && br_allowed_egress(vg, skb) && |
Nikolay Aleksandrov | 7d850ab | 2018-05-24 11:56:48 +0300 | [diff] [blame] | 29 | nbp_switchdev_allowed_egress(p, skb) && |
| 30 | !br_skb_isolated(p, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Eric W. Biederman | 0c4b51f | 2015-09-15 20:04:18 -0500 | [diff] [blame] | 33 | int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Yunjian Wang | 28c1382 | 2019-01-17 09:46:41 +0800 | [diff] [blame] | 35 | skb_push(skb, ETH_HLEN); |
Toshiaki Makita | df356d5 | 2015-07-28 19:05:37 +0900 | [diff] [blame] | 36 | if (!is_skb_forwardable(skb->dev, skb)) |
| 37 | goto drop; |
| 38 | |
Toshiaki Makita | df356d5 | 2015-07-28 19:05:37 +0900 | [diff] [blame] | 39 | br_drop_fake_rtable(skb); |
Toshiaki Makita | df356d5 | 2015-07-28 19:05:37 +0900 | [diff] [blame] | 40 | |
| 41 | if (skb->ip_summed == CHECKSUM_PARTIAL && |
Menglong Dong | a98c0c4 | 2021-01-17 16:09:50 +0800 | [diff] [blame] | 42 | eth_type_vlan(skb->protocol)) { |
Toshiaki Makita | df356d5 | 2015-07-28 19:05:37 +0900 | [diff] [blame] | 43 | int depth; |
| 44 | |
| 45 | if (!__vlan_get_protocol(skb, skb->protocol, &depth)) |
| 46 | goto drop; |
| 47 | |
| 48 | skb_set_network_header(skb, depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Vladimir Oltean | c538115 | 2021-07-23 23:49:11 +0300 | [diff] [blame] | 51 | br_switchdev_frame_set_offload_fwd_mark(skb); |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 52 | |
Toshiaki Makita | df356d5 | 2015-07-28 19:05:37 +0900 | [diff] [blame] | 53 | dev_queue_xmit(skb); |
| 54 | |
| 55 | return 0; |
| 56 | |
| 57 | drop: |
| 58 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | return 0; |
| 60 | } |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 61 | EXPORT_SYMBOL_GPL(br_dev_queue_push_xmit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Eric W. Biederman | 0c4b51f | 2015-09-15 20:04:18 -0500 | [diff] [blame] | 63 | int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Paolo Abeni | 41d1c88 | 2019-01-08 18:45:05 +0100 | [diff] [blame] | 65 | skb->tstamp = 0; |
Eric W. Biederman | 29a26a5 | 2015-09-15 20:04:16 -0500 | [diff] [blame] | 66 | return NF_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, |
| 67 | net, sk, skb, NULL, skb->dev, |
Stephen Hemminger | 9ef513b | 2006-05-25 15:58:54 -0700 | [diff] [blame] | 68 | br_dev_queue_push_xmit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 71 | EXPORT_SYMBOL_GPL(br_forward_finish); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 73 | static void __br_forward(const struct net_bridge_port *to, |
| 74 | struct sk_buff *skb, bool local_orig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 76 | struct net_bridge_vlan_group *vg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | struct net_device *indev; |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 78 | struct net *net; |
| 79 | int br_hook; |
Herbert Xu | 4906f99 | 2009-02-09 15:07:18 -0800 | [diff] [blame] | 80 | |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 81 | /* Mark the skb for forwarding offload early so that br_handle_vlan() |
| 82 | * can know whether to pop the VLAN header on egress or keep it. |
| 83 | */ |
| 84 | nbp_switchdev_frame_mark_tx_fwd_offload(to, skb); |
| 85 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 86 | vg = nbp_vlan_group_rcu(to); |
Roopa Prabhu | 11538d0 | 2017-01-31 22:59:55 -0800 | [diff] [blame] | 87 | skb = br_handle_vlan(to->br, to, vg, skb); |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 88 | if (!skb) |
| 89 | return; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | indev = skb->dev; |
| 92 | skb->dev = to->dev; |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 93 | if (!local_orig) { |
| 94 | if (skb_warn_if_lro(skb)) { |
| 95 | kfree_skb(skb); |
| 96 | return; |
| 97 | } |
| 98 | br_hook = NF_BR_FORWARD; |
| 99 | skb_forward_csum(skb); |
| 100 | net = dev_net(indev); |
| 101 | } else { |
| 102 | if (unlikely(netpoll_tx_running(to->br->dev))) { |
Yunjian Wang | 28c1382 | 2019-01-17 09:46:41 +0800 | [diff] [blame] | 103 | skb_push(skb, ETH_HLEN); |
| 104 | if (!is_skb_forwardable(skb->dev, skb)) |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 105 | kfree_skb(skb); |
Yunjian Wang | 28c1382 | 2019-01-17 09:46:41 +0800 | [diff] [blame] | 106 | else |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 107 | br_netpoll_send_skb(to, skb); |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | br_hook = NF_BR_LOCAL_OUT; |
| 111 | net = dev_net(skb->dev); |
| 112 | indev = NULL; |
| 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 115 | NF_HOOK(NFPROTO_BRIDGE, br_hook, |
| 116 | net, NULL, skb, indev, skb->dev, |
Jan Engelhardt | 713aefa | 2010-03-23 04:07:21 +0100 | [diff] [blame] | 117 | br_forward_finish); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
David S. Miller | 87faf3c | 2010-03-16 14:37:47 -0700 | [diff] [blame] | 120 | static int deliver_clone(const struct net_bridge_port *prev, |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 121 | struct sk_buff *skb, bool local_orig) |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 122 | { |
Herbert Xu | fed396a | 2010-06-15 21:43:07 -0700 | [diff] [blame] | 123 | struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev; |
| 124 | |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 125 | skb = skb_clone(skb, GFP_ATOMIC); |
| 126 | if (!skb) { |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 127 | dev->stats.tx_dropped++; |
| 128 | return -ENOMEM; |
| 129 | } |
| 130 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 131 | __br_forward(prev, skb, local_orig); |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 135 | /** |
| 136 | * br_forward - forward a packet to a specific port |
| 137 | * @to: destination port |
| 138 | * @skb: packet being forwarded |
| 139 | * @local_rcv: packet will be received locally after forwarding |
| 140 | * @local_orig: packet is locally originated |
| 141 | * |
| 142 | * Should be called with rcu_read_lock. |
| 143 | */ |
| 144 | void br_forward(const struct net_bridge_port *to, |
| 145 | struct sk_buff *skb, bool local_rcv, bool local_orig) |
| 146 | { |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 147 | if (unlikely(!to)) |
| 148 | goto out; |
| 149 | |
| 150 | /* redirect to backup link if the destination port is down */ |
| 151 | if (rcu_access_pointer(to->backup_port) && !netif_carrier_ok(to->dev)) { |
| 152 | struct net_bridge_port *backup_port; |
| 153 | |
| 154 | backup_port = rcu_dereference(to->backup_port); |
| 155 | if (unlikely(!backup_port)) |
| 156 | goto out; |
| 157 | to = backup_port; |
| 158 | } |
| 159 | |
| 160 | if (should_deliver(to, skb)) { |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 161 | if (local_rcv) |
| 162 | deliver_clone(to, skb, local_orig); |
| 163 | else |
| 164 | __br_forward(to, skb, local_orig); |
| 165 | return; |
| 166 | } |
| 167 | |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 168 | out: |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 169 | if (!local_rcv) |
| 170 | kfree_skb(skb); |
| 171 | } |
| 172 | EXPORT_SYMBOL_GPL(br_forward); |
| 173 | |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 174 | static struct net_bridge_port *maybe_deliver( |
| 175 | struct net_bridge_port *prev, struct net_bridge_port *p, |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 176 | struct sk_buff *skb, bool local_orig) |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 177 | { |
Pablo Neira Ayuso | 847d44e | 2019-04-04 13:56:38 +0200 | [diff] [blame] | 178 | u8 igmp_type = br_multicast_igmp_type(skb); |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 179 | int err; |
| 180 | |
| 181 | if (!should_deliver(p, skb)) |
| 182 | return prev; |
| 183 | |
Tobias Waldekranz | 4721119 | 2021-07-22 18:55:38 +0300 | [diff] [blame] | 184 | nbp_switchdev_frame_mark_tx_fwd_to_hwdom(p, skb); |
| 185 | |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 186 | if (!prev) |
| 187 | goto out; |
| 188 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 189 | err = deliver_clone(prev, skb, local_orig); |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 190 | if (err) |
| 191 | return ERR_PTR(err); |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 192 | out: |
Pablo Neira Ayuso | 847d44e | 2019-04-04 13:56:38 +0200 | [diff] [blame] | 193 | br_multicast_count(p->br, p, skb, igmp_type, BR_MCAST_DIR_TX); |
| 194 | |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 195 | return p; |
| 196 | } |
| 197 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 198 | /* called under rcu_read_lock */ |
| 199 | void br_flood(struct net_bridge *br, struct sk_buff *skb, |
Nikolay Aleksandrov | 8addd5e | 2016-08-31 15:36:51 +0200 | [diff] [blame] | 200 | enum br_pkt_type pkt_type, bool local_rcv, bool local_orig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 202 | struct net_bridge_port *prev = NULL; |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 203 | struct net_bridge_port *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | list_for_each_entry_rcu(p, &br->port_list, list) { |
Mike Manning | 99f906e | 2017-04-26 14:48:09 +0100 | [diff] [blame] | 206 | /* Do not flood unicast traffic to ports that turn it off, nor |
| 207 | * other traffic if flood off, except for traffic we originate |
| 208 | */ |
| 209 | switch (pkt_type) { |
| 210 | case BR_PKT_UNICAST: |
| 211 | if (!(p->flags & BR_FLOOD)) |
| 212 | continue; |
| 213 | break; |
| 214 | case BR_PKT_MULTICAST: |
| 215 | if (!(p->flags & BR_MCAST_FLOOD) && skb->dev != br->dev) |
| 216 | continue; |
| 217 | break; |
| 218 | case BR_PKT_BROADCAST: |
| 219 | if (!(p->flags & BR_BCAST_FLOOD) && skb->dev != br->dev) |
| 220 | continue; |
| 221 | break; |
| 222 | } |
Kyeyoon Park | 9585011 | 2014-10-23 14:49:17 -0700 | [diff] [blame] | 223 | |
| 224 | /* Do not flood to ports that enable proxy ARP */ |
| 225 | if (p->flags & BR_PROXYARP) |
| 226 | continue; |
Roopa Prabhu | 821f1b2 | 2017-10-06 22:12:37 -0700 | [diff] [blame] | 227 | if ((p->flags & (BR_PROXYARP_WIFI | BR_NEIGH_SUPPRESS)) && |
Jouni Malinen | 842a9ae | 2015-03-04 12:54:21 +0200 | [diff] [blame] | 228 | BR_INPUT_SKB_CB(skb)->proxyarp_replied) |
| 229 | continue; |
Kyeyoon Park | 9585011 | 2014-10-23 14:49:17 -0700 | [diff] [blame] | 230 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 231 | prev = maybe_deliver(prev, p, skb, local_orig); |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 232 | if (IS_ERR(prev)) |
| 233 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Herbert Xu | b33084b | 2010-02-27 19:41:41 +0000 | [diff] [blame] | 236 | if (!prev) |
| 237 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Nikolay Aleksandrov | b35c5f6 | 2016-07-14 06:10:01 +0300 | [diff] [blame] | 239 | if (local_rcv) |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 240 | deliver_clone(prev, skb, local_orig); |
Herbert Xu | 025d89c | 2010-02-27 19:41:43 +0000 | [diff] [blame] | 241 | else |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 242 | __br_forward(prev, skb, local_orig); |
Herbert Xu | b33084b | 2010-02-27 19:41:41 +0000 | [diff] [blame] | 243 | return; |
| 244 | |
| 245 | out: |
Nikolay Aleksandrov | b35c5f6 | 2016-07-14 06:10:01 +0300 | [diff] [blame] | 246 | if (!local_rcv) |
Herbert Xu | b33084b | 2010-02-27 19:41:41 +0000 | [diff] [blame] | 247 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 250 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
Arnd Bergmann | 5b9d6b1 | 2017-01-25 23:29:33 +0100 | [diff] [blame] | 251 | static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb, |
| 252 | const unsigned char *addr, bool local_orig) |
| 253 | { |
| 254 | struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev; |
| 255 | const unsigned char *src = eth_hdr(skb)->h_source; |
| 256 | |
| 257 | if (!should_deliver(p, skb)) |
| 258 | return; |
| 259 | |
| 260 | /* Even with hairpin, no soliloquies - prevent breaking IPv6 DAD */ |
| 261 | if (skb->dev == p->dev && ether_addr_equal(src, addr)) |
| 262 | return; |
| 263 | |
| 264 | skb = skb_copy(skb, GFP_ATOMIC); |
| 265 | if (!skb) { |
| 266 | dev->stats.tx_dropped++; |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | if (!is_broadcast_ether_addr(addr)) |
| 271 | memcpy(eth_hdr(skb)->h_dest, addr, ETH_ALEN); |
| 272 | |
| 273 | __br_forward(p, skb, local_orig); |
| 274 | } |
| 275 | |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 276 | /* called with rcu_read_lock */ |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 277 | void br_multicast_flood(struct net_bridge_mdb_entry *mdst, |
| 278 | struct sk_buff *skb, |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 279 | struct net_bridge_mcast *brmctx, |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 280 | bool local_rcv, bool local_orig) |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 281 | { |
stephen hemminger | afe0159 | 2010-04-27 15:01:07 +0000 | [diff] [blame] | 282 | struct net_bridge_port *prev = NULL; |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 283 | struct net_bridge_port_group *p; |
Nikolay Aleksandrov | 36cfec7 | 2020-09-22 10:30:27 +0300 | [diff] [blame] | 284 | bool allow_mode_include = true; |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 285 | struct hlist_node *rp; |
| 286 | |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 287 | rp = br_multicast_get_first_rport_node(brmctx, skb); |
Linus Lüssing | 44ebb08 | 2021-05-13 15:20:44 +0200 | [diff] [blame] | 288 | |
Nikolay Aleksandrov | 36cfec7 | 2020-09-22 10:30:27 +0300 | [diff] [blame] | 289 | if (mdst) { |
| 290 | p = rcu_dereference(mdst->ports); |
Nikolay Aleksandrov | adc4703 | 2021-07-19 20:06:25 +0300 | [diff] [blame] | 291 | if (br_multicast_should_handle_mode(brmctx, mdst->addr.proto) && |
Nikolay Aleksandrov | 36cfec7 | 2020-09-22 10:30:27 +0300 | [diff] [blame] | 292 | br_multicast_is_star_g(&mdst->addr)) |
| 293 | allow_mode_include = false; |
| 294 | } else { |
| 295 | p = NULL; |
| 296 | } |
| 297 | |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 298 | while (p || rp) { |
stephen hemminger | afe0159 | 2010-04-27 15:01:07 +0000 | [diff] [blame] | 299 | struct net_bridge_port *port, *lport, *rport; |
| 300 | |
Nikolay Aleksandrov | 085b53c | 2020-09-22 10:30:22 +0300 | [diff] [blame] | 301 | lport = p ? p->key.port : NULL; |
Linus Lüssing | 44ebb08 | 2021-05-13 15:20:44 +0200 | [diff] [blame] | 302 | rport = br_multicast_rport_from_node_skb(rp, skb); |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 303 | |
Felix Fietkau | 6db6f0e | 2017-01-21 21:01:32 +0100 | [diff] [blame] | 304 | if ((unsigned long)lport > (unsigned long)rport) { |
| 305 | port = lport; |
| 306 | |
| 307 | if (port->flags & BR_MULTICAST_TO_UNICAST) { |
| 308 | maybe_deliver_addr(lport, skb, p->eth_addr, |
| 309 | local_orig); |
| 310 | goto delivered; |
| 311 | } |
Nikolay Aleksandrov | 36cfec7 | 2020-09-22 10:30:27 +0300 | [diff] [blame] | 312 | if ((!allow_mode_include && |
| 313 | p->filter_mode == MCAST_INCLUDE) || |
| 314 | (p->flags & MDB_PG_FLAGS_BLOCKED)) |
| 315 | goto delivered; |
Felix Fietkau | 6db6f0e | 2017-01-21 21:01:32 +0100 | [diff] [blame] | 316 | } else { |
| 317 | port = rport; |
| 318 | } |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 319 | |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 320 | prev = maybe_deliver(prev, port, skb, local_orig); |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 321 | if (IS_ERR(prev)) |
| 322 | goto out; |
Pablo Neira Ayuso | 847d44e | 2019-04-04 13:56:38 +0200 | [diff] [blame] | 323 | delivered: |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 324 | if ((unsigned long)lport >= (unsigned long)port) |
stephen hemminger | 83f6a74 | 2010-04-27 15:01:06 +0000 | [diff] [blame] | 325 | p = rcu_dereference(p->next); |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 326 | if ((unsigned long)rport >= (unsigned long)port) |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 327 | rp = rcu_dereference(hlist_next_rcu(rp)); |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | if (!prev) |
| 331 | goto out; |
| 332 | |
Nikolay Aleksandrov | b35c5f6 | 2016-07-14 06:10:01 +0300 | [diff] [blame] | 333 | if (local_rcv) |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 334 | deliver_clone(prev, skb, local_orig); |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 335 | else |
Nikolay Aleksandrov | 37b090e | 2016-07-14 06:10:02 +0300 | [diff] [blame] | 336 | __br_forward(prev, skb, local_orig); |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 337 | return; |
| 338 | |
| 339 | out: |
Nikolay Aleksandrov | b35c5f6 | 2016-07-14 06:10:01 +0300 | [diff] [blame] | 340 | if (!local_rcv) |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 341 | kfree_skb(skb); |
| 342 | } |
Herbert Xu | 5cb5e94 | 2010-02-27 19:41:46 +0000 | [diff] [blame] | 343 | #endif |