originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /* Copyright (C) 2009-2012 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 "originator.h"
  21. #include "hash.h"
  22. #include "translation-table.h"
  23. #include "routing.h"
  24. #include "gateway_client.h"
  25. #include "hard-interface.h"
  26. #include "unicast.h"
  27. #include "soft-interface.h"
  28. #include "bridge_loop_avoidance.h"
  29. static void batadv_purge_orig(struct work_struct *work);
  30. static void batadv_start_purge_timer(struct bat_priv *bat_priv)
  31. {
  32. INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig);
  33. queue_delayed_work(batadv_event_workqueue,
  34. &bat_priv->orig_work, msecs_to_jiffies(1000));
  35. }
  36. /* returns 1 if they are the same originator */
  37. static int batadv_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 batadv_originator_init(struct bat_priv *bat_priv)
  43. {
  44. if (bat_priv->orig_hash)
  45. return 0;
  46. bat_priv->orig_hash = batadv_hash_new(1024);
  47. if (!bat_priv->orig_hash)
  48. goto err;
  49. batadv_start_purge_timer(bat_priv);
  50. return 0;
  51. err:
  52. return -ENOMEM;
  53. }
  54. void batadv_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 *batadv_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 *batadv_neigh_node_new(struct hard_iface *hard_iface,
  71. const uint8_t *neigh_addr,
  72. uint32_t seqno)
  73. {
  74. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  75. struct neigh_node *neigh_node;
  76. neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
  77. if (!neigh_node)
  78. goto out;
  79. INIT_HLIST_NODE(&neigh_node->list);
  80. memcpy(neigh_node->addr, neigh_addr, ETH_ALEN);
  81. spin_lock_init(&neigh_node->lq_update_lock);
  82. /* extra reference for return */
  83. atomic_set(&neigh_node->refcount, 2);
  84. batadv_dbg(DBG_BATMAN, bat_priv,
  85. "Creating new neighbor %pM, initial seqno %d\n",
  86. neigh_addr, seqno);
  87. out:
  88. return neigh_node;
  89. }
  90. static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
  91. {
  92. struct hlist_node *node, *node_tmp;
  93. struct neigh_node *neigh_node, *tmp_neigh_node;
  94. struct orig_node *orig_node;
  95. orig_node = container_of(rcu, struct orig_node, rcu);
  96. spin_lock_bh(&orig_node->neigh_list_lock);
  97. /* for all bonding members ... */
  98. list_for_each_entry_safe(neigh_node, tmp_neigh_node,
  99. &orig_node->bond_list, bonding_list) {
  100. list_del_rcu(&neigh_node->bonding_list);
  101. batadv_neigh_node_free_ref(neigh_node);
  102. }
  103. /* for all neighbors towards this originator ... */
  104. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  105. &orig_node->neigh_list, list) {
  106. hlist_del_rcu(&neigh_node->list);
  107. batadv_neigh_node_free_ref(neigh_node);
  108. }
  109. spin_unlock_bh(&orig_node->neigh_list_lock);
  110. batadv_frag_list_free(&orig_node->frag_list);
  111. batadv_tt_global_del_orig(orig_node->bat_priv, orig_node,
  112. "originator timed out");
  113. kfree(orig_node->tt_buff);
  114. kfree(orig_node->bcast_own);
  115. kfree(orig_node->bcast_own_sum);
  116. kfree(orig_node);
  117. }
  118. void batadv_orig_node_free_ref(struct orig_node *orig_node)
  119. {
  120. if (atomic_dec_and_test(&orig_node->refcount))
  121. call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
  122. }
  123. void batadv_originator_free(struct bat_priv *bat_priv)
  124. {
  125. struct hashtable_t *hash = bat_priv->orig_hash;
  126. struct hlist_node *node, *node_tmp;
  127. struct hlist_head *head;
  128. spinlock_t *list_lock; /* spinlock to protect write access */
  129. struct orig_node *orig_node;
  130. uint32_t i;
  131. if (!hash)
  132. return;
  133. cancel_delayed_work_sync(&bat_priv->orig_work);
  134. bat_priv->orig_hash = NULL;
  135. for (i = 0; i < hash->size; i++) {
  136. head = &hash->table[i];
  137. list_lock = &hash->list_locks[i];
  138. spin_lock_bh(list_lock);
  139. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  140. head, hash_entry) {
  141. hlist_del_rcu(node);
  142. batadv_orig_node_free_ref(orig_node);
  143. }
  144. spin_unlock_bh(list_lock);
  145. }
  146. batadv_hash_destroy(hash);
  147. }
  148. /* this function finds or creates an originator entry for the given
  149. * address if it does not exits
  150. */
  151. struct orig_node *batadv_get_orig_node(struct bat_priv *bat_priv,
  152. const uint8_t *addr)
  153. {
  154. struct orig_node *orig_node;
  155. int size;
  156. int hash_added;
  157. orig_node = batadv_orig_hash_find(bat_priv, addr);
  158. if (orig_node)
  159. return orig_node;
  160. batadv_dbg(DBG_BATMAN, bat_priv, "Creating new originator: %pM\n",
  161. 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 = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
  199. batadv_choose_orig, orig_node,
  200. &orig_node->hash_entry);
  201. if (hash_added != 0)
  202. goto free_bcast_own_sum;
  203. return orig_node;
  204. free_bcast_own_sum:
  205. kfree(orig_node->bcast_own_sum);
  206. free_bcast_own:
  207. kfree(orig_node->bcast_own);
  208. free_orig_node:
  209. kfree(orig_node);
  210. return NULL;
  211. }
  212. static bool batadv_purge_orig_neighbors(struct bat_priv *bat_priv,
  213. struct orig_node *orig_node,
  214. struct neigh_node **best_neigh_node)
  215. {
  216. struct hlist_node *node, *node_tmp;
  217. struct neigh_node *neigh_node;
  218. bool neigh_purged = false;
  219. unsigned long last_seen;
  220. struct hard_iface *if_incoming;
  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. last_seen = neigh_node->last_seen;
  227. if_incoming = neigh_node->if_incoming;
  228. if ((batadv_has_timed_out(last_seen, PURGE_TIMEOUT)) ||
  229. (if_incoming->if_status == IF_INACTIVE) ||
  230. (if_incoming->if_status == IF_NOT_IN_USE) ||
  231. (if_incoming->if_status == IF_TO_BE_REMOVED)) {
  232. if ((if_incoming->if_status == IF_INACTIVE) ||
  233. (if_incoming->if_status == IF_NOT_IN_USE) ||
  234. (if_incoming->if_status == IF_TO_BE_REMOVED))
  235. batadv_dbg(DBG_BATMAN, bat_priv,
  236. "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
  237. orig_node->orig, neigh_node->addr,
  238. if_incoming->net_dev->name);
  239. else
  240. batadv_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. batadv_bonding_candidate_del(orig_node, neigh_node);
  247. batadv_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 batadv_purge_orig_node(struct bat_priv *bat_priv,
  258. struct orig_node *orig_node)
  259. {
  260. struct neigh_node *best_neigh_node;
  261. if (batadv_has_timed_out(orig_node->last_seen, 2 * PURGE_TIMEOUT)) {
  262. batadv_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 (batadv_purge_orig_neighbors(bat_priv, orig_node,
  269. &best_neigh_node))
  270. batadv_update_route(bat_priv, orig_node,
  271. best_neigh_node);
  272. }
  273. return false;
  274. }
  275. static void _batadv_purge_orig(struct bat_priv *bat_priv)
  276. {
  277. struct hashtable_t *hash = bat_priv->orig_hash;
  278. struct hlist_node *node, *node_tmp;
  279. struct hlist_head *head;
  280. spinlock_t *list_lock; /* spinlock to protect write access */
  281. struct orig_node *orig_node;
  282. uint32_t i;
  283. if (!hash)
  284. return;
  285. /* for all origins... */
  286. for (i = 0; i < hash->size; i++) {
  287. head = &hash->table[i];
  288. list_lock = &hash->list_locks[i];
  289. spin_lock_bh(list_lock);
  290. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  291. head, hash_entry) {
  292. if (batadv_purge_orig_node(bat_priv, orig_node)) {
  293. if (orig_node->gw_flags)
  294. batadv_gw_node_delete(bat_priv,
  295. orig_node);
  296. hlist_del_rcu(node);
  297. batadv_orig_node_free_ref(orig_node);
  298. continue;
  299. }
  300. if (batadv_has_timed_out(orig_node->last_frag_packet,
  301. FRAG_TIMEOUT))
  302. batadv_frag_list_free(&orig_node->frag_list);
  303. }
  304. spin_unlock_bh(list_lock);
  305. }
  306. batadv_gw_node_purge(bat_priv);
  307. batadv_gw_election(bat_priv);
  308. }
  309. static void batadv_purge_orig(struct work_struct *work)
  310. {
  311. struct delayed_work *delayed_work =
  312. container_of(work, struct delayed_work, work);
  313. struct bat_priv *bat_priv =
  314. container_of(delayed_work, struct bat_priv, orig_work);
  315. _batadv_purge_orig(bat_priv);
  316. batadv_start_purge_timer(bat_priv);
  317. }
  318. void batadv_purge_orig_ref(struct bat_priv *bat_priv)
  319. {
  320. _batadv_purge_orig(bat_priv);
  321. }
  322. int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
  323. {
  324. struct net_device *net_dev = (struct net_device *)seq->private;
  325. struct bat_priv *bat_priv = netdev_priv(net_dev);
  326. struct hashtable_t *hash = bat_priv->orig_hash;
  327. struct hlist_node *node, *node_tmp;
  328. struct hlist_head *head;
  329. struct hard_iface *primary_if;
  330. struct orig_node *orig_node;
  331. struct neigh_node *neigh_node, *neigh_node_tmp;
  332. int batman_count = 0;
  333. int last_seen_secs;
  334. int last_seen_msecs;
  335. uint32_t i;
  336. int ret = 0;
  337. primary_if = batadv_primary_if_get_selected(bat_priv);
  338. if (!primary_if) {
  339. ret = seq_printf(seq,
  340. "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
  341. net_dev->name);
  342. goto out;
  343. }
  344. if (primary_if->if_status != IF_ACTIVE) {
  345. ret = seq_printf(seq,
  346. "BATMAN mesh %s disabled - primary interface not active\n",
  347. net_dev->name);
  348. goto out;
  349. }
  350. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  351. SOURCE_VERSION, primary_if->net_dev->name,
  352. primary_if->net_dev->dev_addr, net_dev->name);
  353. seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
  354. "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop",
  355. "outgoingIF", "Potential nexthops");
  356. for (i = 0; i < hash->size; i++) {
  357. head = &hash->table[i];
  358. rcu_read_lock();
  359. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  360. neigh_node = batadv_orig_node_get_router(orig_node);
  361. if (!neigh_node)
  362. continue;
  363. if (neigh_node->tq_avg == 0)
  364. goto next;
  365. last_seen_secs = jiffies_to_msecs(jiffies -
  366. orig_node->last_seen) / 1000;
  367. last_seen_msecs = jiffies_to_msecs(jiffies -
  368. orig_node->last_seen) % 1000;
  369. seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
  370. orig_node->orig, last_seen_secs,
  371. last_seen_msecs, neigh_node->tq_avg,
  372. neigh_node->addr,
  373. neigh_node->if_incoming->net_dev->name);
  374. hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp,
  375. &orig_node->neigh_list, list) {
  376. seq_printf(seq, " %pM (%3i)",
  377. neigh_node_tmp->addr,
  378. neigh_node_tmp->tq_avg);
  379. }
  380. seq_printf(seq, "\n");
  381. batman_count++;
  382. next:
  383. batadv_neigh_node_free_ref(neigh_node);
  384. }
  385. rcu_read_unlock();
  386. }
  387. if (batman_count == 0)
  388. seq_printf(seq, "No batman nodes in range ...\n");
  389. out:
  390. if (primary_if)
  391. batadv_hardif_free_ref(primary_if);
  392. return ret;
  393. }
  394. static int batadv_orig_node_add_if(struct orig_node *orig_node, int max_if_num)
  395. {
  396. void *data_ptr;
  397. data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
  398. GFP_ATOMIC);
  399. if (!data_ptr)
  400. return -ENOMEM;
  401. memcpy(data_ptr, orig_node->bcast_own,
  402. (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
  403. kfree(orig_node->bcast_own);
  404. orig_node->bcast_own = data_ptr;
  405. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  406. if (!data_ptr)
  407. return -ENOMEM;
  408. memcpy(data_ptr, orig_node->bcast_own_sum,
  409. (max_if_num - 1) * sizeof(uint8_t));
  410. kfree(orig_node->bcast_own_sum);
  411. orig_node->bcast_own_sum = data_ptr;
  412. return 0;
  413. }
  414. int batadv_orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
  415. {
  416. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  417. struct hashtable_t *hash = bat_priv->orig_hash;
  418. struct hlist_node *node;
  419. struct hlist_head *head;
  420. struct orig_node *orig_node;
  421. uint32_t i;
  422. int ret;
  423. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  424. * if_num
  425. */
  426. for (i = 0; i < hash->size; i++) {
  427. head = &hash->table[i];
  428. rcu_read_lock();
  429. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  430. spin_lock_bh(&orig_node->ogm_cnt_lock);
  431. ret = batadv_orig_node_add_if(orig_node, max_if_num);
  432. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  433. if (ret == -ENOMEM)
  434. goto err;
  435. }
  436. rcu_read_unlock();
  437. }
  438. return 0;
  439. err:
  440. rcu_read_unlock();
  441. return -ENOMEM;
  442. }
  443. static int batadv_orig_node_del_if(struct orig_node *orig_node,
  444. int max_if_num, int del_if_num)
  445. {
  446. void *data_ptr = NULL;
  447. int chunk_size;
  448. /* last interface was removed */
  449. if (max_if_num == 0)
  450. goto free_bcast_own;
  451. chunk_size = sizeof(unsigned long) * NUM_WORDS;
  452. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  453. if (!data_ptr)
  454. return -ENOMEM;
  455. /* copy first part */
  456. memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
  457. /* copy second part */
  458. memcpy((char *)data_ptr + del_if_num * chunk_size,
  459. orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
  460. (max_if_num - del_if_num) * chunk_size);
  461. free_bcast_own:
  462. kfree(orig_node->bcast_own);
  463. orig_node->bcast_own = data_ptr;
  464. if (max_if_num == 0)
  465. goto free_own_sum;
  466. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  467. if (!data_ptr)
  468. return -ENOMEM;
  469. memcpy(data_ptr, orig_node->bcast_own_sum,
  470. del_if_num * sizeof(uint8_t));
  471. memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
  472. orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
  473. (max_if_num - del_if_num) * sizeof(uint8_t));
  474. free_own_sum:
  475. kfree(orig_node->bcast_own_sum);
  476. orig_node->bcast_own_sum = data_ptr;
  477. return 0;
  478. }
  479. int batadv_orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
  480. {
  481. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  482. struct hashtable_t *hash = bat_priv->orig_hash;
  483. struct hlist_node *node;
  484. struct hlist_head *head;
  485. struct hard_iface *hard_iface_tmp;
  486. struct orig_node *orig_node;
  487. uint32_t i;
  488. int ret;
  489. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  490. * if_num
  491. */
  492. for (i = 0; i < hash->size; i++) {
  493. head = &hash->table[i];
  494. rcu_read_lock();
  495. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  496. spin_lock_bh(&orig_node->ogm_cnt_lock);
  497. ret = batadv_orig_node_del_if(orig_node, max_if_num,
  498. hard_iface->if_num);
  499. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  500. if (ret == -ENOMEM)
  501. goto err;
  502. }
  503. rcu_read_unlock();
  504. }
  505. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  506. rcu_read_lock();
  507. list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) {
  508. if (hard_iface_tmp->if_status == IF_NOT_IN_USE)
  509. continue;
  510. if (hard_iface == hard_iface_tmp)
  511. continue;
  512. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  513. continue;
  514. if (hard_iface_tmp->if_num > hard_iface->if_num)
  515. hard_iface_tmp->if_num--;
  516. }
  517. rcu_read_unlock();
  518. hard_iface->if_num = -1;
  519. return 0;
  520. err:
  521. rcu_read_unlock();
  522. return -ENOMEM;
  523. }