blob: 4ea5c8bbe286aa8c299c98bd1d69530875bc2057 [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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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 Aleksandrov2594e9062015-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;
Roopa Prabhue3cfddd2017-08-30 22:18:13 -0700586 if (unlikely(fdb_modified)) {
587 trace_br_fdb_update(br, source, addr, vid, added_by_user);
Jon Maxwellc65c7a32014-05-29 17:27:16 +1000588 fdb_notify(br, fdb, RTM_NEWNEIGH);
Roopa Prabhue3cfddd2017-08-30 22:18:13 -0700589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591 } else {
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800592 spin_lock(&br->hash_lock);
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100593 if (likely(!fdb_find_rcu(head, addr, vid))) {
Roopa Prabhub7af1472015-10-27 07:52:56 -0700594 fdb = fdb_create(head, source, addr, vid, 0, 0);
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900595 if (fdb) {
596 if (unlikely(added_by_user))
597 fdb->added_by_user = 1;
Roopa Prabhue3cfddd2017-08-30 22:18:13 -0700598 trace_br_fdb_update(br, source, addr, vid, added_by_user);
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000599 fdb_notify(br, fdb, RTM_NEWNEIGH);
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900600 }
stephen hemmingerf58ee4e2011-12-06 13:02:24 +0000601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /* else we lose race and someone else inserts
603 * it first, don't bother updating
604 */
Stephen Hemmingerf8ae7372006-03-20 22:58:36 -0800605 spin_unlock(&br->hash_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000608
Roopa Prabhu37418732015-10-08 10:38:52 -0700609static int fdb_to_nud(const struct net_bridge *br,
610 const struct net_bridge_fdb_entry *fdb)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000611{
612 if (fdb->is_local)
613 return NUD_PERMANENT;
614 else if (fdb->is_static)
615 return NUD_NOARP;
Roopa Prabhu37418732015-10-08 10:38:52 -0700616 else if (has_expired(br, fdb))
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000617 return NUD_STALE;
618 else
619 return NUD_REACHABLE;
620}
621
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000622static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000623 const struct net_bridge_fdb_entry *fdb,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000624 u32 portid, u32 seq, int type, unsigned int flags)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000625{
626 unsigned long now = jiffies;
627 struct nda_cacheinfo ci;
628 struct nlmsghdr *nlh;
629 struct ndmsg *ndm;
630
Eric W. Biederman15e47302012-09-07 20:12:54 +0000631 nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000632 if (nlh == NULL)
633 return -EMSGSIZE;
634
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000635 ndm = nlmsg_data(nlh);
636 ndm->ndm_family = AF_BRIDGE;
637 ndm->ndm_pad1 = 0;
638 ndm->ndm_pad2 = 0;
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200639 ndm->ndm_flags = 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000640 ndm->ndm_type = 0;
stephen hemminger43598812011-12-08 07:17:49 +0000641 ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex;
Roopa Prabhu37418732015-10-08 10:38:52 -0700642 ndm->ndm_state = fdb_to_nud(br, fdb);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000643
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +0200644 if (fdb->offloaded)
645 ndm->ndm_flags |= NTF_OFFLOADED;
646 if (fdb->added_by_external_learn)
647 ndm->ndm_flags |= NTF_EXT_LEARNED;
648
David S. Miller2eb812e2012-04-01 20:49:54 -0400649 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->addr))
650 goto nla_put_failure;
Roopa Prabhu41c389d2014-05-27 22:39:37 -0700651 if (nla_put_u32(skb, NDA_MASTER, br->dev->ifindex))
652 goto nla_put_failure;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000653 ci.ndm_used = jiffies_to_clock_t(now - fdb->used);
654 ci.ndm_confirmed = 0;
655 ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated);
656 ci.ndm_refcnt = 0;
David S. Miller2eb812e2012-04-01 20:49:54 -0400657 if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
658 goto nla_put_failure;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000659
Toshiaki Makita47fab412014-07-30 13:31:51 +0900660 if (fdb->vlan_id && nla_put(skb, NDA_VLAN, sizeof(u16), &fdb->vlan_id))
Vlad Yasevich1690be62013-02-13 12:00:18 +0000661 goto nla_put_failure;
662
Johannes Berg053c0952015-01-16 22:09:00 +0100663 nlmsg_end(skb, nlh);
664 return 0;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000665
666nla_put_failure:
667 nlmsg_cancel(skb, nlh);
668 return -EMSGSIZE;
669}
670
671static inline size_t fdb_nlmsg_size(void)
672{
673 return NLMSG_ALIGN(sizeof(struct ndmsg))
674 + nla_total_size(ETH_ALEN) /* NDA_LLADDR */
Roopa Prabhu41c389d2014-05-27 22:39:37 -0700675 + nla_total_size(sizeof(u32)) /* NDA_MASTER */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000676 + nla_total_size(sizeof(u16)) /* NDA_VLAN */
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000677 + nla_total_size(sizeof(struct nda_cacheinfo));
678}
679
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000680static void fdb_notify(struct net_bridge *br,
681 const struct net_bridge_fdb_entry *fdb, int type)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000682{
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000683 struct net *net = dev_net(br->dev);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000684 struct sk_buff *skb;
685 int err = -ENOBUFS;
686
Arkadi Sharshevsky6b26b512017-06-08 08:44:14 +0200687 br_switchdev_fdb_notify(fdb, type);
688
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000689 skb = nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC);
690 if (skb == NULL)
691 goto errout;
692
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000693 err = fdb_fill_info(skb, br, fdb, 0, 0, type, 0);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000694 if (err < 0) {
695 /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */
696 WARN_ON(err == -EMSGSIZE);
697 kfree_skb(skb);
698 goto errout;
699 }
700 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
701 return;
702errout:
tanxiaojun87e823b2013-12-19 13:28:10 +0800703 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000704}
705
706/* Dump information about entries, in response to GETNEIGH */
John Fastabend77162022012-04-15 06:43:56 +0000707int br_fdb_dump(struct sk_buff *skb,
708 struct netlink_callback *cb,
709 struct net_device *dev,
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400710 struct net_device *filter_dev,
Roopa Prabhud2976532016-08-30 21:56:45 -0700711 int *idx)
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000712{
John Fastabend77162022012-04-15 06:43:56 +0000713 struct net_bridge *br = netdev_priv(dev);
Roopa Prabhud2976532016-08-30 21:56:45 -0700714 int err = 0;
John Fastabend77162022012-04-15 06:43:56 +0000715 int i;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000716
John Fastabend77162022012-04-15 06:43:56 +0000717 if (!(dev->priv_flags & IFF_EBRIDGE))
718 goto out;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000719
Roopa Prabhud2976532016-08-30 21:56:45 -0700720 if (!filter_dev) {
721 err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
722 if (err < 0)
723 goto out;
724 }
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000725
John Fastabend77162022012-04-15 06:43:56 +0000726 for (i = 0; i < BR_HASH_SIZE; i++) {
John Fastabend77162022012-04-15 06:43:56 +0000727 struct net_bridge_fdb_entry *f;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000728
Sasha Levinb67bfe02013-02-27 17:06:00 -0800729 hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
MINOURA Makoto / 箕浦 真472681d2016-02-25 14:20:48 +0900730
Roopa Prabhud2976532016-08-30 21:56:45 -0700731 if (*idx < cb->args[2])
John Fastabend77162022012-04-15 06:43:56 +0000732 goto skip;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000733
Jamal Hadi Salim5e6d2432014-07-10 07:01:59 -0400734 if (filter_dev &&
735 (!f->dst || f->dst->dev != filter_dev)) {
736 if (filter_dev != dev)
737 goto skip;
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000738 /* !f->dst is a special case for bridge
Jamal Hadi Salim5e6d2432014-07-10 07:01:59 -0400739 * It means the MAC belongs to the bridge
740 * Therefore need a little more filtering
741 * we only want to dump the !f->dst case
742 */
743 if (f->dst)
744 goto skip;
745 }
Hubert Sokolowski6cb69742015-01-05 17:29:21 +0000746 if (!filter_dev && f->dst)
747 goto skip;
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400748
MINOURA Makoto / 箕浦 真472681d2016-02-25 14:20:48 +0900749 err = fdb_fill_info(skb, br, f,
750 NETLINK_CB(cb->skb).portid,
751 cb->nlh->nlmsg_seq,
752 RTM_NEWNEIGH,
753 NLM_F_MULTI);
Roopa Prabhud2976532016-08-30 21:56:45 -0700754 if (err < 0)
755 goto out;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000756skip:
Roopa Prabhud2976532016-08-30 21:56:45 -0700757 *idx += 1;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000758 }
759 }
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000760
John Fastabend77162022012-04-15 06:43:56 +0000761out:
Roopa Prabhud2976532016-08-30 21:56:45 -0700762 return err;
stephen hemmingerb078f0d2011-04-04 14:03:30 +0000763}
stephen hemminger36fd2b62011-04-04 14:03:31 +0000764
stephen hemminger292d1392011-11-09 18:30:08 +0000765/* Update (create or replace) forwarding database entry */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900766static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
767 const __u8 *addr, __u16 state, __u16 flags, __u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000768{
Vlad Yasevich2ba071e2013-02-13 12:00:16 +0000769 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
stephen hemminger36fd2b62011-04-04 14:03:31 +0000770 struct net_bridge_fdb_entry *fdb;
roopab0a397f2013-04-22 12:56:49 +0000771 bool modified = false;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000772
Wilson Kokeb8d7ba2015-05-25 06:39:31 -0700773 /* If the port cannot learn allow only local and static entries */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900774 if (source && !(state & NUD_PERMANENT) && !(state & NUD_NOARP) &&
Wilson Kokeb8d7ba2015-05-25 06:39:31 -0700775 !(source->state == BR_STATE_LEARNING ||
776 source->state == BR_STATE_FORWARDING))
777 return -EPERM;
778
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900779 if (!source && !(state & NUD_PERMANENT)) {
780 pr_info("bridge: RTM_NEWNEIGH %s without NUD_PERMANENT\n",
781 br->dev->name);
782 return -EINVAL;
783 }
784
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100785 fdb = br_fdb_find(br, addr, vid);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000786 if (fdb == NULL) {
787 if (!(flags & NLM_F_CREATE))
788 return -ENOENT;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000789
Roopa Prabhub7af1472015-10-27 07:52:56 -0700790 fdb = fdb_create(head, source, addr, vid, 0, 0);
stephen hemminger64af1ba2011-09-30 14:37:27 +0000791 if (!fdb)
792 return -ENOMEM;
roopab0a397f2013-04-22 12:56:49 +0000793
794 modified = true;
stephen hemminger64af1ba2011-09-30 14:37:27 +0000795 } else {
796 if (flags & NLM_F_EXCL)
797 return -EEXIST;
roopab0a397f2013-04-22 12:56:49 +0000798
799 if (fdb->dst != source) {
800 fdb->dst = source;
801 modified = true;
802 }
stephen hemminger64af1ba2011-09-30 14:37:27 +0000803 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000804
Roopa Prabhu37418732015-10-08 10:38:52 -0700805 if (fdb_to_nud(br, fdb) != state) {
Vlad Yasevich145beee2014-05-16 09:59:19 -0400806 if (state & NUD_PERMANENT) {
807 fdb->is_local = 1;
808 if (!fdb->is_static) {
809 fdb->is_static = 1;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100810 fdb_add_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400811 }
812 } else if (state & NUD_NOARP) {
stephen hemminger292d1392011-11-09 18:30:08 +0000813 fdb->is_local = 0;
Vlad Yasevich145beee2014-05-16 09:59:19 -0400814 if (!fdb->is_static) {
815 fdb->is_static = 1;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100816 fdb_add_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400817 }
818 } else {
819 fdb->is_local = 0;
820 if (fdb->is_static) {
821 fdb->is_static = 0;
Jiri Pirko020ec6b2014-11-28 14:34:12 +0100822 fdb_del_hw_addr(br, addr);
Vlad Yasevich145beee2014-05-16 09:59:19 -0400823 }
824 }
stephen hemminger292d1392011-11-09 18:30:08 +0000825
roopab0a397f2013-04-22 12:56:49 +0000826 modified = true;
827 }
Toshiaki Makitaa5642ab2014-02-07 16:48:18 +0900828 fdb->added_by_user = 1;
roopab0a397f2013-04-22 12:56:49 +0000829
830 fdb->used = jiffies;
831 if (modified) {
832 fdb->updated = jiffies;
stephen hemminger31e8a49c2011-12-08 07:17:41 +0000833 fdb_notify(br, fdb, RTM_NEWNEIGH);
stephen hemminger292d1392011-11-09 18:30:08 +0000834 }
835
stephen hemminger36fd2b62011-04-04 14:03:31 +0000836 return 0;
837}
838
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900839static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
840 struct net_bridge_port *p, const unsigned char *addr,
841 u16 nlh_flags, u16 vid)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000842{
843 int err = 0;
844
845 if (ndm->ndm_flags & NTF_USE) {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900846 if (!p) {
847 pr_info("bridge: RTM_NEWNEIGH %s with NTF_USE is not supported\n",
848 br->dev->name);
849 return -EINVAL;
850 }
Nikolay Aleksandrovc4c832f2015-06-06 06:49:00 -0700851 local_bh_disable();
Vlad Yasevich1690be62013-02-13 12:00:18 +0000852 rcu_read_lock();
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900853 br_fdb_update(br, p, addr, vid, true);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000854 rcu_read_unlock();
Nikolay Aleksandrovc4c832f2015-06-06 06:49:00 -0700855 local_bh_enable();
Nikolay Aleksandroveb100e02017-03-23 12:27:13 +0200856 } else if (ndm->ndm_flags & NTF_EXT_LEARNED) {
857 err = br_fdb_external_learn_add(br, p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000858 } else {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900859 spin_lock_bh(&br->hash_lock);
860 err = fdb_add_entry(br, p, addr, ndm->ndm_state,
Vlad Yasevich1690be62013-02-13 12:00:18 +0000861 nlh_flags, vid);
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900862 spin_unlock_bh(&br->hash_lock);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000863 }
864
865 return err;
866}
867
stephen hemminger36fd2b62011-04-04 14:03:31 +0000868/* Add new permanent fdb entry with RTM_NEWNEIGH */
stephen hemmingeredc7d572012-10-01 12:32:33 +0000869int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
870 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100871 const unsigned char *addr, u16 vid, u16 nlh_flags)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000872{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200873 struct net_bridge_vlan_group *vg;
Roopa Prabhu37418732015-10-08 10:38:52 -0700874 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200875 struct net_bridge_vlan *v;
Roopa Prabhu37418732015-10-08 10:38:52 -0700876 struct net_bridge *br = NULL;
John Fastabend77162022012-04-15 06:43:56 +0000877 int err = 0;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000878
Roopa Prabhub74fd302017-08-29 13:16:57 -0700879 trace_br_fdb_add(ndm, dev, addr, vid, nlh_flags);
880
stephen hemminger292d1392011-11-09 18:30:08 +0000881 if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE))) {
882 pr_info("bridge: RTM_NEWNEIGH with invalid state %#x\n", ndm->ndm_state);
883 return -EINVAL;
884 }
885
Stephen Hemminger537f7f82013-06-25 09:34:36 -0700886 if (is_zero_ether_addr(addr)) {
887 pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n");
888 return -EINVAL;
889 }
890
Roopa Prabhu37418732015-10-08 10:38:52 -0700891 if (dev->priv_flags & IFF_EBRIDGE) {
892 br = netdev_priv(dev);
893 vg = br_vlan_group(br);
894 } else {
895 p = br_port_get_rtnl(dev);
896 if (!p) {
897 pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n",
898 dev->name);
899 return -EINVAL;
900 }
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900901 br = p->br;
Roopa Prabhu37418732015-10-08 10:38:52 -0700902 vg = nbp_vlan_group(p);
stephen hemminger36fd2b62011-04-04 14:03:31 +0000903 }
904
Jiri Pirkof6f64242014-11-28 14:34:15 +0100905 if (vid) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200906 v = br_vlan_find(vg, vid);
Roopa Prabhu37418732015-10-08 10:38:52 -0700907 if (!v || !br_vlan_should_use(v)) {
908 pr_info("bridge: RTM_NEWNEIGH with unconfigured vlan %d on %s\n", vid, dev->name);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000909 return -EINVAL;
910 }
911
912 /* VID was specified, so use it. */
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900913 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid);
stephen hemminger292d1392011-11-09 18:30:08 +0000914 } else {
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900915 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200916 if (err || !vg || !vg->num_vlans)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000917 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000918
919 /* We have vlans configured on this port and user didn't
920 * specify a VLAN. To be nice, add/update entry for every
921 * vlan on this port.
922 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200923 list_for_each_entry(v, &vg->vlan_list, vlist) {
Roopa Prabhu37418732015-10-08 10:38:52 -0700924 if (!br_vlan_should_use(v))
925 continue;
Toshiaki Makita7bb90c32016-08-04 11:11:19 +0900926 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000927 if (err)
928 goto out;
Vlad Yasevich1690be62013-02-13 12:00:18 +0000929 }
stephen hemminger292d1392011-11-09 18:30:08 +0000930 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000931
Vlad Yasevich1690be62013-02-13 12:00:18 +0000932out:
933 return err;
934}
935
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100936static int fdb_delete_by_addr_and_port(struct net_bridge *br,
937 const struct net_bridge_port *p,
Nikolay Aleksandrov8c86f962015-06-09 03:34:13 -0700938 const u8 *addr, u16 vlan)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000939{
Vlad Yasevich1690be62013-02-13 12:00:18 +0000940 struct net_bridge_fdb_entry *fdb;
941
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +0100942 fdb = br_fdb_find(br, addr, vlan);
Nikolay Aleksandrov8c86f962015-06-09 03:34:13 -0700943 if (!fdb || fdb->dst != p)
Vlad Yasevich1690be62013-02-13 12:00:18 +0000944 return -ENOENT;
945
946 fdb_delete(br, fdb);
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100947
Vlad Yasevich1690be62013-02-13 12:00:18 +0000948 return 0;
949}
950
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100951static int __br_fdb_delete(struct net_bridge *br,
952 const struct net_bridge_port *p,
Vlad Yasevich1690be62013-02-13 12:00:18 +0000953 const unsigned char *addr, u16 vid)
954{
955 int err;
956
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100957 spin_lock_bh(&br->hash_lock);
958 err = fdb_delete_by_addr_and_port(br, p, addr, vid);
959 spin_unlock_bh(&br->hash_lock);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000960
stephen hemminger36fd2b62011-04-04 14:03:31 +0000961 return err;
962}
963
stephen hemminger36fd2b62011-04-04 14:03:31 +0000964/* Remove neighbor entry with RTM_DELNEIGH */
Vlad Yasevich1690be62013-02-13 12:00:18 +0000965int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
966 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100967 const unsigned char *addr, u16 vid)
stephen hemminger36fd2b62011-04-04 14:03:31 +0000968{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200969 struct net_bridge_vlan_group *vg;
Roopa Prabhu37418732015-10-08 10:38:52 -0700970 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200971 struct net_bridge_vlan *v;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100972 struct net_bridge *br;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000973 int err;
974
Roopa Prabhu37418732015-10-08 10:38:52 -0700975 if (dev->priv_flags & IFF_EBRIDGE) {
976 br = netdev_priv(dev);
977 vg = br_vlan_group(br);
978 } else {
979 p = br_port_get_rtnl(dev);
980 if (!p) {
981 pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n",
982 dev->name);
983 return -EINVAL;
984 }
985 vg = nbp_vlan_group(p);
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100986 br = p->br;
stephen hemminger36fd2b62011-04-04 14:03:31 +0000987 }
988
Jiri Pirkof6f64242014-11-28 14:34:15 +0100989 if (vid) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200990 v = br_vlan_find(vg, vid);
991 if (!v) {
Roopa Prabhu37418732015-10-08 10:38:52 -0700992 pr_info("bridge: RTM_DELNEIGH with unconfigured vlan %d on %s\n", vid, dev->name);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000993 return -EINVAL;
994 }
stephen hemminger36fd2b62011-04-04 14:03:31 +0000995
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100996 err = __br_fdb_delete(br, p, addr, vid);
Vlad Yasevich1690be62013-02-13 12:00:18 +0000997 } else {
Toshiaki Makita25d3b492015-02-09 20:16:17 +0900998 err = -ENOENT;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +0100999 err &= __br_fdb_delete(br, p, addr, 0);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001000 if (!vg || !vg->num_vlans)
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +01001001 return err;
Vlad Yasevich1690be62013-02-13 12:00:18 +00001002
Roopa Prabhu37418732015-10-08 10:38:52 -07001003 list_for_each_entry(v, &vg->vlan_list, vlist) {
1004 if (!br_vlan_should_use(v))
1005 continue;
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +01001006 err &= __br_fdb_delete(br, p, addr, v->vid);
Roopa Prabhu37418732015-10-08 10:38:52 -07001007 }
Vlad Yasevich1690be62013-02-13 12:00:18 +00001008 }
Nikolay Aleksandrov5019ab52017-02-13 14:59:11 +01001009
stephen hemminger36fd2b62011-04-04 14:03:31 +00001010 return err;
1011}
Vlad Yasevich8db24af2014-05-16 09:59:17 -04001012
1013int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p)
1014{
1015 struct net_bridge_fdb_entry *fdb, *tmp;
1016 int i;
1017 int err;
1018
1019 ASSERT_RTNL();
1020
1021 for (i = 0; i < BR_HASH_SIZE; i++) {
1022 hlist_for_each_entry(fdb, &br->hash[i], hlist) {
1023 /* We only care for static entries */
1024 if (!fdb->is_static)
1025 continue;
1026
1027 err = dev_uc_add(p->dev, fdb->addr.addr);
1028 if (err)
1029 goto rollback;
1030 }
1031 }
1032 return 0;
1033
1034rollback:
1035 for (i = 0; i < BR_HASH_SIZE; i++) {
1036 hlist_for_each_entry(tmp, &br->hash[i], hlist) {
1037 /* If we reached the fdb that failed, we can stop */
1038 if (tmp == fdb)
1039 break;
1040
1041 /* We only care for static entries */
1042 if (!tmp->is_static)
1043 continue;
1044
1045 dev_uc_del(p->dev, tmp->addr.addr);
1046 }
1047 }
1048 return err;
1049}
1050
1051void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p)
1052{
1053 struct net_bridge_fdb_entry *fdb;
1054 int i;
1055
1056 ASSERT_RTNL();
1057
1058 for (i = 0; i < BR_HASH_SIZE; i++) {
1059 hlist_for_each_entry_rcu(fdb, &br->hash[i], hlist) {
1060 /* We only care for static entries */
1061 if (!fdb->is_static)
1062 continue;
1063
1064 dev_uc_del(p->dev, fdb->addr.addr);
1065 }
1066 }
1067}
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001068
Jiri Pirko3aeb6612015-01-15 23:49:37 +01001069int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001070 const unsigned char *addr, u16 vid)
1071{
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001072 struct net_bridge_fdb_entry *fdb;
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001073 struct hlist_head *head;
1074 bool modified = false;
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001075 int err = 0;
1076
Roopa Prabhub74fd302017-08-29 13:16:57 -07001077 trace_br_fdb_external_learn_add(br, p, addr, vid);
1078
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001079 spin_lock_bh(&br->hash_lock);
1080
1081 head = &br->hash[br_mac_hash(addr, vid)];
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +01001082 fdb = br_fdb_find(br, addr, vid);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001083 if (!fdb) {
Roopa Prabhub7af1472015-10-27 07:52:56 -07001084 fdb = fdb_create(head, p, addr, vid, 0, 0);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001085 if (!fdb) {
1086 err = -ENOMEM;
1087 goto err_unlock;
1088 }
1089 fdb->added_by_external_learn = 1;
1090 fdb_notify(br, fdb, RTM_NEWNEIGH);
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001091 } else {
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001092 fdb->updated = jiffies;
Nikolay Aleksandrov7597b262017-07-03 15:14:59 -07001093
1094 if (fdb->dst != p) {
1095 fdb->dst = p;
1096 modified = true;
1097 }
1098
1099 if (fdb->added_by_external_learn) {
1100 /* Refresh entry */
1101 fdb->used = jiffies;
1102 } else if (!fdb->added_by_user) {
1103 /* Take over SW learned entry */
1104 fdb->added_by_external_learn = 1;
1105 modified = true;
1106 }
1107
1108 if (modified)
1109 fdb_notify(br, fdb, RTM_NEWNEIGH);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001110 }
1111
1112err_unlock:
1113 spin_unlock_bh(&br->hash_lock);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001114
1115 return err;
1116}
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001117
Jiri Pirko3aeb6612015-01-15 23:49:37 +01001118int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001119 const unsigned char *addr, u16 vid)
1120{
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001121 struct net_bridge_fdb_entry *fdb;
1122 int err = 0;
1123
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001124 spin_lock_bh(&br->hash_lock);
1125
Nikolay Aleksandrovbfd0aea2017-02-13 14:59:09 +01001126 fdb = br_fdb_find(br, addr, vid);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001127 if (fdb && fdb->added_by_external_learn)
1128 fdb_delete(br, fdb);
1129 else
1130 err = -ENOENT;
1131
1132 spin_unlock_bh(&br->hash_lock);
Scott Feldmancf6b8e12014-11-28 14:34:21 +01001133
1134 return err;
1135}
Arkadi Sharshevsky9fe8bce2017-06-08 08:44:15 +02001136
1137void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
1138 const unsigned char *addr, u16 vid)
1139{
1140 struct net_bridge_fdb_entry *fdb;
1141
1142 spin_lock_bh(&br->hash_lock);
1143
1144 fdb = br_fdb_find(br, addr, vid);
1145 if (fdb)
1146 fdb->offloaded = 1;
1147
1148 spin_unlock_bh(&br->hash_lock);
1149}