originator.c 17 KB

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