Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Forwarding database |
| 3 | * Linux ethernet bridge |
| 4 | * |
| 5 | * Authors: |
| 6 | * Lennert Buytenhek <buytenh@gnu.org> |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version |
| 11 | * 2 of the License, or (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
Franck Bui-Huu | 8252474 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 16 | #include <linux/rculist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/times.h> |
| 19 | #include <linux/netdevice.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/jhash.h> |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 22 | #include <linux/random.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 24 | #include <linux/atomic.h> |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 26 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "br_private.h" |
| 28 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 29 | static struct kmem_cache *br_fdb_cache __read_mostly; |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame^] | 30 | static struct net_bridge_fdb_entry *fdb_find(struct hlist_head *head, |
| 31 | const unsigned char *addr, |
| 32 | __u16 vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source, |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 34 | const unsigned char *addr, u16 vid); |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 35 | static void fdb_notify(struct net_bridge *br, |
| 36 | const struct net_bridge_fdb_entry *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 38 | static u32 fdb_salt __read_mostly; |
| 39 | |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 40 | int __init br_fdb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
| 42 | br_fdb_cache = kmem_cache_create("bridge_fdb_cache", |
| 43 | sizeof(struct net_bridge_fdb_entry), |
| 44 | 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 45 | SLAB_HWCACHE_ALIGN, NULL); |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 46 | if (!br_fdb_cache) |
| 47 | return -ENOMEM; |
| 48 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 49 | get_random_bytes(&fdb_salt, sizeof(fdb_salt)); |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 50 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Andrew Morton | 73afc90 | 2007-12-05 21:35:23 -0800 | [diff] [blame] | 53 | void br_fdb_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | kmem_cache_destroy(br_fdb_cache); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /* if topology_changing then use forward_delay (default 15 sec) |
| 60 | * otherwise keep longer (default 5 minutes) |
| 61 | */ |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 62 | static inline unsigned long hold_time(const struct net_bridge *br) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
| 64 | return br->topology_change ? br->forward_delay : br->ageing_time; |
| 65 | } |
| 66 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 67 | static inline int has_expired(const struct net_bridge *br, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | const struct net_bridge_fdb_entry *fdb) |
| 69 | { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 70 | return !fdb->is_static && |
stephen hemminger | 7cd8861 | 2011-04-04 14:03:28 +0000 | [diff] [blame] | 71 | time_before_eq(fdb->updated + hold_time(br), jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 74 | static inline int br_mac_hash(const unsigned char *mac, __u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 76 | /* use 1 byte of OUI and 3 bytes of NIC */ |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 77 | u32 key = get_unaligned((u32 *)(mac + 2)); |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 78 | return jhash_2words(key, vid, fdb_salt) & (BR_HASH_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 81 | static void fdb_rcu_free(struct rcu_head *head) |
| 82 | { |
| 83 | struct net_bridge_fdb_entry *ent |
| 84 | = container_of(head, struct net_bridge_fdb_entry, rcu); |
| 85 | kmem_cache_free(br_fdb_cache, ent); |
| 86 | } |
| 87 | |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 88 | static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | hlist_del_rcu(&f->hlist); |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 91 | fdb_notify(br, f, RTM_DELNEIGH); |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 92 | call_rcu(&f->rcu, fdb_rcu_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Toshiaki Makita | 960b589 | 2014-02-07 16:48:23 +0900 | [diff] [blame] | 95 | /* Delete a local entry if no other port had the same address. */ |
| 96 | static void fdb_delete_local(struct net_bridge *br, |
| 97 | const struct net_bridge_port *p, |
| 98 | struct net_bridge_fdb_entry *f) |
| 99 | { |
| 100 | const unsigned char *addr = f->addr.addr; |
| 101 | u16 vid = f->vlan_id; |
| 102 | struct net_bridge_port *op; |
| 103 | |
| 104 | /* Maybe another port has same hw addr? */ |
| 105 | list_for_each_entry(op, &br->port_list, list) { |
| 106 | if (op != p && ether_addr_equal(op->dev->dev_addr, addr) && |
| 107 | (!vid || nbp_vlan_find(op, vid))) { |
| 108 | f->dst = op; |
Toshiaki Makita | a778e6d | 2014-02-07 16:48:24 +0900 | [diff] [blame] | 109 | f->added_by_user = 0; |
Toshiaki Makita | 960b589 | 2014-02-07 16:48:23 +0900 | [diff] [blame] | 110 | return; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /* Maybe bridge device has same hw addr? */ |
| 115 | if (p && ether_addr_equal(br->dev->dev_addr, addr) && |
| 116 | (!vid || br_vlan_find(br, vid))) { |
| 117 | f->dst = NULL; |
Toshiaki Makita | a778e6d | 2014-02-07 16:48:24 +0900 | [diff] [blame] | 118 | f->added_by_user = 0; |
Toshiaki Makita | 960b589 | 2014-02-07 16:48:23 +0900 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | |
| 122 | fdb_delete(br, f); |
| 123 | } |
| 124 | |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame^] | 125 | void br_fdb_find_delete_local(struct net_bridge *br, |
| 126 | const struct net_bridge_port *p, |
| 127 | const unsigned char *addr, u16 vid) |
| 128 | { |
| 129 | struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; |
| 130 | struct net_bridge_fdb_entry *f; |
| 131 | |
| 132 | spin_lock_bh(&br->hash_lock); |
| 133 | f = fdb_find(head, addr, vid); |
| 134 | if (f && f->is_local && !f->added_by_user && f->dst == p) |
| 135 | fdb_delete_local(br, p, f); |
| 136 | spin_unlock_bh(&br->hash_lock); |
| 137 | } |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr) |
| 140 | { |
| 141 | struct net_bridge *br = p->br; |
Toshiaki Makita | 2836882 | 2014-02-07 16:48:19 +0900 | [diff] [blame] | 142 | struct net_port_vlans *pv = nbp_get_vlan_info(p); |
| 143 | bool no_vlan = !pv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | int i; |
Toshiaki Makita | 2836882 | 2014-02-07 16:48:19 +0900 | [diff] [blame] | 145 | u16 vid; |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | spin_lock_bh(&br->hash_lock); |
| 148 | |
| 149 | /* Search all chains since old address/hash is unknown */ |
| 150 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 151 | struct hlist_node *h; |
| 152 | hlist_for_each(h, &br->hash[i]) { |
| 153 | struct net_bridge_fdb_entry *f; |
| 154 | |
| 155 | f = hlist_entry(h, struct net_bridge_fdb_entry, hlist); |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 156 | if (f->dst == p && f->is_local && !f->added_by_user) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* delete old one */ |
Toshiaki Makita | 960b589 | 2014-02-07 16:48:23 +0900 | [diff] [blame] | 158 | fdb_delete_local(br, p, f); |
| 159 | |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 160 | /* if this port has no vlan information |
| 161 | * configured, we can safely be done at |
| 162 | * this point. |
| 163 | */ |
| 164 | if (no_vlan) |
Toshiaki Makita | 2836882 | 2014-02-07 16:48:19 +0900 | [diff] [blame] | 165 | goto insert; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Toshiaki Makita | 2836882 | 2014-02-07 16:48:19 +0900 | [diff] [blame] | 170 | insert: |
| 171 | /* insert new address, may fail if invalid address or dup. */ |
| 172 | fdb_insert(br, p, newaddr, 0); |
| 173 | |
| 174 | if (no_vlan) |
| 175 | goto done; |
| 176 | |
| 177 | /* Now add entries for every VLAN configured on the port. |
| 178 | * This function runs under RTNL so the bitmap will not change |
| 179 | * from under us. |
| 180 | */ |
| 181 | for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) |
| 182 | fdb_insert(br, p, newaddr, vid); |
| 183 | |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 184 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | spin_unlock_bh(&br->hash_lock); |
| 186 | } |
| 187 | |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 188 | void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr) |
| 189 | { |
| 190 | struct net_bridge_fdb_entry *f; |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 191 | struct net_port_vlans *pv; |
| 192 | u16 vid = 0; |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 193 | |
| 194 | /* If old entry was unassociated with any port, then delete it. */ |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 195 | f = __br_fdb_get(br, br->dev->dev_addr, 0); |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 196 | if (f && f->is_local && !f->dst) |
Toshiaki Makita | 960b589 | 2014-02-07 16:48:23 +0900 | [diff] [blame] | 197 | fdb_delete_local(br, NULL, f); |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 198 | |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 199 | fdb_insert(br, NULL, newaddr, 0); |
| 200 | |
| 201 | /* Now remove and add entries for every VLAN configured on the |
| 202 | * bridge. This function runs under RTNL so the bitmap will not |
| 203 | * change from under us. |
| 204 | */ |
| 205 | pv = br_get_vlan_info(br); |
| 206 | if (!pv) |
| 207 | return; |
| 208 | |
Toshiaki Makita | ef40b7e | 2013-08-20 17:10:18 +0900 | [diff] [blame] | 209 | for_each_set_bit_from(vid, pv->vlan_bitmap, VLAN_N_VID) { |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 210 | f = __br_fdb_get(br, br->dev->dev_addr, vid); |
| 211 | if (f && f->is_local && !f->dst) |
Toshiaki Makita | 960b589 | 2014-02-07 16:48:23 +0900 | [diff] [blame] | 212 | fdb_delete_local(br, NULL, f); |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 213 | fdb_insert(br, NULL, newaddr, vid); |
| 214 | } |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | void br_fdb_cleanup(unsigned long _data) |
| 218 | { |
| 219 | struct net_bridge *br = (struct net_bridge *)_data; |
| 220 | unsigned long delay = hold_time(br); |
stephen hemminger | 25442e0 | 2010-06-15 06:14:12 +0000 | [diff] [blame] | 221 | unsigned long next_timer = jiffies + br->ageing_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | int i; |
| 223 | |
Eric Dumazet | 27a4293 | 2012-01-16 04:35:50 +0000 | [diff] [blame] | 224 | spin_lock(&br->hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 226 | struct net_bridge_fdb_entry *f; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 227 | struct hlist_node *n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 229 | hlist_for_each_entry_safe(f, n, &br->hash[i], hlist) { |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 230 | unsigned long this_timer; |
| 231 | if (f->is_static) |
| 232 | continue; |
stephen hemminger | 7cd8861 | 2011-04-04 14:03:28 +0000 | [diff] [blame] | 233 | this_timer = f->updated + delay; |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 234 | if (time_before_eq(this_timer, jiffies)) |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 235 | fdb_delete(br, f); |
Fabio Checconi | 2bec008 | 2008-03-20 15:54:58 -0700 | [diff] [blame] | 236 | else if (time_before(this_timer, next_timer)) |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 237 | next_timer = this_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
Eric Dumazet | 27a4293 | 2012-01-16 04:35:50 +0000 | [diff] [blame] | 240 | spin_unlock(&br->hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
stephen hemminger | 25442e0 | 2010-06-15 06:14:12 +0000 | [diff] [blame] | 242 | mod_timer(&br->gc_timer, round_jiffies_up(next_timer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 245 | /* Completely flush all dynamic entries in forwarding database.*/ |
| 246 | void br_fdb_flush(struct net_bridge *br) |
| 247 | { |
| 248 | int i; |
Stephen Hemminger | 1a62069 | 2006-10-12 14:45:38 -0700 | [diff] [blame] | 249 | |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 250 | spin_lock_bh(&br->hash_lock); |
| 251 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 252 | struct net_bridge_fdb_entry *f; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 253 | struct hlist_node *n; |
| 254 | hlist_for_each_entry_safe(f, n, &br->hash[i], hlist) { |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 255 | if (!f->is_static) |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 256 | fdb_delete(br, f); |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | spin_unlock_bh(&br->hash_lock); |
| 260 | } |
| 261 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 262 | /* Flush all entries referring to a specific port. |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 263 | * if do_all is set also flush static entries |
| 264 | */ |
Stephen Hemminger | 1a62069 | 2006-10-12 14:45:38 -0700 | [diff] [blame] | 265 | void br_fdb_delete_by_port(struct net_bridge *br, |
| 266 | const struct net_bridge_port *p, |
| 267 | int do_all) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
| 269 | int i; |
| 270 | |
| 271 | spin_lock_bh(&br->hash_lock); |
| 272 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 273 | struct hlist_node *h, *g; |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | hlist_for_each_safe(h, g, &br->hash[i]) { |
| 276 | struct net_bridge_fdb_entry *f |
| 277 | = hlist_entry(h, struct net_bridge_fdb_entry, hlist); |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 278 | if (f->dst != p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | continue; |
| 280 | |
Stephen Hemminger | 1a62069 | 2006-10-12 14:45:38 -0700 | [diff] [blame] | 281 | if (f->is_static && !do_all) |
| 282 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Toshiaki Makita | a778e6d | 2014-02-07 16:48:24 +0900 | [diff] [blame] | 284 | if (f->is_local) |
| 285 | fdb_delete_local(br, p, f); |
| 286 | else |
| 287 | fdb_delete(br, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | spin_unlock_bh(&br->hash_lock); |
| 291 | } |
| 292 | |
stephen hemminger | eeaf61d | 2010-07-27 08:26:30 +0000 | [diff] [blame] | 293 | /* No locking or refcounting, assumes caller has rcu_read_lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br, |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 295 | const unsigned char *addr, |
| 296 | __u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | struct net_bridge_fdb_entry *fdb; |
| 299 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 300 | hlist_for_each_entry_rcu(fdb, |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 301 | &br->hash[br_mac_hash(addr, vid)], hlist) { |
| 302 | if (ether_addr_equal(fdb->addr.addr, addr) && |
| 303 | fdb->vlan_id == vid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | if (unlikely(has_expired(br, fdb))) |
| 305 | break; |
| 306 | return fdb; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | return NULL; |
| 311 | } |
| 312 | |
Igor Maravić | e6373c4 | 2011-12-12 02:58:25 +0000 | [diff] [blame] | 313 | #if IS_ENABLED(CONFIG_ATM_LANE) |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 314 | /* Interface used by ATM LANE hook to test |
| 315 | * if an addr is on some other bridge port */ |
| 316 | int br_fdb_test_addr(struct net_device *dev, unsigned char *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
| 318 | struct net_bridge_fdb_entry *fdb; |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 319 | struct net_bridge_port *port; |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 320 | int ret; |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | rcu_read_lock(); |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 323 | port = br_port_get_rcu(dev); |
| 324 | if (!port) |
| 325 | ret = 0; |
| 326 | else { |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 327 | fdb = __br_fdb_get(port->br, addr, 0); |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 328 | ret = fdb && fdb->dst && fdb->dst->dev != dev && |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 329 | fdb->dst->state == BR_STATE_FORWARDING; |
| 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 333 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 335 | #endif /* CONFIG_ATM_LANE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | /* |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 338 | * Fill buffer with forwarding table records in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | * the API format. |
| 340 | */ |
| 341 | int br_fdb_fillbuf(struct net_bridge *br, void *buf, |
| 342 | unsigned long maxnum, unsigned long skip) |
| 343 | { |
| 344 | struct __fdb_entry *fe = buf; |
| 345 | int i, num = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | struct net_bridge_fdb_entry *f; |
| 347 | |
| 348 | memset(buf, 0, maxnum*sizeof(struct __fdb_entry)); |
| 349 | |
| 350 | rcu_read_lock(); |
| 351 | for (i = 0; i < BR_HASH_SIZE; i++) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 352 | hlist_for_each_entry_rcu(f, &br->hash[i], hlist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (num >= maxnum) |
| 354 | goto out; |
| 355 | |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 356 | if (has_expired(br, f)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | continue; |
| 358 | |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 359 | /* ignore pseudo entry for local MAC address */ |
| 360 | if (!f->dst) |
| 361 | continue; |
| 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (skip) { |
| 364 | --skip; |
| 365 | continue; |
| 366 | } |
| 367 | |
| 368 | /* convert from internal format to API */ |
| 369 | memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN); |
Stephen Hemminger | ae4f8fc | 2008-05-02 16:53:33 -0700 | [diff] [blame] | 370 | |
| 371 | /* due to ABI compat need to split into hi/lo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | fe->port_no = f->dst->port_no; |
Stephen Hemminger | ae4f8fc | 2008-05-02 16:53:33 -0700 | [diff] [blame] | 373 | fe->port_hi = f->dst->port_no >> 8; |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | fe->is_local = f->is_local; |
| 376 | if (!f->is_static) |
Eric Dumazet | a399a80 | 2012-08-08 21:13:53 +0000 | [diff] [blame] | 377 | fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | ++fe; |
| 379 | ++num; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | out: |
| 384 | rcu_read_unlock(); |
| 385 | |
| 386 | return num; |
| 387 | } |
| 388 | |
stephen hemminger | 664de48 | 2011-04-04 14:03:29 +0000 | [diff] [blame] | 389 | static struct net_bridge_fdb_entry *fdb_find(struct hlist_head *head, |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 390 | const unsigned char *addr, |
| 391 | __u16 vid) |
stephen hemminger | 664de48 | 2011-04-04 14:03:29 +0000 | [diff] [blame] | 392 | { |
stephen hemminger | 664de48 | 2011-04-04 14:03:29 +0000 | [diff] [blame] | 393 | struct net_bridge_fdb_entry *fdb; |
| 394 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 395 | hlist_for_each_entry(fdb, head, hlist) { |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 396 | if (ether_addr_equal(fdb->addr.addr, addr) && |
| 397 | fdb->vlan_id == vid) |
stephen hemminger | 664de48 | 2011-04-04 14:03:29 +0000 | [diff] [blame] | 398 | return fdb; |
| 399 | } |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | static struct net_bridge_fdb_entry *fdb_find_rcu(struct hlist_head *head, |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 404 | const unsigned char *addr, |
| 405 | __u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | struct net_bridge_fdb_entry *fdb; |
| 408 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 409 | hlist_for_each_entry_rcu(fdb, head, hlist) { |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 410 | if (ether_addr_equal(fdb->addr.addr, addr) && |
| 411 | fdb->vlan_id == vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | return fdb; |
| 413 | } |
| 414 | return NULL; |
| 415 | } |
| 416 | |
| 417 | static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head, |
| 418 | struct net_bridge_port *source, |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 419 | const unsigned char *addr, |
| 420 | __u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | struct net_bridge_fdb_entry *fdb; |
| 423 | |
| 424 | fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC); |
| 425 | if (fdb) { |
| 426 | memcpy(fdb->addr.addr, addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | fdb->dst = source; |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 428 | fdb->vlan_id = vid; |
stephen hemminger | 03e9b64 | 2011-04-04 14:03:27 +0000 | [diff] [blame] | 429 | fdb->is_local = 0; |
| 430 | fdb->is_static = 0; |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 431 | fdb->added_by_user = 0; |
stephen hemminger | 7cd8861 | 2011-04-04 14:03:28 +0000 | [diff] [blame] | 432 | fdb->updated = fdb->used = jiffies; |
Pavel Emelyanov | 1158f76 | 2011-02-04 13:02:36 -0800 | [diff] [blame] | 433 | hlist_add_head_rcu(&fdb->hlist, head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | return fdb; |
| 436 | } |
| 437 | |
| 438 | static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source, |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 439 | const unsigned char *addr, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 441 | struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | struct net_bridge_fdb_entry *fdb; |
| 443 | |
| 444 | if (!is_valid_ether_addr(addr)) |
| 445 | return -EINVAL; |
| 446 | |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 447 | fdb = fdb_find(head, addr, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (fdb) { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 449 | /* it is okay to have multiple ports with same |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | * address, just use the first one. |
| 451 | */ |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 452 | if (fdb->is_local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | return 0; |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 454 | br_warn(br, "adding interface %s with same address " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | "as a received packet\n", |
Hong zhi guo | 9b46922 | 2013-03-23 02:27:50 +0000 | [diff] [blame] | 456 | source ? source->dev->name : br->dev->name); |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 457 | fdb_delete(br, fdb); |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 460 | fdb = fdb_create(head, source, addr, vid); |
stephen hemminger | 03e9b64 | 2011-04-04 14:03:27 +0000 | [diff] [blame] | 461 | if (!fdb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | return -ENOMEM; |
| 463 | |
stephen hemminger | 03e9b64 | 2011-04-04 14:03:27 +0000 | [diff] [blame] | 464 | fdb->is_local = fdb->is_static = 1; |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 465 | fdb_notify(br, fdb, RTM_NEWNEIGH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
stephen hemminger | 03e9b64 | 2011-04-04 14:03:27 +0000 | [diff] [blame] | 469 | /* Add entry for local address of interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source, |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 471 | const unsigned char *addr, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
| 473 | int ret; |
| 474 | |
| 475 | spin_lock_bh(&br->hash_lock); |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 476 | ret = fdb_insert(br, source, addr, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | spin_unlock_bh(&br->hash_lock); |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 482 | const unsigned char *addr, u16 vid, bool added_by_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 484 | struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | struct net_bridge_fdb_entry *fdb; |
| 486 | |
| 487 | /* some users want to always flood. */ |
| 488 | if (hold_time(br) == 0) |
| 489 | return; |
| 490 | |
Stephen Hemminger | df1c0b8 | 2007-08-30 22:15:35 -0700 | [diff] [blame] | 491 | /* ignore packets unless we are using this port */ |
| 492 | if (!(source->state == BR_STATE_LEARNING || |
| 493 | source->state == BR_STATE_FORWARDING)) |
| 494 | return; |
| 495 | |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 496 | fdb = fdb_find_rcu(head, addr, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (likely(fdb)) { |
| 498 | /* attempt to update an entry for a local interface */ |
| 499 | if (unlikely(fdb->is_local)) { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 500 | if (net_ratelimit()) |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 501 | br_warn(br, "received packet on %s with " |
| 502 | "own address as source address\n", |
| 503 | source->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } else { |
| 505 | /* fastpath: update of existing entry */ |
| 506 | fdb->dst = source; |
stephen hemminger | 7cd8861 | 2011-04-04 14:03:28 +0000 | [diff] [blame] | 507 | fdb->updated = jiffies; |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 508 | if (unlikely(added_by_user)) |
| 509 | fdb->added_by_user = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | } else { |
Stephen Hemminger | f8ae737 | 2006-03-20 22:58:36 -0800 | [diff] [blame] | 512 | spin_lock(&br->hash_lock); |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 513 | if (likely(!fdb_find(head, addr, vid))) { |
| 514 | fdb = fdb_create(head, source, addr, vid); |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 515 | if (fdb) { |
| 516 | if (unlikely(added_by_user)) |
| 517 | fdb->added_by_user = 1; |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 518 | fdb_notify(br, fdb, RTM_NEWNEIGH); |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 519 | } |
stephen hemminger | f58ee4e | 2011-12-06 13:02:24 +0000 | [diff] [blame] | 520 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* else we lose race and someone else inserts |
| 522 | * it first, don't bother updating |
| 523 | */ |
Stephen Hemminger | f8ae737 | 2006-03-20 22:58:36 -0800 | [diff] [blame] | 524 | spin_unlock(&br->hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 527 | |
| 528 | static int fdb_to_nud(const struct net_bridge_fdb_entry *fdb) |
| 529 | { |
| 530 | if (fdb->is_local) |
| 531 | return NUD_PERMANENT; |
| 532 | else if (fdb->is_static) |
| 533 | return NUD_NOARP; |
| 534 | else if (has_expired(fdb->dst->br, fdb)) |
| 535 | return NUD_STALE; |
| 536 | else |
| 537 | return NUD_REACHABLE; |
| 538 | } |
| 539 | |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 540 | static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br, |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 541 | const struct net_bridge_fdb_entry *fdb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 542 | u32 portid, u32 seq, int type, unsigned int flags) |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 543 | { |
| 544 | unsigned long now = jiffies; |
| 545 | struct nda_cacheinfo ci; |
| 546 | struct nlmsghdr *nlh; |
| 547 | struct ndmsg *ndm; |
| 548 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 549 | nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags); |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 550 | if (nlh == NULL) |
| 551 | return -EMSGSIZE; |
| 552 | |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 553 | ndm = nlmsg_data(nlh); |
| 554 | ndm->ndm_family = AF_BRIDGE; |
| 555 | ndm->ndm_pad1 = 0; |
| 556 | ndm->ndm_pad2 = 0; |
| 557 | ndm->ndm_flags = 0; |
| 558 | ndm->ndm_type = 0; |
stephen hemminger | 4359881 | 2011-12-08 07:17:49 +0000 | [diff] [blame] | 559 | ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 560 | ndm->ndm_state = fdb_to_nud(fdb); |
| 561 | |
David S. Miller | 2eb812e | 2012-04-01 20:49:54 -0400 | [diff] [blame] | 562 | if (nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->addr)) |
| 563 | goto nla_put_failure; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 564 | ci.ndm_used = jiffies_to_clock_t(now - fdb->used); |
| 565 | ci.ndm_confirmed = 0; |
| 566 | ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated); |
| 567 | ci.ndm_refcnt = 0; |
David S. Miller | 2eb812e | 2012-04-01 20:49:54 -0400 | [diff] [blame] | 568 | if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci)) |
| 569 | goto nla_put_failure; |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 570 | |
| 571 | if (nla_put(skb, NDA_VLAN, sizeof(u16), &fdb->vlan_id)) |
| 572 | goto nla_put_failure; |
| 573 | |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 574 | return nlmsg_end(skb, nlh); |
| 575 | |
| 576 | nla_put_failure: |
| 577 | nlmsg_cancel(skb, nlh); |
| 578 | return -EMSGSIZE; |
| 579 | } |
| 580 | |
| 581 | static inline size_t fdb_nlmsg_size(void) |
| 582 | { |
| 583 | return NLMSG_ALIGN(sizeof(struct ndmsg)) |
| 584 | + nla_total_size(ETH_ALEN) /* NDA_LLADDR */ |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 585 | + nla_total_size(sizeof(u16)) /* NDA_VLAN */ |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 586 | + nla_total_size(sizeof(struct nda_cacheinfo)); |
| 587 | } |
| 588 | |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 589 | static void fdb_notify(struct net_bridge *br, |
| 590 | const struct net_bridge_fdb_entry *fdb, int type) |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 591 | { |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 592 | struct net *net = dev_net(br->dev); |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 593 | struct sk_buff *skb; |
| 594 | int err = -ENOBUFS; |
| 595 | |
| 596 | skb = nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC); |
| 597 | if (skb == NULL) |
| 598 | goto errout; |
| 599 | |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 600 | err = fdb_fill_info(skb, br, fdb, 0, 0, type, 0); |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 601 | if (err < 0) { |
| 602 | /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */ |
| 603 | WARN_ON(err == -EMSGSIZE); |
| 604 | kfree_skb(skb); |
| 605 | goto errout; |
| 606 | } |
| 607 | rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC); |
| 608 | return; |
| 609 | errout: |
tanxiaojun | 87e823b | 2013-12-19 13:28:10 +0800 | [diff] [blame] | 610 | rtnl_set_sk_err(net, RTNLGRP_NEIGH, err); |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* Dump information about entries, in response to GETNEIGH */ |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 614 | int br_fdb_dump(struct sk_buff *skb, |
| 615 | struct netlink_callback *cb, |
| 616 | struct net_device *dev, |
| 617 | int idx) |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 618 | { |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 619 | struct net_bridge *br = netdev_priv(dev); |
| 620 | int i; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 621 | |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 622 | if (!(dev->priv_flags & IFF_EBRIDGE)) |
| 623 | goto out; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 624 | |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 625 | for (i = 0; i < BR_HASH_SIZE; i++) { |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 626 | struct net_bridge_fdb_entry *f; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 627 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 628 | hlist_for_each_entry_rcu(f, &br->hash[i], hlist) { |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 629 | if (idx < cb->args[0]) |
| 630 | goto skip; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 631 | |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 632 | if (fdb_fill_info(skb, br, f, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 633 | NETLINK_CB(cb->skb).portid, |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 634 | cb->nlh->nlmsg_seq, |
| 635 | RTM_NEWNEIGH, |
| 636 | NLM_F_MULTI) < 0) |
| 637 | break; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 638 | skip: |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 639 | ++idx; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 642 | |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 643 | out: |
| 644 | return idx; |
stephen hemminger | b078f0d | 2011-04-04 14:03:30 +0000 | [diff] [blame] | 645 | } |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 646 | |
stephen hemminger | 292d139 | 2011-11-09 18:30:08 +0000 | [diff] [blame] | 647 | /* Update (create or replace) forwarding database entry */ |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 648 | static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr, |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 649 | __u16 state, __u16 flags, __u16 vid) |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 650 | { |
| 651 | struct net_bridge *br = source->br; |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 652 | struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 653 | struct net_bridge_fdb_entry *fdb; |
roopa | b0a397f | 2013-04-22 12:56:49 +0000 | [diff] [blame] | 654 | bool modified = false; |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 655 | |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 656 | fdb = fdb_find(head, addr, vid); |
stephen hemminger | 64af1ba | 2011-09-30 14:37:27 +0000 | [diff] [blame] | 657 | if (fdb == NULL) { |
| 658 | if (!(flags & NLM_F_CREATE)) |
| 659 | return -ENOENT; |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 660 | |
Vlad Yasevich | 2ba071e | 2013-02-13 12:00:16 +0000 | [diff] [blame] | 661 | fdb = fdb_create(head, source, addr, vid); |
stephen hemminger | 64af1ba | 2011-09-30 14:37:27 +0000 | [diff] [blame] | 662 | if (!fdb) |
| 663 | return -ENOMEM; |
roopa | b0a397f | 2013-04-22 12:56:49 +0000 | [diff] [blame] | 664 | |
| 665 | modified = true; |
stephen hemminger | 64af1ba | 2011-09-30 14:37:27 +0000 | [diff] [blame] | 666 | } else { |
| 667 | if (flags & NLM_F_EXCL) |
| 668 | return -EEXIST; |
roopa | b0a397f | 2013-04-22 12:56:49 +0000 | [diff] [blame] | 669 | |
| 670 | if (fdb->dst != source) { |
| 671 | fdb->dst = source; |
| 672 | modified = true; |
| 673 | } |
stephen hemminger | 64af1ba | 2011-09-30 14:37:27 +0000 | [diff] [blame] | 674 | } |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 675 | |
stephen hemminger | 292d139 | 2011-11-09 18:30:08 +0000 | [diff] [blame] | 676 | if (fdb_to_nud(fdb) != state) { |
| 677 | if (state & NUD_PERMANENT) |
| 678 | fdb->is_local = fdb->is_static = 1; |
| 679 | else if (state & NUD_NOARP) { |
| 680 | fdb->is_local = 0; |
| 681 | fdb->is_static = 1; |
| 682 | } else |
| 683 | fdb->is_local = fdb->is_static = 0; |
| 684 | |
roopa | b0a397f | 2013-04-22 12:56:49 +0000 | [diff] [blame] | 685 | modified = true; |
| 686 | } |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 687 | fdb->added_by_user = 1; |
roopa | b0a397f | 2013-04-22 12:56:49 +0000 | [diff] [blame] | 688 | |
| 689 | fdb->used = jiffies; |
| 690 | if (modified) { |
| 691 | fdb->updated = jiffies; |
stephen hemminger | 31e8a49c | 2011-12-08 07:17:41 +0000 | [diff] [blame] | 692 | fdb_notify(br, fdb, RTM_NEWNEIGH); |
stephen hemminger | 292d139 | 2011-11-09 18:30:08 +0000 | [diff] [blame] | 693 | } |
| 694 | |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 695 | return 0; |
| 696 | } |
| 697 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 698 | static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge_port *p, |
| 699 | const unsigned char *addr, u16 nlh_flags, u16 vid) |
| 700 | { |
| 701 | int err = 0; |
| 702 | |
| 703 | if (ndm->ndm_flags & NTF_USE) { |
| 704 | rcu_read_lock(); |
Toshiaki Makita | a5642ab | 2014-02-07 16:48:18 +0900 | [diff] [blame] | 705 | br_fdb_update(p->br, p, addr, vid, true); |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 706 | rcu_read_unlock(); |
| 707 | } else { |
| 708 | spin_lock_bh(&p->br->hash_lock); |
| 709 | err = fdb_add_entry(p, addr, ndm->ndm_state, |
| 710 | nlh_flags, vid); |
| 711 | spin_unlock_bh(&p->br->hash_lock); |
| 712 | } |
| 713 | |
| 714 | return err; |
| 715 | } |
| 716 | |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 717 | /* Add new permanent fdb entry with RTM_NEWNEIGH */ |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 718 | int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 719 | struct net_device *dev, |
stephen hemminger | 6b6e272 | 2012-09-17 10:03:26 +0000 | [diff] [blame] | 720 | const unsigned char *addr, u16 nlh_flags) |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 721 | { |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 722 | struct net_bridge_port *p; |
John Fastabend | 7716202 | 2012-04-15 06:43:56 +0000 | [diff] [blame] | 723 | int err = 0; |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 724 | struct net_port_vlans *pv; |
| 725 | unsigned short vid = VLAN_N_VID; |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 726 | |
stephen hemminger | 292d139 | 2011-11-09 18:30:08 +0000 | [diff] [blame] | 727 | if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE))) { |
| 728 | pr_info("bridge: RTM_NEWNEIGH with invalid state %#x\n", ndm->ndm_state); |
| 729 | return -EINVAL; |
| 730 | } |
| 731 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 732 | if (tb[NDA_VLAN]) { |
| 733 | if (nla_len(tb[NDA_VLAN]) != sizeof(unsigned short)) { |
| 734 | pr_info("bridge: RTM_NEWNEIGH with invalid vlan\n"); |
| 735 | return -EINVAL; |
| 736 | } |
| 737 | |
| 738 | vid = nla_get_u16(tb[NDA_VLAN]); |
| 739 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 740 | if (!vid || vid >= VLAN_VID_MASK) { |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 741 | pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n", |
| 742 | vid); |
| 743 | return -EINVAL; |
| 744 | } |
| 745 | } |
| 746 | |
Stephen Hemminger | 537f7f8 | 2013-06-25 09:34:36 -0700 | [diff] [blame] | 747 | if (is_zero_ether_addr(addr)) { |
| 748 | pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n"); |
| 749 | return -EINVAL; |
| 750 | } |
| 751 | |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 752 | p = br_port_get_rtnl(dev); |
| 753 | if (p == NULL) { |
| 754 | pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n", |
| 755 | dev->name); |
| 756 | return -EINVAL; |
| 757 | } |
| 758 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 759 | pv = nbp_get_vlan_info(p); |
| 760 | if (vid != VLAN_N_VID) { |
| 761 | if (!pv || !test_bit(vid, pv->vlan_bitmap)) { |
| 762 | pr_info("bridge: RTM_NEWNEIGH with unconfigured " |
| 763 | "vlan %d on port %s\n", vid, dev->name); |
| 764 | return -EINVAL; |
| 765 | } |
| 766 | |
| 767 | /* VID was specified, so use it. */ |
| 768 | err = __br_fdb_add(ndm, p, addr, nlh_flags, vid); |
stephen hemminger | 292d139 | 2011-11-09 18:30:08 +0000 | [diff] [blame] | 769 | } else { |
Toshiaki Makita | ef40b7e | 2013-08-20 17:10:18 +0900 | [diff] [blame] | 770 | if (!pv || bitmap_empty(pv->vlan_bitmap, VLAN_N_VID)) { |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 771 | err = __br_fdb_add(ndm, p, addr, nlh_flags, 0); |
| 772 | goto out; |
| 773 | } |
| 774 | |
| 775 | /* We have vlans configured on this port and user didn't |
| 776 | * specify a VLAN. To be nice, add/update entry for every |
| 777 | * vlan on this port. |
| 778 | */ |
Toshiaki Makita | ef40b7e | 2013-08-20 17:10:18 +0900 | [diff] [blame] | 779 | for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) { |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 780 | err = __br_fdb_add(ndm, p, addr, nlh_flags, vid); |
| 781 | if (err) |
| 782 | goto out; |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 783 | } |
stephen hemminger | 292d139 | 2011-11-09 18:30:08 +0000 | [diff] [blame] | 784 | } |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 785 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 786 | out: |
| 787 | return err; |
| 788 | } |
| 789 | |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame^] | 790 | static int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr, u16 vlan) |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 791 | { |
| 792 | struct hlist_head *head = &br->hash[br_mac_hash(addr, vlan)]; |
| 793 | struct net_bridge_fdb_entry *fdb; |
| 794 | |
| 795 | fdb = fdb_find(head, addr, vlan); |
| 796 | if (!fdb) |
| 797 | return -ENOENT; |
| 798 | |
| 799 | fdb_delete(br, fdb); |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static int __br_fdb_delete(struct net_bridge_port *p, |
| 804 | const unsigned char *addr, u16 vid) |
| 805 | { |
| 806 | int err; |
| 807 | |
| 808 | spin_lock_bh(&p->br->hash_lock); |
| 809 | err = fdb_delete_by_addr(p->br, addr, vid); |
| 810 | spin_unlock_bh(&p->br->hash_lock); |
| 811 | |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 812 | return err; |
| 813 | } |
| 814 | |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 815 | /* Remove neighbor entry with RTM_DELNEIGH */ |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 816 | int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], |
| 817 | struct net_device *dev, |
stephen hemminger | 6b6e272 | 2012-09-17 10:03:26 +0000 | [diff] [blame] | 818 | const unsigned char *addr) |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 819 | { |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 820 | struct net_bridge_port *p; |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 821 | int err; |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 822 | struct net_port_vlans *pv; |
| 823 | unsigned short vid = VLAN_N_VID; |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 824 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 825 | if (tb[NDA_VLAN]) { |
| 826 | if (nla_len(tb[NDA_VLAN]) != sizeof(unsigned short)) { |
| 827 | pr_info("bridge: RTM_NEWNEIGH with invalid vlan\n"); |
| 828 | return -EINVAL; |
| 829 | } |
| 830 | |
| 831 | vid = nla_get_u16(tb[NDA_VLAN]); |
| 832 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 833 | if (!vid || vid >= VLAN_VID_MASK) { |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 834 | pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n", |
| 835 | vid); |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | } |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 839 | p = br_port_get_rtnl(dev); |
| 840 | if (p == NULL) { |
| 841 | pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n", |
| 842 | dev->name); |
| 843 | return -EINVAL; |
| 844 | } |
| 845 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 846 | pv = nbp_get_vlan_info(p); |
| 847 | if (vid != VLAN_N_VID) { |
| 848 | if (!pv || !test_bit(vid, pv->vlan_bitmap)) { |
| 849 | pr_info("bridge: RTM_DELNEIGH with unconfigured " |
| 850 | "vlan %d on port %s\n", vid, dev->name); |
| 851 | return -EINVAL; |
| 852 | } |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 853 | |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 854 | err = __br_fdb_delete(p, addr, vid); |
| 855 | } else { |
Toshiaki Makita | ef40b7e | 2013-08-20 17:10:18 +0900 | [diff] [blame] | 856 | if (!pv || bitmap_empty(pv->vlan_bitmap, VLAN_N_VID)) { |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 857 | err = __br_fdb_delete(p, addr, 0); |
| 858 | goto out; |
| 859 | } |
| 860 | |
| 861 | /* We have vlans configured on this port and user didn't |
| 862 | * specify a VLAN. To be nice, add/update entry for every |
| 863 | * vlan on this port. |
| 864 | */ |
| 865 | err = -ENOENT; |
Toshiaki Makita | ef40b7e | 2013-08-20 17:10:18 +0900 | [diff] [blame] | 866 | for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) { |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 867 | err &= __br_fdb_delete(p, addr, vid); |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | out: |
stephen hemminger | 36fd2b6 | 2011-04-04 14:03:31 +0000 | [diff] [blame] | 871 | return err; |
| 872 | } |