originator.c 16 KB

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