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