3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/rculist.h>
17 #include <linux/spinlock.h>
18 #include <linux/times.h>
19 #include <linux/netdevice.h>
20 #include <linux/etherdevice.h>
21 #include <linux/jhash.h>
22 #include <linux/random.h>
23 #include <linux/slab.h>
24 #include <linux/atomic.h>
25 #include <asm/unaligned.h>
26 #include <linux/if_vlan.h>
27 #include "br_private.h"
29 static struct kmem_cache
*br_fdb_cache __read_mostly
;
30 static struct net_bridge_fdb_entry
*fdb_find(struct hlist_head
*head
,
31 const unsigned char *addr
,
33 static int fdb_insert(struct net_bridge
*br
, struct net_bridge_port
*source
,
34 const unsigned char *addr
, u16 vid
);
35 static void fdb_notify(struct net_bridge
*br
,
36 const struct net_bridge_fdb_entry
*, int);
38 static u32 fdb_salt __read_mostly
;
40 int __init
br_fdb_init(void)
42 br_fdb_cache
= kmem_cache_create("bridge_fdb_cache",
43 sizeof(struct net_bridge_fdb_entry
),
45 SLAB_HWCACHE_ALIGN
, NULL
);
49 get_random_bytes(&fdb_salt
, sizeof(fdb_salt
));
53 void br_fdb_fini(void)
55 kmem_cache_destroy(br_fdb_cache
);
59 /* if topology_changing then use forward_delay (default 15 sec)
60 * otherwise keep longer (default 5 minutes)
62 static inline unsigned long hold_time(const struct net_bridge
*br
)
64 return br
->topology_change
? br
->forward_delay
: br
->ageing_time
;
67 static inline int has_expired(const struct net_bridge
*br
,
68 const struct net_bridge_fdb_entry
*fdb
)
70 return !fdb
->is_static
&&
71 time_before_eq(fdb
->updated
+ hold_time(br
), jiffies
);
74 static inline int br_mac_hash(const unsigned char *mac
, __u16 vid
)
76 /* use 1 byte of OUI and 3 bytes of NIC */
77 u32 key
= get_unaligned((u32
*)(mac
+ 2));
78 return jhash_2words(key
, vid
, fdb_salt
) & (BR_HASH_SIZE
- 1);
81 static void fdb_rcu_free(struct rcu_head
*head
)
83 struct net_bridge_fdb_entry
*ent
84 = container_of(head
, struct net_bridge_fdb_entry
, rcu
);
85 kmem_cache_free(br_fdb_cache
, ent
);
88 static void fdb_delete(struct net_bridge
*br
, struct net_bridge_fdb_entry
*f
)
90 hlist_del_rcu(&f
->hlist
);
91 fdb_notify(br
, f
, RTM_DELNEIGH
);
92 call_rcu(&f
->rcu
, fdb_rcu_free
);
95 /* Delete a local entry if no other port had the same address. */
96 static void fdb_delete_local(struct net_bridge
*br
,
97 const struct net_bridge_port
*p
,
98 struct net_bridge_fdb_entry
*f
)
100 const unsigned char *addr
= f
->addr
.addr
;
101 u16 vid
= f
->vlan_id
;
102 struct net_bridge_port
*op
;
104 /* Maybe another port has same hw addr? */
105 list_for_each_entry(op
, &br
->port_list
, list
) {
106 if (op
!= p
&& ether_addr_equal(op
->dev
->dev_addr
, addr
) &&
107 (!vid
|| nbp_vlan_find(op
, vid
))) {
109 f
->added_by_user
= 0;
114 /* Maybe bridge device has same hw addr? */
115 if (p
&& ether_addr_equal(br
->dev
->dev_addr
, addr
) &&
116 (!vid
|| br_vlan_find(br
, vid
))) {
118 f
->added_by_user
= 0;
125 void br_fdb_find_delete_local(struct net_bridge
*br
,
126 const struct net_bridge_port
*p
,
127 const unsigned char *addr
, u16 vid
)
129 struct hlist_head
*head
= &br
->hash
[br_mac_hash(addr
, vid
)];
130 struct net_bridge_fdb_entry
*f
;
132 spin_lock_bh(&br
->hash_lock
);
133 f
= fdb_find(head
, addr
, vid
);
134 if (f
&& f
->is_local
&& !f
->added_by_user
&& f
->dst
== p
)
135 fdb_delete_local(br
, p
, f
);
136 spin_unlock_bh(&br
->hash_lock
);
139 void br_fdb_changeaddr(struct net_bridge_port
*p
, const unsigned char *newaddr
)
141 struct net_bridge
*br
= p
->br
;
142 struct net_port_vlans
*pv
= nbp_get_vlan_info(p
);
147 spin_lock_bh(&br
->hash_lock
);
149 /* Search all chains since old address/hash is unknown */
150 for (i
= 0; i
< BR_HASH_SIZE
; i
++) {
151 struct hlist_node
*h
;
152 hlist_for_each(h
, &br
->hash
[i
]) {
153 struct net_bridge_fdb_entry
*f
;
155 f
= hlist_entry(h
, struct net_bridge_fdb_entry
, hlist
);
156 if (f
->dst
== p
&& f
->is_local
&& !f
->added_by_user
) {
158 fdb_delete_local(br
, p
, f
);
160 /* if this port has no vlan information
161 * configured, we can safely be done at
171 /* insert new address, may fail if invalid address or dup. */
172 fdb_insert(br
, p
, newaddr
, 0);
177 /* Now add entries for every VLAN configured on the port.
178 * This function runs under RTNL so the bitmap will not change
181 for_each_set_bit(vid
, pv
->vlan_bitmap
, VLAN_N_VID
)
182 fdb_insert(br
, p
, newaddr
, vid
);
185 spin_unlock_bh(&br
->hash_lock
);
188 void br_fdb_change_mac_address(struct net_bridge
*br
, const u8
*newaddr
)
190 struct net_bridge_fdb_entry
*f
;
191 struct net_port_vlans
*pv
;
194 spin_lock_bh(&br
->hash_lock
);
196 /* If old entry was unassociated with any port, then delete it. */
197 f
= __br_fdb_get(br
, br
->dev
->dev_addr
, 0);
198 if (f
&& f
->is_local
&& !f
->dst
)
199 fdb_delete_local(br
, NULL
, f
);
201 fdb_insert(br
, NULL
, newaddr
, 0);
203 /* Now remove and add entries for every VLAN configured on the
204 * bridge. This function runs under RTNL so the bitmap will not
205 * change from under us.
207 pv
= br_get_vlan_info(br
);
211 for_each_set_bit_from(vid
, pv
->vlan_bitmap
, VLAN_N_VID
) {
212 f
= __br_fdb_get(br
, br
->dev
->dev_addr
, vid
);
213 if (f
&& f
->is_local
&& !f
->dst
)
214 fdb_delete_local(br
, NULL
, f
);
215 fdb_insert(br
, NULL
, newaddr
, vid
);
218 spin_unlock_bh(&br
->hash_lock
);
221 void br_fdb_cleanup(unsigned long _data
)
223 struct net_bridge
*br
= (struct net_bridge
*)_data
;
224 unsigned long delay
= hold_time(br
);
225 unsigned long next_timer
= jiffies
+ br
->ageing_time
;
228 spin_lock(&br
->hash_lock
);
229 for (i
= 0; i
< BR_HASH_SIZE
; i
++) {
230 struct net_bridge_fdb_entry
*f
;
231 struct hlist_node
*n
;
233 hlist_for_each_entry_safe(f
, n
, &br
->hash
[i
], hlist
) {
234 unsigned long this_timer
;
237 this_timer
= f
->updated
+ delay
;
238 if (time_before_eq(this_timer
, jiffies
))
240 else if (time_before(this_timer
, next_timer
))
241 next_timer
= this_timer
;
244 spin_unlock(&br
->hash_lock
);
246 mod_timer(&br
->gc_timer
, round_jiffies_up(next_timer
));
249 /* Completely flush all dynamic entries in forwarding database.*/
250 void br_fdb_flush(struct net_bridge
*br
)
254 spin_lock_bh(&br
->hash_lock
);
255 for (i
= 0; i
< BR_HASH_SIZE
; i
++) {
256 struct net_bridge_fdb_entry
*f
;
257 struct hlist_node
*n
;
258 hlist_for_each_entry_safe(f
, n
, &br
->hash
[i
], hlist
) {
263 spin_unlock_bh(&br
->hash_lock
);
266 /* Flush all entries referring to a specific port.
267 * if do_all is set also flush static entries
269 void br_fdb_delete_by_port(struct net_bridge
*br
,
270 const struct net_bridge_port
*p
,
275 spin_lock_bh(&br
->hash_lock
);
276 for (i
= 0; i
< BR_HASH_SIZE
; i
++) {
277 struct hlist_node
*h
, *g
;
279 hlist_for_each_safe(h
, g
, &br
->hash
[i
]) {
280 struct net_bridge_fdb_entry
*f
281 = hlist_entry(h
, struct net_bridge_fdb_entry
, hlist
);
285 if (f
->is_static
&& !do_all
)
289 fdb_delete_local(br
, p
, f
);
294 spin_unlock_bh(&br
->hash_lock
);
297 /* No locking or refcounting, assumes caller has rcu_read_lock */
298 struct net_bridge_fdb_entry
*__br_fdb_get(struct net_bridge
*br
,
299 const unsigned char *addr
,
302 struct net_bridge_fdb_entry
*fdb
;
304 hlist_for_each_entry_rcu(fdb
,
305 &br
->hash
[br_mac_hash(addr
, vid
)], hlist
) {
306 if (ether_addr_equal(fdb
->addr
.addr
, addr
) &&
307 fdb
->vlan_id
== vid
) {
308 if (unlikely(has_expired(br
, fdb
)))
317 #if IS_ENABLED(CONFIG_ATM_LANE)
318 /* Interface used by ATM LANE hook to test
319 * if an addr is on some other bridge port */
320 int br_fdb_test_addr(struct net_device
*dev
, unsigned char *addr
)
322 struct net_bridge_fdb_entry
*fdb
;
323 struct net_bridge_port
*port
;
327 port
= br_port_get_rcu(dev
);
331 fdb
= __br_fdb_get(port
->br
, addr
, 0);
332 ret
= fdb
&& fdb
->dst
&& fdb
->dst
->dev
!= dev
&&
333 fdb
->dst
->state
== BR_STATE_FORWARDING
;
339 #endif /* CONFIG_ATM_LANE */
342 * Fill buffer with forwarding table records in
345 int br_fdb_fillbuf(struct net_bridge
*br
, void *buf
,
346 unsigned long maxnum
, unsigned long skip
)
348 struct __fdb_entry
*fe
= buf
;
350 struct net_bridge_fdb_entry
*f
;
352 memset(buf
, 0, maxnum
*sizeof(struct __fdb_entry
));
355 for (i
= 0; i
< BR_HASH_SIZE
; i
++) {
356 hlist_for_each_entry_rcu(f
, &br
->hash
[i
], hlist
) {
360 if (has_expired(br
, f
))
363 /* ignore pseudo entry for local MAC address */
372 /* convert from internal format to API */
373 memcpy(fe
->mac_addr
, f
->addr
.addr
, ETH_ALEN
);
375 /* due to ABI compat need to split into hi/lo */
376 fe
->port_no
= f
->dst
->port_no
;
377 fe
->port_hi
= f
->dst
->port_no
>> 8;
379 fe
->is_local
= f
->is_local
;
381 fe
->ageing_timer_value
= jiffies_delta_to_clock_t(jiffies
- f
->updated
);
393 static struct net_bridge_fdb_entry
*fdb_find(struct hlist_head
*head
,
394 const unsigned char *addr
,
397 struct net_bridge_fdb_entry
*fdb
;
399 hlist_for_each_entry(fdb
, head
, hlist
) {
400 if (ether_addr_equal(fdb
->addr
.addr
, addr
) &&
407 static struct net_bridge_fdb_entry
*fdb_find_rcu(struct hlist_head
*head
,
408 const unsigned char *addr
,
411 struct net_bridge_fdb_entry
*fdb
;
413 hlist_for_each_entry_rcu(fdb
, head
, hlist
) {
414 if (ether_addr_equal(fdb
->addr
.addr
, addr
) &&
421 static struct net_bridge_fdb_entry
*fdb_create(struct hlist_head
*head
,
422 struct net_bridge_port
*source
,
423 const unsigned char *addr
,
426 struct net_bridge_fdb_entry
*fdb
;
428 fdb
= kmem_cache_alloc(br_fdb_cache
, GFP_ATOMIC
);
430 memcpy(fdb
->addr
.addr
, addr
, ETH_ALEN
);
435 fdb
->added_by_user
= 0;
436 fdb
->updated
= fdb
->used
= jiffies
;
437 hlist_add_head_rcu(&fdb
->hlist
, head
);
442 static int fdb_insert(struct net_bridge
*br
, struct net_bridge_port
*source
,
443 const unsigned char *addr
, u16 vid
)
445 struct hlist_head
*head
= &br
->hash
[br_mac_hash(addr
, vid
)];
446 struct net_bridge_fdb_entry
*fdb
;
448 if (!is_valid_ether_addr(addr
))
451 fdb
= fdb_find(head
, addr
, vid
);
453 /* it is okay to have multiple ports with same
454 * address, just use the first one.
458 br_warn(br
, "adding interface %s with same address "
459 "as a received packet\n",
460 source
? source
->dev
->name
: br
->dev
->name
);
464 fdb
= fdb_create(head
, source
, addr
, vid
);
468 fdb
->is_local
= fdb
->is_static
= 1;
469 fdb_notify(br
, fdb
, RTM_NEWNEIGH
);
473 /* Add entry for local address of interface */
474 int br_fdb_insert(struct net_bridge
*br
, struct net_bridge_port
*source
,
475 const unsigned char *addr
, u16 vid
)
479 spin_lock_bh(&br
->hash_lock
);
480 ret
= fdb_insert(br
, source
, addr
, vid
);
481 spin_unlock_bh(&br
->hash_lock
);
485 void br_fdb_update(struct net_bridge
*br
, struct net_bridge_port
*source
,
486 const unsigned char *addr
, u16 vid
, bool added_by_user
)
488 struct hlist_head
*head
= &br
->hash
[br_mac_hash(addr
, vid
)];
489 struct net_bridge_fdb_entry
*fdb
;
490 bool fdb_modified
= false;
492 /* some users want to always flood. */
493 if (hold_time(br
) == 0)
496 /* ignore packets unless we are using this port */
497 if (!(source
->state
== BR_STATE_LEARNING
||
498 source
->state
== BR_STATE_FORWARDING
))
501 fdb
= fdb_find_rcu(head
, addr
, vid
);
503 /* attempt to update an entry for a local interface */
504 if (unlikely(fdb
->is_local
)) {
506 br_warn(br
, "received packet on %s with "
507 "own address as source address\n",
510 /* fastpath: update of existing entry */
511 if (unlikely(source
!= fdb
->dst
)) {
515 fdb
->updated
= jiffies
;
516 if (unlikely(added_by_user
))
517 fdb
->added_by_user
= 1;
518 if (unlikely(fdb_modified
))
519 fdb_notify(br
, fdb
, RTM_NEWNEIGH
);
522 spin_lock(&br
->hash_lock
);
523 if (likely(!fdb_find(head
, addr
, vid
))) {
524 fdb
= fdb_create(head
, source
, addr
, vid
);
526 if (unlikely(added_by_user
))
527 fdb
->added_by_user
= 1;
528 fdb_notify(br
, fdb
, RTM_NEWNEIGH
);
531 /* else we lose race and someone else inserts
532 * it first, don't bother updating
534 spin_unlock(&br
->hash_lock
);
538 static int fdb_to_nud(const struct net_bridge_fdb_entry
*fdb
)
541 return NUD_PERMANENT
;
542 else if (fdb
->is_static
)
544 else if (has_expired(fdb
->dst
->br
, fdb
))
547 return NUD_REACHABLE
;
550 static int fdb_fill_info(struct sk_buff
*skb
, const struct net_bridge
*br
,
551 const struct net_bridge_fdb_entry
*fdb
,
552 u32 portid
, u32 seq
, int type
, unsigned int flags
)
554 unsigned long now
= jiffies
;
555 struct nda_cacheinfo ci
;
556 struct nlmsghdr
*nlh
;
559 nlh
= nlmsg_put(skb
, portid
, seq
, type
, sizeof(*ndm
), flags
);
563 ndm
= nlmsg_data(nlh
);
564 ndm
->ndm_family
= AF_BRIDGE
;
569 ndm
->ndm_ifindex
= fdb
->dst
? fdb
->dst
->dev
->ifindex
: br
->dev
->ifindex
;
570 ndm
->ndm_state
= fdb_to_nud(fdb
);
572 if (nla_put(skb
, NDA_LLADDR
, ETH_ALEN
, &fdb
->addr
))
573 goto nla_put_failure
;
574 ci
.ndm_used
= jiffies_to_clock_t(now
- fdb
->used
);
575 ci
.ndm_confirmed
= 0;
576 ci
.ndm_updated
= jiffies_to_clock_t(now
- fdb
->updated
);
578 if (nla_put(skb
, NDA_CACHEINFO
, sizeof(ci
), &ci
))
579 goto nla_put_failure
;
581 if (nla_put(skb
, NDA_VLAN
, sizeof(u16
), &fdb
->vlan_id
))
582 goto nla_put_failure
;
584 return nlmsg_end(skb
, nlh
);
587 nlmsg_cancel(skb
, nlh
);
591 static inline size_t fdb_nlmsg_size(void)
593 return NLMSG_ALIGN(sizeof(struct ndmsg
))
594 + nla_total_size(ETH_ALEN
) /* NDA_LLADDR */
595 + nla_total_size(sizeof(u16
)) /* NDA_VLAN */
596 + nla_total_size(sizeof(struct nda_cacheinfo
));
599 static void fdb_notify(struct net_bridge
*br
,
600 const struct net_bridge_fdb_entry
*fdb
, int type
)
602 struct net
*net
= dev_net(br
->dev
);
606 skb
= nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC
);
610 err
= fdb_fill_info(skb
, br
, fdb
, 0, 0, type
, 0);
612 /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */
613 WARN_ON(err
== -EMSGSIZE
);
617 rtnl_notify(skb
, net
, 0, RTNLGRP_NEIGH
, NULL
, GFP_ATOMIC
);
620 rtnl_set_sk_err(net
, RTNLGRP_NEIGH
, err
);
623 /* Dump information about entries, in response to GETNEIGH */
624 int br_fdb_dump(struct sk_buff
*skb
,
625 struct netlink_callback
*cb
,
626 struct net_device
*dev
,
629 struct net_bridge
*br
= netdev_priv(dev
);
632 if (!(dev
->priv_flags
& IFF_EBRIDGE
))
635 for (i
= 0; i
< BR_HASH_SIZE
; i
++) {
636 struct net_bridge_fdb_entry
*f
;
638 hlist_for_each_entry_rcu(f
, &br
->hash
[i
], hlist
) {
639 if (idx
< cb
->args
[0])
642 if (fdb_fill_info(skb
, br
, f
,
643 NETLINK_CB(cb
->skb
).portid
,
657 /* Update (create or replace) forwarding database entry */
658 static int fdb_add_entry(struct net_bridge_port
*source
, const __u8
*addr
,
659 __u16 state
, __u16 flags
, __u16 vid
)
661 struct net_bridge
*br
= source
->br
;
662 struct hlist_head
*head
= &br
->hash
[br_mac_hash(addr
, vid
)];
663 struct net_bridge_fdb_entry
*fdb
;
664 bool modified
= false;
666 fdb
= fdb_find(head
, addr
, vid
);
668 if (!(flags
& NLM_F_CREATE
))
671 fdb
= fdb_create(head
, source
, addr
, vid
);
677 if (flags
& NLM_F_EXCL
)
680 if (fdb
->dst
!= source
) {
686 if (fdb_to_nud(fdb
) != state
) {
687 if (state
& NUD_PERMANENT
)
688 fdb
->is_local
= fdb
->is_static
= 1;
689 else if (state
& NUD_NOARP
) {
693 fdb
->is_local
= fdb
->is_static
= 0;
697 fdb
->added_by_user
= 1;
701 fdb
->updated
= jiffies
;
702 fdb_notify(br
, fdb
, RTM_NEWNEIGH
);
708 static int __br_fdb_add(struct ndmsg
*ndm
, struct net_bridge_port
*p
,
709 const unsigned char *addr
, u16 nlh_flags
, u16 vid
)
713 if (ndm
->ndm_flags
& NTF_USE
) {
715 br_fdb_update(p
->br
, p
, addr
, vid
, true);
718 spin_lock_bh(&p
->br
->hash_lock
);
719 err
= fdb_add_entry(p
, addr
, ndm
->ndm_state
,
721 spin_unlock_bh(&p
->br
->hash_lock
);
727 /* Add new permanent fdb entry with RTM_NEWNEIGH */
728 int br_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
729 struct net_device
*dev
,
730 const unsigned char *addr
, u16 nlh_flags
)
732 struct net_bridge_port
*p
;
734 struct net_port_vlans
*pv
;
735 unsigned short vid
= VLAN_N_VID
;
737 if (!(ndm
->ndm_state
& (NUD_PERMANENT
|NUD_NOARP
|NUD_REACHABLE
))) {
738 pr_info("bridge: RTM_NEWNEIGH with invalid state %#x\n", ndm
->ndm_state
);
743 if (nla_len(tb
[NDA_VLAN
]) != sizeof(unsigned short)) {
744 pr_info("bridge: RTM_NEWNEIGH with invalid vlan\n");
748 vid
= nla_get_u16(tb
[NDA_VLAN
]);
750 if (!vid
|| vid
>= VLAN_VID_MASK
) {
751 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n",
757 if (is_zero_ether_addr(addr
)) {
758 pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n");
762 p
= br_port_get_rtnl(dev
);
764 pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n",
769 pv
= nbp_get_vlan_info(p
);
770 if (vid
!= VLAN_N_VID
) {
771 if (!pv
|| !test_bit(vid
, pv
->vlan_bitmap
)) {
772 pr_info("bridge: RTM_NEWNEIGH with unconfigured "
773 "vlan %d on port %s\n", vid
, dev
->name
);
777 /* VID was specified, so use it. */
778 err
= __br_fdb_add(ndm
, p
, addr
, nlh_flags
, vid
);
780 if (!pv
|| bitmap_empty(pv
->vlan_bitmap
, VLAN_N_VID
)) {
781 err
= __br_fdb_add(ndm
, p
, addr
, nlh_flags
, 0);
785 /* We have vlans configured on this port and user didn't
786 * specify a VLAN. To be nice, add/update entry for every
789 for_each_set_bit(vid
, pv
->vlan_bitmap
, VLAN_N_VID
) {
790 err
= __br_fdb_add(ndm
, p
, addr
, nlh_flags
, vid
);
800 static int fdb_delete_by_addr(struct net_bridge
*br
, const u8
*addr
, u16 vlan
)
802 struct hlist_head
*head
= &br
->hash
[br_mac_hash(addr
, vlan
)];
803 struct net_bridge_fdb_entry
*fdb
;
805 fdb
= fdb_find(head
, addr
, vlan
);
813 static int __br_fdb_delete(struct net_bridge_port
*p
,
814 const unsigned char *addr
, u16 vid
)
818 spin_lock_bh(&p
->br
->hash_lock
);
819 err
= fdb_delete_by_addr(p
->br
, addr
, vid
);
820 spin_unlock_bh(&p
->br
->hash_lock
);
825 /* Remove neighbor entry with RTM_DELNEIGH */
826 int br_fdb_delete(struct ndmsg
*ndm
, struct nlattr
*tb
[],
827 struct net_device
*dev
,
828 const unsigned char *addr
)
830 struct net_bridge_port
*p
;
832 struct net_port_vlans
*pv
;
833 unsigned short vid
= VLAN_N_VID
;
836 if (nla_len(tb
[NDA_VLAN
]) != sizeof(unsigned short)) {
837 pr_info("bridge: RTM_NEWNEIGH with invalid vlan\n");
841 vid
= nla_get_u16(tb
[NDA_VLAN
]);
843 if (!vid
|| vid
>= VLAN_VID_MASK
) {
844 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n",
849 p
= br_port_get_rtnl(dev
);
851 pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n",
856 pv
= nbp_get_vlan_info(p
);
857 if (vid
!= VLAN_N_VID
) {
858 if (!pv
|| !test_bit(vid
, pv
->vlan_bitmap
)) {
859 pr_info("bridge: RTM_DELNEIGH with unconfigured "
860 "vlan %d on port %s\n", vid
, dev
->name
);
864 err
= __br_fdb_delete(p
, addr
, vid
);
866 if (!pv
|| bitmap_empty(pv
->vlan_bitmap
, VLAN_N_VID
)) {
867 err
= __br_fdb_delete(p
, addr
, 0);
871 /* We have vlans configured on this port and user didn't
872 * specify a VLAN. To be nice, add/update entry for every
876 for_each_set_bit(vid
, pv
->vlan_bitmap
, VLAN_N_VID
) {
877 err
&= __br_fdb_delete(p
, addr
, vid
);