br_fdb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Forwarding database
  3. * Linux ethernet bridge
  4. *
  5. * Authors:
  6. * Lennert Buytenhek <buytenh@gnu.org>
  7. *
  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.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/rculist.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/times.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/jhash.h>
  21. #include <linux/random.h>
  22. #include <linux/slab.h>
  23. #include <asm/atomic.h>
  24. #include <asm/unaligned.h>
  25. #include "br_private.h"
  26. static struct kmem_cache *br_fdb_cache __read_mostly;
  27. static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
  28. const unsigned char *addr);
  29. static void fdb_notify(const struct net_bridge_fdb_entry *, int);
  30. static u32 fdb_salt __read_mostly;
  31. int __init br_fdb_init(void)
  32. {
  33. br_fdb_cache = kmem_cache_create("bridge_fdb_cache",
  34. sizeof(struct net_bridge_fdb_entry),
  35. 0,
  36. SLAB_HWCACHE_ALIGN, NULL);
  37. if (!br_fdb_cache)
  38. return -ENOMEM;
  39. get_random_bytes(&fdb_salt, sizeof(fdb_salt));
  40. return 0;
  41. }
  42. void br_fdb_fini(void)
  43. {
  44. kmem_cache_destroy(br_fdb_cache);
  45. }
  46. /* if topology_changing then use forward_delay (default 15 sec)
  47. * otherwise keep longer (default 5 minutes)
  48. */
  49. static inline unsigned long hold_time(const struct net_bridge *br)
  50. {
  51. return br->topology_change ? br->forward_delay : br->ageing_time;
  52. }
  53. static inline int has_expired(const struct net_bridge *br,
  54. const struct net_bridge_fdb_entry *fdb)
  55. {
  56. return !fdb->is_static &&
  57. time_before_eq(fdb->updated + hold_time(br), jiffies);
  58. }
  59. static inline int br_mac_hash(const unsigned char *mac)
  60. {
  61. /* use 1 byte of OUI cnd 3 bytes of NIC */
  62. u32 key = get_unaligned((u32 *)(mac + 2));
  63. return jhash_1word(key, fdb_salt) & (BR_HASH_SIZE - 1);
  64. }
  65. static void fdb_rcu_free(struct rcu_head *head)
  66. {
  67. struct net_bridge_fdb_entry *ent
  68. = container_of(head, struct net_bridge_fdb_entry, rcu);
  69. kmem_cache_free(br_fdb_cache, ent);
  70. }
  71. static inline void fdb_delete(struct net_bridge_fdb_entry *f)
  72. {
  73. fdb_notify(f, RTM_DELNEIGH);
  74. hlist_del_rcu(&f->hlist);
  75. call_rcu(&f->rcu, fdb_rcu_free);
  76. }
  77. void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
  78. {
  79. struct net_bridge *br = p->br;
  80. int i;
  81. spin_lock_bh(&br->hash_lock);
  82. /* Search all chains since old address/hash is unknown */
  83. for (i = 0; i < BR_HASH_SIZE; i++) {
  84. struct hlist_node *h;
  85. hlist_for_each(h, &br->hash[i]) {
  86. struct net_bridge_fdb_entry *f;
  87. f = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
  88. if (f->dst == p && f->is_local) {
  89. /* maybe another port has same hw addr? */
  90. struct net_bridge_port *op;
  91. list_for_each_entry(op, &br->port_list, list) {
  92. if (op != p &&
  93. !compare_ether_addr(op->dev->dev_addr,
  94. f->addr.addr)) {
  95. f->dst = op;
  96. goto insert;
  97. }
  98. }
  99. /* delete old one */
  100. fdb_delete(f);
  101. goto insert;
  102. }
  103. }
  104. }
  105. insert:
  106. /* insert new address, may fail if invalid address or dup. */
  107. fdb_insert(br, p, newaddr);
  108. spin_unlock_bh(&br->hash_lock);
  109. }
  110. void br_fdb_cleanup(unsigned long _data)
  111. {
  112. struct net_bridge *br = (struct net_bridge *)_data;
  113. unsigned long delay = hold_time(br);
  114. unsigned long next_timer = jiffies + br->ageing_time;
  115. int i;
  116. spin_lock_bh(&br->hash_lock);
  117. for (i = 0; i < BR_HASH_SIZE; i++) {
  118. struct net_bridge_fdb_entry *f;
  119. struct hlist_node *h, *n;
  120. hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) {
  121. unsigned long this_timer;
  122. if (f->is_static)
  123. continue;
  124. this_timer = f->updated + delay;
  125. if (time_before_eq(this_timer, jiffies))
  126. fdb_delete(f);
  127. else if (time_before(this_timer, next_timer))
  128. next_timer = this_timer;
  129. }
  130. }
  131. spin_unlock_bh(&br->hash_lock);
  132. mod_timer(&br->gc_timer, round_jiffies_up(next_timer));
  133. }
  134. /* Completely flush all dynamic entries in forwarding database.*/
  135. void br_fdb_flush(struct net_bridge *br)
  136. {
  137. int i;
  138. spin_lock_bh(&br->hash_lock);
  139. for (i = 0; i < BR_HASH_SIZE; i++) {
  140. struct net_bridge_fdb_entry *f;
  141. struct hlist_node *h, *n;
  142. hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) {
  143. if (!f->is_static)
  144. fdb_delete(f);
  145. }
  146. }
  147. spin_unlock_bh(&br->hash_lock);
  148. }
  149. /* Flush all entries referring to a specific port.
  150. * if do_all is set also flush static entries
  151. */
  152. void br_fdb_delete_by_port(struct net_bridge *br,
  153. const struct net_bridge_port *p,
  154. int do_all)
  155. {
  156. int i;
  157. spin_lock_bh(&br->hash_lock);
  158. for (i = 0; i < BR_HASH_SIZE; i++) {
  159. struct hlist_node *h, *g;
  160. hlist_for_each_safe(h, g, &br->hash[i]) {
  161. struct net_bridge_fdb_entry *f
  162. = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
  163. if (f->dst != p)
  164. continue;
  165. if (f->is_static && !do_all)
  166. continue;
  167. /*
  168. * if multiple ports all have the same device address
  169. * then when one port is deleted, assign
  170. * the local entry to other port
  171. */
  172. if (f->is_local) {
  173. struct net_bridge_port *op;
  174. list_for_each_entry(op, &br->port_list, list) {
  175. if (op != p &&
  176. !compare_ether_addr(op->dev->dev_addr,
  177. f->addr.addr)) {
  178. f->dst = op;
  179. goto skip_delete;
  180. }
  181. }
  182. }
  183. fdb_delete(f);
  184. skip_delete: ;
  185. }
  186. }
  187. spin_unlock_bh(&br->hash_lock);
  188. }
  189. /* No locking or refcounting, assumes caller has rcu_read_lock */
  190. struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
  191. const unsigned char *addr)
  192. {
  193. struct hlist_node *h;
  194. struct net_bridge_fdb_entry *fdb;
  195. hlist_for_each_entry_rcu(fdb, h, &br->hash[br_mac_hash(addr)], hlist) {
  196. if (!compare_ether_addr(fdb->addr.addr, addr)) {
  197. if (unlikely(has_expired(br, fdb)))
  198. break;
  199. return fdb;
  200. }
  201. }
  202. return NULL;
  203. }
  204. #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
  205. /* Interface used by ATM LANE hook to test
  206. * if an addr is on some other bridge port */
  207. int br_fdb_test_addr(struct net_device *dev, unsigned char *addr)
  208. {
  209. struct net_bridge_fdb_entry *fdb;
  210. struct net_bridge_port *port;
  211. int ret;
  212. rcu_read_lock();
  213. port = br_port_get_rcu(dev);
  214. if (!port)
  215. ret = 0;
  216. else {
  217. fdb = __br_fdb_get(port->br, addr);
  218. ret = fdb && fdb->dst->dev != dev &&
  219. fdb->dst->state == BR_STATE_FORWARDING;
  220. }
  221. rcu_read_unlock();
  222. return ret;
  223. }
  224. #endif /* CONFIG_ATM_LANE */
  225. /*
  226. * Fill buffer with forwarding table records in
  227. * the API format.
  228. */
  229. int br_fdb_fillbuf(struct net_bridge *br, void *buf,
  230. unsigned long maxnum, unsigned long skip)
  231. {
  232. struct __fdb_entry *fe = buf;
  233. int i, num = 0;
  234. struct hlist_node *h;
  235. struct net_bridge_fdb_entry *f;
  236. memset(buf, 0, maxnum*sizeof(struct __fdb_entry));
  237. rcu_read_lock();
  238. for (i = 0; i < BR_HASH_SIZE; i++) {
  239. hlist_for_each_entry_rcu(f, h, &br->hash[i], hlist) {
  240. if (num >= maxnum)
  241. goto out;
  242. if (has_expired(br, f))
  243. continue;
  244. if (skip) {
  245. --skip;
  246. continue;
  247. }
  248. /* convert from internal format to API */
  249. memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN);
  250. /* due to ABI compat need to split into hi/lo */
  251. fe->port_no = f->dst->port_no;
  252. fe->port_hi = f->dst->port_no >> 8;
  253. fe->is_local = f->is_local;
  254. if (!f->is_static)
  255. fe->ageing_timer_value = jiffies_to_clock_t(jiffies - f->updated);
  256. ++fe;
  257. ++num;
  258. }
  259. }
  260. out:
  261. rcu_read_unlock();
  262. return num;
  263. }
  264. static struct net_bridge_fdb_entry *fdb_find(struct hlist_head *head,
  265. const unsigned char *addr)
  266. {
  267. struct hlist_node *h;
  268. struct net_bridge_fdb_entry *fdb;
  269. hlist_for_each_entry(fdb, h, head, hlist) {
  270. if (!compare_ether_addr(fdb->addr.addr, addr))
  271. return fdb;
  272. }
  273. return NULL;
  274. }
  275. static struct net_bridge_fdb_entry *fdb_find_rcu(struct hlist_head *head,
  276. const unsigned char *addr)
  277. {
  278. struct hlist_node *h;
  279. struct net_bridge_fdb_entry *fdb;
  280. hlist_for_each_entry_rcu(fdb, h, head, hlist) {
  281. if (!compare_ether_addr(fdb->addr.addr, addr))
  282. return fdb;
  283. }
  284. return NULL;
  285. }
  286. static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head,
  287. struct net_bridge_port *source,
  288. const unsigned char *addr)
  289. {
  290. struct net_bridge_fdb_entry *fdb;
  291. fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC);
  292. if (fdb) {
  293. memcpy(fdb->addr.addr, addr, ETH_ALEN);
  294. fdb->dst = source;
  295. fdb->is_local = 0;
  296. fdb->is_static = 0;
  297. fdb->updated = fdb->used = jiffies;
  298. hlist_add_head_rcu(&fdb->hlist, head);
  299. fdb_notify(fdb, RTM_NEWNEIGH);
  300. }
  301. return fdb;
  302. }
  303. static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
  304. const unsigned char *addr)
  305. {
  306. struct hlist_head *head = &br->hash[br_mac_hash(addr)];
  307. struct net_bridge_fdb_entry *fdb;
  308. if (!is_valid_ether_addr(addr))
  309. return -EINVAL;
  310. fdb = fdb_find(head, addr);
  311. if (fdb) {
  312. /* it is okay to have multiple ports with same
  313. * address, just use the first one.
  314. */
  315. if (fdb->is_local)
  316. return 0;
  317. br_warn(br, "adding interface %s with same address "
  318. "as a received packet\n",
  319. source->dev->name);
  320. fdb_delete(fdb);
  321. }
  322. fdb = fdb_create(head, source, addr);
  323. if (!fdb)
  324. return -ENOMEM;
  325. fdb->is_local = fdb->is_static = 1;
  326. return 0;
  327. }
  328. /* Add entry for local address of interface */
  329. int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
  330. const unsigned char *addr)
  331. {
  332. int ret;
  333. spin_lock_bh(&br->hash_lock);
  334. ret = fdb_insert(br, source, addr);
  335. spin_unlock_bh(&br->hash_lock);
  336. return ret;
  337. }
  338. void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
  339. const unsigned char *addr)
  340. {
  341. struct hlist_head *head = &br->hash[br_mac_hash(addr)];
  342. struct net_bridge_fdb_entry *fdb;
  343. /* some users want to always flood. */
  344. if (hold_time(br) == 0)
  345. return;
  346. /* ignore packets unless we are using this port */
  347. if (!(source->state == BR_STATE_LEARNING ||
  348. source->state == BR_STATE_FORWARDING))
  349. return;
  350. fdb = fdb_find_rcu(head, addr);
  351. if (likely(fdb)) {
  352. /* attempt to update an entry for a local interface */
  353. if (unlikely(fdb->is_local)) {
  354. if (net_ratelimit())
  355. br_warn(br, "received packet on %s with "
  356. "own address as source address\n",
  357. source->dev->name);
  358. } else {
  359. /* fastpath: update of existing entry */
  360. fdb->dst = source;
  361. fdb->updated = jiffies;
  362. }
  363. } else {
  364. spin_lock(&br->hash_lock);
  365. if (likely(!fdb_find(head, addr)))
  366. fdb_create(head, source, addr);
  367. /* else we lose race and someone else inserts
  368. * it first, don't bother updating
  369. */
  370. spin_unlock(&br->hash_lock);
  371. }
  372. }
  373. static int fdb_to_nud(const struct net_bridge_fdb_entry *fdb)
  374. {
  375. if (fdb->is_local)
  376. return NUD_PERMANENT;
  377. else if (fdb->is_static)
  378. return NUD_NOARP;
  379. else if (has_expired(fdb->dst->br, fdb))
  380. return NUD_STALE;
  381. else
  382. return NUD_REACHABLE;
  383. }
  384. static int fdb_fill_info(struct sk_buff *skb,
  385. const struct net_bridge_fdb_entry *fdb,
  386. u32 pid, u32 seq, int type, unsigned int flags)
  387. {
  388. unsigned long now = jiffies;
  389. struct nda_cacheinfo ci;
  390. struct nlmsghdr *nlh;
  391. struct ndmsg *ndm;
  392. nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), flags);
  393. if (nlh == NULL)
  394. return -EMSGSIZE;
  395. ndm = nlmsg_data(nlh);
  396. ndm->ndm_family = AF_BRIDGE;
  397. ndm->ndm_pad1 = 0;
  398. ndm->ndm_pad2 = 0;
  399. ndm->ndm_flags = 0;
  400. ndm->ndm_type = 0;
  401. ndm->ndm_ifindex = fdb->dst->dev->ifindex;
  402. ndm->ndm_state = fdb_to_nud(fdb);
  403. NLA_PUT(skb, NDA_LLADDR, ETH_ALEN, &fdb->addr);
  404. ci.ndm_used = jiffies_to_clock_t(now - fdb->used);
  405. ci.ndm_confirmed = 0;
  406. ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated);
  407. ci.ndm_refcnt = 0;
  408. NLA_PUT(skb, NDA_CACHEINFO, sizeof(ci), &ci);
  409. return nlmsg_end(skb, nlh);
  410. nla_put_failure:
  411. nlmsg_cancel(skb, nlh);
  412. return -EMSGSIZE;
  413. }
  414. static inline size_t fdb_nlmsg_size(void)
  415. {
  416. return NLMSG_ALIGN(sizeof(struct ndmsg))
  417. + nla_total_size(ETH_ALEN) /* NDA_LLADDR */
  418. + nla_total_size(sizeof(struct nda_cacheinfo));
  419. }
  420. static void fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
  421. {
  422. struct net *net = dev_net(fdb->dst->dev);
  423. struct sk_buff *skb;
  424. int err = -ENOBUFS;
  425. skb = nlmsg_new(fdb_nlmsg_size(), GFP_ATOMIC);
  426. if (skb == NULL)
  427. goto errout;
  428. err = fdb_fill_info(skb, fdb, 0, 0, type, 0);
  429. if (err < 0) {
  430. /* -EMSGSIZE implies BUG in fdb_nlmsg_size() */
  431. WARN_ON(err == -EMSGSIZE);
  432. kfree_skb(skb);
  433. goto errout;
  434. }
  435. rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
  436. return;
  437. errout:
  438. if (err < 0)
  439. rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
  440. }
  441. /* Dump information about entries, in response to GETNEIGH */
  442. int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
  443. {
  444. struct net *net = sock_net(skb->sk);
  445. struct net_device *dev;
  446. int idx = 0;
  447. rcu_read_lock();
  448. for_each_netdev_rcu(net, dev) {
  449. struct net_bridge *br = netdev_priv(dev);
  450. int i;
  451. if (!(dev->priv_flags & IFF_EBRIDGE))
  452. continue;
  453. for (i = 0; i < BR_HASH_SIZE; i++) {
  454. struct hlist_node *h;
  455. struct net_bridge_fdb_entry *f;
  456. hlist_for_each_entry_rcu(f, h, &br->hash[i], hlist) {
  457. if (idx < cb->args[0])
  458. goto skip;
  459. if (fdb_fill_info(skb, f,
  460. NETLINK_CB(cb->skb).pid,
  461. cb->nlh->nlmsg_seq,
  462. RTM_NEWNEIGH,
  463. NLM_F_MULTI) < 0)
  464. break;
  465. skip:
  466. ++idx;
  467. }
  468. }
  469. }
  470. rcu_read_unlock();
  471. cb->args[0] = idx;
  472. return skb->len;
  473. }
  474. /* Create new static fdb entry */
  475. static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr,
  476. __u16 state)
  477. {
  478. struct net_bridge *br = source->br;
  479. struct hlist_head *head = &br->hash[br_mac_hash(addr)];
  480. struct net_bridge_fdb_entry *fdb;
  481. fdb = fdb_find(head, addr);
  482. if (fdb)
  483. return -EEXIST;
  484. fdb = fdb_create(head, source, addr);
  485. if (!fdb)
  486. return -ENOMEM;
  487. if (state & NUD_PERMANENT)
  488. fdb->is_local = fdb->is_static = 1;
  489. else if (state & NUD_NOARP)
  490. fdb->is_static = 1;
  491. return 0;
  492. }
  493. /* Add new permanent fdb entry with RTM_NEWNEIGH */
  494. int br_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  495. {
  496. struct net *net = sock_net(skb->sk);
  497. struct ndmsg *ndm;
  498. struct nlattr *tb[NDA_MAX+1];
  499. struct net_device *dev;
  500. struct net_bridge_port *p;
  501. const __u8 *addr;
  502. int err;
  503. ASSERT_RTNL();
  504. err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
  505. if (err < 0)
  506. return err;
  507. ndm = nlmsg_data(nlh);
  508. if (ndm->ndm_ifindex == 0) {
  509. pr_info("bridge: RTM_NEWNEIGH with invalid ifindex\n");
  510. return -EINVAL;
  511. }
  512. dev = __dev_get_by_index(net, ndm->ndm_ifindex);
  513. if (dev == NULL) {
  514. pr_info("bridge: RTM_NEWNEIGH with unknown ifindex\n");
  515. return -ENODEV;
  516. }
  517. if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
  518. pr_info("bridge: RTM_NEWNEIGH with invalid address\n");
  519. return -EINVAL;
  520. }
  521. addr = nla_data(tb[NDA_LLADDR]);
  522. if (!is_valid_ether_addr(addr)) {
  523. pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n");
  524. return -EINVAL;
  525. }
  526. p = br_port_get_rtnl(dev);
  527. if (p == NULL) {
  528. pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n",
  529. dev->name);
  530. return -EINVAL;
  531. }
  532. spin_lock_bh(&p->br->hash_lock);
  533. err = fdb_add_entry(p, addr, ndm->ndm_state);
  534. spin_unlock_bh(&p->br->hash_lock);
  535. return err;
  536. }
  537. static int fdb_delete_by_addr(struct net_bridge_port *p, const u8 *addr)
  538. {
  539. struct net_bridge *br = p->br;
  540. struct hlist_head *head = &br->hash[br_mac_hash(addr)];
  541. struct net_bridge_fdb_entry *fdb;
  542. fdb = fdb_find(head, addr);
  543. if (!fdb)
  544. return -ENOENT;
  545. fdb_delete(fdb);
  546. return 0;
  547. }
  548. /* Remove neighbor entry with RTM_DELNEIGH */
  549. int br_fdb_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  550. {
  551. struct net *net = sock_net(skb->sk);
  552. struct ndmsg *ndm;
  553. struct net_bridge_port *p;
  554. struct nlattr *llattr;
  555. const __u8 *addr;
  556. struct net_device *dev;
  557. int err;
  558. ASSERT_RTNL();
  559. if (nlmsg_len(nlh) < sizeof(*ndm))
  560. return -EINVAL;
  561. ndm = nlmsg_data(nlh);
  562. if (ndm->ndm_ifindex == 0) {
  563. pr_info("bridge: RTM_DELNEIGH with invalid ifindex\n");
  564. return -EINVAL;
  565. }
  566. dev = __dev_get_by_index(net, ndm->ndm_ifindex);
  567. if (dev == NULL) {
  568. pr_info("bridge: RTM_DELNEIGH with unknown ifindex\n");
  569. return -ENODEV;
  570. }
  571. llattr = nlmsg_find_attr(nlh, sizeof(*ndm), NDA_LLADDR);
  572. if (llattr == NULL || nla_len(llattr) != ETH_ALEN) {
  573. pr_info("bridge: RTM_DELNEIGH with invalid address\n");
  574. return -EINVAL;
  575. }
  576. addr = nla_data(llattr);
  577. p = br_port_get_rtnl(dev);
  578. if (p == NULL) {
  579. pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n",
  580. dev->name);
  581. return -EINVAL;
  582. }
  583. spin_lock_bh(&p->br->hash_lock);
  584. err = fdb_delete_by_addr(p, addr);
  585. spin_unlock_bh(&p->br->hash_lock);
  586. return err;
  587. }