14 #include <linux/kernel.h>
19 #include <linux/netdevice.h>
22 #include <linux/random.h>
23 #include <linux/slab.h>
25 #include <asm/unaligned.h>
30 const unsigned char *
addr);
58 static inline unsigned long hold_time(
const struct net_bridge *br)
63 static inline int has_expired(
const struct net_bridge *br,
70 static inline int br_mac_hash(
const unsigned char *
mac)
86 hlist_del_rcu(&f->
hlist);
110 ether_addr_equal(op->
dev->dev_addr,
125 fdb_insert(br, p, newaddr);
139 fdb_insert(br,
NULL, newaddr);
145 unsigned long delay = hold_time(br);
155 unsigned long this_timer;
162 next_timer = this_timer;
217 ether_addr_equal(op->
dev->dev_addr,
234 const unsigned char *
addr)
239 hlist_for_each_entry_rcu(fdb, h, &br->
hash[br_mac_hash(addr)],
hlist) {
240 if (ether_addr_equal(fdb->
addr.
addr, addr)) {
250 #if IS_ENABLED(CONFIG_ATM_LANE)
260 port = br_port_get_rcu(dev);
265 ret = fdb && fdb->
dst && fdb->
dst->dev != dev &&
279 unsigned long maxnum,
unsigned long skip)
290 hlist_for_each_entry_rcu(f, h, &br->
hash[i],
hlist) {
294 if (has_expired(br, f))
328 const unsigned char *addr)
334 if (ether_addr_equal(fdb->
addr.
addr, addr))
341 const unsigned char *addr)
346 hlist_for_each_entry_rcu(fdb, h, head,
hlist) {
347 if (ether_addr_equal(fdb->
addr.
addr, addr))
355 const unsigned char *addr)
366 hlist_add_head_rcu(&fdb->
hlist, head);
372 const unsigned char *addr)
377 if (!is_valid_ether_addr(addr))
380 fdb = fdb_find(head, addr);
387 br_warn(br,
"adding interface %s with same address "
388 "as a received packet\n",
393 fdb = fdb_create(head, source, addr);
404 const unsigned char *addr)
409 ret = fdb_insert(br, source, addr);
415 const unsigned char *addr)
421 if (hold_time(br) == 0)
429 fdb = fdb_find_rcu(head, addr);
434 br_warn(br,
"received packet on %s with "
435 "own address as source address\n",
444 if (
likely(!fdb_find(head, addr))) {
445 fdb = fdb_create(head, source, addr);
462 else if (has_expired(fdb->
dst->br, fdb))
477 nlh = nlmsg_put(skb, portid, seq, type,
sizeof(*ndm), flags);
481 ndm = nlmsg_data(nlh);
491 goto nla_put_failure;
493 ci.ndm_confirmed = 0;
497 goto nla_put_failure;
498 return nlmsg_end(skb, nlh);
501 nlmsg_cancel(skb, nlh);
505 static inline size_t fdb_nlmsg_size(
void)
519 skb = nlmsg_new(fdb_nlmsg_size(),
GFP_ATOMIC);
523 err = fdb_fill_info(skb, br, fdb, 0, 0, type, 0);
553 hlist_for_each_entry_rcu(f, h, &br->
hash[i],
hlist) {
554 if (idx < cb->
args[0])
557 if (fdb_fill_info(skb, br, f,
580 fdb = fdb_find(head, addr);
585 fdb = fdb_create(head, source, addr);
594 if (fdb_to_nud(fdb) != state) {
613 const unsigned char *addr,
u16 nlh_flags)
623 p = br_port_get_rtnl(dev);
625 pr_info(
"bridge: RTM_NEWNEIGH %s not a bridge port\n",
635 spin_lock_bh(&p->
br->hash_lock);
636 err = fdb_add_entry(p, addr, ndm->
ndm_state, nlh_flags);
637 spin_unlock_bh(&p->
br->hash_lock);
649 fdb = fdb_find(head, addr);
653 fdb_delete(p->
br, fdb);
659 const unsigned char *addr)
664 p = br_port_get_rtnl(dev);
666 pr_info(
"bridge: RTM_DELNEIGH %s not a bridge port\n",
671 spin_lock_bh(&p->
br->hash_lock);
672 err = fdb_delete_by_addr(p, addr);
673 spin_unlock_bh(&p->
br->hash_lock);