blob: 60aca9109a508d5a75c5b34befbdca8c7364fe52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Forwarding database
3 * Linux ethernet bridge
4 *
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * 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-Huu82524742008-05-12 21:21:05 +020016#include <linux/rculist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#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 Hemminger3f890922007-03-21 13:42:33 -070022#include <linux/random.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Arun Sharma600634972011-07-26 16:09:06 -070024#include <linux/atomic.h>
Stephen Hemminger3f890922007-03-21 13:42:33 -070025#include <asm/unaligned.h>
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000026#include <linux/if_vlan.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "br_private.h"
28
Christoph Lametere18b8902006-12-06 20:33:20 -080029static struct kmem_cache *br_fdb_cache __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000031 const unsigned char *addr, u16 vid);
stephen hemminger31e8a49c2011-12-08 07:17:41 +000032static void fdb_notify(struct net_bridge *br,
33 const struct net_bridge_fdb_entry *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Stephen Hemminger3f890922007-03-21 13:42:33 -070035static u32 fdb_salt __read_mostly;
36
Akinobu Mita87a596e2007-04-07 18:57:07 +090037int __init br_fdb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 br_fdb_cache = kmem_cache_create("bridge_fdb_cache",
40 sizeof(struct net_bridge_fdb_entry),
41 0,
Paul Mundt20c2df82007-07-20 10:11:58 +090042 SLAB_HWCACHE_ALIGN, NULL);
Akinobu Mita87a596e2007-04-07 18:57:07 +090043 if (!br_fdb_cache)
44 return -ENOMEM;
45
Stephen Hemminger3f890922007-03-21 13:42:33 -070046 get_random_bytes(&fdb_salt, sizeof(fdb_salt));
Akinobu Mita87a596e2007-04-07 18:57:07 +090047 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Andrew Morton73afc902007-12-05 21:35:23 -080050void br_fdb_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
52 kmem_cache_destroy(br_fdb_cache);
53}
54
55
56/* if topology_changing then use forward_delay (default 15 sec)
57 * otherwise keep longer (default 5 minutes)
58 */
Stephen Hemminger3f890922007-03-21 13:42:33 -070059static inline unsigned long hold_time(const struct net_bridge *br)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 return br->topology_change ? br->forward_delay : br->ageing_time;
62}
63
Stephen Hemminger3f890922007-03-21 13:42:33 -070064static inline int has_expired(const struct net_bridge *br,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 const struct net_bridge_fdb_entry *fdb)
66{
Joe Perchesf64f9e72009-11-29 16:55:45 -080067 return !fdb->is_static &&
stephen hemminger7cd88612011-04-04 14:03:28 +000068 time_before_eq(fdb->updated + hold_time(br), jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000071static inline int br_mac_hash(const unsigned char *mac, __u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000073 /* use 1 byte of OUI and 3 bytes of NIC */
Stephen Hemminger3f890922007-03-21 13:42:33 -070074 u32 key = get_unaligned((u32 *)(mac + 2));
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000075 return jhash_2words(key, vid, fdb_salt) & (BR_HASH_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Michał Mirosławda678292009-06-05 05:35:28 +000078static void fdb_rcu_free(struct rcu_head *head)
79{
80 struct net_bridge_fdb_entry *ent
81 = container_of(head, struct net_bridge_fdb_entry, rcu);
82 kmem_cache_free(br_fdb_cache, ent);
83}
84
stephen hemminger31e8a49c2011-12-08 07:17:41 +000085static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 hlist_del_rcu(&f->hlist);
stephen hemminger31e8a49c2011-12-08 07:17:41 +000088 fdb_notify(br, f, RTM_DELNEIGH);
Michał Mirosławda678292009-06-05 05:35:28 +000089 call_rcu(&f->rcu, fdb_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
93{
94 struct net_bridge *br = p->br;
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000095 bool no_vlan = (nbp_get_vlan_info(p) == NULL) ? true : false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 int i;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +090097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 spin_lock_bh(&br->hash_lock);
99
100 /* Search all chains since old address/hash is unknown */
101 for (i = 0; i < BR_HASH_SIZE; i++) {
102 struct hlist_node *h;
103 hlist_for_each(h, &br->hash[i]) {
104 struct net_bridge_fdb_entry *f;
105
106 f = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
107 if (f->dst == p && f->is_local) {
108 /* maybe another port has same hw addr? */
109 struct net_bridge_port *op;
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000110 u16 vid = f->vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 list_for_each_entry(op, &br->port_list, list) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900112 if (op != p &&
Joe Perches9a7b6ef92012-05-08 18:56:49 +0000113 ether_addr_equal(op->dev->dev_addr,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000114 f->addr.addr) &&
115 nbp_vlan_find(op, vid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 f->dst = op;
117 goto insert;
118 }
119 }
120
121 /* delete old one */
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000122 fdb_delete(br, f);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000123insert:
124 /* insert new address, may fail if invalid
125 * address or dup.
126 */
127 fdb_insert(br, p, newaddr, vid);
128
129 /* if this port has no vlan information
130 * configured, we can safely be done at
131 * this point.
132 */
133 if (no_vlan)
134 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136 }
137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000139done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 spin_unlock_bh(&br->hash_lock);
141}
142
stephen hemminger43598812011-12-08 07:17:49 +0000143void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
144{
145 struct net_bridge_fdb_entry *f;
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000146 struct net_port_vlans *pv;
147 u16 vid = 0;
stephen hemminger43598812011-12-08 07:17:49 +0000148
149 /* If old entry was unassociated with any port, then delete it. */
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000150 f = __br_fdb_get(br, br->dev->dev_addr, 0);
stephen hemminger43598812011-12-08 07:17:49 +0000151 if (f && f->is_local && !f->dst)
152 fdb_delete(br, f);
153
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000154 fdb_insert(br, NULL, newaddr, 0);
155
156 /* Now remove and add entries for every VLAN configured on the
157 * bridge. This function runs under RTNL so the bitmap will not
158 * change from under us.
159 */
160 pv = br_get_vlan_info(br);
161 if (!pv)
162 return;
163
Wei Yongjun5096e3c2013-03-11 05:43:48 +0000164 for_each_set_bit_from(vid, pv->vlan_bitmap, BR_VLAN_BITMAP_LEN) {
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000165 f = __br_fdb_get(br, br->dev->dev_addr, vid);
166 if (f && f->is_local && !f->dst)
167 fdb_delete(br, f);
168 fdb_insert(br, NULL, newaddr, vid);
169 }
stephen hemminger43598812011-12-08 07:17:49 +0000170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172void br_fdb_cleanup(unsigned long _data)
173{
174 struct net_bridge *br = (struct net_bridge *)_data;
175 unsigned long delay = hold_time(br);
stephen hemminger25442e02010-06-15 06:14:12 +0000176 unsigned long next_timer = jiffies + br->ageing_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 int i;
178
Eric Dumazet27a42932012-01-16 04:35:50 +0000179 spin_lock(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 for (i = 0; i < BR_HASH_SIZE; i++) {
181 struct net_bridge_fdb_entry *f;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800182 struct hlist_node *n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Sasha Levinb67bfe02013-02-27 17:06:00 -0800184 hlist_for_each_entry_safe(f, n, &br->hash[i], hlist) {
Baruch Even071f7722007-05-31 01:20:45 -0700185 unsigned long this_timer;
186 if (f->is_static)
187 continue;
stephen hemminger7cd88612011-04-04 14:03:28 +0000188 this_timer = f->updated + delay;
Baruch Even071f7722007-05-31 01:20:45 -0700189 if (time_before_eq(this_timer, jiffies))
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000190 fdb_delete(br, f);
Fabio Checconi2bec0082008-03-20 15:54:58 -0700191 else if (time_before(this_timer, next_timer))
Baruch Even071f7722007-05-31 01:20:45 -0700192 next_timer = this_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194 }
Eric Dumazet27a42932012-01-16 04:35:50 +0000195 spin_unlock(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
stephen hemminger25442e02010-06-15 06:14:12 +0000197 mod_timer(&br->gc_timer, round_jiffies_up(next_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700200/* Completely flush all dynamic entries in forwarding database.*/
201void br_fdb_flush(struct net_bridge *br)
202{
203 int i;
Stephen Hemminger1a620692006-10-12 14:45:38 -0700204
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700205 spin_lock_bh(&br->hash_lock);
206 for (i = 0; i < BR_HASH_SIZE; i++) {
207 struct net_bridge_fdb_entry *f;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800208 struct hlist_node *n;
209 hlist_for_each_entry_safe(f, n, &br->hash[i], hlist) {
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700210 if (!f->is_static)
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000211 fdb_delete(br, f);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700212 }
213 }
214 spin_unlock_bh(&br->hash_lock);
215}
216
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300217/* Flush all entries referring to a specific port.
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700218 * if do_all is set also flush static entries
219 */
Stephen Hemminger1a620692006-10-12 14:45:38 -0700220void br_fdb_delete_by_port(struct net_bridge *br,
221 const struct net_bridge_port *p,
222 int do_all)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 int i;
225
226 spin_lock_bh(&br->hash_lock);
227 for (i = 0; i < BR_HASH_SIZE; i++) {
228 struct hlist_node *h, *g;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 hlist_for_each_safe(h, g, &br->hash[i]) {
231 struct net_bridge_fdb_entry *f
232 = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900233 if (f->dst != p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 continue;
235
Stephen Hemminger1a620692006-10-12 14:45:38 -0700236 if (f->is_static && !do_all)
237 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /*
239 * if multiple ports all have the same device address
240 * then when one port is deleted, assign
241 * the local entry to other port
242 */
243 if (f->is_local) {
244 struct net_bridge_port *op;
245 list_for_each_entry(op, &br->port_list, list) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900246 if (op != p &&
Joe Perches9a7b6ef92012-05-08 18:56:49 +0000247 ether_addr_equal(op->dev->dev_addr,
248 f->addr.addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 f->dst = op;
250 goto skip_delete;
251 }
252 }
253 }
254
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000255 fdb_delete(br, f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 skip_delete: ;
257 }
258 }
259 spin_unlock_bh(&br->hash_lock);
260}
261
stephen hemmingereeaf61d2010-07-27 08:26:30 +0000262/* No locking or refcounting, assumes caller has rcu_read_lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000264 const unsigned char *addr,
265 __u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 struct net_bridge_fdb_entry *fdb;
268
Sasha Levinb67bfe02013-02-27 17:06:00 -0800269 hlist_for_each_entry_rcu(fdb,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000270 &br->hash[br_mac_hash(addr, vid)], hlist) {
271 if (ether_addr_equal(fdb->addr.addr, addr) &&
272 fdb->vlan_id == vid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (unlikely(has_expired(br, fdb)))
274 break;
275 return fdb;
276 }
277 }
278
279 return NULL;
280}
281
Igor Maraviće6373c42011-12-12 02:58:25 +0000282#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +0000283/* Interface used by ATM LANE hook to test
284 * if an addr is on some other bridge port */
285int br_fdb_test_addr(struct net_device *dev, unsigned char *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct net_bridge_fdb_entry *fdb;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000288 struct net_bridge_port *port;
Michał Mirosławda678292009-06-05 05:35:28 +0000289 int ret;
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 rcu_read_lock();
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000292 port = br_port_get_rcu(dev);
293 if (!port)
294 ret = 0;
295 else {
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000296 fdb = __br_fdb_get(port->br, addr, 0);
stephen hemminger43598812011-12-08 07:17:49 +0000297 ret = fdb && fdb->dst && fdb->dst->dev != dev &&
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000298 fdb->dst->state == BR_STATE_FORWARDING;
299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Michał Mirosławda678292009-06-05 05:35:28 +0000302 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
Michał Mirosławda678292009-06-05 05:35:28 +0000304#endif /* CONFIG_ATM_LANE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306/*
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900307 * Fill buffer with forwarding table records in
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 * the API format.
309 */
310int br_fdb_fillbuf(struct net_bridge *br, void *buf,
311 unsigned long maxnum, unsigned long skip)
312{
313 struct __fdb_entry *fe = buf;
314 int i, num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 struct net_bridge_fdb_entry *f;
316
317 memset(buf, 0, maxnum*sizeof(struct __fdb_entry));
318
319 rcu_read_lock();
320 for (i = 0; i < BR_HASH_SIZE; i++) {
Sasha Levinb67bfe02013-02-27 17:06:00 -0800321 hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (num >= maxnum)
323 goto out;
324
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900325 if (has_expired(br, f))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 continue;
327
stephen hemminger43598812011-12-08 07:17:49 +0000328 /* ignore pseudo entry for local MAC address */
329 if (!f->dst)
330 continue;
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (skip) {
333 --skip;
334 continue;
335 }
336
337 /* convert from internal format to API */
338 memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN);
Stephen Hemmingerae4f8fc2008-05-02 16:53:33 -0700339
340 /* due to ABI compat need to split into hi/lo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 fe->port_no = f->dst->port_no;
Stephen Hemmingerae4f8fc2008-05-02 16:53:33 -0700342 fe->port_hi = f->dst->port_no >> 8;
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 fe->is_local = f->is_local;
345 if (!f->is_static)
Eric Dumazeta399a802012-08-08 21:13:53 +0000346 fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 ++fe;
348 ++num;
349 }
350 }
351
352 out:
353 rcu_read_unlock();
354
355 return num;
356}
357
stephen hemminger664de482011-04-04 14:03:29 +0000358static struct net_bridge_fdb_entry *fdb_find(struct hlist_head *head,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000359 const unsigned char *addr,
360 __u16 vid)
stephen hemminger664de482011-04-04 14:03:29 +0000361{
stephen hemminger664de482011-04-04 14:03:29 +0000362 struct net_bridge_fdb_entry *fdb;
363
Sasha Levinb67bfe02013-02-27 17:06:00 -0800364 hlist_for_each_entry(fdb, head, hlist) {
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000365 if (ether_addr_equal(fdb->addr.addr, addr) &&
366 fdb->vlan_id == vid)
stephen hemminger664de482011-04-04 14:03:29 +0000367 return fdb;
368 }
369 return NULL;
370}
371
372static struct net_bridge_fdb_entry *fdb_find_rcu(struct hlist_head *head,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000373 const unsigned char *addr,
374 __u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 struct net_bridge_fdb_entry *fdb;
377
Sasha Levinb67bfe02013-02-27 17:06:00 -0800378 hlist_for_each_entry_rcu(fdb, head, hlist) {
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000379 if (ether_addr_equal(fdb->addr.addr, addr) &&
380 fdb->vlan_id == vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return fdb;
382 }
383 return NULL;
384}
385
386static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head,
387 struct net_bridge_port *source,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000388 const unsigned char *addr,
389 __u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
391 struct net_bridge_fdb_entry *fdb;
392
393 fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC);
394 if (fdb) {
395 memcpy(fdb->addr.addr, addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 fdb->dst = source;
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000397 fdb->vlan_id = vid;
stephen hemminger03e9b642011-04-04 14:03:27 +0000398 fdb->is_local = 0;
399 fdb->is_static = 0;
stephen hemminger7cd88612011-04-04 14:03:28 +0000400 fdb->updated = fdb->used = jiffies;
Pavel Emelyanov1158f762011-02-04 13:02:36 -0800401 hlist_add_head_rcu(&fdb->hlist, head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403 return fdb;
404}
405
406static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000407 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000409 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 struct net_bridge_fdb_entry *fdb;
411
412 if (!is_valid_ether_addr(addr))
413 return -EINVAL;
414
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000415 fdb = fdb_find(head, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (fdb) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900417 /* it is okay to have multiple ports with same
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 * address, just use the first one.
419 */
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900420 if (fdb->is_local)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return 0;
stephen hemminger28a16c92010-05-10 09:31:09 +0000422 br_warn(br, "adding interface %s with same address "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 "as a received packet\n",
Hong zhi guo9b469222013-03-23 02:27:50 +0000424 source ? source->dev->name : br->dev->name);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000425 fdb_delete(br, fdb);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000428 fdb = fdb_create(head, source, addr, vid);
stephen hemminger03e9b642011-04-04 14:03:27 +0000429 if (!fdb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return -ENOMEM;
431
stephen hemminger03e9b642011-04-04 14:03:27 +0000432 fdb->is_local = fdb->is_static = 1;
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000433 fdb_notify(br, fdb, RTM_NEWNEIGH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return 0;
435}
436
stephen hemminger03e9b642011-04-04 14:03:27 +0000437/* Add entry for local address of interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000439 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 int ret;
442
443 spin_lock_bh(&br->hash_lock);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000444 ret = fdb_insert(br, source, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 spin_unlock_bh(&br->hash_lock);
446 return ret;
447}
448
449void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000450 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000452 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 struct net_bridge_fdb_entry *fdb;
454
455 /* some users want to always flood. */
456 if (hold_time(br) == 0)
457 return;
458
Stephen Hemmingerdf1c0b82007-08-30 22:15:35 -0700459 /* ignore packets unless we are using this port */
460 if (!(source->state == BR_STATE_LEARNING ||
461 source->state == BR_STATE_FORWARDING))
462 return;
463
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000464 fdb = fdb_find_rcu(head, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if (likely(fdb)) {
466 /* attempt to update an entry for a local interface */
467 if (unlikely(fdb->is_local)) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900468 if (net_ratelimit())
stephen hemminger28a16c92010-05-10 09:31:09 +0000469 br_warn(br, "received packet on %s with "
470 "own address as source address\n",
471 source->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 } else {
473 /* fastpath: update of existing entry */
474 fdb->dst = source;
stephen hemminger7cd88612011-04-04 14:03:28 +0000475 fdb->updated = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477 } else {
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800478 spin_lock(&br->hash_lock);
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000479 if (likely(!fdb_find(head, addr, vid))) {
480 fdb = fdb_create(head, source, addr, vid);
stephen hemmingerf58ee4e2011-12-06 13:02:24 +0000481 if (fdb)
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000482 fdb_notify(br, fdb, RTM_NEWNEIGH);
stephen hemmingerf58ee4e2011-12-06 13:02:24 +0000483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* else we lose race and someone else inserts
485 * it first, don't bother updating
486 */
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800487 spin_unlock(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000490
491static int fdb_to_nud(const struct net_bridge_fdb_entry *fdb)
492{
493 if (fdb->is_local)
494 return NUD_PERMANENT;
495 else if (fdb->is_static)
496 return NUD_NOARP;
497 else if (has_expired(fdb->dst->br, fdb))
498 return NUD_STALE;
499 else
500 return NUD_REACHABLE;
501}
502
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000503static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000504 const struct net_bridge_fdb_entry *fdb,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000505 u32 portid, u32 seq, int type, unsigned int flags)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000506{
507 unsigned long now = jiffies;
508 struct nda_cacheinfo ci;
509 struct nlmsghdr *nlh;
510 struct ndmsg *ndm;
511
Eric W. Biederman15e47302012-09-07 20:12:54 +0000512 nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000513 if (nlh == NULL)
514 return -EMSGSIZE;
515
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000516 ndm = nlmsg_data(nlh);
517 ndm->ndm_family = AF_BRIDGE;
518 ndm->ndm_pad1 = 0;
519 ndm->ndm_pad2 = 0;
520 ndm->ndm_flags = 0;
521 ndm->ndm_type = 0;
stephen hemminger43598812011-12-08 07:17:49 +0000522 ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000523 ndm->ndm_state = fdb_to_nud(fdb);
524
David S. Miller2eb812e2012-04-01 20:49:54 -0400525 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->addr))
526 goto nla_put_failure;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000527 ci.ndm_used = jiffies_to_clock_t(now - fdb->used);
528 ci.ndm_confirmed = 0;
529 ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated);
530 ci.ndm_refcnt = 0;
David S. Miller2eb812e2012-04-01 20:49:54 -0400531 if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
532 goto nla_put_failure;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000533
534 if (nla_put(skb, NDA_VLAN, sizeof(u16), &fdb->vlan_id))
535 goto nla_put_failure;
536
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000537 return nlmsg_end(skb, nlh);
538
539nla_put_failure:
540 nlmsg_cancel(skb, nlh);
541 return -EMSGSIZE;
542}
543
544static inline size_t fdb_nlmsg_size(void)
545{
546 return NLMSG_ALIGN(sizeof(struct ndmsg))
547 + nla_total_size(ETH_ALEN) /* NDA_LLADDR */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000548 + nla_total_size(sizeof(u16)) /* NDA_VLAN */
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000549 + nla_total_size(sizeof(struct nda_cacheinfo));
550}
551
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000552static void fdb_notify(struct net_bridge *br,
553 const struct net_bridge_fdb_entry *fdb, int type)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000554{
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000555 struct net *net = dev_net(br->dev);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000556 struct sk_buff *skb;
557 int err = -ENOBUFS;
558
559 skb = nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC);
560 if (skb == NULL)
561 goto errout;
562
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000563 err = fdb_fill_info(skb, br, fdb, 0, 0, type, 0);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000564 if (err < 0) {
565 /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */
566 WARN_ON(err == -EMSGSIZE);
567 kfree_skb(skb);
568 goto errout;
569 }
570 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
571 return;
572errout:
573 if (err < 0)
574 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
575}
576
577/* Dump information about entries, in response to GETNEIGH */
John Fastabend77162022012-04-15 06:43:56 +0000578int br_fdb_dump(struct sk_buff *skb,
579 struct netlink_callback *cb,
580 struct net_device *dev,
581 int idx)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000582{
John Fastabend77162022012-04-15 06:43:56 +0000583 struct net_bridge *br = netdev_priv(dev);
584 int i;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000585
John Fastabend77162022012-04-15 06:43:56 +0000586 if (!(dev->priv_flags & IFF_EBRIDGE))
587 goto out;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000588
John Fastabend77162022012-04-15 06:43:56 +0000589 for (i = 0; i < BR_HASH_SIZE; i++) {
John Fastabend77162022012-04-15 06:43:56 +0000590 struct net_bridge_fdb_entry *f;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000591
Sasha Levinb67bfe02013-02-27 17:06:00 -0800592 hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
John Fastabend77162022012-04-15 06:43:56 +0000593 if (idx < cb->args[0])
594 goto skip;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000595
John Fastabend77162022012-04-15 06:43:56 +0000596 if (fdb_fill_info(skb, br, f,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000597 NETLINK_CB(cb->skb).portid,
John Fastabend77162022012-04-15 06:43:56 +0000598 cb->nlh->nlmsg_seq,
599 RTM_NEWNEIGH,
600 NLM_F_MULTI) < 0)
601 break;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000602skip:
John Fastabend77162022012-04-15 06:43:56 +0000603 ++idx;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000604 }
605 }
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000606
John Fastabend77162022012-04-15 06:43:56 +0000607out:
608 return idx;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000609}
stephen hemminger36fd2b62011-04-04 14:03:31 +0000610
stephen hemminger292d1392011-11-09 18:30:08 +0000611/* Update (create or replace) forwarding database entry */
stephen hemminger36fd2b62011-04-04 14:03:31 +0000612static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000613 __u16 state, __u16 flags, __u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000614{
615 struct net_bridge *br = source->br;
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000616 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
stephen hemminger36fd2b62011-04-04 14:03:31 +0000617 struct net_bridge_fdb_entry *fdb;
roopab0a397f2013-04-22 12:56:49 +0000618 bool modified = false;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000619
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000620 fdb = fdb_find(head, addr, vid);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000621 if (fdb == NULL) {
622 if (!(flags & NLM_F_CREATE))
623 return -ENOENT;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000624
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000625 fdb = fdb_create(head, source, addr, vid);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000626 if (!fdb)
627 return -ENOMEM;
roopab0a397f2013-04-22 12:56:49 +0000628
629 modified = true;
stephen hemminger64af1ba2011-09-30 14:37:27 +0000630 } else {
631 if (flags & NLM_F_EXCL)
632 return -EEXIST;
roopab0a397f2013-04-22 12:56:49 +0000633
634 if (fdb->dst != source) {
635 fdb->dst = source;
636 modified = true;
637 }
stephen hemminger64af1ba2011-09-30 14:37:27 +0000638 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000639
stephen hemminger292d1392011-11-09 18:30:08 +0000640 if (fdb_to_nud(fdb) != state) {
641 if (state & NUD_PERMANENT)
642 fdb->is_local = fdb->is_static = 1;
643 else if (state & NUD_NOARP) {
644 fdb->is_local = 0;
645 fdb->is_static = 1;
646 } else
647 fdb->is_local = fdb->is_static = 0;
648
roopab0a397f2013-04-22 12:56:49 +0000649 modified = true;
650 }
651
652 fdb->used = jiffies;
653 if (modified) {
654 fdb->updated = jiffies;
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000655 fdb_notify(br, fdb, RTM_NEWNEIGH);
stephen hemminger292d1392011-11-09 18:30:08 +0000656 }
657
stephen hemminger36fd2b62011-04-04 14:03:31 +0000658 return 0;
659}
660
Vlad Yasevich1690be62013-02-13 12:00:18 +0000661static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge_port *p,
662 const unsigned char *addr, u16 nlh_flags, u16 vid)
663{
664 int err = 0;
665
666 if (ndm->ndm_flags & NTF_USE) {
667 rcu_read_lock();
668 br_fdb_update(p->br, p, addr, vid);
669 rcu_read_unlock();
670 } else {
671 spin_lock_bh(&p->br->hash_lock);
672 err = fdb_add_entry(p, addr, ndm->ndm_state,
673 nlh_flags, vid);
674 spin_unlock_bh(&p->br->hash_lock);
675 }
676
677 return err;
678}
679
stephen hemminger36fd2b62011-04-04 14:03:31 +0000680/* Add new permanent fdb entry with RTM_NEWNEIGH */
stephen hemmingeredc7d572012-10-01 12:32:33 +0000681int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
682 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +0000683 const unsigned char *addr, u16 nlh_flags)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000684{
stephen hemminger36fd2b62011-04-04 14:03:31 +0000685 struct net_bridge_port *p;
John Fastabend77162022012-04-15 06:43:56 +0000686 int err = 0;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000687 struct net_port_vlans *pv;
688 unsigned short vid = VLAN_N_VID;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000689
stephen hemminger292d1392011-11-09 18:30:08 +0000690 if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE))) {
691 pr_info("bridge: RTM_NEWNEIGH with invalid state %#x\n", ndm->ndm_state);
692 return -EINVAL;
693 }
694
Vlad Yasevich1690be62013-02-13 12:00:18 +0000695 if (tb[NDA_VLAN]) {
696 if (nla_len(tb[NDA_VLAN]) != sizeof(unsigned short)) {
697 pr_info("bridge: RTM_NEWNEIGH with invalid vlan\n");
698 return -EINVAL;
699 }
700
701 vid = nla_get_u16(tb[NDA_VLAN]);
702
703 if (vid >= VLAN_N_VID) {
704 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n",
705 vid);
706 return -EINVAL;
707 }
708 }
709
Stephen Hemminger537f7f82013-06-25 09:34:36 -0700710 if (is_zero_ether_addr(addr)) {
711 pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n");
712 return -EINVAL;
713 }
714
stephen hemminger36fd2b62011-04-04 14:03:31 +0000715 p = br_port_get_rtnl(dev);
716 if (p == NULL) {
717 pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n",
718 dev->name);
719 return -EINVAL;
720 }
721
Vlad Yasevich1690be62013-02-13 12:00:18 +0000722 pv = nbp_get_vlan_info(p);
723 if (vid != VLAN_N_VID) {
724 if (!pv || !test_bit(vid, pv->vlan_bitmap)) {
725 pr_info("bridge: RTM_NEWNEIGH with unconfigured "
726 "vlan %d on port %s\n", vid, dev->name);
727 return -EINVAL;
728 }
729
730 /* VID was specified, so use it. */
731 err = __br_fdb_add(ndm, p, addr, nlh_flags, vid);
stephen hemminger292d1392011-11-09 18:30:08 +0000732 } else {
Vlad Yasevich1690be62013-02-13 12:00:18 +0000733 if (!pv || bitmap_empty(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN)) {
734 err = __br_fdb_add(ndm, p, addr, nlh_flags, 0);
735 goto out;
736 }
737
738 /* We have vlans configured on this port and user didn't
739 * specify a VLAN. To be nice, add/update entry for every
740 * vlan on this port.
741 */
Wei Yongjun74694e72013-03-11 05:45:23 +0000742 for_each_set_bit(vid, pv->vlan_bitmap, BR_VLAN_BITMAP_LEN) {
Vlad Yasevich1690be62013-02-13 12:00:18 +0000743 err = __br_fdb_add(ndm, p, addr, nlh_flags, vid);
744 if (err)
745 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000746 }
stephen hemminger292d1392011-11-09 18:30:08 +0000747 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000748
Vlad Yasevich1690be62013-02-13 12:00:18 +0000749out:
750 return err;
751}
752
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000753int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr,
754 u16 vlan)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000755{
756 struct hlist_head *head = &br->hash[br_mac_hash(addr, vlan)];
757 struct net_bridge_fdb_entry *fdb;
758
759 fdb = fdb_find(head, addr, vlan);
760 if (!fdb)
761 return -ENOENT;
762
763 fdb_delete(br, fdb);
764 return 0;
765}
766
767static int __br_fdb_delete(struct net_bridge_port *p,
768 const unsigned char *addr, u16 vid)
769{
770 int err;
771
772 spin_lock_bh(&p->br->hash_lock);
773 err = fdb_delete_by_addr(p->br, addr, vid);
774 spin_unlock_bh(&p->br->hash_lock);
775
stephen hemminger36fd2b62011-04-04 14:03:31 +0000776 return err;
777}
778
stephen hemminger36fd2b62011-04-04 14:03:31 +0000779/* Remove neighbor entry with RTM_DELNEIGH */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000780int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
781 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +0000782 const unsigned char *addr)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000783{
stephen hemminger36fd2b62011-04-04 14:03:31 +0000784 struct net_bridge_port *p;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000785 int err;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000786 struct net_port_vlans *pv;
787 unsigned short vid = VLAN_N_VID;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000788
Vlad Yasevich1690be62013-02-13 12:00:18 +0000789 if (tb[NDA_VLAN]) {
790 if (nla_len(tb[NDA_VLAN]) != sizeof(unsigned short)) {
791 pr_info("bridge: RTM_NEWNEIGH with invalid vlan\n");
792 return -EINVAL;
793 }
794
795 vid = nla_get_u16(tb[NDA_VLAN]);
796
797 if (vid >= VLAN_N_VID) {
798 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n",
799 vid);
800 return -EINVAL;
801 }
802 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000803 p = br_port_get_rtnl(dev);
804 if (p == NULL) {
805 pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n",
806 dev->name);
807 return -EINVAL;
808 }
809
Vlad Yasevich1690be62013-02-13 12:00:18 +0000810 pv = nbp_get_vlan_info(p);
811 if (vid != VLAN_N_VID) {
812 if (!pv || !test_bit(vid, pv->vlan_bitmap)) {
813 pr_info("bridge: RTM_DELNEIGH with unconfigured "
814 "vlan %d on port %s\n", vid, dev->name);
815 return -EINVAL;
816 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000817
Vlad Yasevich1690be62013-02-13 12:00:18 +0000818 err = __br_fdb_delete(p, addr, vid);
819 } else {
820 if (!pv || bitmap_empty(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN)) {
821 err = __br_fdb_delete(p, addr, 0);
822 goto out;
823 }
824
825 /* We have vlans configured on this port and user didn't
826 * specify a VLAN. To be nice, add/update entry for every
827 * vlan on this port.
828 */
829 err = -ENOENT;
Wei Yongjun74694e72013-03-11 05:45:23 +0000830 for_each_set_bit(vid, pv->vlan_bitmap, BR_VLAN_BITMAP_LEN) {
Vlad Yasevich1690be62013-02-13 12:00:18 +0000831 err &= __br_fdb_delete(p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000832 }
833 }
834out:
stephen hemminger36fd2b62011-04-04 14:03:31 +0000835 return err;
836}