blob: be5e1da6d824077933896379c3c551127714ba42 [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>
Scott Feldmanb4ad7ba2015-06-14 11:33:11 -070027#include <net/switchdev.h>
Roopa Prabhub74fd302017-08-29 13:16:57 -070028#include <trace/events/bridge.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "br_private.h"
30
Christoph Lametere18b8902006-12-06 20:33:20 -080031static struct kmem_cache *br_fdb_cache __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000033 const unsigned char *addr, u16 vid);
stephen hemminger31e8a49c2011-12-08 07:17:41 +000034static void fdb_notify(struct net_bridge *br,
35 const struct net_bridge_fdb_entry *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Stephen Hemminger3f890922007-03-21 13:42:33 -070037static u32 fdb_salt __read_mostly;
38
Akinobu Mita87a596e2007-04-07 18:57:07 +090039int __init br_fdb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 br_fdb_cache = kmem_cache_create("bridge_fdb_cache",
42 sizeof(struct net_bridge_fdb_entry),
43 0,
Paul Mundt20c2df82007-07-20 10:11:58 +090044 SLAB_HWCACHE_ALIGN, NULL);
Akinobu Mita87a596e2007-04-07 18:57:07 +090045 if (!br_fdb_cache)
46 return -ENOMEM;
47
Stephen Hemminger3f890922007-03-21 13:42:33 -070048 get_random_bytes(&fdb_salt, sizeof(fdb_salt));
Akinobu Mita87a596e2007-04-07 18:57:07 +090049 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
Andrew Morton73afc902007-12-05 21:35:23 -080052void br_fdb_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 kmem_cache_destroy(br_fdb_cache);
55}
56
57
58/* if topology_changing then use forward_delay (default 15 sec)
59 * otherwise keep longer (default 5 minutes)
60 */
Stephen Hemminger3f890922007-03-21 13:42:33 -070061static inline unsigned long hold_time(const struct net_bridge *br)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 return br->topology_change ? br->forward_delay : br->ageing_time;
64}
65
Stephen Hemminger3f890922007-03-21 13:42:33 -070066static inline int has_expired(const struct net_bridge *br,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 const struct net_bridge_fdb_entry *fdb)
68{
Roopa Prabhueda7a5e2017-02-16 13:38:04 -080069 return !fdb->is_static && !fdb->added_by_external_learn &&
stephen hemminger7cd88612011-04-04 14:03:28 +000070 time_before_eq(fdb->updated + hold_time(br), jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000073static inline int br_mac_hash(const unsigned char *mac, __u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000075 /* use 1 byte of OUI and 3 bytes of NIC */
Stephen Hemminger3f890922007-03-21 13:42:33 -070076 u32 key = get_unaligned((u32 *)(mac + 2));
Vlad Yasevich2ba071e2013-02-13 12:00:16 +000077 return jhash_2words(key, vid, fdb_salt) & (BR_HASH_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Michał Mirosławda678292009-06-05 05:35:28 +000080static void fdb_rcu_free(struct rcu_head *head)
81{
82 struct net_bridge_fdb_entry *ent
83 = container_of(head, struct net_bridge_fdb_entry, rcu);
84 kmem_cache_free(br_fdb_cache, ent);
85}
86
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +010087static struct net_bridge_fdb_entry *fdb_find_rcu(struct hlist_head *head,
88 const unsigned char *addr,
89 __u16 vid)
90{
91 struct net_bridge_fdb_entry *f;
92
Nikolay Aleksandrov410b3d42017-02-13 14:59:10 +010093 WARN_ON_ONCE(!rcu_read_lock_held());
94
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +010095 hlist_for_each_entry_rcu(f, head, hlist)
96 if (ether_addr_equal(f->addr.addr, addr) && f->vlan_id == vid)
97 break;
98
99 return f;
100}
101
102/* requires bridge hash_lock */
103static struct net_bridge_fdb_entry *br_fdb_find(struct net_bridge *br,
104 const unsigned char *addr,
105 __u16 vid)
106{
107 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
108 struct net_bridge_fdb_entry *fdb;
109
WANG Congd12c9172017-03-16 10:32:42 -0700110 lockdep_assert_held_once(&br->hash_lock);
Nikolay Aleksandrov410b3d42017-02-13 14:59:10 +0100111
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100112 rcu_read_lock();
113 fdb = fdb_find_rcu(head, addr, vid);
114 rcu_read_unlock();
115
116 return fdb;
117}
118
119struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
120 const unsigned char *addr,
121 __u16 vid)
122{
123 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
124
125 return fdb_find_rcu(head, addr, vid);
126}
127
Vlad Yasevich145beee2014-05-16 09:59:19 -0400128/* When a static FDB entry is added, the mac address from the entry is
129 * added to the bridge private HW address list and all required ports
130 * are then updated with the new information.
131 * Called under RTNL.
132 */
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100133static void fdb_add_hw_addr(struct net_bridge *br, const unsigned char *addr)
Vlad Yasevich145beee2014-05-16 09:59:19 -0400134{
135 int err;
Li RongQinga3f5ee72014-06-18 16:07:16 +0800136 struct net_bridge_port *p;
Vlad Yasevich145beee2014-05-16 09:59:19 -0400137
138 ASSERT_RTNL();
139
140 list_for_each_entry(p, &br->port_list, list) {
141 if (!br_promisc_port(p)) {
142 err = dev_uc_add(p->dev, addr);
143 if (err)
144 goto undo;
145 }
146 }
147
148 return;
149undo:
Li RongQinga3f5ee72014-06-18 16:07:16 +0800150 list_for_each_entry_continue_reverse(p, &br->port_list, list) {
151 if (!br_promisc_port(p))
152 dev_uc_del(p->dev, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400153 }
154}
155
156/* When a static FDB entry is deleted, the HW address from that entry is
157 * also removed from the bridge private HW address list and updates all
158 * the ports with needed information.
159 * Called under RTNL.
160 */
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100161static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
Vlad Yasevich145beee2014-05-16 09:59:19 -0400162{
163 struct net_bridge_port *p;
164
165 ASSERT_RTNL();
166
167 list_for_each_entry(p, &br->port_list, list) {
168 if (!br_promisc_port(p))
169 dev_uc_del(p->dev, addr);
170 }
171}
172
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000173static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Roopa Prabhub74fd302017-08-29 13:16:57 -0700175 trace_fdb_delete(br, f);
176
Vlad Yasevich145beee2014-05-16 09:59:19 -0400177 if (f->is_static)
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100178 fdb_del_hw_addr(br, f->addr.addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400179
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100180 hlist_del_init_rcu(&f->hlist);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000181 fdb_notify(br, f, RTM_DELNEIGH);
Michał Mirosławda678292009-06-05 05:35:28 +0000182 call_rcu(&f->rcu, fdb_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
Toshiaki Makita960b5892014-02-07 16:48:23 +0900185/* Delete a local entry if no other port had the same address. */
186static void fdb_delete_local(struct net_bridge *br,
187 const struct net_bridge_port *p,
188 struct net_bridge_fdb_entry *f)
189{
190 const unsigned char *addr = f->addr.addr;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200191 struct net_bridge_vlan_group *vg;
192 const struct net_bridge_vlan *v;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900193 struct net_bridge_port *op;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200194 u16 vid = f->vlan_id;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900195
196 /* Maybe another port has same hw addr? */
197 list_for_each_entry(op, &br->port_list, list) {
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200198 vg = nbp_vlan_group(op);
Toshiaki Makita960b5892014-02-07 16:48:23 +0900199 if (op != p && ether_addr_equal(op->dev->dev_addr, addr) &&
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200200 (!vid || br_vlan_find(vg, vid))) {
Toshiaki Makita960b5892014-02-07 16:48:23 +0900201 f->dst = op;
Toshiaki Makitaa778e6d2014-02-07 16:48:24 +0900202 f->added_by_user = 0;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900203 return;
204 }
205 }
206
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200207 vg = br_vlan_group(br);
208 v = br_vlan_find(vg, vid);
Toshiaki Makita960b5892014-02-07 16:48:23 +0900209 /* Maybe bridge device has same hw addr? */
210 if (p && ether_addr_equal(br->dev->dev_addr, addr) &&
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200211 (!vid || (v && br_vlan_should_use(v)))) {
Toshiaki Makita960b5892014-02-07 16:48:23 +0900212 f->dst = NULL;
Toshiaki Makitaa778e6d2014-02-07 16:48:24 +0900213 f->added_by_user = 0;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900214 return;
215 }
216
217 fdb_delete(br, f);
218}
219
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900220void br_fdb_find_delete_local(struct net_bridge *br,
221 const struct net_bridge_port *p,
222 const unsigned char *addr, u16 vid)
223{
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900224 struct net_bridge_fdb_entry *f;
225
226 spin_lock_bh(&br->hash_lock);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100227 f = br_fdb_find(br, addr, vid);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900228 if (f && f->is_local && !f->added_by_user && f->dst == p)
229 fdb_delete_local(br, p, f);
230 spin_unlock_bh(&br->hash_lock);
231}
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
234{
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200235 struct net_bridge_vlan_group *vg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 struct net_bridge *br = p->br;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200237 struct net_bridge_vlan *v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 int i;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 spin_lock_bh(&br->hash_lock);
241
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200242 vg = nbp_vlan_group(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 /* Search all chains since old address/hash is unknown */
244 for (i = 0; i < BR_HASH_SIZE; i++) {
245 struct hlist_node *h;
246 hlist_for_each(h, &br->hash[i]) {
247 struct net_bridge_fdb_entry *f;
248
249 f = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900250 if (f->dst == p && f->is_local && !f->added_by_user) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /* delete old one */
Toshiaki Makita960b5892014-02-07 16:48:23 +0900252 fdb_delete_local(br, p, f);
253
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000254 /* if this port has no vlan information
255 * configured, we can safely be done at
256 * this point.
257 */
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200258 if (!vg || !vg->num_vlans)
Toshiaki Makita28368822014-02-07 16:48:19 +0900259 goto insert;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261 }
262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Toshiaki Makita28368822014-02-07 16:48:19 +0900264insert:
265 /* insert new address, may fail if invalid address or dup. */
266 fdb_insert(br, p, newaddr, 0);
267
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200268 if (!vg || !vg->num_vlans)
Toshiaki Makita28368822014-02-07 16:48:19 +0900269 goto done;
270
271 /* Now add entries for every VLAN configured on the port.
272 * This function runs under RTNL so the bitmap will not change
273 * from under us.
274 */
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200275 list_for_each_entry(v, &vg->vlan_list, vlist)
276 fdb_insert(br, p, newaddr, v->vid);
Toshiaki Makita28368822014-02-07 16:48:19 +0900277
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000278done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 spin_unlock_bh(&br->hash_lock);
280}
281
stephen hemminger43598812011-12-08 07:17:49 +0000282void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
283{
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200284 struct net_bridge_vlan_group *vg;
stephen hemminger43598812011-12-08 07:17:49 +0000285 struct net_bridge_fdb_entry *f;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200286 struct net_bridge_vlan *v;
stephen hemminger43598812011-12-08 07:17:49 +0000287
Toshiaki Makitaac4c8862014-02-07 16:48:26 +0900288 spin_lock_bh(&br->hash_lock);
289
stephen hemminger43598812011-12-08 07:17:49 +0000290 /* If old entry was unassociated with any port, then delete it. */
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100291 f = br_fdb_find(br, br->dev->dev_addr, 0);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900292 if (f && f->is_local && !f->dst && !f->added_by_user)
Toshiaki Makita960b5892014-02-07 16:48:23 +0900293 fdb_delete_local(br, NULL, f);
stephen hemminger43598812011-12-08 07:17:49 +0000294
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000295 fdb_insert(br, NULL, newaddr, 0);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200296 vg = br_vlan_group(br);
297 if (!vg || !vg->num_vlans)
298 goto out;
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000299 /* Now remove and add entries for every VLAN configured on the
300 * bridge. This function runs under RTNL so the bitmap will not
301 * change from under us.
302 */
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200303 list_for_each_entry(v, &vg->vlan_list, vlist) {
Toshiaki Makita0b148de2016-06-07 19:14:17 +0900304 if (!br_vlan_should_use(v))
305 continue;
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100306 f = br_fdb_find(br, br->dev->dev_addr, v->vid);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900307 if (f && f->is_local && !f->dst && !f->added_by_user)
Toshiaki Makita960b5892014-02-07 16:48:23 +0900308 fdb_delete_local(br, NULL, f);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200309 fdb_insert(br, NULL, newaddr, v->vid);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000310 }
Toshiaki Makitaac4c8862014-02-07 16:48:26 +0900311out:
312 spin_unlock_bh(&br->hash_lock);
stephen hemminger43598812011-12-08 07:17:49 +0000313}
314
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100315void br_fdb_cleanup(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100317 struct net_bridge *br = container_of(work, struct net_bridge,
318 gc_work.work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 unsigned long delay = hold_time(br);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100320 unsigned long work_delay = delay;
321 unsigned long now = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 int i;
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 for (i = 0; i < BR_HASH_SIZE; i++) {
325 struct net_bridge_fdb_entry *f;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800326 struct hlist_node *n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100328 if (!br->hash[i].first)
329 continue;
330
331 spin_lock_bh(&br->hash_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800332 hlist_for_each_entry_safe(f, n, &br->hash[i], hlist) {
Baruch Even071f7722007-05-31 01:20:45 -0700333 unsigned long this_timer;
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100334
David S. Miller3fcf9012015-02-04 23:52:44 -0800335 if (f->is_static)
Baruch Even071f7722007-05-31 01:20:45 -0700336 continue;
Siva Mannemdcd45e02015-09-23 08:39:19 -0700337 if (f->added_by_external_learn)
338 continue;
stephen hemminger7cd88612011-04-04 14:03:28 +0000339 this_timer = f->updated + delay;
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100340 if (time_after(this_timer, now))
341 work_delay = min(work_delay, this_timer - now);
342 else
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000343 fdb_delete(br, f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100345 spin_unlock_bh(&br->hash_lock);
346 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100349 /* Cleanup minimum 10 milliseconds apart */
350 work_delay = max_t(unsigned long, work_delay, msecs_to_jiffies(10));
351 mod_delayed_work(system_long_wq, &br->gc_work, work_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700354/* Completely flush all dynamic entries in forwarding database.*/
355void br_fdb_flush(struct net_bridge *br)
356{
357 int i;
Stephen Hemminger1a620692006-10-12 14:45:38 -0700358
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700359 spin_lock_bh(&br->hash_lock);
360 for (i = 0; i < BR_HASH_SIZE; i++) {
361 struct net_bridge_fdb_entry *f;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800362 struct hlist_node *n;
363 hlist_for_each_entry_safe(f, n, &br->hash[i], hlist) {
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700364 if (!f->is_static)
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000365 fdb_delete(br, f);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700366 }
367 }
368 spin_unlock_bh(&br->hash_lock);
369}
370
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300371/* Flush all entries referring to a specific port.
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700372 * if do_all is set also flush static entries
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700373 * if vid is set delete all entries that match the vlan_id
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700374 */
Stephen Hemminger1a620692006-10-12 14:45:38 -0700375void br_fdb_delete_by_port(struct net_bridge *br,
376 const struct net_bridge_port *p,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700377 u16 vid,
Stephen Hemminger1a620692006-10-12 14:45:38 -0700378 int do_all)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 int i;
381
382 spin_lock_bh(&br->hash_lock);
383 for (i = 0; i < BR_HASH_SIZE; i++) {
384 struct hlist_node *h, *g;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 hlist_for_each_safe(h, g, &br->hash[i]) {
387 struct net_bridge_fdb_entry *f
388 = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900389 if (f->dst != p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 continue;
391
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700392 if (!do_all)
393 if (f->is_static || (vid && f->vlan_id != vid))
394 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Toshiaki Makitaa778e6d2014-02-07 16:48:24 +0900396 if (f->is_local)
397 fdb_delete_local(br, p, f);
398 else
399 fdb_delete(br, f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401 }
402 spin_unlock_bh(&br->hash_lock);
403}
404
Igor Maraviće6373c42011-12-12 02:58:25 +0000405#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +0000406/* Interface used by ATM LANE hook to test
407 * if an addr is on some other bridge port */
408int br_fdb_test_addr(struct net_device *dev, unsigned char *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
410 struct net_bridge_fdb_entry *fdb;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000411 struct net_bridge_port *port;
Michał Mirosławda678292009-06-05 05:35:28 +0000412 int ret;
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 rcu_read_lock();
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000415 port = br_port_get_rcu(dev);
416 if (!port)
417 ret = 0;
418 else {
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100419 fdb = br_fdb_find_rcu(port->br, addr, 0);
stephen hemminger43598812011-12-08 07:17:49 +0000420 ret = fdb && fdb->dst && fdb->dst->dev != dev &&
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000421 fdb->dst->state == BR_STATE_FORWARDING;
422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Michał Mirosławda678292009-06-05 05:35:28 +0000425 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
Michał Mirosławda678292009-06-05 05:35:28 +0000427#endif /* CONFIG_ATM_LANE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429/*
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900430 * Fill buffer with forwarding table records in
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 * the API format.
432 */
433int br_fdb_fillbuf(struct net_bridge *br, void *buf,
434 unsigned long maxnum, unsigned long skip)
435{
436 struct __fdb_entry *fe = buf;
437 int i, num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 struct net_bridge_fdb_entry *f;
439
440 memset(buf, 0, maxnum*sizeof(struct __fdb_entry));
441
442 rcu_read_lock();
443 for (i = 0; i < BR_HASH_SIZE; i++) {
Sasha Levinb67bfe02013-02-27 17:06:00 -0800444 hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 if (num >= maxnum)
446 goto out;
447
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900448 if (has_expired(br, f))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 continue;
450
stephen hemminger43598812011-12-08 07:17:49 +0000451 /* ignore pseudo entry for local MAC address */
452 if (!f->dst)
453 continue;
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if (skip) {
456 --skip;
457 continue;
458 }
459
460 /* convert from internal format to API */
461 memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN);
Stephen Hemmingerae4f8fc2008-05-02 16:53:33 -0700462
463 /* due to ABI compat need to split into hi/lo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 fe->port_no = f->dst->port_no;
Stephen Hemmingerae4f8fc2008-05-02 16:53:33 -0700465 fe->port_hi = f->dst->port_no >> 8;
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 fe->is_local = f->is_local;
468 if (!f->is_static)
Eric Dumazeta399a802012-08-08 21:13:53 +0000469 fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 ++fe;
471 ++num;
472 }
473 }
474
475 out:
476 rcu_read_unlock();
477
478 return num;
479}
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head,
482 struct net_bridge_port *source,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000483 const unsigned char *addr,
Roopa Prabhub7af1472015-10-27 07:52:56 -0700484 __u16 vid,
485 unsigned char is_local,
486 unsigned char is_static)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
488 struct net_bridge_fdb_entry *fdb;
489
490 fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC);
491 if (fdb) {
492 memcpy(fdb->addr.addr, addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 fdb->dst = source;
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000494 fdb->vlan_id = vid;
Roopa Prabhub7af1472015-10-27 07:52:56 -0700495 fdb->is_local = is_local;
496 fdb->is_static = is_static;
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900497 fdb->added_by_user = 0;
Scott Feldmancf6b8e12014-11-28 14:34:21 +0100498 fdb->added_by_external_learn = 0;
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200499 fdb->offloaded = 0;
stephen hemminger7cd88612011-04-04 14:03:28 +0000500 fdb->updated = fdb->used = jiffies;
Pavel Emelyanov1158f762011-02-04 13:02:36 -0800501 hlist_add_head_rcu(&fdb->hlist, head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 return fdb;
504}
505
506static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000507 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000509 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 struct net_bridge_fdb_entry *fdb;
511
512 if (!is_valid_ether_addr(addr))
513 return -EINVAL;
514
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100515 fdb = br_fdb_find(br, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (fdb) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900517 /* it is okay to have multiple ports with same
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 * address, just use the first one.
519 */
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900520 if (fdb->is_local)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 return 0;
Roopa Prabhude1dfee2016-10-11 16:12:56 -0700522 br_warn(br, "adding interface %s with same address as a received packet (addr:%pM, vlan:%u)\n",
523 source ? source->dev->name : br->dev->name, addr, vid);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000524 fdb_delete(br, fdb);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Roopa Prabhub7af1472015-10-27 07:52:56 -0700527 fdb = fdb_create(head, source, addr, vid, 1, 1);
stephen hemminger03e9b642011-04-04 14:03:27 +0000528 if (!fdb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return -ENOMEM;
530
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100531 fdb_add_hw_addr(br, addr);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000532 fdb_notify(br, fdb, RTM_NEWNEIGH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 return 0;
534}
535
stephen hemminger03e9b642011-04-04 14:03:27 +0000536/* Add entry for local address of interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000538 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 int ret;
541
542 spin_lock_bh(&br->hash_lock);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000543 ret = fdb_insert(br, source, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 spin_unlock_bh(&br->hash_lock);
545 return ret;
546}
547
548void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900549 const unsigned char *addr, u16 vid, bool added_by_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000551 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 struct net_bridge_fdb_entry *fdb;
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000553 bool fdb_modified = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 /* some users want to always flood. */
556 if (hold_time(br) == 0)
557 return;
558
Stephen Hemmingerdf1c0b82007-08-30 22:15:35 -0700559 /* ignore packets unless we are using this port */
560 if (!(source->state == BR_STATE_LEARNING ||
561 source->state == BR_STATE_FORWARDING))
562 return;
563
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000564 fdb = fdb_find_rcu(head, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (likely(fdb)) {
566 /* attempt to update an entry for a local interface */
567 if (unlikely(fdb->is_local)) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900568 if (net_ratelimit())
Roopa Prabhude1dfee2016-10-11 16:12:56 -0700569 br_warn(br, "received packet on %s with own address as source address (addr:%pM, vlan:%u)\n",
570 source->dev->name, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 } else {
stephen hemmingerca6d4482017-02-07 08:46:46 -0800572 unsigned long now = jiffies;
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* fastpath: update of existing entry */
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000575 if (unlikely(source != fdb->dst)) {
576 fdb->dst = source;
577 fdb_modified = true;
Arkadi Sharshevsky58073b32017-04-28 22:39:07 +0300578 /* Take over HW learned entry */
579 if (unlikely(fdb->added_by_external_learn))
580 fdb->added_by_external_learn = 0;
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000581 }
stephen hemmingerca6d4482017-02-07 08:46:46 -0800582 if (now != fdb->updated)
583 fdb->updated = now;
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900584 if (unlikely(added_by_user))
585 fdb->added_by_user = 1;
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000586 if (unlikely(fdb_modified))
587 fdb_notify(br, fdb, RTM_NEWNEIGH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589 } else {
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800590 spin_lock(&br->hash_lock);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100591 if (likely(!fdb_find_rcu(head, addr, vid))) {
Roopa Prabhub7af1472015-10-27 07:52:56 -0700592 fdb = fdb_create(head, source, addr, vid, 0, 0);
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900593 if (fdb) {
594 if (unlikely(added_by_user))
595 fdb->added_by_user = 1;
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000596 fdb_notify(br, fdb, RTM_NEWNEIGH);
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900597 }
stephen hemmingerf58ee4e2011-12-06 13:02:24 +0000598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 /* else we lose race and someone else inserts
600 * it first, don't bother updating
601 */
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800602 spin_unlock(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000605
Roopa Prabhu37418732015-10-08 10:38:52 -0700606static int fdb_to_nud(const struct net_bridge *br,
607 const struct net_bridge_fdb_entry *fdb)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000608{
609 if (fdb->is_local)
610 return NUD_PERMANENT;
611 else if (fdb->is_static)
612 return NUD_NOARP;
Roopa Prabhu37418732015-10-08 10:38:52 -0700613 else if (has_expired(br, fdb))
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000614 return NUD_STALE;
615 else
616 return NUD_REACHABLE;
617}
618
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000619static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000620 const struct net_bridge_fdb_entry *fdb,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000621 u32 portid, u32 seq, int type, unsigned int flags)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000622{
623 unsigned long now = jiffies;
624 struct nda_cacheinfo ci;
625 struct nlmsghdr *nlh;
626 struct ndmsg *ndm;
627
Eric W. Biederman15e47302012-09-07 20:12:54 +0000628 nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000629 if (nlh == NULL)
630 return -EMSGSIZE;
631
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000632 ndm = nlmsg_data(nlh);
633 ndm->ndm_family = AF_BRIDGE;
634 ndm->ndm_pad1 = 0;
635 ndm->ndm_pad2 = 0;
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200636 ndm->ndm_flags = 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000637 ndm->ndm_type = 0;
stephen hemminger43598812011-12-08 07:17:49 +0000638 ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex;
Roopa Prabhu37418732015-10-08 10:38:52 -0700639 ndm->ndm_state = fdb_to_nud(br, fdb);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000640
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200641 if (fdb->offloaded)
642 ndm->ndm_flags |= NTF_OFFLOADED;
643 if (fdb->added_by_external_learn)
644 ndm->ndm_flags |= NTF_EXT_LEARNED;
645
David S. Miller2eb812e2012-04-01 20:49:54 -0400646 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->addr))
647 goto nla_put_failure;
Roopa Prabhu41c389d2014-05-27 22:39:37 -0700648 if (nla_put_u32(skb, NDA_MASTER, br->dev->ifindex))
649 goto nla_put_failure;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000650 ci.ndm_used = jiffies_to_clock_t(now - fdb->used);
651 ci.ndm_confirmed = 0;
652 ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated);
653 ci.ndm_refcnt = 0;
David S. Miller2eb812e2012-04-01 20:49:54 -0400654 if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
655 goto nla_put_failure;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000656
Toshiaki Makita47fab412014-07-30 13:31:51 +0900657 if (fdb->vlan_id && nla_put(skb, NDA_VLAN, sizeof(u16), &fdb->vlan_id))
Vlad Yasevich1690be62013-02-13 12:00:18 +0000658 goto nla_put_failure;
659
Johannes Berg053c0952015-01-16 22:09:00 +0100660 nlmsg_end(skb, nlh);
661 return 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000662
663nla_put_failure:
664 nlmsg_cancel(skb, nlh);
665 return -EMSGSIZE;
666}
667
668static inline size_t fdb_nlmsg_size(void)
669{
670 return NLMSG_ALIGN(sizeof(struct ndmsg))
671 + nla_total_size(ETH_ALEN) /* NDA_LLADDR */
Roopa Prabhu41c389d2014-05-27 22:39:37 -0700672 + nla_total_size(sizeof(u32)) /* NDA_MASTER */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000673 + nla_total_size(sizeof(u16)) /* NDA_VLAN */
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000674 + nla_total_size(sizeof(struct nda_cacheinfo));
675}
676
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000677static void fdb_notify(struct net_bridge *br,
678 const struct net_bridge_fdb_entry *fdb, int type)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000679{
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000680 struct net *net = dev_net(br->dev);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000681 struct sk_buff *skb;
682 int err = -ENOBUFS;
683
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +0200684 br_switchdev_fdb_notify(fdb, type);
685
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000686 skb = nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC);
687 if (skb == NULL)
688 goto errout;
689
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000690 err = fdb_fill_info(skb, br, fdb, 0, 0, type, 0);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000691 if (err < 0) {
692 /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */
693 WARN_ON(err == -EMSGSIZE);
694 kfree_skb(skb);
695 goto errout;
696 }
697 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
698 return;
699errout:
tanxiaojun87e823b2013-12-19 13:28:10 +0800700 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000701}
702
703/* Dump information about entries, in response to GETNEIGH */
John Fastabend77162022012-04-15 06:43:56 +0000704int br_fdb_dump(struct sk_buff *skb,
705 struct netlink_callback *cb,
706 struct net_device *dev,
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400707 struct net_device *filter_dev,
Roopa Prabhud2976532016-08-30 21:56:45 -0700708 int *idx)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000709{
John Fastabend77162022012-04-15 06:43:56 +0000710 struct net_bridge *br = netdev_priv(dev);
Roopa Prabhud2976532016-08-30 21:56:45 -0700711 int err = 0;
John Fastabend77162022012-04-15 06:43:56 +0000712 int i;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000713
John Fastabend77162022012-04-15 06:43:56 +0000714 if (!(dev->priv_flags & IFF_EBRIDGE))
715 goto out;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000716
Roopa Prabhud2976532016-08-30 21:56:45 -0700717 if (!filter_dev) {
718 err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
719 if (err < 0)
720 goto out;
721 }
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000722
John Fastabend77162022012-04-15 06:43:56 +0000723 for (i = 0; i < BR_HASH_SIZE; i++) {
John Fastabend77162022012-04-15 06:43:56 +0000724 struct net_bridge_fdb_entry *f;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000725
Sasha Levinb67bfe02013-02-27 17:06:00 -0800726 hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
MINOURA Makoto / 箕浦 真472681d2016-02-25 14:20:48 +0900727
Roopa Prabhud2976532016-08-30 21:56:45 -0700728 if (*idx < cb->args[2])
John Fastabend77162022012-04-15 06:43:56 +0000729 goto skip;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000730
Jamal Hadi Salim5e6d2432014-07-10 07:01:59 -0400731 if (filter_dev &&
732 (!f->dst || f->dst->dev != filter_dev)) {
733 if (filter_dev != dev)
734 goto skip;
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000735 /* !f->dst is a special case for bridge
Jamal Hadi Salim5e6d2432014-07-10 07:01:59 -0400736 * It means the MAC belongs to the bridge
737 * Therefore need a little more filtering
738 * we only want to dump the !f->dst case
739 */
740 if (f->dst)
741 goto skip;
742 }
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000743 if (!filter_dev && f->dst)
744 goto skip;
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400745
MINOURA Makoto / 箕浦 真472681d2016-02-25 14:20:48 +0900746 err = fdb_fill_info(skb, br, f,
747 NETLINK_CB(cb->skb).portid,
748 cb->nlh->nlmsg_seq,
749 RTM_NEWNEIGH,
750 NLM_F_MULTI);
Roopa Prabhud2976532016-08-30 21:56:45 -0700751 if (err < 0)
752 goto out;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000753skip:
Roopa Prabhud2976532016-08-30 21:56:45 -0700754 *idx += 1;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000755 }
756 }
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000757
John Fastabend77162022012-04-15 06:43:56 +0000758out:
Roopa Prabhud2976532016-08-30 21:56:45 -0700759 return err;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000760}
stephen hemminger36fd2b62011-04-04 14:03:31 +0000761
stephen hemminger292d1392011-11-09 18:30:08 +0000762/* Update (create or replace) forwarding database entry */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900763static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
764 const __u8 *addr, __u16 state, __u16 flags, __u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000765{
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000766 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
stephen hemminger36fd2b62011-04-04 14:03:31 +0000767 struct net_bridge_fdb_entry *fdb;
roopab0a397f2013-04-22 12:56:49 +0000768 bool modified = false;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000769
Wilson Kokeb8d7ba2015-05-25 06:39:31 -0700770 /* If the port cannot learn allow only local and static entries */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900771 if (source && !(state & NUD_PERMANENT) && !(state & NUD_NOARP) &&
Wilson Kokeb8d7ba2015-05-25 06:39:31 -0700772 !(source->state == BR_STATE_LEARNING ||
773 source->state == BR_STATE_FORWARDING))
774 return -EPERM;
775
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900776 if (!source && !(state & NUD_PERMANENT)) {
777 pr_info("bridge: RTM_NEWNEIGH %s without NUD_PERMANENT\n",
778 br->dev->name);
779 return -EINVAL;
780 }
781
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100782 fdb = br_fdb_find(br, addr, vid);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000783 if (fdb == NULL) {
784 if (!(flags & NLM_F_CREATE))
785 return -ENOENT;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000786
Roopa Prabhub7af1472015-10-27 07:52:56 -0700787 fdb = fdb_create(head, source, addr, vid, 0, 0);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000788 if (!fdb)
789 return -ENOMEM;
roopab0a397f2013-04-22 12:56:49 +0000790
791 modified = true;
stephen hemminger64af1ba2011-09-30 14:37:27 +0000792 } else {
793 if (flags & NLM_F_EXCL)
794 return -EEXIST;
roopab0a397f2013-04-22 12:56:49 +0000795
796 if (fdb->dst != source) {
797 fdb->dst = source;
798 modified = true;
799 }
stephen hemminger64af1ba2011-09-30 14:37:27 +0000800 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000801
Roopa Prabhu37418732015-10-08 10:38:52 -0700802 if (fdb_to_nud(br, fdb) != state) {
Vlad Yasevich145beee2014-05-16 09:59:19 -0400803 if (state & NUD_PERMANENT) {
804 fdb->is_local = 1;
805 if (!fdb->is_static) {
806 fdb->is_static = 1;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100807 fdb_add_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400808 }
809 } else if (state & NUD_NOARP) {
stephen hemminger292d1392011-11-09 18:30:08 +0000810 fdb->is_local = 0;
Vlad Yasevich145beee2014-05-16 09:59:19 -0400811 if (!fdb->is_static) {
812 fdb->is_static = 1;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100813 fdb_add_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400814 }
815 } else {
816 fdb->is_local = 0;
817 if (fdb->is_static) {
818 fdb->is_static = 0;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100819 fdb_del_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400820 }
821 }
stephen hemminger292d1392011-11-09 18:30:08 +0000822
roopab0a397f2013-04-22 12:56:49 +0000823 modified = true;
824 }
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900825 fdb->added_by_user = 1;
roopab0a397f2013-04-22 12:56:49 +0000826
827 fdb->used = jiffies;
828 if (modified) {
829 fdb->updated = jiffies;
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000830 fdb_notify(br, fdb, RTM_NEWNEIGH);
stephen hemminger292d1392011-11-09 18:30:08 +0000831 }
832
stephen hemminger36fd2b62011-04-04 14:03:31 +0000833 return 0;
834}
835
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900836static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
837 struct net_bridge_port *p, const unsigned char *addr,
838 u16 nlh_flags, u16 vid)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000839{
840 int err = 0;
841
842 if (ndm->ndm_flags & NTF_USE) {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900843 if (!p) {
844 pr_info("bridge: RTM_NEWNEIGH %s with NTF_USE is not supported\n",
845 br->dev->name);
846 return -EINVAL;
847 }
Nikolay Aleksandrovc4c832f2015-06-06 06:49:00 -0700848 local_bh_disable();
Vlad Yasevich1690be62013-02-13 12:00:18 +0000849 rcu_read_lock();
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900850 br_fdb_update(br, p, addr, vid, true);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000851 rcu_read_unlock();
Nikolay Aleksandrovc4c832f2015-06-06 06:49:00 -0700852 local_bh_enable();
Nikolay Aleksandroveb100e02017-03-23 12:27:13 +0200853 } else if (ndm->ndm_flags & NTF_EXT_LEARNED) {
854 err = br_fdb_external_learn_add(br, p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000855 } else {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900856 spin_lock_bh(&br->hash_lock);
857 err = fdb_add_entry(br, p, addr, ndm->ndm_state,
Vlad Yasevich1690be62013-02-13 12:00:18 +0000858 nlh_flags, vid);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900859 spin_unlock_bh(&br->hash_lock);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000860 }
861
862 return err;
863}
864
stephen hemminger36fd2b62011-04-04 14:03:31 +0000865/* Add new permanent fdb entry with RTM_NEWNEIGH */
stephen hemmingeredc7d572012-10-01 12:32:33 +0000866int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
867 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100868 const unsigned char *addr, u16 vid, u16 nlh_flags)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000869{
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200870 struct net_bridge_vlan_group *vg;
Roopa Prabhu37418732015-10-08 10:38:52 -0700871 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200872 struct net_bridge_vlan *v;
Roopa Prabhu37418732015-10-08 10:38:52 -0700873 struct net_bridge *br = NULL;
John Fastabend77162022012-04-15 06:43:56 +0000874 int err = 0;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000875
Roopa Prabhub74fd302017-08-29 13:16:57 -0700876 trace_br_fdb_add(ndm, dev, addr, vid, nlh_flags);
877
stephen hemminger292d1392011-11-09 18:30:08 +0000878 if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE))) {
879 pr_info("bridge: RTM_NEWNEIGH with invalid state %#x\n", ndm->ndm_state);
880 return -EINVAL;
881 }
882
Stephen Hemminger537f7f82013-06-25 09:34:36 -0700883 if (is_zero_ether_addr(addr)) {
884 pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n");
885 return -EINVAL;
886 }
887
Roopa Prabhu37418732015-10-08 10:38:52 -0700888 if (dev->priv_flags & IFF_EBRIDGE) {
889 br = netdev_priv(dev);
890 vg = br_vlan_group(br);
891 } else {
892 p = br_port_get_rtnl(dev);
893 if (!p) {
894 pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n",
895 dev->name);
896 return -EINVAL;
897 }
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900898 br = p->br;
Roopa Prabhu37418732015-10-08 10:38:52 -0700899 vg = nbp_vlan_group(p);
stephen hemminger36fd2b62011-04-04 14:03:31 +0000900 }
901
Jiri Pirkof6f64242014-11-28 14:34:15 +0100902 if (vid) {
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200903 v = br_vlan_find(vg, vid);
Roopa Prabhu37418732015-10-08 10:38:52 -0700904 if (!v || !br_vlan_should_use(v)) {
905 pr_info("bridge: RTM_NEWNEIGH with unconfigured vlan %d on %s\n", vid, dev->name);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000906 return -EINVAL;
907 }
908
909 /* VID was specified, so use it. */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900910 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid);
stephen hemminger292d1392011-11-09 18:30:08 +0000911 } else {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900912 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200913 if (err || !vg || !vg->num_vlans)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000914 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000915
916 /* We have vlans configured on this port and user didn't
917 * specify a VLAN. To be nice, add/update entry for every
918 * vlan on this port.
919 */
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200920 list_for_each_entry(v, &vg->vlan_list, vlist) {
Roopa Prabhu37418732015-10-08 10:38:52 -0700921 if (!br_vlan_should_use(v))
922 continue;
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900923 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000924 if (err)
925 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000926 }
stephen hemminger292d1392011-11-09 18:30:08 +0000927 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000928
Vlad Yasevich1690be62013-02-13 12:00:18 +0000929out:
930 return err;
931}
932
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100933static int fdb_delete_by_addr_and_port(struct net_bridge *br,
934 const struct net_bridge_port *p,
Nikolay Aleksandrov8c86f962015-06-09 03:34:13 -0700935 const u8 *addr, u16 vlan)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000936{
Vlad Yasevich1690be62013-02-13 12:00:18 +0000937 struct net_bridge_fdb_entry *fdb;
938
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100939 fdb = br_fdb_find(br, addr, vlan);
Nikolay Aleksandrov8c86f962015-06-09 03:34:13 -0700940 if (!fdb || fdb->dst != p)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000941 return -ENOENT;
942
943 fdb_delete(br, fdb);
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100944
Vlad Yasevich1690be62013-02-13 12:00:18 +0000945 return 0;
946}
947
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100948static int __br_fdb_delete(struct net_bridge *br,
949 const struct net_bridge_port *p,
Vlad Yasevich1690be62013-02-13 12:00:18 +0000950 const unsigned char *addr, u16 vid)
951{
952 int err;
953
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100954 spin_lock_bh(&br->hash_lock);
955 err = fdb_delete_by_addr_and_port(br, p, addr, vid);
956 spin_unlock_bh(&br->hash_lock);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000957
stephen hemminger36fd2b62011-04-04 14:03:31 +0000958 return err;
959}
960
stephen hemminger36fd2b62011-04-04 14:03:31 +0000961/* Remove neighbor entry with RTM_DELNEIGH */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000962int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
963 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100964 const unsigned char *addr, u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000965{
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200966 struct net_bridge_vlan_group *vg;
Roopa Prabhu37418732015-10-08 10:38:52 -0700967 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200968 struct net_bridge_vlan *v;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100969 struct net_bridge *br;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000970 int err;
971
Roopa Prabhu37418732015-10-08 10:38:52 -0700972 if (dev->priv_flags & IFF_EBRIDGE) {
973 br = netdev_priv(dev);
974 vg = br_vlan_group(br);
975 } else {
976 p = br_port_get_rtnl(dev);
977 if (!p) {
978 pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n",
979 dev->name);
980 return -EINVAL;
981 }
982 vg = nbp_vlan_group(p);
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100983 br = p->br;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000984 }
985
Jiri Pirkof6f64242014-11-28 14:34:15 +0100986 if (vid) {
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200987 v = br_vlan_find(vg, vid);
988 if (!v) {
Roopa Prabhu37418732015-10-08 10:38:52 -0700989 pr_info("bridge: RTM_DELNEIGH with unconfigured vlan %d on %s\n", vid, dev->name);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000990 return -EINVAL;
991 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000992
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100993 err = __br_fdb_delete(br, p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000994 } else {
Toshiaki Makita25d3b492015-02-09 20:16:17 +0900995 err = -ENOENT;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100996 err &= __br_fdb_delete(br, p, addr, 0);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200997 if (!vg || !vg->num_vlans)
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100998 return err;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000999
Roopa Prabhu37418732015-10-08 10:38:52 -07001000 list_for_each_entry(v, &vg->vlan_list, vlist) {
1001 if (!br_vlan_should_use(v))
1002 continue;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +01001003 err &= __br_fdb_delete(br, p, addr, v->vid);
Roopa Prabhu37418732015-10-08 10:38:52 -07001004 }
Vlad Yasevich1690be62013-02-13 12:00:18 +00001005 }
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +01001006
stephen hemminger36fd2b62011-04-04 14:03:31 +00001007 return err;
1008}
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001009
1010int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p)
1011{
1012 struct net_bridge_fdb_entry *fdb, *tmp;
1013 int i;
1014 int err;
1015
1016 ASSERT_RTNL();
1017
1018 for (i = 0; i < BR_HASH_SIZE; i++) {
1019 hlist_for_each_entry(fdb, &br->hash[i], hlist) {
1020 /* We only care for static entries */
1021 if (!fdb->is_static)
1022 continue;
1023
1024 err = dev_uc_add(p->dev, fdb->addr.addr);
1025 if (err)
1026 goto rollback;
1027 }
1028 }
1029 return 0;
1030
1031rollback:
1032 for (i = 0; i < BR_HASH_SIZE; i++) {
1033 hlist_for_each_entry(tmp, &br->hash[i], hlist) {
1034 /* If we reached the fdb that failed, we can stop */
1035 if (tmp == fdb)
1036 break;
1037
1038 /* We only care for static entries */
1039 if (!tmp->is_static)
1040 continue;
1041
1042 dev_uc_del(p->dev, tmp->addr.addr);
1043 }
1044 }
1045 return err;
1046}
1047
1048void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p)
1049{
1050 struct net_bridge_fdb_entry *fdb;
1051 int i;
1052
1053 ASSERT_RTNL();
1054
1055 for (i = 0; i < BR_HASH_SIZE; i++) {
1056 hlist_for_each_entry_rcu(fdb, &br->hash[i], hlist) {
1057 /* We only care for static entries */
1058 if (!fdb->is_static)
1059 continue;
1060
1061 dev_uc_del(p->dev, fdb->addr.addr);
1062 }
1063 }
1064}
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001065
Jiri Pirko3aeb6612015-01-15 23:49:37 +01001066int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001067 const unsigned char *addr, u16 vid)
1068{
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001069 struct net_bridge_fdb_entry *fdb;
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001070 struct hlist_head *head;
1071 bool modified = false;
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001072 int err = 0;
1073
Roopa Prabhub74fd302017-08-29 13:16:57 -07001074 trace_br_fdb_external_learn_add(br, p, addr, vid);
1075
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001076 spin_lock_bh(&br->hash_lock);
1077
1078 head = &br->hash[br_mac_hash(addr, vid)];
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +01001079 fdb = br_fdb_find(br, addr, vid);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001080 if (!fdb) {
Roopa Prabhub7af1472015-10-27 07:52:56 -07001081 fdb = fdb_create(head, p, addr, vid, 0, 0);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001082 if (!fdb) {
1083 err = -ENOMEM;
1084 goto err_unlock;
1085 }
1086 fdb->added_by_external_learn = 1;
1087 fdb_notify(br, fdb, RTM_NEWNEIGH);
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001088 } else {
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001089 fdb->updated = jiffies;
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001090
1091 if (fdb->dst != p) {
1092 fdb->dst = p;
1093 modified = true;
1094 }
1095
1096 if (fdb->added_by_external_learn) {
1097 /* Refresh entry */
1098 fdb->used = jiffies;
1099 } else if (!fdb->added_by_user) {
1100 /* Take over SW learned entry */
1101 fdb->added_by_external_learn = 1;
1102 modified = true;
1103 }
1104
1105 if (modified)
1106 fdb_notify(br, fdb, RTM_NEWNEIGH);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001107 }
1108
1109err_unlock:
1110 spin_unlock_bh(&br->hash_lock);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001111
1112 return err;
1113}
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001114
Jiri Pirko3aeb6612015-01-15 23:49:37 +01001115int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001116 const unsigned char *addr, u16 vid)
1117{
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001118 struct net_bridge_fdb_entry *fdb;
1119 int err = 0;
1120
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001121 spin_lock_bh(&br->hash_lock);
1122
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +01001123 fdb = br_fdb_find(br, addr, vid);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001124 if (fdb && fdb->added_by_external_learn)
1125 fdb_delete(br, fdb);
1126 else
1127 err = -ENOENT;
1128
1129 spin_unlock_bh(&br->hash_lock);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001130
1131 return err;
1132}
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +02001133
1134void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
1135 const unsigned char *addr, u16 vid)
1136{
1137 struct net_bridge_fdb_entry *fdb;
1138
1139 spin_lock_bh(&br->hash_lock);
1140
1141 fdb = br_fdb_find(br, addr, vid);
1142 if (fdb)
1143 fdb->offloaded = 1;
1144
1145 spin_unlock_bh(&br->hash_lock);
1146}