originator.c 16 KB

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