originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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_poss_change = false;
  177. orig_node->bat_priv = bat_priv;
  178. memcpy(orig_node->orig, addr, ETH_ALEN);
  179. orig_node->router = NULL;
  180. orig_node->tt_crc = 0;
  181. atomic_set(&orig_node->last_ttvn, 0);
  182. orig_node->tt_buff = NULL;
  183. orig_node->tt_buff_len = 0;
  184. atomic_set(&orig_node->tt_size, 0);
  185. orig_node->bcast_seqno_reset = jiffies - 1
  186. - msecs_to_jiffies(RESET_PROTECTION_MS);
  187. orig_node->batman_seqno_reset = jiffies - 1
  188. - msecs_to_jiffies(RESET_PROTECTION_MS);
  189. atomic_set(&orig_node->bond_candidates, 0);
  190. size = bat_priv->num_ifaces * sizeof(unsigned long) * NUM_WORDS;
  191. orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
  192. if (!orig_node->bcast_own)
  193. goto free_orig_node;
  194. size = bat_priv->num_ifaces * sizeof(uint8_t);
  195. orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
  196. INIT_LIST_HEAD(&orig_node->frag_list);
  197. orig_node->last_frag_packet = 0;
  198. if (!orig_node->bcast_own_sum)
  199. goto free_bcast_own;
  200. hash_added = hash_add(bat_priv->orig_hash, compare_orig,
  201. choose_orig, orig_node, &orig_node->hash_entry);
  202. if (hash_added != 0)
  203. goto free_bcast_own_sum;
  204. return orig_node;
  205. free_bcast_own_sum:
  206. kfree(orig_node->bcast_own_sum);
  207. free_bcast_own:
  208. kfree(orig_node->bcast_own);
  209. free_orig_node:
  210. kfree(orig_node);
  211. return NULL;
  212. }
  213. static bool purge_orig_neighbors(struct bat_priv *bat_priv,
  214. struct orig_node *orig_node,
  215. struct neigh_node **best_neigh_node)
  216. {
  217. struct hlist_node *node, *node_tmp;
  218. struct neigh_node *neigh_node;
  219. bool neigh_purged = false;
  220. *best_neigh_node = NULL;
  221. spin_lock_bh(&orig_node->neigh_list_lock);
  222. /* for all neighbors towards this originator ... */
  223. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  224. &orig_node->neigh_list, list) {
  225. if ((time_after(jiffies,
  226. neigh_node->last_valid + PURGE_TIMEOUT * HZ)) ||
  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 (time_after(jiffies,
  265. orig_node->last_valid + 2 * PURGE_TIMEOUT * HZ)) {
  266. bat_dbg(DBG_BATMAN, bat_priv,
  267. "Originator timeout: originator %pM, last_valid %lu\n",
  268. orig_node->orig, (orig_node->last_valid / HZ));
  269. return true;
  270. } else {
  271. if (purge_orig_neighbors(bat_priv, orig_node,
  272. &best_neigh_node)) {
  273. update_route(bat_priv, orig_node, best_neigh_node);
  274. }
  275. }
  276. return false;
  277. }
  278. static void _purge_orig(struct bat_priv *bat_priv)
  279. {
  280. struct hashtable_t *hash = bat_priv->orig_hash;
  281. struct hlist_node *node, *node_tmp;
  282. struct hlist_head *head;
  283. spinlock_t *list_lock; /* spinlock to protect write access */
  284. struct orig_node *orig_node;
  285. uint32_t i;
  286. if (!hash)
  287. return;
  288. /* for all origins... */
  289. for (i = 0; i < hash->size; i++) {
  290. head = &hash->table[i];
  291. list_lock = &hash->list_locks[i];
  292. spin_lock_bh(list_lock);
  293. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  294. head, hash_entry) {
  295. if (purge_orig_node(bat_priv, orig_node)) {
  296. if (orig_node->gw_flags)
  297. gw_node_delete(bat_priv, orig_node);
  298. hlist_del_rcu(node);
  299. orig_node_free_ref(orig_node);
  300. continue;
  301. }
  302. if (time_after(jiffies, orig_node->last_frag_packet +
  303. msecs_to_jiffies(FRAG_TIMEOUT)))
  304. frag_list_free(&orig_node->frag_list);
  305. }
  306. spin_unlock_bh(list_lock);
  307. }
  308. gw_node_purge(bat_priv);
  309. gw_election(bat_priv);
  310. softif_neigh_purge(bat_priv);
  311. }
  312. static void purge_orig(struct work_struct *work)
  313. {
  314. struct delayed_work *delayed_work =
  315. container_of(work, struct delayed_work, work);
  316. struct bat_priv *bat_priv =
  317. container_of(delayed_work, struct bat_priv, orig_work);
  318. _purge_orig(bat_priv);
  319. start_purge_timer(bat_priv);
  320. }
  321. void purge_orig_ref(struct bat_priv *bat_priv)
  322. {
  323. _purge_orig(bat_priv);
  324. }
  325. int orig_seq_print_text(struct seq_file *seq, void *offset)
  326. {
  327. struct net_device *net_dev = (struct net_device *)seq->private;
  328. struct bat_priv *bat_priv = netdev_priv(net_dev);
  329. struct hashtable_t *hash = bat_priv->orig_hash;
  330. struct hlist_node *node, *node_tmp;
  331. struct hlist_head *head;
  332. struct hard_iface *primary_if;
  333. struct orig_node *orig_node;
  334. struct neigh_node *neigh_node, *neigh_node_tmp;
  335. int batman_count = 0;
  336. int last_seen_secs;
  337. int last_seen_msecs;
  338. uint32_t i;
  339. int ret = 0;
  340. primary_if = primary_if_get_selected(bat_priv);
  341. if (!primary_if) {
  342. ret = seq_printf(seq, "BATMAN mesh %s disabled - "
  343. "please specify interfaces to enable it\n",
  344. net_dev->name);
  345. goto out;
  346. }
  347. if (primary_if->if_status != IF_ACTIVE) {
  348. ret = seq_printf(seq, "BATMAN mesh %s "
  349. "disabled - primary interface not active\n",
  350. net_dev->name);
  351. goto out;
  352. }
  353. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  354. SOURCE_VERSION, primary_if->net_dev->name,
  355. primary_if->net_dev->dev_addr, net_dev->name);
  356. seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
  357. "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop",
  358. "outgoingIF", "Potential nexthops");
  359. for (i = 0; i < hash->size; i++) {
  360. head = &hash->table[i];
  361. rcu_read_lock();
  362. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  363. neigh_node = orig_node_get_router(orig_node);
  364. if (!neigh_node)
  365. continue;
  366. if (neigh_node->tq_avg == 0)
  367. goto next;
  368. last_seen_secs = jiffies_to_msecs(jiffies -
  369. orig_node->last_valid) / 1000;
  370. last_seen_msecs = jiffies_to_msecs(jiffies -
  371. orig_node->last_valid) % 1000;
  372. seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
  373. orig_node->orig, last_seen_secs,
  374. last_seen_msecs, neigh_node->tq_avg,
  375. neigh_node->addr,
  376. neigh_node->if_incoming->net_dev->name);
  377. hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp,
  378. &orig_node->neigh_list, list) {
  379. seq_printf(seq, " %pM (%3i)",
  380. neigh_node_tmp->addr,
  381. neigh_node_tmp->tq_avg);
  382. }
  383. seq_printf(seq, "\n");
  384. batman_count++;
  385. next:
  386. neigh_node_free_ref(neigh_node);
  387. }
  388. rcu_read_unlock();
  389. }
  390. if (batman_count == 0)
  391. seq_printf(seq, "No batman nodes in range ...\n");
  392. out:
  393. if (primary_if)
  394. hardif_free_ref(primary_if);
  395. return ret;
  396. }
  397. static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
  398. {
  399. void *data_ptr;
  400. data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
  401. GFP_ATOMIC);
  402. if (!data_ptr)
  403. return -1;
  404. memcpy(data_ptr, orig_node->bcast_own,
  405. (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
  406. kfree(orig_node->bcast_own);
  407. orig_node->bcast_own = data_ptr;
  408. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  409. if (!data_ptr)
  410. return -1;
  411. memcpy(data_ptr, orig_node->bcast_own_sum,
  412. (max_if_num - 1) * sizeof(uint8_t));
  413. kfree(orig_node->bcast_own_sum);
  414. orig_node->bcast_own_sum = data_ptr;
  415. return 0;
  416. }
  417. int orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
  418. {
  419. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  420. struct hashtable_t *hash = bat_priv->orig_hash;
  421. struct hlist_node *node;
  422. struct hlist_head *head;
  423. struct orig_node *orig_node;
  424. uint32_t i;
  425. int ret;
  426. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  427. * if_num */
  428. for (i = 0; i < hash->size; i++) {
  429. head = &hash->table[i];
  430. rcu_read_lock();
  431. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  432. spin_lock_bh(&orig_node->ogm_cnt_lock);
  433. ret = orig_node_add_if(orig_node, max_if_num);
  434. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  435. if (ret == -1)
  436. goto err;
  437. }
  438. rcu_read_unlock();
  439. }
  440. return 0;
  441. err:
  442. rcu_read_unlock();
  443. return -ENOMEM;
  444. }
  445. static int orig_node_del_if(struct orig_node *orig_node,
  446. int max_if_num, int del_if_num)
  447. {
  448. void *data_ptr = NULL;
  449. int chunk_size;
  450. /* last interface was removed */
  451. if (max_if_num == 0)
  452. goto free_bcast_own;
  453. chunk_size = sizeof(unsigned long) * NUM_WORDS;
  454. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  455. if (!data_ptr)
  456. return -1;
  457. /* copy first part */
  458. memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
  459. /* copy second part */
  460. memcpy((char *)data_ptr + del_if_num * chunk_size,
  461. orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
  462. (max_if_num - del_if_num) * chunk_size);
  463. free_bcast_own:
  464. kfree(orig_node->bcast_own);
  465. orig_node->bcast_own = data_ptr;
  466. if (max_if_num == 0)
  467. goto free_own_sum;
  468. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  469. if (!data_ptr)
  470. return -1;
  471. memcpy(data_ptr, orig_node->bcast_own_sum,
  472. del_if_num * sizeof(uint8_t));
  473. memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
  474. orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
  475. (max_if_num - del_if_num) * sizeof(uint8_t));
  476. free_own_sum:
  477. kfree(orig_node->bcast_own_sum);
  478. orig_node->bcast_own_sum = data_ptr;
  479. return 0;
  480. }
  481. int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
  482. {
  483. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  484. struct hashtable_t *hash = bat_priv->orig_hash;
  485. struct hlist_node *node;
  486. struct hlist_head *head;
  487. struct hard_iface *hard_iface_tmp;
  488. struct orig_node *orig_node;
  489. uint32_t i;
  490. int ret;
  491. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  492. * if_num */
  493. for (i = 0; i < hash->size; i++) {
  494. head = &hash->table[i];
  495. rcu_read_lock();
  496. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  497. spin_lock_bh(&orig_node->ogm_cnt_lock);
  498. ret = orig_node_del_if(orig_node, max_if_num,
  499. hard_iface->if_num);
  500. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  501. if (ret == -1)
  502. goto err;
  503. }
  504. rcu_read_unlock();
  505. }
  506. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  507. rcu_read_lock();
  508. list_for_each_entry_rcu(hard_iface_tmp, &hardif_list, list) {
  509. if (hard_iface_tmp->if_status == IF_NOT_IN_USE)
  510. continue;
  511. if (hard_iface == hard_iface_tmp)
  512. continue;
  513. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  514. continue;
  515. if (hard_iface_tmp->if_num > hard_iface->if_num)
  516. hard_iface_tmp->if_num--;
  517. }
  518. rcu_read_unlock();
  519. hard_iface->if_num = -1;
  520. return 0;
  521. err:
  522. rcu_read_unlock();
  523. return -ENOMEM;
  524. }