originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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 ((has_timed_out(neigh_node->last_valid, PURGE_TIMEOUT)) ||
  227. (neigh_node->if_incoming->if_status == IF_INACTIVE) ||
  228. (neigh_node->if_incoming->if_status == IF_NOT_IN_USE) ||
  229. (neigh_node->if_incoming->if_status == IF_TO_BE_REMOVED)) {
  230. if ((neigh_node->if_incoming->if_status ==
  231. IF_INACTIVE) ||
  232. (neigh_node->if_incoming->if_status ==
  233. IF_NOT_IN_USE) ||
  234. (neigh_node->if_incoming->if_status ==
  235. IF_TO_BE_REMOVED))
  236. bat_dbg(DBG_BATMAN, bat_priv,
  237. "neighbor purge: originator %pM, "
  238. "neighbor: %pM, iface: %s\n",
  239. orig_node->orig, neigh_node->addr,
  240. neigh_node->if_incoming->net_dev->name);
  241. else
  242. bat_dbg(DBG_BATMAN, bat_priv,
  243. "neighbor timeout: originator %pM, "
  244. "neighbor: %pM, last_valid: %lu\n",
  245. orig_node->orig, neigh_node->addr,
  246. (neigh_node->last_valid / HZ));
  247. neigh_purged = true;
  248. hlist_del_rcu(&neigh_node->list);
  249. bonding_candidate_del(orig_node, neigh_node);
  250. neigh_node_free_ref(neigh_node);
  251. } else {
  252. if ((!*best_neigh_node) ||
  253. (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
  254. *best_neigh_node = neigh_node;
  255. }
  256. }
  257. spin_unlock_bh(&orig_node->neigh_list_lock);
  258. return neigh_purged;
  259. }
  260. static bool purge_orig_node(struct bat_priv *bat_priv,
  261. struct orig_node *orig_node)
  262. {
  263. struct neigh_node *best_neigh_node;
  264. if (has_timed_out(orig_node->last_valid, 2 * PURGE_TIMEOUT)) {
  265. bat_dbg(DBG_BATMAN, bat_priv,
  266. "Originator timeout: originator %pM, last_valid %lu\n",
  267. orig_node->orig, (orig_node->last_valid / HZ));
  268. return true;
  269. } else {
  270. if (purge_orig_neighbors(bat_priv, orig_node,
  271. &best_neigh_node)) {
  272. update_route(bat_priv, orig_node, best_neigh_node);
  273. }
  274. }
  275. return false;
  276. }
  277. static void _purge_orig(struct bat_priv *bat_priv)
  278. {
  279. struct hashtable_t *hash = bat_priv->orig_hash;
  280. struct hlist_node *node, *node_tmp;
  281. struct hlist_head *head;
  282. spinlock_t *list_lock; /* spinlock to protect write access */
  283. struct orig_node *orig_node;
  284. uint32_t i;
  285. if (!hash)
  286. return;
  287. /* for all origins... */
  288. for (i = 0; i < hash->size; i++) {
  289. head = &hash->table[i];
  290. list_lock = &hash->list_locks[i];
  291. spin_lock_bh(list_lock);
  292. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  293. head, hash_entry) {
  294. if (purge_orig_node(bat_priv, orig_node)) {
  295. if (orig_node->gw_flags)
  296. gw_node_delete(bat_priv, orig_node);
  297. hlist_del_rcu(node);
  298. orig_node_free_ref(orig_node);
  299. continue;
  300. }
  301. if (has_timed_out(orig_node->last_frag_packet,
  302. FRAG_TIMEOUT))
  303. frag_list_free(&orig_node->frag_list);
  304. }
  305. spin_unlock_bh(list_lock);
  306. }
  307. gw_node_purge(bat_priv);
  308. gw_election(bat_priv);
  309. softif_neigh_purge(bat_priv);
  310. }
  311. static void purge_orig(struct work_struct *work)
  312. {
  313. struct delayed_work *delayed_work =
  314. container_of(work, struct delayed_work, work);
  315. struct bat_priv *bat_priv =
  316. container_of(delayed_work, struct bat_priv, orig_work);
  317. _purge_orig(bat_priv);
  318. start_purge_timer(bat_priv);
  319. }
  320. void purge_orig_ref(struct bat_priv *bat_priv)
  321. {
  322. _purge_orig(bat_priv);
  323. }
  324. int orig_seq_print_text(struct seq_file *seq, void *offset)
  325. {
  326. struct net_device *net_dev = (struct net_device *)seq->private;
  327. struct bat_priv *bat_priv = netdev_priv(net_dev);
  328. struct hashtable_t *hash = bat_priv->orig_hash;
  329. struct hlist_node *node, *node_tmp;
  330. struct hlist_head *head;
  331. struct hard_iface *primary_if;
  332. struct orig_node *orig_node;
  333. struct neigh_node *neigh_node, *neigh_node_tmp;
  334. int batman_count = 0;
  335. int last_seen_secs;
  336. int last_seen_msecs;
  337. uint32_t i;
  338. int ret = 0;
  339. primary_if = primary_if_get_selected(bat_priv);
  340. if (!primary_if) {
  341. ret = seq_printf(seq, "BATMAN mesh %s disabled - "
  342. "please specify interfaces to enable it\n",
  343. net_dev->name);
  344. goto out;
  345. }
  346. if (primary_if->if_status != IF_ACTIVE) {
  347. ret = seq_printf(seq, "BATMAN mesh %s "
  348. "disabled - primary interface not active\n",
  349. net_dev->name);
  350. goto out;
  351. }
  352. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  353. SOURCE_VERSION, primary_if->net_dev->name,
  354. primary_if->net_dev->dev_addr, net_dev->name);
  355. seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
  356. "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop",
  357. "outgoingIF", "Potential nexthops");
  358. for (i = 0; i < hash->size; i++) {
  359. head = &hash->table[i];
  360. rcu_read_lock();
  361. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  362. neigh_node = orig_node_get_router(orig_node);
  363. if (!neigh_node)
  364. continue;
  365. if (neigh_node->tq_avg == 0)
  366. goto next;
  367. last_seen_secs = jiffies_to_msecs(jiffies -
  368. orig_node->last_valid) / 1000;
  369. last_seen_msecs = jiffies_to_msecs(jiffies -
  370. orig_node->last_valid) % 1000;
  371. seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
  372. orig_node->orig, last_seen_secs,
  373. last_seen_msecs, neigh_node->tq_avg,
  374. neigh_node->addr,
  375. neigh_node->if_incoming->net_dev->name);
  376. hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp,
  377. &orig_node->neigh_list, list) {
  378. seq_printf(seq, " %pM (%3i)",
  379. neigh_node_tmp->addr,
  380. neigh_node_tmp->tq_avg);
  381. }
  382. seq_printf(seq, "\n");
  383. batman_count++;
  384. next:
  385. neigh_node_free_ref(neigh_node);
  386. }
  387. rcu_read_unlock();
  388. }
  389. if (batman_count == 0)
  390. seq_printf(seq, "No batman nodes in range ...\n");
  391. out:
  392. if (primary_if)
  393. hardif_free_ref(primary_if);
  394. return ret;
  395. }
  396. static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
  397. {
  398. void *data_ptr;
  399. data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
  400. GFP_ATOMIC);
  401. if (!data_ptr)
  402. return -1;
  403. memcpy(data_ptr, orig_node->bcast_own,
  404. (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
  405. kfree(orig_node->bcast_own);
  406. orig_node->bcast_own = data_ptr;
  407. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  408. if (!data_ptr)
  409. return -1;
  410. memcpy(data_ptr, orig_node->bcast_own_sum,
  411. (max_if_num - 1) * sizeof(uint8_t));
  412. kfree(orig_node->bcast_own_sum);
  413. orig_node->bcast_own_sum = data_ptr;
  414. return 0;
  415. }
  416. int orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
  417. {
  418. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  419. struct hashtable_t *hash = bat_priv->orig_hash;
  420. struct hlist_node *node;
  421. struct hlist_head *head;
  422. struct orig_node *orig_node;
  423. uint32_t i;
  424. int ret;
  425. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  426. * if_num */
  427. for (i = 0; i < hash->size; i++) {
  428. head = &hash->table[i];
  429. rcu_read_lock();
  430. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  431. spin_lock_bh(&orig_node->ogm_cnt_lock);
  432. ret = orig_node_add_if(orig_node, max_if_num);
  433. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  434. if (ret == -1)
  435. goto err;
  436. }
  437. rcu_read_unlock();
  438. }
  439. return 0;
  440. err:
  441. rcu_read_unlock();
  442. return -ENOMEM;
  443. }
  444. static int orig_node_del_if(struct orig_node *orig_node,
  445. int max_if_num, int del_if_num)
  446. {
  447. void *data_ptr = NULL;
  448. int chunk_size;
  449. /* last interface was removed */
  450. if (max_if_num == 0)
  451. goto free_bcast_own;
  452. chunk_size = sizeof(unsigned long) * NUM_WORDS;
  453. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  454. if (!data_ptr)
  455. return -1;
  456. /* copy first part */
  457. memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
  458. /* copy second part */
  459. memcpy((char *)data_ptr + del_if_num * chunk_size,
  460. orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
  461. (max_if_num - del_if_num) * chunk_size);
  462. free_bcast_own:
  463. kfree(orig_node->bcast_own);
  464. orig_node->bcast_own = data_ptr;
  465. if (max_if_num == 0)
  466. goto free_own_sum;
  467. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  468. if (!data_ptr)
  469. return -1;
  470. memcpy(data_ptr, orig_node->bcast_own_sum,
  471. del_if_num * sizeof(uint8_t));
  472. memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
  473. orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
  474. (max_if_num - del_if_num) * sizeof(uint8_t));
  475. free_own_sum:
  476. kfree(orig_node->bcast_own_sum);
  477. orig_node->bcast_own_sum = data_ptr;
  478. return 0;
  479. }
  480. int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
  481. {
  482. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  483. struct hashtable_t *hash = bat_priv->orig_hash;
  484. struct hlist_node *node;
  485. struct hlist_head *head;
  486. struct hard_iface *hard_iface_tmp;
  487. struct orig_node *orig_node;
  488. uint32_t i;
  489. int ret;
  490. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  491. * if_num */
  492. for (i = 0; i < hash->size; i++) {
  493. head = &hash->table[i];
  494. rcu_read_lock();
  495. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  496. spin_lock_bh(&orig_node->ogm_cnt_lock);
  497. ret = orig_node_del_if(orig_node, max_if_num,
  498. hard_iface->if_num);
  499. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  500. if (ret == -1)
  501. goto err;
  502. }
  503. rcu_read_unlock();
  504. }
  505. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  506. rcu_read_lock();
  507. list_for_each_entry_rcu(hard_iface_tmp, &hardif_list, list) {
  508. if (hard_iface_tmp->if_status == IF_NOT_IN_USE)
  509. continue;
  510. if (hard_iface == hard_iface_tmp)
  511. continue;
  512. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  513. continue;
  514. if (hard_iface_tmp->if_num > hard_iface->if_num)
  515. hard_iface_tmp->if_num--;
  516. }
  517. rcu_read_unlock();
  518. hard_iface->if_num = -1;
  519. return 0;
  520. err:
  521. rcu_read_unlock();
  522. return -ENOMEM;
  523. }