originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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 batadv_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 batadv_orig_node,
  40. hash_entry);
  41. return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
  42. }
  43. int batadv_originator_init(struct batadv_priv *bat_priv)
  44. {
  45. if (bat_priv->orig_hash)
  46. return 0;
  47. bat_priv->orig_hash = batadv_hash_new(1024);
  48. if (!bat_priv->orig_hash)
  49. goto err;
  50. batadv_start_purge_timer(bat_priv);
  51. return 0;
  52. err:
  53. return -ENOMEM;
  54. }
  55. void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node)
  56. {
  57. if (atomic_dec_and_test(&neigh_node->refcount))
  58. kfree_rcu(neigh_node, rcu);
  59. }
  60. /* increases the refcounter of a found router */
  61. struct batadv_neigh_node *
  62. batadv_orig_node_get_router(struct batadv_orig_node *orig_node)
  63. {
  64. struct batadv_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 batadv_neigh_node *
  73. batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
  74. const uint8_t *neigh_addr, uint32_t seqno)
  75. {
  76. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  77. struct batadv_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. batadv_dbg(BATADV_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 batadv_orig_node_free_rcu(struct rcu_head *rcu)
  93. {
  94. struct hlist_node *node, *node_tmp;
  95. struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
  96. struct batadv_orig_node *orig_node;
  97. orig_node = container_of(rcu, struct batadv_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. batadv_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. batadv_neigh_node_free_ref(neigh_node);
  110. }
  111. spin_unlock_bh(&orig_node->neigh_list_lock);
  112. batadv_frag_list_free(&orig_node->frag_list);
  113. batadv_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 batadv_orig_node_free_ref(struct batadv_orig_node *orig_node)
  121. {
  122. if (atomic_dec_and_test(&orig_node->refcount))
  123. call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
  124. }
  125. void batadv_originator_free(struct batadv_priv *bat_priv)
  126. {
  127. struct batadv_hashtable *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 batadv_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. batadv_orig_node_free_ref(orig_node);
  145. }
  146. spin_unlock_bh(list_lock);
  147. }
  148. batadv_hash_destroy(hash);
  149. }
  150. /* this function finds or creates an originator entry for the given
  151. * address if it does not exits
  152. */
  153. struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
  154. const uint8_t *addr)
  155. {
  156. struct batadv_orig_node *orig_node;
  157. int size;
  158. int hash_added;
  159. unsigned long reset_time;
  160. orig_node = batadv_orig_hash_find(bat_priv, addr);
  161. if (orig_node)
  162. return orig_node;
  163. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  164. "Creating new originator: %pM\n", addr);
  165. orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
  166. if (!orig_node)
  167. return NULL;
  168. INIT_HLIST_HEAD(&orig_node->neigh_list);
  169. INIT_LIST_HEAD(&orig_node->bond_list);
  170. spin_lock_init(&orig_node->ogm_cnt_lock);
  171. spin_lock_init(&orig_node->bcast_seqno_lock);
  172. spin_lock_init(&orig_node->neigh_list_lock);
  173. spin_lock_init(&orig_node->tt_buff_lock);
  174. /* extra reference for return */
  175. atomic_set(&orig_node->refcount, 2);
  176. orig_node->tt_initialised = false;
  177. orig_node->tt_poss_change = false;
  178. orig_node->bat_priv = bat_priv;
  179. memcpy(orig_node->orig, addr, ETH_ALEN);
  180. orig_node->router = NULL;
  181. orig_node->tt_crc = 0;
  182. atomic_set(&orig_node->last_ttvn, 0);
  183. orig_node->tt_buff = NULL;
  184. orig_node->tt_buff_len = 0;
  185. atomic_set(&orig_node->tt_size, 0);
  186. reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
  187. orig_node->bcast_seqno_reset = reset_time;
  188. orig_node->batman_seqno_reset = reset_time;
  189. atomic_set(&orig_node->bond_candidates, 0);
  190. size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
  191. orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
  192. if (!orig_node->bcast_own)
  193. goto free_orig_node;
  194. size = bat_priv->num_ifaces * sizeof(uint8_t);
  195. orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
  196. INIT_LIST_HEAD(&orig_node->frag_list);
  197. orig_node->last_frag_packet = 0;
  198. if (!orig_node->bcast_own_sum)
  199. goto free_bcast_own;
  200. hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
  201. batadv_choose_orig, orig_node,
  202. &orig_node->hash_entry);
  203. if (hash_added != 0)
  204. goto free_bcast_own_sum;
  205. return orig_node;
  206. free_bcast_own_sum:
  207. kfree(orig_node->bcast_own_sum);
  208. free_bcast_own:
  209. kfree(orig_node->bcast_own);
  210. free_orig_node:
  211. kfree(orig_node);
  212. return NULL;
  213. }
  214. static bool
  215. batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
  216. struct batadv_orig_node *orig_node,
  217. struct batadv_neigh_node **best_neigh_node)
  218. {
  219. struct hlist_node *node, *node_tmp;
  220. struct batadv_neigh_node *neigh_node;
  221. bool neigh_purged = false;
  222. unsigned long last_seen;
  223. struct batadv_hard_iface *if_incoming;
  224. *best_neigh_node = NULL;
  225. spin_lock_bh(&orig_node->neigh_list_lock);
  226. /* for all neighbors towards this originator ... */
  227. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  228. &orig_node->neigh_list, list) {
  229. last_seen = neigh_node->last_seen;
  230. if_incoming = neigh_node->if_incoming;
  231. if ((batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT)) ||
  232. (if_incoming->if_status == BATADV_IF_INACTIVE) ||
  233. (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
  234. (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)) {
  235. if ((if_incoming->if_status == BATADV_IF_INACTIVE) ||
  236. (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
  237. (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED))
  238. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  239. "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
  240. orig_node->orig, neigh_node->addr,
  241. if_incoming->net_dev->name);
  242. else
  243. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  244. "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
  245. orig_node->orig, neigh_node->addr,
  246. jiffies_to_msecs(last_seen));
  247. neigh_purged = true;
  248. hlist_del_rcu(&neigh_node->list);
  249. batadv_bonding_candidate_del(orig_node, neigh_node);
  250. batadv_neigh_node_free_ref(neigh_node);
  251. } else {
  252. if ((!*best_neigh_node) ||
  253. (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
  254. *best_neigh_node = neigh_node;
  255. }
  256. }
  257. spin_unlock_bh(&orig_node->neigh_list_lock);
  258. return neigh_purged;
  259. }
  260. static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
  261. struct batadv_orig_node *orig_node)
  262. {
  263. struct batadv_neigh_node *best_neigh_node;
  264. if (batadv_has_timed_out(orig_node->last_seen,
  265. 2 * BATADV_PURGE_TIMEOUT)) {
  266. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  267. "Originator timeout: originator %pM, last_seen %u\n",
  268. orig_node->orig,
  269. jiffies_to_msecs(orig_node->last_seen));
  270. return true;
  271. } else {
  272. if (batadv_purge_orig_neighbors(bat_priv, orig_node,
  273. &best_neigh_node))
  274. batadv_update_route(bat_priv, orig_node,
  275. best_neigh_node);
  276. }
  277. return false;
  278. }
  279. static void _batadv_purge_orig(struct batadv_priv *bat_priv)
  280. {
  281. struct batadv_hashtable *hash = bat_priv->orig_hash;
  282. struct hlist_node *node, *node_tmp;
  283. struct hlist_head *head;
  284. spinlock_t *list_lock; /* spinlock to protect write access */
  285. struct batadv_orig_node *orig_node;
  286. uint32_t i;
  287. if (!hash)
  288. return;
  289. /* for all origins... */
  290. for (i = 0; i < hash->size; i++) {
  291. head = &hash->table[i];
  292. list_lock = &hash->list_locks[i];
  293. spin_lock_bh(list_lock);
  294. hlist_for_each_entry_safe(orig_node, node, node_tmp,
  295. head, hash_entry) {
  296. if (batadv_purge_orig_node(bat_priv, orig_node)) {
  297. if (orig_node->gw_flags)
  298. batadv_gw_node_delete(bat_priv,
  299. orig_node);
  300. hlist_del_rcu(node);
  301. batadv_orig_node_free_ref(orig_node);
  302. continue;
  303. }
  304. if (batadv_has_timed_out(orig_node->last_frag_packet,
  305. BATADV_FRAG_TIMEOUT))
  306. batadv_frag_list_free(&orig_node->frag_list);
  307. }
  308. spin_unlock_bh(list_lock);
  309. }
  310. batadv_gw_node_purge(bat_priv);
  311. batadv_gw_election(bat_priv);
  312. }
  313. static void batadv_purge_orig(struct work_struct *work)
  314. {
  315. struct delayed_work *delayed_work;
  316. struct batadv_priv *bat_priv;
  317. delayed_work = container_of(work, struct delayed_work, work);
  318. bat_priv = container_of(delayed_work, struct batadv_priv, orig_work);
  319. _batadv_purge_orig(bat_priv);
  320. batadv_start_purge_timer(bat_priv);
  321. }
  322. void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
  323. {
  324. _batadv_purge_orig(bat_priv);
  325. }
  326. int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
  327. {
  328. struct net_device *net_dev = (struct net_device *)seq->private;
  329. struct batadv_priv *bat_priv = netdev_priv(net_dev);
  330. struct batadv_hashtable *hash = bat_priv->orig_hash;
  331. struct hlist_node *node, *node_tmp;
  332. struct hlist_head *head;
  333. struct batadv_hard_iface *primary_if;
  334. struct batadv_orig_node *orig_node;
  335. struct batadv_neigh_node *neigh_node, *neigh_node_tmp;
  336. int batman_count = 0;
  337. int last_seen_secs;
  338. int last_seen_msecs;
  339. unsigned long last_seen_jiffies;
  340. uint32_t i;
  341. int ret = 0;
  342. primary_if = batadv_primary_if_get_selected(bat_priv);
  343. if (!primary_if) {
  344. ret = seq_printf(seq,
  345. "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
  346. net_dev->name);
  347. goto out;
  348. }
  349. if (primary_if->if_status != BATADV_IF_ACTIVE) {
  350. ret = seq_printf(seq,
  351. "BATMAN mesh %s disabled - primary interface not active\n",
  352. net_dev->name);
  353. goto out;
  354. }
  355. seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  356. BATADV_SOURCE_VERSION, primary_if->net_dev->name,
  357. primary_if->net_dev->dev_addr, net_dev->name);
  358. seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
  359. "Originator", "last-seen", "#", BATADV_TQ_MAX_VALUE,
  360. "Nexthop", "outgoingIF", "Potential nexthops");
  361. for (i = 0; i < hash->size; i++) {
  362. head = &hash->table[i];
  363. rcu_read_lock();
  364. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  365. neigh_node = batadv_orig_node_get_router(orig_node);
  366. if (!neigh_node)
  367. continue;
  368. if (neigh_node->tq_avg == 0)
  369. goto next;
  370. last_seen_jiffies = jiffies - orig_node->last_seen;
  371. last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
  372. last_seen_secs = last_seen_msecs / 1000;
  373. last_seen_msecs = last_seen_msecs % 1000;
  374. seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
  375. orig_node->orig, last_seen_secs,
  376. last_seen_msecs, neigh_node->tq_avg,
  377. neigh_node->addr,
  378. neigh_node->if_incoming->net_dev->name);
  379. hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp,
  380. &orig_node->neigh_list, list) {
  381. seq_printf(seq, " %pM (%3i)",
  382. neigh_node_tmp->addr,
  383. neigh_node_tmp->tq_avg);
  384. }
  385. seq_printf(seq, "\n");
  386. batman_count++;
  387. next:
  388. batadv_neigh_node_free_ref(neigh_node);
  389. }
  390. rcu_read_unlock();
  391. }
  392. if (batman_count == 0)
  393. seq_printf(seq, "No batman nodes in range ...\n");
  394. out:
  395. if (primary_if)
  396. batadv_hardif_free_ref(primary_if);
  397. return ret;
  398. }
  399. static int batadv_orig_node_add_if(struct batadv_orig_node *orig_node,
  400. int max_if_num)
  401. {
  402. void *data_ptr;
  403. size_t data_size, old_size;
  404. data_size = max_if_num * sizeof(unsigned long) * BATADV_NUM_WORDS;
  405. old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS;
  406. data_ptr = kmalloc(data_size, GFP_ATOMIC);
  407. if (!data_ptr)
  408. return -ENOMEM;
  409. memcpy(data_ptr, orig_node->bcast_own, old_size);
  410. kfree(orig_node->bcast_own);
  411. orig_node->bcast_own = data_ptr;
  412. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  413. if (!data_ptr)
  414. return -ENOMEM;
  415. memcpy(data_ptr, orig_node->bcast_own_sum,
  416. (max_if_num - 1) * sizeof(uint8_t));
  417. kfree(orig_node->bcast_own_sum);
  418. orig_node->bcast_own_sum = data_ptr;
  419. return 0;
  420. }
  421. int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
  422. int max_if_num)
  423. {
  424. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  425. struct batadv_hashtable *hash = bat_priv->orig_hash;
  426. struct hlist_node *node;
  427. struct hlist_head *head;
  428. struct batadv_orig_node *orig_node;
  429. uint32_t i;
  430. int ret;
  431. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  432. * if_num
  433. */
  434. for (i = 0; i < hash->size; i++) {
  435. head = &hash->table[i];
  436. rcu_read_lock();
  437. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  438. spin_lock_bh(&orig_node->ogm_cnt_lock);
  439. ret = batadv_orig_node_add_if(orig_node, max_if_num);
  440. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  441. if (ret == -ENOMEM)
  442. goto err;
  443. }
  444. rcu_read_unlock();
  445. }
  446. return 0;
  447. err:
  448. rcu_read_unlock();
  449. return -ENOMEM;
  450. }
  451. static int batadv_orig_node_del_if(struct batadv_orig_node *orig_node,
  452. int max_if_num, int del_if_num)
  453. {
  454. void *data_ptr = NULL;
  455. int chunk_size;
  456. /* last interface was removed */
  457. if (max_if_num == 0)
  458. goto free_bcast_own;
  459. chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS;
  460. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  461. if (!data_ptr)
  462. return -ENOMEM;
  463. /* copy first part */
  464. memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
  465. /* copy second part */
  466. memcpy((char *)data_ptr + del_if_num * chunk_size,
  467. orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
  468. (max_if_num - del_if_num) * chunk_size);
  469. free_bcast_own:
  470. kfree(orig_node->bcast_own);
  471. orig_node->bcast_own = data_ptr;
  472. if (max_if_num == 0)
  473. goto free_own_sum;
  474. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  475. if (!data_ptr)
  476. return -ENOMEM;
  477. memcpy(data_ptr, orig_node->bcast_own_sum,
  478. del_if_num * sizeof(uint8_t));
  479. memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
  480. orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
  481. (max_if_num - del_if_num) * sizeof(uint8_t));
  482. free_own_sum:
  483. kfree(orig_node->bcast_own_sum);
  484. orig_node->bcast_own_sum = data_ptr;
  485. return 0;
  486. }
  487. int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
  488. int max_if_num)
  489. {
  490. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  491. struct batadv_hashtable *hash = bat_priv->orig_hash;
  492. struct hlist_node *node;
  493. struct hlist_head *head;
  494. struct batadv_hard_iface *hard_iface_tmp;
  495. struct batadv_orig_node *orig_node;
  496. uint32_t i;
  497. int ret;
  498. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  499. * if_num
  500. */
  501. for (i = 0; i < hash->size; i++) {
  502. head = &hash->table[i];
  503. rcu_read_lock();
  504. hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
  505. spin_lock_bh(&orig_node->ogm_cnt_lock);
  506. ret = batadv_orig_node_del_if(orig_node, max_if_num,
  507. hard_iface->if_num);
  508. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  509. if (ret == -ENOMEM)
  510. goto err;
  511. }
  512. rcu_read_unlock();
  513. }
  514. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  515. rcu_read_lock();
  516. list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) {
  517. if (hard_iface_tmp->if_status == BATADV_IF_NOT_IN_USE)
  518. continue;
  519. if (hard_iface == hard_iface_tmp)
  520. continue;
  521. if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
  522. continue;
  523. if (hard_iface_tmp->if_num > hard_iface->if_num)
  524. hard_iface_tmp->if_num--;
  525. }
  526. rcu_read_unlock();
  527. hard_iface->if_num = -1;
  528. return 0;
  529. err:
  530. rcu_read_unlock();
  531. return -ENOMEM;
  532. }