originator.c 16 KB

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