blob: d9e69e4514beb20d5d8a3672e26d5cc9edfc16fa [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
Nikolay Aleksandroveb793582017-12-12 16:02:50 +020031static const struct rhashtable_params br_fdb_rht_params = {
32 .head_offset = offsetof(struct net_bridge_fdb_entry, rhnode),
33 .key_offset = offsetof(struct net_bridge_fdb_entry, key),
34 .key_len = sizeof(struct net_bridge_fdb_key),
35 .automatic_shrinking = true,
36 .locks_mul = 1,
37};
38
Christoph Lametere18b8902006-12-06 20:33:20 -080039static struct kmem_cache *br_fdb_cache __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000041 const unsigned char *addr, u16 vid);
stephen hemminger31e8a49c2011-12-08 07:17:41 +000042static void fdb_notify(struct net_bridge *br,
43 const struct net_bridge_fdb_entry *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Akinobu Mita87a596e2007-04-07 18:57:07 +090045int __init br_fdb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 br_fdb_cache = kmem_cache_create("bridge_fdb_cache",
48 sizeof(struct net_bridge_fdb_entry),
49 0,
Paul Mundt20c2df82007-07-20 10:11:58 +090050 SLAB_HWCACHE_ALIGN, NULL);
Akinobu Mita87a596e2007-04-07 18:57:07 +090051 if (!br_fdb_cache)
52 return -ENOMEM;
53
Akinobu Mita87a596e2007-04-07 18:57:07 +090054 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Andrew Morton73afc902007-12-05 21:35:23 -080057void br_fdb_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 kmem_cache_destroy(br_fdb_cache);
60}
61
Nikolay Aleksandroveb793582017-12-12 16:02:50 +020062int br_fdb_hash_init(struct net_bridge *br)
63{
64 return rhashtable_init(&br->fdb_hash_tbl, &br_fdb_rht_params);
65}
66
67void br_fdb_hash_fini(struct net_bridge *br)
68{
69 rhashtable_destroy(&br->fdb_hash_tbl);
70}
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/* if topology_changing then use forward_delay (default 15 sec)
73 * otherwise keep longer (default 5 minutes)
74 */
Stephen Hemminger3f890922007-03-21 13:42:33 -070075static inline unsigned long hold_time(const struct net_bridge *br)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 return br->topology_change ? br->forward_delay : br->ageing_time;
78}
79
Stephen Hemminger3f890922007-03-21 13:42:33 -070080static inline int has_expired(const struct net_bridge *br,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 const struct net_bridge_fdb_entry *fdb)
82{
Roopa Prabhueda7a5e2017-02-16 13:38:04 -080083 return !fdb->is_static && !fdb->added_by_external_learn &&
stephen hemminger7cd88612011-04-04 14:03:28 +000084 time_before_eq(fdb->updated + hold_time(br), jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Michał Mirosławda678292009-06-05 05:35:28 +000087static void fdb_rcu_free(struct rcu_head *head)
88{
89 struct net_bridge_fdb_entry *ent
90 = container_of(head, struct net_bridge_fdb_entry, rcu);
91 kmem_cache_free(br_fdb_cache, ent);
92}
93
Nikolay Aleksandroveb793582017-12-12 16:02:50 +020094static struct net_bridge_fdb_entry *fdb_find_rcu(struct rhashtable *tbl,
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +010095 const unsigned char *addr,
96 __u16 vid)
97{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +020098 struct net_bridge_fdb_key key;
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +010099
Nikolay Aleksandrov410b3d42017-02-13 14:59:10 +0100100 WARN_ON_ONCE(!rcu_read_lock_held());
101
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200102 key.vlan_id = vid;
103 memcpy(key.addr.addr, addr, sizeof(key.addr.addr));
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100104
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200105 return rhashtable_lookup(tbl, &key, br_fdb_rht_params);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100106}
107
108/* requires bridge hash_lock */
109static struct net_bridge_fdb_entry *br_fdb_find(struct net_bridge *br,
110 const unsigned char *addr,
111 __u16 vid)
112{
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100113 struct net_bridge_fdb_entry *fdb;
114
WANG Congd12c9172017-03-16 10:32:42 -0700115 lockdep_assert_held_once(&br->hash_lock);
Nikolay Aleksandrov410b3d42017-02-13 14:59:10 +0100116
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100117 rcu_read_lock();
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200118 fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100119 rcu_read_unlock();
120
121 return fdb;
122}
123
124struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
125 const unsigned char *addr,
126 __u16 vid)
127{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200128 return fdb_find_rcu(&br->fdb_hash_tbl, addr, vid);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100129}
130
Vlad Yasevich145beee2014-05-16 09:59:19 -0400131/* When a static FDB entry is added, the mac address from the entry is
132 * added to the bridge private HW address list and all required ports
133 * are then updated with the new information.
134 * Called under RTNL.
135 */
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100136static void fdb_add_hw_addr(struct net_bridge *br, const unsigned char *addr)
Vlad Yasevich145beee2014-05-16 09:59:19 -0400137{
138 int err;
Li RongQinga3f5ee72014-06-18 16:07:16 +0800139 struct net_bridge_port *p;
Vlad Yasevich145beee2014-05-16 09:59:19 -0400140
141 ASSERT_RTNL();
142
143 list_for_each_entry(p, &br->port_list, list) {
144 if (!br_promisc_port(p)) {
145 err = dev_uc_add(p->dev, addr);
146 if (err)
147 goto undo;
148 }
149 }
150
151 return;
152undo:
Li RongQinga3f5ee72014-06-18 16:07:16 +0800153 list_for_each_entry_continue_reverse(p, &br->port_list, list) {
154 if (!br_promisc_port(p))
155 dev_uc_del(p->dev, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400156 }
157}
158
159/* When a static FDB entry is deleted, the HW address from that entry is
160 * also removed from the bridge private HW address list and updates all
161 * the ports with needed information.
162 * Called under RTNL.
163 */
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100164static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
Vlad Yasevich145beee2014-05-16 09:59:19 -0400165{
166 struct net_bridge_port *p;
167
168 ASSERT_RTNL();
169
170 list_for_each_entry(p, &br->port_list, list) {
171 if (!br_promisc_port(p))
172 dev_uc_del(p->dev, addr);
173 }
174}
175
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000176static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Roopa Prabhub74fd302017-08-29 13:16:57 -0700178 trace_fdb_delete(br, f);
179
Vlad Yasevich145beee2014-05-16 09:59:19 -0400180 if (f->is_static)
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200181 fdb_del_hw_addr(br, f->key.addr.addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400182
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200183 hlist_del_init_rcu(&f->fdb_node);
184 rhashtable_remove_fast(&br->fdb_hash_tbl, &f->rhnode,
185 br_fdb_rht_params);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000186 fdb_notify(br, f, RTM_DELNEIGH);
Michał Mirosławda678292009-06-05 05:35:28 +0000187 call_rcu(&f->rcu, fdb_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
Toshiaki Makita960b5892014-02-07 16:48:23 +0900190/* Delete a local entry if no other port had the same address. */
191static void fdb_delete_local(struct net_bridge *br,
192 const struct net_bridge_port *p,
193 struct net_bridge_fdb_entry *f)
194{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200195 const unsigned char *addr = f->key.addr.addr;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200196 struct net_bridge_vlan_group *vg;
197 const struct net_bridge_vlan *v;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900198 struct net_bridge_port *op;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200199 u16 vid = f->key.vlan_id;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900200
201 /* Maybe another port has same hw addr? */
202 list_for_each_entry(op, &br->port_list, list) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200203 vg = nbp_vlan_group(op);
Toshiaki Makita960b5892014-02-07 16:48:23 +0900204 if (op != p && ether_addr_equal(op->dev->dev_addr, addr) &&
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200205 (!vid || br_vlan_find(vg, vid))) {
Toshiaki Makita960b5892014-02-07 16:48:23 +0900206 f->dst = op;
Toshiaki Makitaa778e6d2014-02-07 16:48:24 +0900207 f->added_by_user = 0;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900208 return;
209 }
210 }
211
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200212 vg = br_vlan_group(br);
213 v = br_vlan_find(vg, vid);
Toshiaki Makita960b5892014-02-07 16:48:23 +0900214 /* Maybe bridge device has same hw addr? */
215 if (p && ether_addr_equal(br->dev->dev_addr, addr) &&
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200216 (!vid || (v && br_vlan_should_use(v)))) {
Toshiaki Makita960b5892014-02-07 16:48:23 +0900217 f->dst = NULL;
Toshiaki Makitaa778e6d2014-02-07 16:48:24 +0900218 f->added_by_user = 0;
Toshiaki Makita960b5892014-02-07 16:48:23 +0900219 return;
220 }
221
222 fdb_delete(br, f);
223}
224
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900225void br_fdb_find_delete_local(struct net_bridge *br,
226 const struct net_bridge_port *p,
227 const unsigned char *addr, u16 vid)
228{
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900229 struct net_bridge_fdb_entry *f;
230
231 spin_lock_bh(&br->hash_lock);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100232 f = br_fdb_find(br, addr, vid);
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900233 if (f && f->is_local && !f->added_by_user && f->dst == p)
234 fdb_delete_local(br, p, f);
235 spin_unlock_bh(&br->hash_lock);
236}
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
239{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200240 struct net_bridge_vlan_group *vg;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200241 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 struct net_bridge *br = p->br;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200243 struct net_bridge_vlan *v;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 spin_lock_bh(&br->hash_lock);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200246 vg = nbp_vlan_group(p);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200247 hlist_for_each_entry(f, &br->fdb_list, fdb_node) {
248 if (f->dst == p && f->is_local && !f->added_by_user) {
249 /* delete old one */
250 fdb_delete_local(br, p, f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200252 /* if this port has no vlan information
253 * configured, we can safely be done at
254 * this point.
255 */
256 if (!vg || !vg->num_vlans)
257 goto insert;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Toshiaki Makita28368822014-02-07 16:48:19 +0900261insert:
262 /* insert new address, may fail if invalid address or dup. */
263 fdb_insert(br, p, newaddr, 0);
264
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200265 if (!vg || !vg->num_vlans)
Toshiaki Makita28368822014-02-07 16:48:19 +0900266 goto done;
267
268 /* Now add entries for every VLAN configured on the port.
269 * This function runs under RTNL so the bitmap will not change
270 * from under us.
271 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200272 list_for_each_entry(v, &vg->vlan_list, vlist)
273 fdb_insert(br, p, newaddr, v->vid);
Toshiaki Makita28368822014-02-07 16:48:19 +0900274
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000275done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 spin_unlock_bh(&br->hash_lock);
277}
278
stephen hemminger43598812011-12-08 07:17:49 +0000279void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
280{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200281 struct net_bridge_vlan_group *vg;
stephen hemminger43598812011-12-08 07:17:49 +0000282 struct net_bridge_fdb_entry *f;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200283 struct net_bridge_vlan *v;
stephen hemminger43598812011-12-08 07:17:49 +0000284
Toshiaki Makitaac4c8862014-02-07 16:48:26 +0900285 spin_lock_bh(&br->hash_lock);
286
stephen hemminger43598812011-12-08 07:17:49 +0000287 /* If old entry was unassociated with any port, then delete it. */
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100288 f = br_fdb_find(br, br->dev->dev_addr, 0);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900289 if (f && f->is_local && !f->dst && !f->added_by_user)
Toshiaki Makita960b5892014-02-07 16:48:23 +0900290 fdb_delete_local(br, NULL, f);
stephen hemminger43598812011-12-08 07:17:49 +0000291
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000292 fdb_insert(br, NULL, newaddr, 0);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200293 vg = br_vlan_group(br);
294 if (!vg || !vg->num_vlans)
295 goto out;
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000296 /* Now remove and add entries for every VLAN configured on the
297 * bridge. This function runs under RTNL so the bitmap will not
298 * change from under us.
299 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200300 list_for_each_entry(v, &vg->vlan_list, vlist) {
Toshiaki Makita0b148de2016-06-07 19:14:17 +0900301 if (!br_vlan_should_use(v))
302 continue;
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100303 f = br_fdb_find(br, br->dev->dev_addr, v->vid);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900304 if (f && f->is_local && !f->dst && !f->added_by_user)
Toshiaki Makita960b5892014-02-07 16:48:23 +0900305 fdb_delete_local(br, NULL, f);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200306 fdb_insert(br, NULL, newaddr, v->vid);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000307 }
Toshiaki Makitaac4c8862014-02-07 16:48:26 +0900308out:
309 spin_unlock_bh(&br->hash_lock);
stephen hemminger43598812011-12-08 07:17:49 +0000310}
311
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100312void br_fdb_cleanup(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100314 struct net_bridge *br = container_of(work, struct net_bridge,
315 gc_work.work);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200316 struct net_bridge_fdb_entry *f = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 unsigned long delay = hold_time(br);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100318 unsigned long work_delay = delay;
319 unsigned long now = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200321 /* this part is tricky, in order to avoid blocking learning and
322 * consequently forwarding, we rely on rcu to delete objects with
323 * delayed freeing allowing us to continue traversing
324 */
325 rcu_read_lock();
326 hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
327 unsigned long this_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200329 if (f->is_static || f->added_by_external_learn)
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100330 continue;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200331 this_timer = f->updated + delay;
332 if (time_after(this_timer, now)) {
333 work_delay = min(work_delay, this_timer - now);
334 } else {
335 spin_lock_bh(&br->hash_lock);
336 if (!hlist_unhashed(&f->fdb_node))
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000337 fdb_delete(br, f);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200338 spin_unlock_bh(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
340 }
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200341 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100343 /* Cleanup minimum 10 milliseconds apart */
344 work_delay = max_t(unsigned long, work_delay, msecs_to_jiffies(10));
345 mod_delayed_work(system_long_wq, &br->gc_work, work_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700348/* Completely flush all dynamic entries in forwarding database.*/
349void br_fdb_flush(struct net_bridge *br)
350{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200351 struct net_bridge_fdb_entry *f;
352 struct hlist_node *tmp;
Stephen Hemminger1a620692006-10-12 14:45:38 -0700353
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700354 spin_lock_bh(&br->hash_lock);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200355 hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) {
356 if (!f->is_static)
357 fdb_delete(br, f);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700358 }
359 spin_unlock_bh(&br->hash_lock);
360}
361
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300362/* Flush all entries referring to a specific port.
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700363 * if do_all is set also flush static entries
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700364 * if vid is set delete all entries that match the vlan_id
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700365 */
Stephen Hemminger1a620692006-10-12 14:45:38 -0700366void br_fdb_delete_by_port(struct net_bridge *br,
367 const struct net_bridge_port *p,
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700368 u16 vid,
Stephen Hemminger1a620692006-10-12 14:45:38 -0700369 int do_all)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200371 struct net_bridge_fdb_entry *f;
372 struct hlist_node *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 spin_lock_bh(&br->hash_lock);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200375 hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) {
376 if (f->dst != p)
377 continue;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900378
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200379 if (!do_all)
380 if (f->is_static || (vid && f->key.vlan_id != vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 continue;
382
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200383 if (f->is_local)
384 fdb_delete_local(br, p, f);
385 else
386 fdb_delete(br, f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388 spin_unlock_bh(&br->hash_lock);
389}
390
Igor Maraviće6373c42011-12-12 02:58:25 +0000391#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +0000392/* Interface used by ATM LANE hook to test
393 * if an addr is on some other bridge port */
394int br_fdb_test_addr(struct net_device *dev, unsigned char *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 struct net_bridge_fdb_entry *fdb;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000397 struct net_bridge_port *port;
Michał Mirosławda678292009-06-05 05:35:28 +0000398 int ret;
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 rcu_read_lock();
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000401 port = br_port_get_rcu(dev);
402 if (!port)
403 ret = 0;
404 else {
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100405 fdb = br_fdb_find_rcu(port->br, addr, 0);
stephen hemminger43598812011-12-08 07:17:49 +0000406 ret = fdb && fdb->dst && fdb->dst->dev != dev &&
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000407 fdb->dst->state == BR_STATE_FORWARDING;
408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Michał Mirosławda678292009-06-05 05:35:28 +0000411 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
Michał Mirosławda678292009-06-05 05:35:28 +0000413#endif /* CONFIG_ATM_LANE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415/*
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900416 * Fill buffer with forwarding table records in
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 * the API format.
418 */
419int br_fdb_fillbuf(struct net_bridge *br, void *buf,
420 unsigned long maxnum, unsigned long skip)
421{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 struct net_bridge_fdb_entry *f;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200423 struct __fdb_entry *fe = buf;
424 int num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 memset(buf, 0, maxnum*sizeof(struct __fdb_entry));
427
428 rcu_read_lock();
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200429 hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
430 if (num >= maxnum)
431 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200433 if (has_expired(br, f))
434 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200436 /* ignore pseudo entry for local MAC address */
437 if (!f->dst)
438 continue;
stephen hemminger43598812011-12-08 07:17:49 +0000439
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200440 if (skip) {
441 --skip;
442 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200445 /* convert from internal format to API */
446 memcpy(fe->mac_addr, f->key.addr.addr, ETH_ALEN);
447
448 /* due to ABI compat need to split into hi/lo */
449 fe->port_no = f->dst->port_no;
450 fe->port_hi = f->dst->port_no >> 8;
451
452 fe->is_local = f->is_local;
453 if (!f->is_static)
454 fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated);
455 ++fe;
456 ++num;
457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 rcu_read_unlock();
459
460 return num;
461}
462
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200463static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 struct net_bridge_port *source,
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000465 const unsigned char *addr,
Roopa Prabhub7af1472015-10-27 07:52:56 -0700466 __u16 vid,
467 unsigned char is_local,
468 unsigned char is_static)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 struct net_bridge_fdb_entry *fdb;
471
472 fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC);
473 if (fdb) {
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200474 memcpy(fdb->key.addr.addr, addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 fdb->dst = source;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200476 fdb->key.vlan_id = vid;
Roopa Prabhub7af1472015-10-27 07:52:56 -0700477 fdb->is_local = is_local;
478 fdb->is_static = is_static;
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900479 fdb->added_by_user = 0;
Scott Feldmancf6b8e12014-11-28 14:34:21 +0100480 fdb->added_by_external_learn = 0;
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200481 fdb->offloaded = 0;
stephen hemminger7cd88612011-04-04 14:03:28 +0000482 fdb->updated = fdb->used = jiffies;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200483 if (rhashtable_lookup_insert_fast(&br->fdb_hash_tbl,
484 &fdb->rhnode,
485 br_fdb_rht_params)) {
486 kmem_cache_free(br_fdb_cache, fdb);
487 fdb = NULL;
488 } else {
489 hlist_add_head_rcu(&fdb->fdb_node, &br->fdb_list);
490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492 return fdb;
493}
494
495static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000496 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 struct net_bridge_fdb_entry *fdb;
499
500 if (!is_valid_ether_addr(addr))
501 return -EINVAL;
502
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100503 fdb = br_fdb_find(br, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (fdb) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900505 /* it is okay to have multiple ports with same
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 * address, just use the first one.
507 */
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900508 if (fdb->is_local)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return 0;
Roopa Prabhude1dfee2016-10-11 16:12:56 -0700510 br_warn(br, "adding interface %s with same address as a received packet (addr:%pM, vlan:%u)\n",
511 source ? source->dev->name : br->dev->name, addr, vid);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000512 fdb_delete(br, fdb);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200515 fdb = fdb_create(br, source, addr, vid, 1, 1);
stephen hemminger03e9b642011-04-04 14:03:27 +0000516 if (!fdb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return -ENOMEM;
518
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100519 fdb_add_hw_addr(br, addr);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000520 fdb_notify(br, fdb, RTM_NEWNEIGH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 return 0;
522}
523
stephen hemminger03e9b642011-04-04 14:03:27 +0000524/* Add entry for local address of interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000526 const unsigned char *addr, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 int ret;
529
530 spin_lock_bh(&br->hash_lock);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000531 ret = fdb_insert(br, source, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 spin_unlock_bh(&br->hash_lock);
533 return ret;
534}
535
536void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900537 const unsigned char *addr, u16 vid, bool added_by_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 struct net_bridge_fdb_entry *fdb;
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000540 bool fdb_modified = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* some users want to always flood. */
543 if (hold_time(br) == 0)
544 return;
545
Stephen Hemmingerdf1c0b82007-08-30 22:15:35 -0700546 /* ignore packets unless we are using this port */
547 if (!(source->state == BR_STATE_LEARNING ||
548 source->state == BR_STATE_FORWARDING))
549 return;
550
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200551 fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (likely(fdb)) {
553 /* attempt to update an entry for a local interface */
554 if (unlikely(fdb->is_local)) {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900555 if (net_ratelimit())
Roopa Prabhude1dfee2016-10-11 16:12:56 -0700556 br_warn(br, "received packet on %s with own address as source address (addr:%pM, vlan:%u)\n",
557 source->dev->name, addr, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 } else {
stephen hemmingerca6d4482017-02-07 08:46:46 -0800559 unsigned long now = jiffies;
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 /* fastpath: update of existing entry */
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000562 if (unlikely(source != fdb->dst)) {
563 fdb->dst = source;
564 fdb_modified = true;
Arkadi Sharshevsky58073b32017-04-28 22:39:07 +0300565 /* Take over HW learned entry */
566 if (unlikely(fdb->added_by_external_learn))
567 fdb->added_by_external_learn = 0;
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000568 }
stephen hemmingerca6d4482017-02-07 08:46:46 -0800569 if (now != fdb->updated)
570 fdb->updated = now;
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900571 if (unlikely(added_by_user))
572 fdb->added_by_user = 1;
Roopa Prabhue3cfddd2017-08-30 22:18:13 -0700573 if (unlikely(fdb_modified)) {
574 trace_br_fdb_update(br, source, addr, vid, added_by_user);
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000575 fdb_notify(br, fdb, RTM_NEWNEIGH);
Roopa Prabhue3cfddd2017-08-30 22:18:13 -0700576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578 } else {
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800579 spin_lock(&br->hash_lock);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200580 fdb = fdb_create(br, source, addr, vid, 0, 0);
581 if (fdb) {
582 if (unlikely(added_by_user))
583 fdb->added_by_user = 1;
584 trace_br_fdb_update(br, source, addr, vid,
585 added_by_user);
586 fdb_notify(br, fdb, RTM_NEWNEIGH);
stephen hemmingerf58ee4e2011-12-06 13:02:24 +0000587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /* else we lose race and someone else inserts
589 * it first, don't bother updating
590 */
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800591 spin_unlock(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000594
Roopa Prabhu37418732015-10-08 10:38:52 -0700595static int fdb_to_nud(const struct net_bridge *br,
596 const struct net_bridge_fdb_entry *fdb)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000597{
598 if (fdb->is_local)
599 return NUD_PERMANENT;
600 else if (fdb->is_static)
601 return NUD_NOARP;
Roopa Prabhu37418732015-10-08 10:38:52 -0700602 else if (has_expired(br, fdb))
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000603 return NUD_STALE;
604 else
605 return NUD_REACHABLE;
606}
607
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000608static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000609 const struct net_bridge_fdb_entry *fdb,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000610 u32 portid, u32 seq, int type, unsigned int flags)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000611{
612 unsigned long now = jiffies;
613 struct nda_cacheinfo ci;
614 struct nlmsghdr *nlh;
615 struct ndmsg *ndm;
616
Eric W. Biederman15e47302012-09-07 20:12:54 +0000617 nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000618 if (nlh == NULL)
619 return -EMSGSIZE;
620
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000621 ndm = nlmsg_data(nlh);
622 ndm->ndm_family = AF_BRIDGE;
623 ndm->ndm_pad1 = 0;
624 ndm->ndm_pad2 = 0;
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200625 ndm->ndm_flags = 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000626 ndm->ndm_type = 0;
stephen hemminger43598812011-12-08 07:17:49 +0000627 ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex;
Roopa Prabhu37418732015-10-08 10:38:52 -0700628 ndm->ndm_state = fdb_to_nud(br, fdb);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000629
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200630 if (fdb->offloaded)
631 ndm->ndm_flags |= NTF_OFFLOADED;
632 if (fdb->added_by_external_learn)
633 ndm->ndm_flags |= NTF_EXT_LEARNED;
634
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200635 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->key.addr))
David S. Miller2eb812e2012-04-01 20:49:54 -0400636 goto nla_put_failure;
Roopa Prabhu41c389d2014-05-27 22:39:37 -0700637 if (nla_put_u32(skb, NDA_MASTER, br->dev->ifindex))
638 goto nla_put_failure;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000639 ci.ndm_used = jiffies_to_clock_t(now - fdb->used);
640 ci.ndm_confirmed = 0;
641 ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated);
642 ci.ndm_refcnt = 0;
David S. Miller2eb812e2012-04-01 20:49:54 -0400643 if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
644 goto nla_put_failure;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000645
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200646 if (fdb->key.vlan_id && nla_put(skb, NDA_VLAN, sizeof(u16),
647 &fdb->key.vlan_id))
Vlad Yasevich1690be62013-02-13 12:00:18 +0000648 goto nla_put_failure;
649
Johannes Berg053c0952015-01-16 22:09:00 +0100650 nlmsg_end(skb, nlh);
651 return 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000652
653nla_put_failure:
654 nlmsg_cancel(skb, nlh);
655 return -EMSGSIZE;
656}
657
658static inline size_t fdb_nlmsg_size(void)
659{
660 return NLMSG_ALIGN(sizeof(struct ndmsg))
661 + nla_total_size(ETH_ALEN) /* NDA_LLADDR */
Roopa Prabhu41c389d2014-05-27 22:39:37 -0700662 + nla_total_size(sizeof(u32)) /* NDA_MASTER */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000663 + nla_total_size(sizeof(u16)) /* NDA_VLAN */
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000664 + nla_total_size(sizeof(struct nda_cacheinfo));
665}
666
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000667static void fdb_notify(struct net_bridge *br,
668 const struct net_bridge_fdb_entry *fdb, int type)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000669{
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000670 struct net *net = dev_net(br->dev);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000671 struct sk_buff *skb;
672 int err = -ENOBUFS;
673
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +0200674 br_switchdev_fdb_notify(fdb, type);
675
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000676 skb = nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC);
677 if (skb == NULL)
678 goto errout;
679
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000680 err = fdb_fill_info(skb, br, fdb, 0, 0, type, 0);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000681 if (err < 0) {
682 /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */
683 WARN_ON(err == -EMSGSIZE);
684 kfree_skb(skb);
685 goto errout;
686 }
687 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
688 return;
689errout:
tanxiaojun87e823b2013-12-19 13:28:10 +0800690 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000691}
692
693/* Dump information about entries, in response to GETNEIGH */
John Fastabend77162022012-04-15 06:43:56 +0000694int br_fdb_dump(struct sk_buff *skb,
695 struct netlink_callback *cb,
696 struct net_device *dev,
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400697 struct net_device *filter_dev,
Roopa Prabhud2976532016-08-30 21:56:45 -0700698 int *idx)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000699{
John Fastabend77162022012-04-15 06:43:56 +0000700 struct net_bridge *br = netdev_priv(dev);
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200701 struct net_bridge_fdb_entry *f;
Roopa Prabhud2976532016-08-30 21:56:45 -0700702 int err = 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000703
John Fastabend77162022012-04-15 06:43:56 +0000704 if (!(dev->priv_flags & IFF_EBRIDGE))
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200705 return err;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000706
Roopa Prabhud2976532016-08-30 21:56:45 -0700707 if (!filter_dev) {
708 err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
709 if (err < 0)
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200710 return err;
Roopa Prabhud2976532016-08-30 21:56:45 -0700711 }
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000712
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200713 rcu_read_lock();
714 hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
715 if (*idx < cb->args[2])
716 goto skip;
717 if (filter_dev && (!f->dst || f->dst->dev != filter_dev)) {
718 if (filter_dev != dev)
John Fastabend77162022012-04-15 06:43:56 +0000719 goto skip;
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200720 /* !f->dst is a special case for bridge
721 * It means the MAC belongs to the bridge
722 * Therefore need a little more filtering
723 * we only want to dump the !f->dst case
724 */
725 if (f->dst)
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000726 goto skip;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000727 }
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200728 if (!filter_dev && f->dst)
729 goto skip;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000730
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200731 err = fdb_fill_info(skb, br, f,
732 NETLINK_CB(cb->skb).portid,
733 cb->nlh->nlmsg_seq,
734 RTM_NEWNEIGH,
735 NLM_F_MULTI);
736 if (err < 0)
737 break;
738skip:
739 *idx += 1;
740 }
741 rcu_read_unlock();
742
Roopa Prabhud2976532016-08-30 21:56:45 -0700743 return err;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000744}
stephen hemminger36fd2b62011-04-04 14:03:31 +0000745
stephen hemminger292d1392011-11-09 18:30:08 +0000746/* Update (create or replace) forwarding database entry */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900747static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
748 const __u8 *addr, __u16 state, __u16 flags, __u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000749{
stephen hemminger36fd2b62011-04-04 14:03:31 +0000750 struct net_bridge_fdb_entry *fdb;
roopab0a397f2013-04-22 12:56:49 +0000751 bool modified = false;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000752
Wilson Kokeb8d7ba2015-05-25 06:39:31 -0700753 /* If the port cannot learn allow only local and static entries */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900754 if (source && !(state & NUD_PERMANENT) && !(state & NUD_NOARP) &&
Wilson Kokeb8d7ba2015-05-25 06:39:31 -0700755 !(source->state == BR_STATE_LEARNING ||
756 source->state == BR_STATE_FORWARDING))
757 return -EPERM;
758
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900759 if (!source && !(state & NUD_PERMANENT)) {
760 pr_info("bridge: RTM_NEWNEIGH %s without NUD_PERMANENT\n",
761 br->dev->name);
762 return -EINVAL;
763 }
764
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100765 fdb = br_fdb_find(br, addr, vid);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000766 if (fdb == NULL) {
767 if (!(flags & NLM_F_CREATE))
768 return -ENOENT;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000769
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200770 fdb = fdb_create(br, source, addr, vid, 0, 0);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000771 if (!fdb)
772 return -ENOMEM;
roopab0a397f2013-04-22 12:56:49 +0000773
774 modified = true;
stephen hemminger64af1ba2011-09-30 14:37:27 +0000775 } else {
776 if (flags & NLM_F_EXCL)
777 return -EEXIST;
roopab0a397f2013-04-22 12:56:49 +0000778
779 if (fdb->dst != source) {
780 fdb->dst = source;
781 modified = true;
782 }
stephen hemminger64af1ba2011-09-30 14:37:27 +0000783 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000784
Roopa Prabhu37418732015-10-08 10:38:52 -0700785 if (fdb_to_nud(br, fdb) != state) {
Vlad Yasevich145beee2014-05-16 09:59:19 -0400786 if (state & NUD_PERMANENT) {
787 fdb->is_local = 1;
788 if (!fdb->is_static) {
789 fdb->is_static = 1;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100790 fdb_add_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400791 }
792 } else if (state & NUD_NOARP) {
stephen hemminger292d1392011-11-09 18:30:08 +0000793 fdb->is_local = 0;
Vlad Yasevich145beee2014-05-16 09:59:19 -0400794 if (!fdb->is_static) {
795 fdb->is_static = 1;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100796 fdb_add_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400797 }
798 } else {
799 fdb->is_local = 0;
800 if (fdb->is_static) {
801 fdb->is_static = 0;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100802 fdb_del_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400803 }
804 }
stephen hemminger292d1392011-11-09 18:30:08 +0000805
roopab0a397f2013-04-22 12:56:49 +0000806 modified = true;
807 }
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900808 fdb->added_by_user = 1;
roopab0a397f2013-04-22 12:56:49 +0000809
810 fdb->used = jiffies;
811 if (modified) {
812 fdb->updated = jiffies;
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000813 fdb_notify(br, fdb, RTM_NEWNEIGH);
stephen hemminger292d1392011-11-09 18:30:08 +0000814 }
815
stephen hemminger36fd2b62011-04-04 14:03:31 +0000816 return 0;
817}
818
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900819static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
820 struct net_bridge_port *p, const unsigned char *addr,
821 u16 nlh_flags, u16 vid)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000822{
823 int err = 0;
824
825 if (ndm->ndm_flags & NTF_USE) {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900826 if (!p) {
827 pr_info("bridge: RTM_NEWNEIGH %s with NTF_USE is not supported\n",
828 br->dev->name);
829 return -EINVAL;
830 }
Nikolay Aleksandrovc4c832f2015-06-06 06:49:00 -0700831 local_bh_disable();
Vlad Yasevich1690be62013-02-13 12:00:18 +0000832 rcu_read_lock();
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900833 br_fdb_update(br, p, addr, vid, true);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000834 rcu_read_unlock();
Nikolay Aleksandrovc4c832f2015-06-06 06:49:00 -0700835 local_bh_enable();
Nikolay Aleksandroveb100e02017-03-23 12:27:13 +0200836 } else if (ndm->ndm_flags & NTF_EXT_LEARNED) {
837 err = br_fdb_external_learn_add(br, p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000838 } else {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900839 spin_lock_bh(&br->hash_lock);
840 err = fdb_add_entry(br, p, addr, ndm->ndm_state,
Vlad Yasevich1690be62013-02-13 12:00:18 +0000841 nlh_flags, vid);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900842 spin_unlock_bh(&br->hash_lock);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000843 }
844
845 return err;
846}
847
stephen hemminger36fd2b62011-04-04 14:03:31 +0000848/* Add new permanent fdb entry with RTM_NEWNEIGH */
stephen hemmingeredc7d572012-10-01 12:32:33 +0000849int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
850 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100851 const unsigned char *addr, u16 vid, u16 nlh_flags)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000852{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200853 struct net_bridge_vlan_group *vg;
Roopa Prabhu37418732015-10-08 10:38:52 -0700854 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200855 struct net_bridge_vlan *v;
Roopa Prabhu37418732015-10-08 10:38:52 -0700856 struct net_bridge *br = NULL;
John Fastabend77162022012-04-15 06:43:56 +0000857 int err = 0;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000858
Roopa Prabhub74fd302017-08-29 13:16:57 -0700859 trace_br_fdb_add(ndm, dev, addr, vid, nlh_flags);
860
stephen hemminger292d1392011-11-09 18:30:08 +0000861 if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE))) {
862 pr_info("bridge: RTM_NEWNEIGH with invalid state %#x\n", ndm->ndm_state);
863 return -EINVAL;
864 }
865
Stephen Hemminger537f7f82013-06-25 09:34:36 -0700866 if (is_zero_ether_addr(addr)) {
867 pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n");
868 return -EINVAL;
869 }
870
Roopa Prabhu37418732015-10-08 10:38:52 -0700871 if (dev->priv_flags & IFF_EBRIDGE) {
872 br = netdev_priv(dev);
873 vg = br_vlan_group(br);
874 } else {
875 p = br_port_get_rtnl(dev);
876 if (!p) {
877 pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n",
878 dev->name);
879 return -EINVAL;
880 }
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900881 br = p->br;
Roopa Prabhu37418732015-10-08 10:38:52 -0700882 vg = nbp_vlan_group(p);
stephen hemminger36fd2b62011-04-04 14:03:31 +0000883 }
884
Jiri Pirkof6f64242014-11-28 14:34:15 +0100885 if (vid) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200886 v = br_vlan_find(vg, vid);
Roopa Prabhu37418732015-10-08 10:38:52 -0700887 if (!v || !br_vlan_should_use(v)) {
888 pr_info("bridge: RTM_NEWNEIGH with unconfigured vlan %d on %s\n", vid, dev->name);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000889 return -EINVAL;
890 }
891
892 /* VID was specified, so use it. */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900893 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid);
stephen hemminger292d1392011-11-09 18:30:08 +0000894 } else {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900895 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200896 if (err || !vg || !vg->num_vlans)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000897 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000898
899 /* We have vlans configured on this port and user didn't
900 * specify a VLAN. To be nice, add/update entry for every
901 * vlan on this port.
902 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200903 list_for_each_entry(v, &vg->vlan_list, vlist) {
Roopa Prabhu37418732015-10-08 10:38:52 -0700904 if (!br_vlan_should_use(v))
905 continue;
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900906 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000907 if (err)
908 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000909 }
stephen hemminger292d1392011-11-09 18:30:08 +0000910 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000911
Vlad Yasevich1690be62013-02-13 12:00:18 +0000912out:
913 return err;
914}
915
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100916static int fdb_delete_by_addr_and_port(struct net_bridge *br,
917 const struct net_bridge_port *p,
Nikolay Aleksandrov8c86f962015-06-09 03:34:13 -0700918 const u8 *addr, u16 vlan)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000919{
Vlad Yasevich1690be62013-02-13 12:00:18 +0000920 struct net_bridge_fdb_entry *fdb;
921
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100922 fdb = br_fdb_find(br, addr, vlan);
Nikolay Aleksandrov8c86f962015-06-09 03:34:13 -0700923 if (!fdb || fdb->dst != p)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000924 return -ENOENT;
925
926 fdb_delete(br, fdb);
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100927
Vlad Yasevich1690be62013-02-13 12:00:18 +0000928 return 0;
929}
930
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100931static int __br_fdb_delete(struct net_bridge *br,
932 const struct net_bridge_port *p,
Vlad Yasevich1690be62013-02-13 12:00:18 +0000933 const unsigned char *addr, u16 vid)
934{
935 int err;
936
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100937 spin_lock_bh(&br->hash_lock);
938 err = fdb_delete_by_addr_and_port(br, p, addr, vid);
939 spin_unlock_bh(&br->hash_lock);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000940
stephen hemminger36fd2b62011-04-04 14:03:31 +0000941 return err;
942}
943
stephen hemminger36fd2b62011-04-04 14:03:31 +0000944/* Remove neighbor entry with RTM_DELNEIGH */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000945int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
946 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100947 const unsigned char *addr, u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000948{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200949 struct net_bridge_vlan_group *vg;
Roopa Prabhu37418732015-10-08 10:38:52 -0700950 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200951 struct net_bridge_vlan *v;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100952 struct net_bridge *br;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000953 int err;
954
Roopa Prabhu37418732015-10-08 10:38:52 -0700955 if (dev->priv_flags & IFF_EBRIDGE) {
956 br = netdev_priv(dev);
957 vg = br_vlan_group(br);
958 } else {
959 p = br_port_get_rtnl(dev);
960 if (!p) {
961 pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n",
962 dev->name);
963 return -EINVAL;
964 }
965 vg = nbp_vlan_group(p);
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100966 br = p->br;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000967 }
968
Jiri Pirkof6f64242014-11-28 14:34:15 +0100969 if (vid) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200970 v = br_vlan_find(vg, vid);
971 if (!v) {
Roopa Prabhu37418732015-10-08 10:38:52 -0700972 pr_info("bridge: RTM_DELNEIGH with unconfigured vlan %d on %s\n", vid, dev->name);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000973 return -EINVAL;
974 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000975
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100976 err = __br_fdb_delete(br, p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000977 } else {
Toshiaki Makita25d3b492015-02-09 20:16:17 +0900978 err = -ENOENT;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100979 err &= __br_fdb_delete(br, p, addr, 0);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200980 if (!vg || !vg->num_vlans)
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100981 return err;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000982
Roopa Prabhu37418732015-10-08 10:38:52 -0700983 list_for_each_entry(v, &vg->vlan_list, vlist) {
984 if (!br_vlan_should_use(v))
985 continue;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100986 err &= __br_fdb_delete(br, p, addr, v->vid);
Roopa Prabhu37418732015-10-08 10:38:52 -0700987 }
Vlad Yasevich1690be62013-02-13 12:00:18 +0000988 }
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100989
stephen hemminger36fd2b62011-04-04 14:03:31 +0000990 return err;
991}
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400992
993int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p)
994{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +0200995 struct net_bridge_fdb_entry *f, *tmp;
Geert Uytterhoeven367dc652018-02-01 11:25:27 +0100996 int err = 0;
Vlad Yasevich8db24af2014-05-16 09:59:17 -0400997
998 ASSERT_RTNL();
999
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001000 /* the key here is that static entries change only under rtnl */
1001 rcu_read_lock();
1002 hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
1003 /* We only care for static entries */
1004 if (!f->is_static)
1005 continue;
1006 err = dev_uc_add(p->dev, f->key.addr.addr);
1007 if (err)
1008 goto rollback;
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001009 }
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001010done:
1011 rcu_read_unlock();
1012
1013 return err;
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001014
1015rollback:
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001016 hlist_for_each_entry_rcu(tmp, &br->fdb_list, fdb_node) {
1017 /* We only care for static entries */
1018 if (!tmp->is_static)
1019 continue;
1020 if (tmp == f)
1021 break;
1022 dev_uc_del(p->dev, tmp->key.addr.addr);
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001023 }
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001024
1025 goto done;
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001026}
1027
1028void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p)
1029{
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001030 struct net_bridge_fdb_entry *f;
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001031
1032 ASSERT_RTNL();
1033
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001034 rcu_read_lock();
1035 hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
1036 /* We only care for static entries */
1037 if (!f->is_static)
1038 continue;
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001039
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001040 dev_uc_del(p->dev, f->key.addr.addr);
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001041 }
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001042 rcu_read_unlock();
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001043}
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001044
Jiri Pirko3aeb6612015-01-15 23:49:37 +01001045int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001046 const unsigned char *addr, u16 vid)
1047{
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001048 struct net_bridge_fdb_entry *fdb;
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001049 bool modified = false;
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001050 int err = 0;
1051
Roopa Prabhub74fd302017-08-29 13:16:57 -07001052 trace_br_fdb_external_learn_add(br, p, addr, vid);
1053
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001054 spin_lock_bh(&br->hash_lock);
1055
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +01001056 fdb = br_fdb_find(br, addr, vid);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001057 if (!fdb) {
Nikolay Aleksandroveb793582017-12-12 16:02:50 +02001058 fdb = fdb_create(br, p, addr, vid, 0, 0);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001059 if (!fdb) {
1060 err = -ENOMEM;
1061 goto err_unlock;
1062 }
1063 fdb->added_by_external_learn = 1;
1064 fdb_notify(br, fdb, RTM_NEWNEIGH);
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001065 } else {
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001066 fdb->updated = jiffies;
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001067
1068 if (fdb->dst != p) {
1069 fdb->dst = p;
1070 modified = true;
1071 }
1072
1073 if (fdb->added_by_external_learn) {
1074 /* Refresh entry */
1075 fdb->used = jiffies;
1076 } else if (!fdb->added_by_user) {
1077 /* Take over SW learned entry */
1078 fdb->added_by_external_learn = 1;
1079 modified = true;
1080 }
1081
1082 if (modified)
1083 fdb_notify(br, fdb, RTM_NEWNEIGH);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001084 }
1085
1086err_unlock:
1087 spin_unlock_bh(&br->hash_lock);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001088
1089 return err;
1090}
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001091
Jiri Pirko3aeb6612015-01-15 23:49:37 +01001092int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001093 const unsigned char *addr, u16 vid)
1094{
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001095 struct net_bridge_fdb_entry *fdb;
1096 int err = 0;
1097
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001098 spin_lock_bh(&br->hash_lock);
1099
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +01001100 fdb = br_fdb_find(br, addr, vid);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001101 if (fdb && fdb->added_by_external_learn)
1102 fdb_delete(br, fdb);
1103 else
1104 err = -ENOENT;
1105
1106 spin_unlock_bh(&br->hash_lock);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001107
1108 return err;
1109}
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +02001110
1111void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
1112 const unsigned char *addr, u16 vid)
1113{
1114 struct net_bridge_fdb_entry *fdb;
1115
1116 spin_lock_bh(&br->hash_lock);
1117
1118 fdb = br_fdb_find(br, addr, vid);
1119 if (fdb)
1120 fdb->offloaded = 1;
1121
1122 spin_unlock_bh(&br->hash_lock);
1123}