originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #include "main.h"
  22. #include "originator.h"
  23. #include "hash.h"
  24. #include "translation-table.h"
  25. #include "routing.h"
  26. #include "gateway_client.h"
  27. #include "hard-interface.h"
  28. #include "unicast.h"
  29. #include "soft-interface.h"
  30. static void purge_orig(struct work_struct *work);
  31. static void start_purge_timer(struct bat_priv *bat_priv)
  32. {
  33. INIT_DELAYED_WORK(&bat_priv->orig_work, purge_orig);
  34. queue_delayed_work(bat_event_workqueue, &bat_priv->orig_work, 1 * HZ);
  35. }
  36. /* returns 1 if they are the same originator */
  37. static int compare_orig(const struct hlist_node *node, const void *data2)
  38. {
  39. const void *data1 = container_of(node, struct orig_node, hash_entry);
  40. return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
  41. }
  42. int originator_init(struct bat_priv *bat_priv)
  43. {
  44. if (bat_priv->orig_hash)
  45. return 1;
  46. bat_priv->orig_hash = hash_new(1024);
  47. if (!bat_priv->orig_hash)
  48. goto err;
  49. start_purge_timer(bat_priv);
  50. return 1;
  51. err:
  52. return 0;
  53. }
  54. void neigh_node_free_ref(struct neigh_node *neigh_node)
  55. {
  56. if (atomic_dec_and_test(&neigh_node->refcount))
  57. kfree_rcu(neigh_node, rcu);
  58. }
  59. /* increases the refcounter of a found router */
  60. struct neigh_node *orig_node_get_router(struct orig_node *orig_node)
  61. {
  62. struct neigh_node *router;
  63. rcu_read_lock();
  64. router = rcu_dereference(orig_node->router);
  65. if (router && !atomic_inc_not_zero(&router->refcount))
  66. router = NULL;
  67. rcu_read_unlock();
  68. return router;
  69. }
  70. struct neigh_node *create_neighbor(struct orig_node *orig_node,
  71. struct orig_node *orig_neigh_node,
  72. const uint8_t *neigh,
  73. struct hard_iface *if_incoming)
  74. {
  75. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  76. struct neigh_node *neigh_node;
  77. bat_dbg(DBG_BATMAN, bat_priv,
  78. "Creating new last-hop neighbor of originator\n");
  79. neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
  80. if (!neigh_node)
  81. return NULL;
  82. INIT_HLIST_NODE(&neigh_node->list);
  83. INIT_LIST_HEAD(&neigh_node->bonding_list);
  84. spin_lock_init(&neigh_node->tq_lock);
  85. memcpy(neigh_node->addr, neigh, ETH_ALEN);
  86. neigh_node->orig_node = orig_neigh_node;
  87. neigh_node->if_incoming = if_incoming;
  88. /* extra reference for return */
  89. atomic_set(&neigh_node->refcount, 2);
  90. spin_lock_bh(&orig_node->neigh_list_lock);
  91. hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
  92. spin_unlock_bh(&orig_node->neigh_list_lock);
  93. return neigh_node;
  94. }
  95. static void orig_node_free_rcu(struct rcu_head *rcu)
  96. {
  97. struct hlist_node *node, *node_tmp;
  98. struct neigh_node *neigh_node, *tmp_neigh_node;
  99. struct orig_node *orig_node;
  100. orig_node = container_of(rcu, struct orig_node, rcu);
  101. spin_lock_bh(&orig_node->neigh_list_lock);
  102. /* for all bonding members ... */
  103. list_for_each_entry_safe(neigh_node, tmp_neigh_node,
  104. &orig_node->bond_list, bonding_list) {
  105. list_del_rcu(&neigh_node->bonding_list);
  106. neigh_node_free_ref(neigh_node);
  107. }
  108. /* for all neighbors towards this originator ... */
  109. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  110. &orig_node->neigh_list, list) {
  111. hlist_del_rcu(&neigh_node->list);
  112. neigh_node_free_ref(neigh_node);
  113. }
  114. spin_unlock_bh(&orig_node->neigh_list_lock);
  115. frag_list_free(&orig_node->frag_list);
  116. tt_global_del_orig(orig_node->bat_priv, orig_node,
  117. "originator timed out");
  118. kfree(orig_node->tt_buff);
  119. kfree(orig_node->bcast_own);
  120. kfree(orig_node->bcast_own_sum);
  121. kfree(orig_node);
  122. }
  123. void orig_node_free_ref(struct orig_node *orig_node)
  124. {
  125. if (atomic_dec_and_test(&orig_node->refcount))
  126. call_rcu(&orig_node->rcu, orig_node_free_rcu);
  127. }
  128. void originator_free(struct bat_priv *bat_priv)
  129. {
  130. struct hashtable_t *hash = bat_priv->orig_hash;
  131. struct hlist_node *node, *node_tmp;
  132. struct hlist_head *head;
  133. spinlock_t *list_lock; /* spinlock to protect write access */
  134. struct orig_node *orig_node;
  135. uint32_t i;
  136. if (!hash)
  137. return;
  138. cancel_delayed_work_sync(&bat_priv->orig_work);
  139. bat_priv->orig_hash = NULL;
  140. for (i = 0; i < hash->size; i++) {
  141. head = &hash->table[i];
  142. list_lock = &hash->list_locks[i];
  143. spin_lock_bh(list_lock);
  144. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  145. head, hash_entry) {
  146. hlist_del_rcu(node);
  147. orig_node_free_ref(orig_node);
  148. }
  149. spin_unlock_bh(list_lock);
  150. }
  151. hash_destroy(hash);
  152. }
  153. /* this function finds or creates an originator entry for the given
  154. * address if it does not exits */
  155. struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr)
  156. {
  157. struct orig_node *orig_node;
  158. int size;
  159. int hash_added;
  160. orig_node = orig_hash_find(bat_priv, addr);
  161. if (orig_node)
  162. return orig_node;
  163. bat_dbg(DBG_BATMAN, bat_priv,
  164. "Creating new originator: %pM\n", addr);
  165. orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
  166. if (!orig_node)
  167. return NULL;
  168. INIT_HLIST_HEAD(&orig_node->neigh_list);
  169. INIT_LIST_HEAD(&orig_node->bond_list);
  170. spin_lock_init(&orig_node->ogm_cnt_lock);
  171. spin_lock_init(&orig_node->bcast_seqno_lock);
  172. spin_lock_init(&orig_node->neigh_list_lock);
  173. spin_lock_init(&orig_node->tt_buff_lock);
  174. /* extra reference for return */
  175. atomic_set(&orig_node->refcount, 2);
  176. orig_node->tt_initialised = false;
  177. orig_node->tt_poss_change = false;
  178. orig_node->bat_priv = bat_priv;
  179. memcpy(orig_node->orig, addr, ETH_ALEN);
  180. orig_node->router = NULL;
  181. orig_node->tt_crc = 0;
  182. atomic_set(&orig_node->last_ttvn, 0);
  183. orig_node->tt_buff = NULL;
  184. orig_node->tt_buff_len = 0;
  185. atomic_set(&orig_node->tt_size, 0);
  186. orig_node->bcast_seqno_reset = jiffies - 1
  187. - msecs_to_jiffies(RESET_PROTECTION_MS);
  188. orig_node->batman_seqno_reset = jiffies - 1
  189. - msecs_to_jiffies(RESET_PROTECTION_MS);
  190. atomic_set(&orig_node->bond_candidates, 0);
  191. size = bat_priv->num_ifaces * sizeof(unsigned long) * NUM_WORDS;
  192. orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
  193. if (!orig_node->bcast_own)
  194. goto free_orig_node;
  195. size = bat_priv->num_ifaces * sizeof(uint8_t);
  196. orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
  197. INIT_LIST_HEAD(&orig_node->frag_list);
  198. orig_node->last_frag_packet = 0;
  199. if (!orig_node->bcast_own_sum)
  200. goto free_bcast_own;
  201. hash_added = hash_add(bat_priv->orig_hash, compare_orig,
  202. choose_orig, orig_node, &orig_node->hash_entry);
  203. if (hash_added != 0)
  204. goto free_bcast_own_sum;
  205. return orig_node;
  206. free_bcast_own_sum:
  207. kfree(orig_node->bcast_own_sum);
  208. free_bcast_own:
  209. kfree(orig_node->bcast_own);
  210. free_orig_node:
  211. kfree(orig_node);
  212. return NULL;
  213. }
  214. static bool purge_orig_neighbors(struct bat_priv *bat_priv,
  215. struct orig_node *orig_node,
  216. struct neigh_node **best_neigh_node)
  217. {
  218. struct hlist_node *node, *node_tmp;
  219. struct neigh_node *neigh_node;
  220. bool neigh_purged = false;
  221. *best_neigh_node = NULL;
  222. spin_lock_bh(&orig_node->neigh_list_lock);
  223. /* for all neighbors towards this originator ... */
  224. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  225. &orig_node->neigh_list, list) {
  226. if ((time_after(jiffies,
  227. neigh_node->last_valid + PURGE_TIMEOUT * HZ)) ||
  228. (neigh_node->if_incoming->if_status == IF_INACTIVE) ||
  229. (neigh_node->if_incoming->if_status == IF_NOT_IN_USE) ||
  230. (neigh_node->if_incoming->if_status == IF_TO_BE_REMOVED)) {
  231. if ((neigh_node->if_incoming->if_status ==
  232. IF_INACTIVE) ||
  233. (neigh_node->if_incoming->if_status ==
  234. IF_NOT_IN_USE) ||
  235. (neigh_node->if_incoming->if_status ==
  236. IF_TO_BE_REMOVED))
  237. bat_dbg(DBG_BATMAN, bat_priv,
  238. "neighbor purge: originator %pM, "
  239. "neighbor: %pM, iface: %s\n",
  240. orig_node->orig, neigh_node->addr,
  241. neigh_node->if_incoming->net_dev->name);
  242. else
  243. bat_dbg(DBG_BATMAN, bat_priv,
  244. "neighbor timeout: originator %pM, "
  245. "neighbor: %pM, last_valid: %lu\n",
  246. orig_node->orig, neigh_node->addr,
  247. (neigh_node->last_valid / HZ));
  248. neigh_purged = true;
  249. hlist_del_rcu(&neigh_node->list);
  250. bonding_candidate_del(orig_node, neigh_node);
  251. neigh_node_free_ref(neigh_node);
  252. } else {
  253. if ((!*best_neigh_node) ||
  254. (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
  255. *best_neigh_node = neigh_node;
  256. }
  257. }
  258. spin_unlock_bh(&orig_node->neigh_list_lock);
  259. return neigh_purged;
  260. }
  261. static bool purge_orig_node(struct bat_priv *bat_priv,
  262. struct orig_node *orig_node)
  263. {
  264. struct neigh_node *best_neigh_node;
  265. if (time_after(jiffies,
  266. orig_node->last_valid + 2 * PURGE_TIMEOUT * HZ)) {
  267. bat_dbg(DBG_BATMAN, bat_priv,
  268. "Originator timeout: originator %pM, last_valid %lu\n",
  269. orig_node->orig, (orig_node->last_valid / HZ));
  270. return true;
  271. } else {
  272. if (purge_orig_neighbors(bat_priv, orig_node,
  273. &best_neigh_node)) {
  274. update_route(bat_priv, orig_node, best_neigh_node);
  275. }
  276. }
  277. return false;
  278. }
  279. static void _purge_orig(struct bat_priv *bat_priv)
  280. {
  281. struct hashtable_t *hash = bat_priv->orig_hash;
  282. struct hlist_node *node, *node_tmp;
  283. struct hlist_head *head;
  284. spinlock_t *list_lock; /* spinlock to protect write access */
  285. struct orig_node *orig_node;
  286. uint32_t i;
  287. if (!hash)
  288. return;
  289. /* for all origins... */
  290. for (i = 0; i < hash->size; i++) {
  291. head = &hash->table[i];
  292. list_lock = &hash->list_locks[i];
  293. spin_lock_bh(list_lock);
  294. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  295. head, hash_entry) {
  296. if (purge_orig_node(bat_priv, orig_node)) {
  297. if (orig_node->gw_flags)
  298. gw_node_delete(bat_priv, orig_node);
  299. hlist_del_rcu(node);
  300. orig_node_free_ref(orig_node);
  301. continue;
  302. }
  303. if (time_after(jiffies, orig_node->last_frag_packet +
  304. msecs_to_jiffies(FRAG_TIMEOUT)))
  305. frag_list_free(&orig_node->frag_list);
  306. }
  307. spin_unlock_bh(list_lock);
  308. }
  309. gw_node_purge(bat_priv);
  310. gw_election(bat_priv);
  311. softif_neigh_purge(bat_priv);
  312. }
  313. static void purge_orig(struct work_struct *work)
  314. {
  315. struct delayed_work *delayed_work =
  316. container_of(work, struct delayed_work, work);
  317. struct bat_priv *bat_priv =
  318. container_of(delayed_work, struct bat_priv, orig_work);
  319. _purge_orig(bat_priv);
  320. start_purge_timer(bat_priv);
  321. }
  322. void purge_orig_ref(struct bat_priv *bat_priv)
  323. {
  324. _purge_orig(bat_priv);
  325. }
  326. int orig_seq_print_text(struct seq_file *seq, void *offset)
  327. {
  328. struct net_device *net_dev = (struct net_device *)seq->private;
  329. struct bat_priv *bat_priv = netdev_priv(net_dev);
  330. struct hashtable_t *hash = bat_priv->orig_hash;
  331. struct hlist_node *node, *node_tmp;
  332. struct hlist_head *head;
  333. struct hard_iface *primary_if;
  334. struct orig_node *orig_node;
  335. struct neigh_node *neigh_node, *neigh_node_tmp;
  336. int batman_count = 0;
  337. int last_seen_secs;
  338. int last_seen_msecs;
  339. uint32_t i;
  340. int ret = 0;
  341. primary_if = primary_if_get_selected(bat_priv);
  342. if (!primary_if) {
  343. ret = seq_printf(seq, "BATMAN mesh %s disabled - "
  344. "please specify interfaces to enable it\n",
  345. net_dev->name);
  346. goto out;
  347. }
  348. if (primary_if->if_status != IF_ACTIVE) {
  349. ret = seq_printf(seq, "BATMAN mesh %s "
  350. "disabled - primary interface not active\n",
  351. net_dev->name);
  352. goto out;
  353. }
  354. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  355. SOURCE_VERSION, primary_if->net_dev->name,
  356. primary_if->net_dev->dev_addr, net_dev->name);
  357. seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
  358. "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop",
  359. "outgoingIF", "Potential nexthops");
  360. for (i = 0; i < hash->size; i++) {
  361. head = &hash->table[i];
  362. rcu_read_lock();
  363. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  364. neigh_node = orig_node_get_router(orig_node);
  365. if (!neigh_node)
  366. continue;
  367. if (neigh_node->tq_avg == 0)
  368. goto next;
  369. last_seen_secs = jiffies_to_msecs(jiffies -
  370. orig_node->last_valid) / 1000;
  371. last_seen_msecs = jiffies_to_msecs(jiffies -
  372. orig_node->last_valid) % 1000;
  373. seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
  374. orig_node->orig, last_seen_secs,
  375. last_seen_msecs, neigh_node->tq_avg,
  376. neigh_node->addr,
  377. neigh_node->if_incoming->net_dev->name);
  378. hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp,
  379. &orig_node->neigh_list, list) {
  380. seq_printf(seq, " %pM (%3i)",
  381. neigh_node_tmp->addr,
  382. neigh_node_tmp->tq_avg);
  383. }
  384. seq_printf(seq, "\n");
  385. batman_count++;
  386. next:
  387. neigh_node_free_ref(neigh_node);
  388. }
  389. rcu_read_unlock();
  390. }
  391. if (batman_count == 0)
  392. seq_printf(seq, "No batman nodes in range ...\n");
  393. out:
  394. if (primary_if)
  395. hardif_free_ref(primary_if);
  396. return ret;
  397. }
  398. static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
  399. {
  400. void *data_ptr;
  401. data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
  402. GFP_ATOMIC);
  403. if (!data_ptr)
  404. return -1;
  405. memcpy(data_ptr, orig_node->bcast_own,
  406. (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
  407. kfree(orig_node->bcast_own);
  408. orig_node->bcast_own = data_ptr;
  409. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  410. if (!data_ptr)
  411. return -1;
  412. memcpy(data_ptr, orig_node->bcast_own_sum,
  413. (max_if_num - 1) * sizeof(uint8_t));
  414. kfree(orig_node->bcast_own_sum);
  415. orig_node->bcast_own_sum = data_ptr;
  416. return 0;
  417. }
  418. int orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
  419. {
  420. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  421. struct hashtable_t *hash = bat_priv->orig_hash;
  422. struct hlist_node *node;
  423. struct hlist_head *head;
  424. struct orig_node *orig_node;
  425. uint32_t i;
  426. int ret;
  427. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  428. * if_num */
  429. for (i = 0; i < hash->size; i++) {
  430. head = &hash->table[i];
  431. rcu_read_lock();
  432. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  433. spin_lock_bh(&orig_node->ogm_cnt_lock);
  434. ret = orig_node_add_if(orig_node, max_if_num);
  435. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  436. if (ret == -1)
  437. goto err;
  438. }
  439. rcu_read_unlock();
  440. }
  441. return 0;
  442. err:
  443. rcu_read_unlock();
  444. return -ENOMEM;
  445. }
  446. static int orig_node_del_if(struct orig_node *orig_node,
  447. int max_if_num, int del_if_num)
  448. {
  449. void *data_ptr = NULL;
  450. int chunk_size;
  451. /* last interface was removed */
  452. if (max_if_num == 0)
  453. goto free_bcast_own;
  454. chunk_size = sizeof(unsigned long) * NUM_WORDS;
  455. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  456. if (!data_ptr)
  457. return -1;
  458. /* copy first part */
  459. memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
  460. /* copy second part */
  461. memcpy((char *)data_ptr + del_if_num * chunk_size,
  462. orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
  463. (max_if_num - del_if_num) * chunk_size);
  464. free_bcast_own:
  465. kfree(orig_node->bcast_own);
  466. orig_node->bcast_own = data_ptr;
  467. if (max_if_num == 0)
  468. goto free_own_sum;
  469. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  470. if (!data_ptr)
  471. return -1;
  472. memcpy(data_ptr, orig_node->bcast_own_sum,
  473. del_if_num * sizeof(uint8_t));
  474. memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
  475. orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
  476. (max_if_num - del_if_num) * sizeof(uint8_t));
  477. free_own_sum:
  478. kfree(orig_node->bcast_own_sum);
  479. orig_node->bcast_own_sum = data_ptr;
  480. return 0;
  481. }
  482. int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
  483. {
  484. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  485. struct hashtable_t *hash = bat_priv->orig_hash;
  486. struct hlist_node *node;
  487. struct hlist_head *head;
  488. struct hard_iface *hard_iface_tmp;
  489. struct orig_node *orig_node;
  490. uint32_t i;
  491. int ret;
  492. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  493. * if_num */
  494. for (i = 0; i < hash->size; i++) {
  495. head = &hash->table[i];
  496. rcu_read_lock();
  497. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  498. spin_lock_bh(&orig_node->ogm_cnt_lock);
  499. ret = orig_node_del_if(orig_node, max_if_num,
  500. hard_iface->if_num);
  501. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  502. if (ret == -1)
  503. goto err;
  504. }
  505. rcu_read_unlock();
  506. }
  507. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  508. rcu_read_lock();
  509. list_for_each_entry_rcu(hard_iface_tmp, &hardif_list, list) {
  510. if (hard_iface_tmp->if_status == IF_NOT_IN_USE)
  511. continue;
  512. if (hard_iface == hard_iface_tmp)
  513. continue;
  514. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  515. continue;
  516. if (hard_iface_tmp->if_num > hard_iface->if_num)
  517. hard_iface_tmp->if_num--;
  518. }
  519. rcu_read_unlock();
  520. hard_iface->if_num = -1;
  521. return 0;
  522. err:
  523. rcu_read_unlock();
  524. return -ENOMEM;
  525. }