originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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 "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 "unicast.h"
  28. #include "soft-interface.h"
  29. #include "bridge_loop_avoidance.h"
  30. static void batadv_purge_orig(struct work_struct *work);
  31. static void batadv_start_purge_timer(struct batadv_priv *bat_priv)
  32. {
  33. INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig);
  34. queue_delayed_work(batadv_event_workqueue,
  35. &bat_priv->orig_work, msecs_to_jiffies(1000));
  36. }
  37. /* returns 1 if they are the same originator */
  38. static int batadv_compare_orig(const struct hlist_node *node, const void *data2)
  39. {
  40. const void *data1 = container_of(node, struct batadv_orig_node,
  41. hash_entry);
  42. return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
  43. }
  44. int batadv_originator_init(struct batadv_priv *bat_priv)
  45. {
  46. if (bat_priv->orig_hash)
  47. return 0;
  48. bat_priv->orig_hash = batadv_hash_new(1024);
  49. if (!bat_priv->orig_hash)
  50. goto err;
  51. batadv_start_purge_timer(bat_priv);
  52. return 0;
  53. err:
  54. return -ENOMEM;
  55. }
  56. void batadv_neigh_node_free_ref(struct batadv_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 batadv_neigh_node *
  63. batadv_orig_node_get_router(struct batadv_orig_node *orig_node)
  64. {
  65. struct batadv_neigh_node *router;
  66. rcu_read_lock();
  67. router = rcu_dereference(orig_node->router);
  68. if (router && !atomic_inc_not_zero(&router->refcount))
  69. router = NULL;
  70. rcu_read_unlock();
  71. return router;
  72. }
  73. struct batadv_neigh_node *
  74. batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
  75. const uint8_t *neigh_addr, uint32_t seqno)
  76. {
  77. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  78. struct batadv_neigh_node *neigh_node;
  79. neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
  80. if (!neigh_node)
  81. goto out;
  82. INIT_HLIST_NODE(&neigh_node->list);
  83. memcpy(neigh_node->addr, neigh_addr, ETH_ALEN);
  84. spin_lock_init(&neigh_node->lq_update_lock);
  85. /* extra reference for return */
  86. atomic_set(&neigh_node->refcount, 2);
  87. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  88. "Creating new neighbor %pM, initial seqno %d\n",
  89. neigh_addr, seqno);
  90. out:
  91. return neigh_node;
  92. }
  93. static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
  94. {
  95. struct hlist_node *node, *node_tmp;
  96. struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
  97. struct batadv_orig_node *orig_node;
  98. orig_node = container_of(rcu, struct batadv_orig_node, rcu);
  99. spin_lock_bh(&orig_node->neigh_list_lock);
  100. /* for all bonding members ... */
  101. list_for_each_entry_safe(neigh_node, tmp_neigh_node,
  102. &orig_node->bond_list, bonding_list) {
  103. list_del_rcu(&neigh_node->bonding_list);
  104. batadv_neigh_node_free_ref(neigh_node);
  105. }
  106. /* for all neighbors towards this originator ... */
  107. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  108. &orig_node->neigh_list, list) {
  109. hlist_del_rcu(&neigh_node->list);
  110. batadv_neigh_node_free_ref(neigh_node);
  111. }
  112. spin_unlock_bh(&orig_node->neigh_list_lock);
  113. batadv_frag_list_free(&orig_node->frag_list);
  114. batadv_tt_global_del_orig(orig_node->bat_priv, orig_node,
  115. "originator timed out");
  116. kfree(orig_node->tt_buff);
  117. kfree(orig_node->bcast_own);
  118. kfree(orig_node->bcast_own_sum);
  119. kfree(orig_node);
  120. }
  121. void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node)
  122. {
  123. if (atomic_dec_and_test(&orig_node->refcount))
  124. call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
  125. }
  126. void batadv_originator_free(struct batadv_priv *bat_priv)
  127. {
  128. struct batadv_hashtable *hash = bat_priv->orig_hash;
  129. struct hlist_node *node, *node_tmp;
  130. struct hlist_head *head;
  131. spinlock_t *list_lock; /* spinlock to protect write access */
  132. struct batadv_orig_node *orig_node;
  133. uint32_t i;
  134. if (!hash)
  135. return;
  136. cancel_delayed_work_sync(&bat_priv->orig_work);
  137. bat_priv->orig_hash = NULL;
  138. for (i = 0; i < hash->size; i++) {
  139. head = &hash->table[i];
  140. list_lock = &hash->list_locks[i];
  141. spin_lock_bh(list_lock);
  142. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  143. head, hash_entry) {
  144. hlist_del_rcu(node);
  145. batadv_orig_node_free_ref(orig_node);
  146. }
  147. spin_unlock_bh(list_lock);
  148. }
  149. batadv_hash_destroy(hash);
  150. }
  151. /* this function finds or creates an originator entry for the given
  152. * address if it does not exits
  153. */
  154. struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
  155. const uint8_t *addr)
  156. {
  157. struct batadv_orig_node *orig_node;
  158. int size;
  159. int hash_added;
  160. unsigned long reset_time;
  161. orig_node = batadv_orig_hash_find(bat_priv, addr);
  162. if (orig_node)
  163. return orig_node;
  164. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  165. "Creating new originator: %pM\n", addr);
  166. orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
  167. if (!orig_node)
  168. return NULL;
  169. INIT_HLIST_HEAD(&orig_node->neigh_list);
  170. INIT_LIST_HEAD(&orig_node->bond_list);
  171. spin_lock_init(&orig_node->ogm_cnt_lock);
  172. spin_lock_init(&orig_node->bcast_seqno_lock);
  173. spin_lock_init(&orig_node->neigh_list_lock);
  174. spin_lock_init(&orig_node->tt_buff_lock);
  175. /* extra reference for return */
  176. atomic_set(&orig_node->refcount, 2);
  177. orig_node->tt_initialised = false;
  178. orig_node->bat_priv = bat_priv;
  179. memcpy(orig_node->orig, addr, ETH_ALEN);
  180. batadv_dat_init_orig_node_addr(orig_node);
  181. orig_node->router = NULL;
  182. orig_node->tt_crc = 0;
  183. atomic_set(&orig_node->last_ttvn, 0);
  184. orig_node->tt_buff = NULL;
  185. orig_node->tt_buff_len = 0;
  186. atomic_set(&orig_node->tt_size, 0);
  187. reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
  188. orig_node->bcast_seqno_reset = reset_time;
  189. orig_node->batman_seqno_reset = reset_time;
  190. atomic_set(&orig_node->bond_candidates, 0);
  191. size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_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 = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
  202. batadv_choose_orig, orig_node,
  203. &orig_node->hash_entry);
  204. if (hash_added != 0)
  205. goto free_bcast_own_sum;
  206. return orig_node;
  207. free_bcast_own_sum:
  208. kfree(orig_node->bcast_own_sum);
  209. free_bcast_own:
  210. kfree(orig_node->bcast_own);
  211. free_orig_node:
  212. kfree(orig_node);
  213. return NULL;
  214. }
  215. static bool
  216. batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
  217. struct batadv_orig_node *orig_node,
  218. struct batadv_neigh_node **best_neigh_node)
  219. {
  220. struct hlist_node *node, *node_tmp;
  221. struct batadv_neigh_node *neigh_node;
  222. bool neigh_purged = false;
  223. unsigned long last_seen;
  224. struct batadv_hard_iface *if_incoming;
  225. *best_neigh_node = NULL;
  226. spin_lock_bh(&orig_node->neigh_list_lock);
  227. /* for all neighbors towards this originator ... */
  228. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  229. &orig_node->neigh_list, list) {
  230. last_seen = neigh_node->last_seen;
  231. if_incoming = neigh_node->if_incoming;
  232. if ((batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT)) ||
  233. (if_incoming->if_status == BATADV_IF_INACTIVE) ||
  234. (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
  235. (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)) {
  236. if ((if_incoming->if_status == BATADV_IF_INACTIVE) ||
  237. (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
  238. (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED))
  239. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  240. "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
  241. orig_node->orig, neigh_node->addr,
  242. if_incoming->net_dev->name);
  243. else
  244. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  245. "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
  246. orig_node->orig, neigh_node->addr,
  247. jiffies_to_msecs(last_seen));
  248. neigh_purged = true;
  249. hlist_del_rcu(&neigh_node->list);
  250. batadv_bonding_candidate_del(orig_node, neigh_node);
  251. batadv_neigh_node_free_ref(neigh_node);
  252. } else {
  253. if ((!*best_neigh_node) ||
  254. (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
  255. *best_neigh_node = neigh_node;
  256. }
  257. }
  258. spin_unlock_bh(&orig_node->neigh_list_lock);
  259. return neigh_purged;
  260. }
  261. static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
  262. struct batadv_orig_node *orig_node)
  263. {
  264. struct batadv_neigh_node *best_neigh_node;
  265. if (batadv_has_timed_out(orig_node->last_seen,
  266. 2 * BATADV_PURGE_TIMEOUT)) {
  267. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  268. "Originator timeout: originator %pM, last_seen %u\n",
  269. orig_node->orig,
  270. jiffies_to_msecs(orig_node->last_seen));
  271. return true;
  272. } else {
  273. if (batadv_purge_orig_neighbors(bat_priv, orig_node,
  274. &best_neigh_node))
  275. batadv_update_route(bat_priv, orig_node,
  276. best_neigh_node);
  277. }
  278. return false;
  279. }
  280. static void _batadv_purge_orig(struct batadv_priv *bat_priv)
  281. {
  282. struct batadv_hashtable *hash = bat_priv->orig_hash;
  283. struct hlist_node *node, *node_tmp;
  284. struct hlist_head *head;
  285. spinlock_t *list_lock; /* spinlock to protect write access */
  286. struct batadv_orig_node *orig_node;
  287. uint32_t i;
  288. if (!hash)
  289. return;
  290. /* for all origins... */
  291. for (i = 0; i < hash->size; i++) {
  292. head = &hash->table[i];
  293. list_lock = &hash->list_locks[i];
  294. spin_lock_bh(list_lock);
  295. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  296. head, hash_entry) {
  297. if (batadv_purge_orig_node(bat_priv, orig_node)) {
  298. if (orig_node->gw_flags)
  299. batadv_gw_node_delete(bat_priv,
  300. orig_node);
  301. hlist_del_rcu(node);
  302. batadv_orig_node_free_ref(orig_node);
  303. continue;
  304. }
  305. if (batadv_has_timed_out(orig_node->last_frag_packet,
  306. BATADV_FRAG_TIMEOUT))
  307. batadv_frag_list_free(&orig_node->frag_list);
  308. }
  309. spin_unlock_bh(list_lock);
  310. }
  311. batadv_gw_node_purge(bat_priv);
  312. batadv_gw_election(bat_priv);
  313. }
  314. static void batadv_purge_orig(struct work_struct *work)
  315. {
  316. struct delayed_work *delayed_work;
  317. struct batadv_priv *bat_priv;
  318. delayed_work = container_of(work, struct delayed_work, work);
  319. bat_priv = container_of(delayed_work, struct batadv_priv, orig_work);
  320. _batadv_purge_orig(bat_priv);
  321. batadv_start_purge_timer(bat_priv);
  322. }
  323. void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
  324. {
  325. _batadv_purge_orig(bat_priv);
  326. }
  327. int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
  328. {
  329. struct net_device *net_dev = (struct net_device *)seq->private;
  330. struct batadv_priv *bat_priv = netdev_priv(net_dev);
  331. struct batadv_hashtable *hash = bat_priv->orig_hash;
  332. struct hlist_node *node, *node_tmp;
  333. struct hlist_head *head;
  334. struct batadv_hard_iface *primary_if;
  335. struct batadv_orig_node *orig_node;
  336. struct batadv_neigh_node *neigh_node, *neigh_node_tmp;
  337. int batman_count = 0;
  338. int last_seen_secs;
  339. int last_seen_msecs;
  340. unsigned long last_seen_jiffies;
  341. uint32_t i;
  342. primary_if = batadv_seq_print_text_primary_if_get(seq);
  343. if (!primary_if)
  344. goto out;
  345. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  346. BATADV_SOURCE_VERSION, primary_if->net_dev->name,
  347. primary_if->net_dev->dev_addr, net_dev->name);
  348. seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
  349. "Originator", "last-seen", "#", BATADV_TQ_MAX_VALUE,
  350. "Nexthop", "outgoingIF", "Potential nexthops");
  351. for (i = 0; i < hash->size; i++) {
  352. head = &hash->table[i];
  353. rcu_read_lock();
  354. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  355. neigh_node = batadv_orig_node_get_router(orig_node);
  356. if (!neigh_node)
  357. continue;
  358. if (neigh_node->tq_avg == 0)
  359. goto next;
  360. last_seen_jiffies = jiffies - orig_node->last_seen;
  361. last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
  362. last_seen_secs = last_seen_msecs / 1000;
  363. last_seen_msecs = last_seen_msecs % 1000;
  364. seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
  365. orig_node->orig, last_seen_secs,
  366. last_seen_msecs, neigh_node->tq_avg,
  367. neigh_node->addr,
  368. neigh_node->if_incoming->net_dev->name);
  369. hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp,
  370. &orig_node->neigh_list, list) {
  371. seq_printf(seq, " %pM (%3i)",
  372. neigh_node_tmp->addr,
  373. neigh_node_tmp->tq_avg);
  374. }
  375. seq_printf(seq, "\n");
  376. batman_count++;
  377. next:
  378. batadv_neigh_node_free_ref(neigh_node);
  379. }
  380. rcu_read_unlock();
  381. }
  382. if (batman_count == 0)
  383. seq_printf(seq, "No batman nodes in range ...\n");
  384. out:
  385. if (primary_if)
  386. batadv_hardif_free_ref(primary_if);
  387. return 0;
  388. }
  389. static int batadv_orig_node_add_if(struct batadv_orig_node *orig_node,
  390. int max_if_num)
  391. {
  392. void *data_ptr;
  393. size_t data_size, old_size;
  394. data_size = max_if_num * sizeof(unsigned long) * BATADV_NUM_WORDS;
  395. old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS;
  396. data_ptr = kmalloc(data_size, GFP_ATOMIC);
  397. if (!data_ptr)
  398. return -ENOMEM;
  399. memcpy(data_ptr, orig_node->bcast_own, old_size);
  400. kfree(orig_node->bcast_own);
  401. orig_node->bcast_own = data_ptr;
  402. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  403. if (!data_ptr)
  404. return -ENOMEM;
  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 batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
  412. int max_if_num)
  413. {
  414. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  415. struct batadv_hashtable *hash = bat_priv->orig_hash;
  416. struct hlist_node *node;
  417. struct hlist_head *head;
  418. struct batadv_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. */
  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 = batadv_orig_node_add_if(orig_node, max_if_num);
  430. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  431. if (ret == -ENOMEM)
  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 batadv_orig_node_del_if(struct batadv_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) * BATADV_NUM_WORDS;
  450. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  451. if (!data_ptr)
  452. return -ENOMEM;
  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 -ENOMEM;
  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 batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
  478. int max_if_num)
  479. {
  480. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  481. struct batadv_hashtable *hash = bat_priv->orig_hash;
  482. struct hlist_node *node;
  483. struct hlist_head *head;
  484. struct batadv_hard_iface *hard_iface_tmp;
  485. struct batadv_orig_node *orig_node;
  486. uint32_t i;
  487. int ret;
  488. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  489. * if_num
  490. */
  491. for (i = 0; i < hash->size; i++) {
  492. head = &hash->table[i];
  493. rcu_read_lock();
  494. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  495. spin_lock_bh(&orig_node->ogm_cnt_lock);
  496. ret = batadv_orig_node_del_if(orig_node, max_if_num,
  497. hard_iface->if_num);
  498. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  499. if (ret == -ENOMEM)
  500. goto err;
  501. }
  502. rcu_read_unlock();
  503. }
  504. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  505. rcu_read_lock();
  506. list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) {
  507. if (hard_iface_tmp->if_status == BATADV_IF_NOT_IN_USE)
  508. continue;
  509. if (hard_iface == hard_iface_tmp)
  510. continue;
  511. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  512. continue;
  513. if (hard_iface_tmp->if_num > hard_iface->if_num)
  514. hard_iface_tmp->if_num--;
  515. }
  516. rcu_read_unlock();
  517. hard_iface->if_num = -1;
  518. return 0;
  519. err:
  520. rcu_read_unlock();
  521. return -ENOMEM;
  522. }