originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /* Copyright (C) 2009-2013 B.A.T.M.A.N. contributors:
  2. *
  3. * Marek Lindner, Simon Wunderlich
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA
  18. */
  19. #include "main.h"
  20. #include "distributed-arp-table.h"
  21. #include "originator.h"
  22. #include "hash.h"
  23. #include "translation-table.h"
  24. #include "routing.h"
  25. #include "gateway_client.h"
  26. #include "hard-interface.h"
  27. #include "soft-interface.h"
  28. #include "bridge_loop_avoidance.h"
  29. #include "network-coding.h"
  30. #include "fragmentation.h"
  31. /* hash class keys */
  32. static struct lock_class_key batadv_orig_hash_lock_class_key;
  33. static void batadv_purge_orig(struct work_struct *work);
  34. /* returns 1 if they are the same originator */
  35. int batadv_compare_orig(const struct hlist_node *node, const void *data2)
  36. {
  37. const void *data1 = container_of(node, struct batadv_orig_node,
  38. hash_entry);
  39. return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
  40. }
  41. /**
  42. * batadv_orig_node_vlan_get - get an orig_node_vlan object
  43. * @orig_node: the originator serving the VLAN
  44. * @vid: the VLAN identifier
  45. *
  46. * Returns the vlan object identified by vid and belonging to orig_node or NULL
  47. * if it does not exist.
  48. */
  49. struct batadv_orig_node_vlan *
  50. batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
  51. unsigned short vid)
  52. {
  53. struct batadv_orig_node_vlan *vlan = NULL, *tmp;
  54. rcu_read_lock();
  55. list_for_each_entry_rcu(tmp, &orig_node->vlan_list, list) {
  56. if (tmp->vid != vid)
  57. continue;
  58. if (!atomic_inc_not_zero(&tmp->refcount))
  59. continue;
  60. vlan = tmp;
  61. break;
  62. }
  63. rcu_read_unlock();
  64. return vlan;
  65. }
  66. /**
  67. * batadv_orig_node_vlan_new - search and possibly create an orig_node_vlan
  68. * object
  69. * @orig_node: the originator serving the VLAN
  70. * @vid: the VLAN identifier
  71. *
  72. * Returns NULL in case of failure or the vlan object identified by vid and
  73. * belonging to orig_node otherwise. The object is created and added to the list
  74. * if it does not exist.
  75. *
  76. * The object is returned with refcounter increased by 1.
  77. */
  78. struct batadv_orig_node_vlan *
  79. batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
  80. unsigned short vid)
  81. {
  82. struct batadv_orig_node_vlan *vlan;
  83. spin_lock_bh(&orig_node->vlan_list_lock);
  84. /* first look if an object for this vid already exists */
  85. vlan = batadv_orig_node_vlan_get(orig_node, vid);
  86. if (vlan)
  87. goto out;
  88. vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
  89. if (!vlan)
  90. goto out;
  91. atomic_set(&vlan->refcount, 2);
  92. vlan->vid = vid;
  93. list_add_rcu(&vlan->list, &orig_node->vlan_list);
  94. out:
  95. spin_unlock_bh(&orig_node->vlan_list_lock);
  96. return vlan;
  97. }
  98. /**
  99. * batadv_orig_node_vlan_free_ref - decrement the refcounter and possibly free
  100. * the originator-vlan object
  101. * @orig_vlan: the originator-vlan object to release
  102. */
  103. void batadv_orig_node_vlan_free_ref(struct batadv_orig_node_vlan *orig_vlan)
  104. {
  105. if (atomic_dec_and_test(&orig_vlan->refcount))
  106. kfree_rcu(orig_vlan, rcu);
  107. }
  108. int batadv_originator_init(struct batadv_priv *bat_priv)
  109. {
  110. if (bat_priv->orig_hash)
  111. return 0;
  112. bat_priv->orig_hash = batadv_hash_new(1024);
  113. if (!bat_priv->orig_hash)
  114. goto err;
  115. batadv_hash_set_lock_class(bat_priv->orig_hash,
  116. &batadv_orig_hash_lock_class_key);
  117. INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig);
  118. queue_delayed_work(batadv_event_workqueue,
  119. &bat_priv->orig_work,
  120. msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD));
  121. return 0;
  122. err:
  123. return -ENOMEM;
  124. }
  125. void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node)
  126. {
  127. if (atomic_dec_and_test(&neigh_node->refcount))
  128. kfree_rcu(neigh_node, rcu);
  129. }
  130. /* increases the refcounter of a found router */
  131. struct batadv_neigh_node *
  132. batadv_orig_node_get_router(struct batadv_orig_node *orig_node)
  133. {
  134. struct batadv_neigh_node *router;
  135. rcu_read_lock();
  136. router = rcu_dereference(orig_node->router);
  137. if (router && !atomic_inc_not_zero(&router->refcount))
  138. router = NULL;
  139. rcu_read_unlock();
  140. return router;
  141. }
  142. /**
  143. * batadv_neigh_node_new - create and init a new neigh_node object
  144. * @hard_iface: the interface where the neighbour is connected to
  145. * @neigh_addr: the mac address of the neighbour interface
  146. * @orig_node: originator object representing the neighbour
  147. *
  148. * Allocates a new neigh_node object and initialises all the generic fields.
  149. * Returns the new object or NULL on failure.
  150. */
  151. struct batadv_neigh_node *
  152. batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
  153. const uint8_t *neigh_addr,
  154. struct batadv_orig_node *orig_node)
  155. {
  156. struct batadv_neigh_node *neigh_node;
  157. neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
  158. if (!neigh_node)
  159. goto out;
  160. INIT_HLIST_NODE(&neigh_node->list);
  161. memcpy(neigh_node->addr, neigh_addr, ETH_ALEN);
  162. neigh_node->if_incoming = hard_iface;
  163. neigh_node->orig_node = orig_node;
  164. INIT_LIST_HEAD(&neigh_node->bonding_list);
  165. /* extra reference for return */
  166. atomic_set(&neigh_node->refcount, 2);
  167. out:
  168. return neigh_node;
  169. }
  170. static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
  171. {
  172. struct hlist_node *node_tmp;
  173. struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
  174. struct batadv_orig_node *orig_node;
  175. orig_node = container_of(rcu, struct batadv_orig_node, rcu);
  176. spin_lock_bh(&orig_node->neigh_list_lock);
  177. /* for all bonding members ... */
  178. list_for_each_entry_safe(neigh_node, tmp_neigh_node,
  179. &orig_node->bond_list, bonding_list) {
  180. list_del_rcu(&neigh_node->bonding_list);
  181. batadv_neigh_node_free_ref(neigh_node);
  182. }
  183. /* for all neighbors towards this originator ... */
  184. hlist_for_each_entry_safe(neigh_node, node_tmp,
  185. &orig_node->neigh_list, list) {
  186. hlist_del_rcu(&neigh_node->list);
  187. batadv_neigh_node_free_ref(neigh_node);
  188. }
  189. spin_unlock_bh(&orig_node->neigh_list_lock);
  190. /* Free nc_nodes */
  191. batadv_nc_purge_orig(orig_node->bat_priv, orig_node, NULL);
  192. batadv_frag_purge_orig(orig_node, NULL);
  193. batadv_tt_global_del_orig(orig_node->bat_priv, orig_node, -1,
  194. "originator timed out");
  195. if (orig_node->bat_priv->bat_algo_ops->bat_orig_free)
  196. orig_node->bat_priv->bat_algo_ops->bat_orig_free(orig_node);
  197. kfree(orig_node->tt_buff);
  198. kfree(orig_node);
  199. }
  200. /**
  201. * batadv_orig_node_free_ref - decrement the orig node refcounter and possibly
  202. * schedule an rcu callback for freeing it
  203. * @orig_node: the orig node to free
  204. */
  205. void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node)
  206. {
  207. if (atomic_dec_and_test(&orig_node->refcount))
  208. call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
  209. }
  210. /**
  211. * batadv_orig_node_free_ref_now - decrement the orig node refcounter and
  212. * possibly free it (without rcu callback)
  213. * @orig_node: the orig node to free
  214. */
  215. void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node)
  216. {
  217. if (atomic_dec_and_test(&orig_node->refcount))
  218. batadv_orig_node_free_rcu(&orig_node->rcu);
  219. }
  220. void batadv_originator_free(struct batadv_priv *bat_priv)
  221. {
  222. struct batadv_hashtable *hash = bat_priv->orig_hash;
  223. struct hlist_node *node_tmp;
  224. struct hlist_head *head;
  225. spinlock_t *list_lock; /* spinlock to protect write access */
  226. struct batadv_orig_node *orig_node;
  227. uint32_t i;
  228. if (!hash)
  229. return;
  230. cancel_delayed_work_sync(&bat_priv->orig_work);
  231. bat_priv->orig_hash = NULL;
  232. for (i = 0; i < hash->size; i++) {
  233. head = &hash->table[i];
  234. list_lock = &hash->list_locks[i];
  235. spin_lock_bh(list_lock);
  236. hlist_for_each_entry_safe(orig_node, node_tmp,
  237. head, hash_entry) {
  238. hlist_del_rcu(&orig_node->hash_entry);
  239. batadv_orig_node_free_ref(orig_node);
  240. }
  241. spin_unlock_bh(list_lock);
  242. }
  243. batadv_hash_destroy(hash);
  244. }
  245. /**
  246. * batadv_orig_node_new - creates a new orig_node
  247. * @bat_priv: the bat priv with all the soft interface information
  248. * @addr: the mac address of the originator
  249. *
  250. * Creates a new originator object and initialise all the generic fields.
  251. * The new object is not added to the originator list.
  252. * Returns the newly created object or NULL on failure.
  253. */
  254. struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
  255. const uint8_t *addr)
  256. {
  257. struct batadv_orig_node *orig_node;
  258. struct batadv_orig_node_vlan *vlan;
  259. unsigned long reset_time;
  260. int i;
  261. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  262. "Creating new originator: %pM\n", addr);
  263. orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
  264. if (!orig_node)
  265. return NULL;
  266. INIT_HLIST_HEAD(&orig_node->neigh_list);
  267. INIT_LIST_HEAD(&orig_node->bond_list);
  268. INIT_LIST_HEAD(&orig_node->vlan_list);
  269. spin_lock_init(&orig_node->bcast_seqno_lock);
  270. spin_lock_init(&orig_node->neigh_list_lock);
  271. spin_lock_init(&orig_node->tt_buff_lock);
  272. spin_lock_init(&orig_node->tt_lock);
  273. spin_lock_init(&orig_node->vlan_list_lock);
  274. batadv_nc_init_orig(orig_node);
  275. /* extra reference for return */
  276. atomic_set(&orig_node->refcount, 2);
  277. orig_node->tt_initialised = false;
  278. orig_node->bat_priv = bat_priv;
  279. memcpy(orig_node->orig, addr, ETH_ALEN);
  280. batadv_dat_init_orig_node_addr(orig_node);
  281. orig_node->router = NULL;
  282. atomic_set(&orig_node->last_ttvn, 0);
  283. orig_node->tt_buff = NULL;
  284. orig_node->tt_buff_len = 0;
  285. reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
  286. orig_node->bcast_seqno_reset = reset_time;
  287. orig_node->batman_seqno_reset = reset_time;
  288. atomic_set(&orig_node->bond_candidates, 0);
  289. /* create a vlan object for the "untagged" LAN */
  290. vlan = batadv_orig_node_vlan_new(orig_node, BATADV_NO_FLAGS);
  291. if (!vlan)
  292. goto free_orig_node;
  293. /* batadv_orig_node_vlan_new() increases the refcounter.
  294. * Immediately release vlan since it is not needed anymore in this
  295. * context
  296. */
  297. batadv_orig_node_vlan_free_ref(vlan);
  298. for (i = 0; i < BATADV_FRAG_BUFFER_COUNT; i++) {
  299. INIT_HLIST_HEAD(&orig_node->fragments[i].head);
  300. spin_lock_init(&orig_node->fragments[i].lock);
  301. orig_node->fragments[i].size = 0;
  302. }
  303. return orig_node;
  304. free_orig_node:
  305. kfree(orig_node);
  306. return NULL;
  307. }
  308. static bool
  309. batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
  310. struct batadv_orig_node *orig_node,
  311. struct batadv_neigh_node **best_neigh)
  312. {
  313. struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
  314. struct hlist_node *node_tmp;
  315. struct batadv_neigh_node *neigh_node;
  316. bool neigh_purged = false;
  317. unsigned long last_seen;
  318. struct batadv_hard_iface *if_incoming;
  319. *best_neigh = NULL;
  320. spin_lock_bh(&orig_node->neigh_list_lock);
  321. /* for all neighbors towards this originator ... */
  322. hlist_for_each_entry_safe(neigh_node, node_tmp,
  323. &orig_node->neigh_list, list) {
  324. last_seen = neigh_node->last_seen;
  325. if_incoming = neigh_node->if_incoming;
  326. if ((batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT)) ||
  327. (if_incoming->if_status == BATADV_IF_INACTIVE) ||
  328. (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
  329. (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)) {
  330. if ((if_incoming->if_status == BATADV_IF_INACTIVE) ||
  331. (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
  332. (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED))
  333. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  334. "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
  335. orig_node->orig, neigh_node->addr,
  336. if_incoming->net_dev->name);
  337. else
  338. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  339. "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
  340. orig_node->orig, neigh_node->addr,
  341. jiffies_to_msecs(last_seen));
  342. neigh_purged = true;
  343. hlist_del_rcu(&neigh_node->list);
  344. batadv_bonding_candidate_del(orig_node, neigh_node);
  345. batadv_neigh_node_free_ref(neigh_node);
  346. } else {
  347. /* store the best_neighbour if this is the first
  348. * iteration or if a better neighbor has been found
  349. */
  350. if (!*best_neigh ||
  351. bao->bat_neigh_cmp(neigh_node, *best_neigh) > 0)
  352. *best_neigh = neigh_node;
  353. }
  354. }
  355. spin_unlock_bh(&orig_node->neigh_list_lock);
  356. return neigh_purged;
  357. }
  358. static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
  359. struct batadv_orig_node *orig_node)
  360. {
  361. struct batadv_neigh_node *best_neigh_node;
  362. if (batadv_has_timed_out(orig_node->last_seen,
  363. 2 * BATADV_PURGE_TIMEOUT)) {
  364. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  365. "Originator timeout: originator %pM, last_seen %u\n",
  366. orig_node->orig,
  367. jiffies_to_msecs(orig_node->last_seen));
  368. return true;
  369. } else {
  370. if (batadv_purge_orig_neighbors(bat_priv, orig_node,
  371. &best_neigh_node))
  372. batadv_update_route(bat_priv, orig_node,
  373. best_neigh_node);
  374. }
  375. return false;
  376. }
  377. static void _batadv_purge_orig(struct batadv_priv *bat_priv)
  378. {
  379. struct batadv_hashtable *hash = bat_priv->orig_hash;
  380. struct hlist_node *node_tmp;
  381. struct hlist_head *head;
  382. spinlock_t *list_lock; /* spinlock to protect write access */
  383. struct batadv_orig_node *orig_node;
  384. uint32_t i;
  385. if (!hash)
  386. return;
  387. /* for all origins... */
  388. for (i = 0; i < hash->size; i++) {
  389. head = &hash->table[i];
  390. list_lock = &hash->list_locks[i];
  391. spin_lock_bh(list_lock);
  392. hlist_for_each_entry_safe(orig_node, node_tmp,
  393. head, hash_entry) {
  394. if (batadv_purge_orig_node(bat_priv, orig_node)) {
  395. batadv_gw_node_delete(bat_priv, orig_node);
  396. hlist_del_rcu(&orig_node->hash_entry);
  397. batadv_orig_node_free_ref(orig_node);
  398. continue;
  399. }
  400. batadv_frag_purge_orig(orig_node,
  401. batadv_frag_check_entry);
  402. }
  403. spin_unlock_bh(list_lock);
  404. }
  405. batadv_gw_node_purge(bat_priv);
  406. batadv_gw_election(bat_priv);
  407. }
  408. static void batadv_purge_orig(struct work_struct *work)
  409. {
  410. struct delayed_work *delayed_work;
  411. struct batadv_priv *bat_priv;
  412. delayed_work = container_of(work, struct delayed_work, work);
  413. bat_priv = container_of(delayed_work, struct batadv_priv, orig_work);
  414. _batadv_purge_orig(bat_priv);
  415. queue_delayed_work(batadv_event_workqueue,
  416. &bat_priv->orig_work,
  417. msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD));
  418. }
  419. void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
  420. {
  421. _batadv_purge_orig(bat_priv);
  422. }
  423. int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
  424. {
  425. struct net_device *net_dev = (struct net_device *)seq->private;
  426. struct batadv_priv *bat_priv = netdev_priv(net_dev);
  427. struct batadv_hard_iface *primary_if;
  428. primary_if = batadv_seq_print_text_primary_if_get(seq);
  429. if (!primary_if)
  430. return 0;
  431. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
  432. BATADV_SOURCE_VERSION, primary_if->net_dev->name,
  433. primary_if->net_dev->dev_addr, net_dev->name,
  434. bat_priv->bat_algo_ops->name);
  435. batadv_hardif_free_ref(primary_if);
  436. if (!bat_priv->bat_algo_ops->bat_orig_print) {
  437. seq_puts(seq,
  438. "No printing function for this routing protocol\n");
  439. return 0;
  440. }
  441. bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq);
  442. return 0;
  443. }
  444. int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
  445. int max_if_num)
  446. {
  447. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  448. struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
  449. struct batadv_hashtable *hash = bat_priv->orig_hash;
  450. struct hlist_head *head;
  451. struct batadv_orig_node *orig_node;
  452. uint32_t i;
  453. int ret;
  454. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  455. * if_num
  456. */
  457. for (i = 0; i < hash->size; i++) {
  458. head = &hash->table[i];
  459. rcu_read_lock();
  460. hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
  461. ret = 0;
  462. if (bao->bat_orig_add_if)
  463. ret = bao->bat_orig_add_if(orig_node,
  464. max_if_num);
  465. if (ret == -ENOMEM)
  466. goto err;
  467. }
  468. rcu_read_unlock();
  469. }
  470. return 0;
  471. err:
  472. rcu_read_unlock();
  473. return -ENOMEM;
  474. }
  475. int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
  476. int max_if_num)
  477. {
  478. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  479. struct batadv_hashtable *hash = bat_priv->orig_hash;
  480. struct hlist_head *head;
  481. struct batadv_hard_iface *hard_iface_tmp;
  482. struct batadv_orig_node *orig_node;
  483. struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
  484. uint32_t i;
  485. int ret;
  486. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  487. * if_num
  488. */
  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, head, hash_entry) {
  493. ret = 0;
  494. if (bao->bat_orig_del_if)
  495. ret = bao->bat_orig_del_if(orig_node,
  496. max_if_num,
  497. hard_iface->if_num);
  498. if (ret == -ENOMEM)
  499. goto err;
  500. }
  501. rcu_read_unlock();
  502. }
  503. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  504. rcu_read_lock();
  505. list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) {
  506. if (hard_iface_tmp->if_status == BATADV_IF_NOT_IN_USE)
  507. continue;
  508. if (hard_iface == hard_iface_tmp)
  509. continue;
  510. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  511. continue;
  512. if (hard_iface_tmp->if_num > hard_iface->if_num)
  513. hard_iface_tmp->if_num--;
  514. }
  515. rcu_read_unlock();
  516. hard_iface->if_num = -1;
  517. return 0;
  518. err:
  519. rcu_read_unlock();
  520. return -ENOMEM;
  521. }