originator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (C) 2009-2011 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. /* increase the reference counter for this originator */
  22. #include "main.h"
  23. #include "originator.h"
  24. #include "hash.h"
  25. #include "translation-table.h"
  26. #include "routing.h"
  27. #include "gateway_client.h"
  28. #include "hard-interface.h"
  29. #include "unicast.h"
  30. #include "soft-interface.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, &bat_priv->orig_work, 1 * HZ);
  36. }
  37. int originator_init(struct bat_priv *bat_priv)
  38. {
  39. if (bat_priv->orig_hash)
  40. return 1;
  41. spin_lock_bh(&bat_priv->orig_hash_lock);
  42. bat_priv->orig_hash = hash_new(1024);
  43. if (!bat_priv->orig_hash)
  44. goto err;
  45. spin_unlock_bh(&bat_priv->orig_hash_lock);
  46. start_purge_timer(bat_priv);
  47. return 1;
  48. err:
  49. spin_unlock_bh(&bat_priv->orig_hash_lock);
  50. return 0;
  51. }
  52. void neigh_node_free_ref(struct kref *refcount)
  53. {
  54. struct neigh_node *neigh_node;
  55. neigh_node = container_of(refcount, struct neigh_node, refcount);
  56. kfree(neigh_node);
  57. }
  58. static void neigh_node_free_rcu(struct rcu_head *rcu)
  59. {
  60. struct neigh_node *neigh_node;
  61. neigh_node = container_of(rcu, struct neigh_node, rcu);
  62. kref_put(&neigh_node->refcount, neigh_node_free_ref);
  63. }
  64. struct neigh_node *create_neighbor(struct orig_node *orig_node,
  65. struct orig_node *orig_neigh_node,
  66. uint8_t *neigh,
  67. struct batman_if *if_incoming)
  68. {
  69. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  70. struct neigh_node *neigh_node;
  71. bat_dbg(DBG_BATMAN, bat_priv,
  72. "Creating new last-hop neighbor of originator\n");
  73. neigh_node = kzalloc(sizeof(struct neigh_node), GFP_ATOMIC);
  74. if (!neigh_node)
  75. return NULL;
  76. INIT_HLIST_NODE(&neigh_node->list);
  77. memcpy(neigh_node->addr, neigh, ETH_ALEN);
  78. neigh_node->orig_node = orig_neigh_node;
  79. neigh_node->if_incoming = if_incoming;
  80. kref_init(&neigh_node->refcount);
  81. spin_lock_bh(&orig_node->neigh_list_lock);
  82. hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
  83. spin_unlock_bh(&orig_node->neigh_list_lock);
  84. return neigh_node;
  85. }
  86. void orig_node_free_ref(struct kref *refcount)
  87. {
  88. struct hlist_node *node, *node_tmp;
  89. struct neigh_node *neigh_node;
  90. struct orig_node *orig_node;
  91. orig_node = container_of(refcount, struct orig_node, refcount);
  92. spin_lock_bh(&orig_node->neigh_list_lock);
  93. /* for all neighbors towards this originator ... */
  94. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  95. &orig_node->neigh_list, list) {
  96. hlist_del_rcu(&neigh_node->list);
  97. call_rcu(&neigh_node->rcu, neigh_node_free_rcu);
  98. }
  99. spin_unlock_bh(&orig_node->neigh_list_lock);
  100. frag_list_free(&orig_node->frag_list);
  101. hna_global_del_orig(orig_node->bat_priv, orig_node,
  102. "originator timed out");
  103. kfree(orig_node->bcast_own);
  104. kfree(orig_node->bcast_own_sum);
  105. kfree(orig_node);
  106. }
  107. void originator_free(struct bat_priv *bat_priv)
  108. {
  109. struct hashtable_t *hash = bat_priv->orig_hash;
  110. struct hlist_node *walk, *safe;
  111. struct hlist_head *head;
  112. struct element_t *bucket;
  113. spinlock_t *list_lock; /* spinlock to protect write access */
  114. struct orig_node *orig_node;
  115. int i;
  116. if (!hash)
  117. return;
  118. cancel_delayed_work_sync(&bat_priv->orig_work);
  119. spin_lock_bh(&bat_priv->orig_hash_lock);
  120. bat_priv->orig_hash = NULL;
  121. for (i = 0; i < hash->size; i++) {
  122. head = &hash->table[i];
  123. list_lock = &hash->list_locks[i];
  124. spin_lock_bh(list_lock);
  125. hlist_for_each_entry_safe(bucket, walk, safe, head, hlist) {
  126. orig_node = bucket->data;
  127. hlist_del_rcu(walk);
  128. call_rcu(&bucket->rcu, bucket_free_rcu);
  129. kref_put(&orig_node->refcount, orig_node_free_ref);
  130. }
  131. spin_unlock_bh(list_lock);
  132. }
  133. hash_destroy(hash);
  134. spin_unlock_bh(&bat_priv->orig_hash_lock);
  135. }
  136. static void bucket_free_orig_rcu(struct rcu_head *rcu)
  137. {
  138. struct element_t *bucket;
  139. struct orig_node *orig_node;
  140. bucket = container_of(rcu, struct element_t, rcu);
  141. orig_node = bucket->data;
  142. kref_put(&orig_node->refcount, orig_node_free_ref);
  143. kfree(bucket);
  144. }
  145. /* this function finds or creates an originator entry for the given
  146. * address if it does not exits */
  147. struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
  148. {
  149. struct orig_node *orig_node;
  150. int size;
  151. int hash_added;
  152. rcu_read_lock();
  153. orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
  154. compare_orig, choose_orig,
  155. addr));
  156. rcu_read_unlock();
  157. if (orig_node) {
  158. kref_get(&orig_node->refcount);
  159. return orig_node;
  160. }
  161. bat_dbg(DBG_BATMAN, bat_priv,
  162. "Creating new originator: %pM\n", addr);
  163. orig_node = kzalloc(sizeof(struct orig_node), GFP_ATOMIC);
  164. if (!orig_node)
  165. return NULL;
  166. INIT_HLIST_HEAD(&orig_node->neigh_list);
  167. spin_lock_init(&orig_node->ogm_cnt_lock);
  168. spin_lock_init(&orig_node->neigh_list_lock);
  169. kref_init(&orig_node->refcount);
  170. orig_node->bat_priv = bat_priv;
  171. memcpy(orig_node->orig, addr, ETH_ALEN);
  172. orig_node->router = NULL;
  173. orig_node->hna_buff = NULL;
  174. orig_node->bcast_seqno_reset = jiffies - 1
  175. - msecs_to_jiffies(RESET_PROTECTION_MS);
  176. orig_node->batman_seqno_reset = jiffies - 1
  177. - msecs_to_jiffies(RESET_PROTECTION_MS);
  178. size = bat_priv->num_ifaces * sizeof(unsigned long) * NUM_WORDS;
  179. orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
  180. if (!orig_node->bcast_own)
  181. goto free_orig_node;
  182. size = bat_priv->num_ifaces * sizeof(uint8_t);
  183. orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
  184. INIT_LIST_HEAD(&orig_node->frag_list);
  185. orig_node->last_frag_packet = 0;
  186. if (!orig_node->bcast_own_sum)
  187. goto free_bcast_own;
  188. hash_added = hash_add(bat_priv->orig_hash, compare_orig, choose_orig,
  189. orig_node);
  190. if (hash_added < 0)
  191. goto free_bcast_own_sum;
  192. /* extra reference for return */
  193. kref_get(&orig_node->refcount);
  194. return orig_node;
  195. free_bcast_own_sum:
  196. kfree(orig_node->bcast_own_sum);
  197. free_bcast_own:
  198. kfree(orig_node->bcast_own);
  199. free_orig_node:
  200. kfree(orig_node);
  201. return NULL;
  202. }
  203. static bool purge_orig_neighbors(struct bat_priv *bat_priv,
  204. struct orig_node *orig_node,
  205. struct neigh_node **best_neigh_node)
  206. {
  207. struct hlist_node *node, *node_tmp;
  208. struct neigh_node *neigh_node;
  209. bool neigh_purged = false;
  210. *best_neigh_node = NULL;
  211. spin_lock_bh(&orig_node->neigh_list_lock);
  212. /* for all neighbors towards this originator ... */
  213. hlist_for_each_entry_safe(neigh_node, node, node_tmp,
  214. &orig_node->neigh_list, list) {
  215. if ((time_after(jiffies,
  216. neigh_node->last_valid + PURGE_TIMEOUT * HZ)) ||
  217. (neigh_node->if_incoming->if_status == IF_INACTIVE) ||
  218. (neigh_node->if_incoming->if_status == IF_NOT_IN_USE) ||
  219. (neigh_node->if_incoming->if_status == IF_TO_BE_REMOVED)) {
  220. if ((neigh_node->if_incoming->if_status ==
  221. IF_INACTIVE) ||
  222. (neigh_node->if_incoming->if_status ==
  223. IF_NOT_IN_USE) ||
  224. (neigh_node->if_incoming->if_status ==
  225. IF_TO_BE_REMOVED))
  226. bat_dbg(DBG_BATMAN, bat_priv,
  227. "neighbor purge: originator %pM, "
  228. "neighbor: %pM, iface: %s\n",
  229. orig_node->orig, neigh_node->addr,
  230. neigh_node->if_incoming->net_dev->name);
  231. else
  232. bat_dbg(DBG_BATMAN, bat_priv,
  233. "neighbor timeout: originator %pM, "
  234. "neighbor: %pM, last_valid: %lu\n",
  235. orig_node->orig, neigh_node->addr,
  236. (neigh_node->last_valid / HZ));
  237. neigh_purged = true;
  238. hlist_del_rcu(&neigh_node->list);
  239. call_rcu(&neigh_node->rcu, neigh_node_free_rcu);
  240. } else {
  241. if ((!*best_neigh_node) ||
  242. (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
  243. *best_neigh_node = neigh_node;
  244. }
  245. }
  246. spin_unlock_bh(&orig_node->neigh_list_lock);
  247. return neigh_purged;
  248. }
  249. static bool purge_orig_node(struct bat_priv *bat_priv,
  250. struct orig_node *orig_node)
  251. {
  252. struct neigh_node *best_neigh_node;
  253. if (time_after(jiffies,
  254. orig_node->last_valid + 2 * PURGE_TIMEOUT * HZ)) {
  255. bat_dbg(DBG_BATMAN, bat_priv,
  256. "Originator timeout: originator %pM, last_valid %lu\n",
  257. orig_node->orig, (orig_node->last_valid / HZ));
  258. return true;
  259. } else {
  260. if (purge_orig_neighbors(bat_priv, orig_node,
  261. &best_neigh_node)) {
  262. update_routes(bat_priv, orig_node,
  263. best_neigh_node,
  264. orig_node->hna_buff,
  265. orig_node->hna_buff_len);
  266. /* update bonding candidates, we could have lost
  267. * some candidates. */
  268. update_bonding_candidates(orig_node);
  269. }
  270. }
  271. return false;
  272. }
  273. static void _purge_orig(struct bat_priv *bat_priv)
  274. {
  275. struct hashtable_t *hash = bat_priv->orig_hash;
  276. struct hlist_node *walk, *safe;
  277. struct hlist_head *head;
  278. struct element_t *bucket;
  279. spinlock_t *list_lock; /* spinlock to protect write access */
  280. struct orig_node *orig_node;
  281. int i;
  282. if (!hash)
  283. return;
  284. spin_lock_bh(&bat_priv->orig_hash_lock);
  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(bucket, walk, safe, head, hlist) {
  291. orig_node = bucket->data;
  292. if (purge_orig_node(bat_priv, orig_node)) {
  293. if (orig_node->gw_flags)
  294. gw_node_delete(bat_priv, orig_node);
  295. hlist_del_rcu(walk);
  296. call_rcu(&bucket->rcu, bucket_free_orig_rcu);
  297. continue;
  298. }
  299. if (time_after(jiffies, orig_node->last_frag_packet +
  300. msecs_to_jiffies(FRAG_TIMEOUT)))
  301. frag_list_free(&orig_node->frag_list);
  302. }
  303. spin_unlock_bh(list_lock);
  304. }
  305. spin_unlock_bh(&bat_priv->orig_hash_lock);
  306. gw_node_purge(bat_priv);
  307. gw_election(bat_priv);
  308. softif_neigh_purge(bat_priv);
  309. }
  310. static void purge_orig(struct work_struct *work)
  311. {
  312. struct delayed_work *delayed_work =
  313. container_of(work, struct delayed_work, work);
  314. struct bat_priv *bat_priv =
  315. container_of(delayed_work, struct bat_priv, orig_work);
  316. _purge_orig(bat_priv);
  317. start_purge_timer(bat_priv);
  318. }
  319. void purge_orig_ref(struct bat_priv *bat_priv)
  320. {
  321. _purge_orig(bat_priv);
  322. }
  323. int orig_seq_print_text(struct seq_file *seq, void *offset)
  324. {
  325. struct net_device *net_dev = (struct net_device *)seq->private;
  326. struct bat_priv *bat_priv = netdev_priv(net_dev);
  327. struct hashtable_t *hash = bat_priv->orig_hash;
  328. struct hlist_node *walk, *node;
  329. struct hlist_head *head;
  330. struct element_t *bucket;
  331. struct orig_node *orig_node;
  332. struct neigh_node *neigh_node;
  333. int batman_count = 0;
  334. int last_seen_secs;
  335. int last_seen_msecs;
  336. int i;
  337. if ((!bat_priv->primary_if) ||
  338. (bat_priv->primary_if->if_status != IF_ACTIVE)) {
  339. if (!bat_priv->primary_if)
  340. return seq_printf(seq, "BATMAN mesh %s disabled - "
  341. "please specify interfaces to enable it\n",
  342. net_dev->name);
  343. return seq_printf(seq, "BATMAN mesh %s "
  344. "disabled - primary interface not active\n",
  345. net_dev->name);
  346. }
  347. seq_printf(seq, "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%pM (%s)]\n",
  348. SOURCE_VERSION, REVISION_VERSION_STR,
  349. bat_priv->primary_if->net_dev->name,
  350. bat_priv->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. spin_lock_bh(&bat_priv->orig_hash_lock);
  355. for (i = 0; i < hash->size; i++) {
  356. head = &hash->table[i];
  357. rcu_read_lock();
  358. hlist_for_each_entry_rcu(bucket, walk, head, hlist) {
  359. orig_node = bucket->data;
  360. if (!orig_node->router)
  361. continue;
  362. if (orig_node->router->tq_avg == 0)
  363. continue;
  364. last_seen_secs = jiffies_to_msecs(jiffies -
  365. orig_node->last_valid) / 1000;
  366. last_seen_msecs = jiffies_to_msecs(jiffies -
  367. orig_node->last_valid) % 1000;
  368. neigh_node = orig_node->router;
  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, node,
  375. &orig_node->neigh_list, list) {
  376. seq_printf(seq, " %pM (%3i)", neigh_node->addr,
  377. neigh_node->tq_avg);
  378. }
  379. seq_printf(seq, "\n");
  380. batman_count++;
  381. }
  382. rcu_read_unlock();
  383. }
  384. spin_unlock_bh(&bat_priv->orig_hash_lock);
  385. if ((batman_count == 0))
  386. seq_printf(seq, "No batman nodes in range ...\n");
  387. return 0;
  388. }
  389. static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
  390. {
  391. void *data_ptr;
  392. data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
  393. GFP_ATOMIC);
  394. if (!data_ptr) {
  395. pr_err("Can't resize orig: out of memory\n");
  396. return -1;
  397. }
  398. memcpy(data_ptr, orig_node->bcast_own,
  399. (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
  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. pr_err("Can't resize orig: out of memory\n");
  405. return -1;
  406. }
  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 orig_hash_add_if(struct batman_if *batman_if, int max_if_num)
  414. {
  415. struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
  416. struct hashtable_t *hash = bat_priv->orig_hash;
  417. struct hlist_node *walk;
  418. struct hlist_head *head;
  419. struct element_t *bucket;
  420. struct orig_node *orig_node;
  421. int i, ret;
  422. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  423. * if_num */
  424. spin_lock_bh(&bat_priv->orig_hash_lock);
  425. for (i = 0; i < hash->size; i++) {
  426. head = &hash->table[i];
  427. rcu_read_lock();
  428. hlist_for_each_entry_rcu(bucket, walk, head, hlist) {
  429. orig_node = bucket->data;
  430. spin_lock_bh(&orig_node->ogm_cnt_lock);
  431. ret = orig_node_add_if(orig_node, max_if_num);
  432. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  433. if (ret == -1)
  434. goto err;
  435. }
  436. rcu_read_unlock();
  437. }
  438. spin_unlock_bh(&bat_priv->orig_hash_lock);
  439. return 0;
  440. err:
  441. rcu_read_unlock();
  442. spin_unlock_bh(&bat_priv->orig_hash_lock);
  443. return -ENOMEM;
  444. }
  445. static int orig_node_del_if(struct orig_node *orig_node,
  446. int max_if_num, int del_if_num)
  447. {
  448. void *data_ptr = NULL;
  449. int chunk_size;
  450. /* last interface was removed */
  451. if (max_if_num == 0)
  452. goto free_bcast_own;
  453. chunk_size = sizeof(unsigned long) * NUM_WORDS;
  454. data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
  455. if (!data_ptr) {
  456. pr_err("Can't resize orig: out of memory\n");
  457. return -1;
  458. }
  459. /* copy first part */
  460. memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
  461. /* copy second part */
  462. memcpy(data_ptr + del_if_num * chunk_size,
  463. orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
  464. (max_if_num - del_if_num) * chunk_size);
  465. free_bcast_own:
  466. kfree(orig_node->bcast_own);
  467. orig_node->bcast_own = data_ptr;
  468. if (max_if_num == 0)
  469. goto free_own_sum;
  470. data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
  471. if (!data_ptr) {
  472. pr_err("Can't resize orig: out of memory\n");
  473. return -1;
  474. }
  475. memcpy(data_ptr, orig_node->bcast_own_sum,
  476. del_if_num * sizeof(uint8_t));
  477. memcpy(data_ptr + del_if_num * sizeof(uint8_t),
  478. orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
  479. (max_if_num - del_if_num) * sizeof(uint8_t));
  480. free_own_sum:
  481. kfree(orig_node->bcast_own_sum);
  482. orig_node->bcast_own_sum = data_ptr;
  483. return 0;
  484. }
  485. int orig_hash_del_if(struct batman_if *batman_if, int max_if_num)
  486. {
  487. struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
  488. struct hashtable_t *hash = bat_priv->orig_hash;
  489. struct hlist_node *walk;
  490. struct hlist_head *head;
  491. struct element_t *bucket;
  492. struct batman_if *batman_if_tmp;
  493. struct orig_node *orig_node;
  494. int i, ret;
  495. /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
  496. * if_num */
  497. spin_lock_bh(&bat_priv->orig_hash_lock);
  498. for (i = 0; i < hash->size; i++) {
  499. head = &hash->table[i];
  500. rcu_read_lock();
  501. hlist_for_each_entry_rcu(bucket, walk, head, hlist) {
  502. orig_node = bucket->data;
  503. spin_lock_bh(&orig_node->ogm_cnt_lock);
  504. ret = orig_node_del_if(orig_node, max_if_num,
  505. batman_if->if_num);
  506. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  507. if (ret == -1)
  508. goto err;
  509. }
  510. rcu_read_unlock();
  511. }
  512. /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
  513. rcu_read_lock();
  514. list_for_each_entry_rcu(batman_if_tmp, &if_list, list) {
  515. if (batman_if_tmp->if_status == IF_NOT_IN_USE)
  516. continue;
  517. if (batman_if == batman_if_tmp)
  518. continue;
  519. if (batman_if->soft_iface != batman_if_tmp->soft_iface)
  520. continue;
  521. if (batman_if_tmp->if_num > batman_if->if_num)
  522. batman_if_tmp->if_num--;
  523. }
  524. rcu_read_unlock();
  525. batman_if->if_num = -1;
  526. spin_unlock_bh(&bat_priv->orig_hash_lock);
  527. return 0;
  528. err:
  529. rcu_read_unlock();
  530. spin_unlock_bh(&bat_priv->orig_hash_lock);
  531. return -ENOMEM;
  532. }