]> git.karo-electronics.de Git - karo-tx-linux.git/blob - net/batman-adv/originator.c
867778e8184d20ce6eaa19fb941279489f4980d9
[karo-tx-linux.git] / net / batman-adv / originator.c
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
20 #include "main.h"
21 #include "distributed-arp-table.h"
22 #include "originator.h"
23 #include "hash.h"
24 #include "translation-table.h"
25 #include "routing.h"
26 #include "gateway_client.h"
27 #include "hard-interface.h"
28 #include "soft-interface.h"
29 #include "bridge_loop_avoidance.h"
30 #include "network-coding.h"
31 #include "fragmentation.h"
32
33 /* hash class keys */
34 static struct lock_class_key batadv_orig_hash_lock_class_key;
35
36 static void batadv_purge_orig(struct work_struct *work);
37
38 /* returns 1 if they are the same originator */
39 static int batadv_compare_orig(const struct hlist_node *node, const void *data2)
40 {
41         const void *data1 = container_of(node, struct batadv_orig_node,
42                                          hash_entry);
43
44         return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
45 }
46
47 int batadv_originator_init(struct batadv_priv *bat_priv)
48 {
49         if (bat_priv->orig_hash)
50                 return 0;
51
52         bat_priv->orig_hash = batadv_hash_new(1024);
53
54         if (!bat_priv->orig_hash)
55                 goto err;
56
57         batadv_hash_set_lock_class(bat_priv->orig_hash,
58                                    &batadv_orig_hash_lock_class_key);
59
60         INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig);
61         queue_delayed_work(batadv_event_workqueue,
62                            &bat_priv->orig_work,
63                            msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD));
64
65         return 0;
66
67 err:
68         return -ENOMEM;
69 }
70
71 void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node)
72 {
73         if (atomic_dec_and_test(&neigh_node->refcount))
74                 kfree_rcu(neigh_node, rcu);
75 }
76
77 /* increases the refcounter of a found router */
78 struct batadv_neigh_node *
79 batadv_orig_node_get_router(struct batadv_orig_node *orig_node)
80 {
81         struct batadv_neigh_node *router;
82
83         rcu_read_lock();
84         router = rcu_dereference(orig_node->router);
85
86         if (router && !atomic_inc_not_zero(&router->refcount))
87                 router = NULL;
88
89         rcu_read_unlock();
90         return router;
91 }
92
93 struct batadv_neigh_node *
94 batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
95                       const uint8_t *neigh_addr)
96 {
97         struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
98         struct batadv_neigh_node *neigh_node;
99
100         neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
101         if (!neigh_node)
102                 goto out;
103
104         INIT_HLIST_NODE(&neigh_node->list);
105
106         memcpy(neigh_node->addr, neigh_addr, ETH_ALEN);
107         spin_lock_init(&neigh_node->lq_update_lock);
108
109         /* extra reference for return */
110         atomic_set(&neigh_node->refcount, 2);
111
112         batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
113                    "Creating new neighbor %pM on interface %s\n", neigh_addr,
114                    hard_iface->net_dev->name);
115
116 out:
117         return neigh_node;
118 }
119
120 static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
121 {
122         struct hlist_node *node_tmp;
123         struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
124         struct batadv_orig_node *orig_node;
125
126         orig_node = container_of(rcu, struct batadv_orig_node, rcu);
127
128         spin_lock_bh(&orig_node->neigh_list_lock);
129
130         /* for all bonding members ... */
131         list_for_each_entry_safe(neigh_node, tmp_neigh_node,
132                                  &orig_node->bond_list, bonding_list) {
133                 list_del_rcu(&neigh_node->bonding_list);
134                 batadv_neigh_node_free_ref(neigh_node);
135         }
136
137         /* for all neighbors towards this originator ... */
138         hlist_for_each_entry_safe(neigh_node, node_tmp,
139                                   &orig_node->neigh_list, list) {
140                 hlist_del_rcu(&neigh_node->list);
141                 batadv_neigh_node_free_ref(neigh_node);
142         }
143
144         spin_unlock_bh(&orig_node->neigh_list_lock);
145
146         /* Free nc_nodes */
147         batadv_nc_purge_orig(orig_node->bat_priv, orig_node, NULL);
148
149         batadv_frag_purge_orig(orig_node, NULL);
150
151         batadv_tt_global_del_orig(orig_node->bat_priv, orig_node,
152                                   "originator timed out");
153
154         kfree(orig_node->tt_buff);
155         kfree(orig_node->bcast_own);
156         kfree(orig_node->bcast_own_sum);
157         kfree(orig_node);
158 }
159
160 /**
161  * batadv_orig_node_free_ref - decrement the orig node refcounter and possibly
162  * schedule an rcu callback for freeing it
163  * @orig_node: the orig node to free
164  */
165 void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node)
166 {
167         if (atomic_dec_and_test(&orig_node->refcount))
168                 call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
169 }
170
171 /**
172  * batadv_orig_node_free_ref_now - decrement the orig node refcounter and
173  * possibly free it (without rcu callback)
174  * @orig_node: the orig node to free
175  */
176 void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node)
177 {
178         if (atomic_dec_and_test(&orig_node->refcount))
179                 batadv_orig_node_free_rcu(&orig_node->rcu);
180 }
181
182 void batadv_originator_free(struct batadv_priv *bat_priv)
183 {
184         struct batadv_hashtable *hash = bat_priv->orig_hash;
185         struct hlist_node *node_tmp;
186         struct hlist_head *head;
187         spinlock_t *list_lock; /* spinlock to protect write access */
188         struct batadv_orig_node *orig_node;
189         uint32_t i;
190
191         if (!hash)
192                 return;
193
194         cancel_delayed_work_sync(&bat_priv->orig_work);
195
196         bat_priv->orig_hash = NULL;
197
198         for (i = 0; i < hash->size; i++) {
199                 head = &hash->table[i];
200                 list_lock = &hash->list_locks[i];
201
202                 spin_lock_bh(list_lock);
203                 hlist_for_each_entry_safe(orig_node, node_tmp,
204                                           head, hash_entry) {
205                         hlist_del_rcu(&orig_node->hash_entry);
206                         batadv_orig_node_free_ref(orig_node);
207                 }
208                 spin_unlock_bh(list_lock);
209         }
210
211         batadv_hash_destroy(hash);
212 }
213
214 /* this function finds or creates an originator entry for the given
215  * address if it does not exits
216  */
217 struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
218                                               const uint8_t *addr)
219 {
220         struct batadv_orig_node *orig_node;
221         int size, i;
222         int hash_added;
223         unsigned long reset_time;
224
225         orig_node = batadv_orig_hash_find(bat_priv, addr);
226         if (orig_node)
227                 return orig_node;
228
229         batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
230                    "Creating new originator: %pM\n", addr);
231
232         orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
233         if (!orig_node)
234                 return NULL;
235
236         INIT_HLIST_HEAD(&orig_node->neigh_list);
237         INIT_LIST_HEAD(&orig_node->bond_list);
238         spin_lock_init(&orig_node->ogm_cnt_lock);
239         spin_lock_init(&orig_node->bcast_seqno_lock);
240         spin_lock_init(&orig_node->neigh_list_lock);
241         spin_lock_init(&orig_node->tt_buff_lock);
242         spin_lock_init(&orig_node->tt_lock);
243
244         batadv_nc_init_orig(orig_node);
245
246         /* extra reference for return */
247         atomic_set(&orig_node->refcount, 2);
248
249         orig_node->tt_initialised = false;
250         orig_node->bat_priv = bat_priv;
251         memcpy(orig_node->orig, addr, ETH_ALEN);
252         batadv_dat_init_orig_node_addr(orig_node);
253         orig_node->router = NULL;
254         orig_node->tt_crc = 0;
255         atomic_set(&orig_node->last_ttvn, 0);
256         orig_node->tt_buff = NULL;
257         orig_node->tt_buff_len = 0;
258         atomic_set(&orig_node->tt_size, 0);
259         reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
260         orig_node->bcast_seqno_reset = reset_time;
261         orig_node->batman_seqno_reset = reset_time;
262
263         atomic_set(&orig_node->bond_candidates, 0);
264
265         size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
266
267         orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
268         if (!orig_node->bcast_own)
269                 goto free_orig_node;
270
271         size = bat_priv->num_ifaces * sizeof(uint8_t);
272         orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
273
274         for (i = 0; i < BATADV_FRAG_BUFFER_COUNT; i++) {
275                 INIT_HLIST_HEAD(&orig_node->fragments[i].head);
276                 spin_lock_init(&orig_node->fragments[i].lock);
277                 orig_node->fragments[i].size = 0;
278         }
279
280         if (!orig_node->bcast_own_sum)
281                 goto free_bcast_own;
282
283         hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
284                                      batadv_choose_orig, orig_node,
285                                      &orig_node->hash_entry);
286         if (hash_added != 0)
287                 goto free_bcast_own_sum;
288
289         return orig_node;
290 free_bcast_own_sum:
291         kfree(orig_node->bcast_own_sum);
292 free_bcast_own:
293         kfree(orig_node->bcast_own);
294 free_orig_node:
295         kfree(orig_node);
296         return NULL;
297 }
298
299 static bool
300 batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
301                             struct batadv_orig_node *orig_node,
302                             struct batadv_neigh_node **best_neigh_node)
303 {
304         struct hlist_node *node_tmp;
305         struct batadv_neigh_node *neigh_node;
306         bool neigh_purged = false;
307         unsigned long last_seen;
308         struct batadv_hard_iface *if_incoming;
309
310         *best_neigh_node = NULL;
311
312         spin_lock_bh(&orig_node->neigh_list_lock);
313
314         /* for all neighbors towards this originator ... */
315         hlist_for_each_entry_safe(neigh_node, node_tmp,
316                                   &orig_node->neigh_list, list) {
317                 last_seen = neigh_node->last_seen;
318                 if_incoming = neigh_node->if_incoming;
319
320                 if ((batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT)) ||
321                     (if_incoming->if_status == BATADV_IF_INACTIVE) ||
322                     (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
323                     (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)) {
324                         if ((if_incoming->if_status == BATADV_IF_INACTIVE) ||
325                             (if_incoming->if_status == BATADV_IF_NOT_IN_USE) ||
326                             (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED))
327                                 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
328                                            "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
329                                            orig_node->orig, neigh_node->addr,
330                                            if_incoming->net_dev->name);
331                         else
332                                 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
333                                            "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
334                                            orig_node->orig, neigh_node->addr,
335                                            jiffies_to_msecs(last_seen));
336
337                         neigh_purged = true;
338
339                         hlist_del_rcu(&neigh_node->list);
340                         batadv_bonding_candidate_del(orig_node, neigh_node);
341                         batadv_neigh_node_free_ref(neigh_node);
342                 } else {
343                         if ((!*best_neigh_node) ||
344                             (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
345                                 *best_neigh_node = neigh_node;
346                 }
347         }
348
349         spin_unlock_bh(&orig_node->neigh_list_lock);
350         return neigh_purged;
351 }
352
353 static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
354                                    struct batadv_orig_node *orig_node)
355 {
356         struct batadv_neigh_node *best_neigh_node;
357
358         if (batadv_has_timed_out(orig_node->last_seen,
359                                  2 * BATADV_PURGE_TIMEOUT)) {
360                 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
361                            "Originator timeout: originator %pM, last_seen %u\n",
362                            orig_node->orig,
363                            jiffies_to_msecs(orig_node->last_seen));
364                 return true;
365         } else {
366                 if (batadv_purge_orig_neighbors(bat_priv, orig_node,
367                                                 &best_neigh_node))
368                         batadv_update_route(bat_priv, orig_node,
369                                             best_neigh_node);
370         }
371
372         return false;
373 }
374
375 static void _batadv_purge_orig(struct batadv_priv *bat_priv)
376 {
377         struct batadv_hashtable *hash = bat_priv->orig_hash;
378         struct hlist_node *node_tmp;
379         struct hlist_head *head;
380         spinlock_t *list_lock; /* spinlock to protect write access */
381         struct batadv_orig_node *orig_node;
382         uint32_t i;
383
384         if (!hash)
385                 return;
386
387         /* for all origins... */
388         for (i = 0; i < hash->size; i++) {
389                 head = &hash->table[i];
390                 list_lock = &hash->list_locks[i];
391
392                 spin_lock_bh(list_lock);
393                 hlist_for_each_entry_safe(orig_node, node_tmp,
394                                           head, hash_entry) {
395                         if (batadv_purge_orig_node(bat_priv, orig_node)) {
396                                 batadv_gw_node_delete(bat_priv, orig_node);
397                                 hlist_del_rcu(&orig_node->hash_entry);
398                                 batadv_orig_node_free_ref(orig_node);
399                                 continue;
400                         }
401
402                         batadv_frag_purge_orig(orig_node,
403                                                batadv_frag_check_entry);
404                 }
405                 spin_unlock_bh(list_lock);
406         }
407
408         batadv_gw_node_purge(bat_priv);
409         batadv_gw_election(bat_priv);
410 }
411
412 static void batadv_purge_orig(struct work_struct *work)
413 {
414         struct delayed_work *delayed_work;
415         struct batadv_priv *bat_priv;
416
417         delayed_work = container_of(work, struct delayed_work, work);
418         bat_priv = container_of(delayed_work, struct batadv_priv, orig_work);
419         _batadv_purge_orig(bat_priv);
420         queue_delayed_work(batadv_event_workqueue,
421                            &bat_priv->orig_work,
422                            msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD));
423 }
424
425 void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
426 {
427         _batadv_purge_orig(bat_priv);
428 }
429
430 int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
431 {
432         struct net_device *net_dev = (struct net_device *)seq->private;
433         struct batadv_priv *bat_priv = netdev_priv(net_dev);
434         struct batadv_hashtable *hash = bat_priv->orig_hash;
435         struct hlist_head *head;
436         struct batadv_hard_iface *primary_if;
437         struct batadv_orig_node *orig_node;
438         struct batadv_neigh_node *neigh_node, *neigh_node_tmp;
439         int batman_count = 0;
440         int last_seen_secs;
441         int last_seen_msecs;
442         unsigned long last_seen_jiffies;
443         uint32_t i;
444
445         primary_if = batadv_seq_print_text_primary_if_get(seq);
446         if (!primary_if)
447                 goto out;
448
449         seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
450                    BATADV_SOURCE_VERSION, primary_if->net_dev->name,
451                    primary_if->net_dev->dev_addr, net_dev->name);
452         seq_printf(seq, "  %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
453                    "Originator", "last-seen", "#", BATADV_TQ_MAX_VALUE,
454                    "Nexthop", "outgoingIF", "Potential nexthops");
455
456         for (i = 0; i < hash->size; i++) {
457                 head = &hash->table[i];
458
459                 rcu_read_lock();
460                 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
461                         neigh_node = batadv_orig_node_get_router(orig_node);
462                         if (!neigh_node)
463                                 continue;
464
465                         if (neigh_node->tq_avg == 0)
466                                 goto next;
467
468                         last_seen_jiffies = jiffies - orig_node->last_seen;
469                         last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
470                         last_seen_secs = last_seen_msecs / 1000;
471                         last_seen_msecs = last_seen_msecs % 1000;
472
473                         seq_printf(seq, "%pM %4i.%03is   (%3i) %pM [%10s]:",
474                                    orig_node->orig, last_seen_secs,
475                                    last_seen_msecs, neigh_node->tq_avg,
476                                    neigh_node->addr,
477                                    neigh_node->if_incoming->net_dev->name);
478
479                         hlist_for_each_entry_rcu(neigh_node_tmp,
480                                                  &orig_node->neigh_list, list) {
481                                 seq_printf(seq, " %pM (%3i)",
482                                            neigh_node_tmp->addr,
483                                            neigh_node_tmp->tq_avg);
484                         }
485
486                         seq_puts(seq, "\n");
487                         batman_count++;
488
489 next:
490                         batadv_neigh_node_free_ref(neigh_node);
491                 }
492                 rcu_read_unlock();
493         }
494
495         if (batman_count == 0)
496                 seq_puts(seq, "No batman nodes in range ...\n");
497
498 out:
499         if (primary_if)
500                 batadv_hardif_free_ref(primary_if);
501         return 0;
502 }
503
504 static int batadv_orig_node_add_if(struct batadv_orig_node *orig_node,
505                                    int max_if_num)
506 {
507         void *data_ptr;
508         size_t data_size, old_size;
509
510         data_size = max_if_num * sizeof(unsigned long) * BATADV_NUM_WORDS;
511         old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS;
512         data_ptr = kmalloc(data_size, GFP_ATOMIC);
513         if (!data_ptr)
514                 return -ENOMEM;
515
516         memcpy(data_ptr, orig_node->bcast_own, old_size);
517         kfree(orig_node->bcast_own);
518         orig_node->bcast_own = data_ptr;
519
520         data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
521         if (!data_ptr)
522                 return -ENOMEM;
523
524         memcpy(data_ptr, orig_node->bcast_own_sum,
525                (max_if_num - 1) * sizeof(uint8_t));
526         kfree(orig_node->bcast_own_sum);
527         orig_node->bcast_own_sum = data_ptr;
528
529         return 0;
530 }
531
532 int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
533                             int max_if_num)
534 {
535         struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
536         struct batadv_hashtable *hash = bat_priv->orig_hash;
537         struct hlist_head *head;
538         struct batadv_orig_node *orig_node;
539         uint32_t i;
540         int ret;
541
542         /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
543          * if_num
544          */
545         for (i = 0; i < hash->size; i++) {
546                 head = &hash->table[i];
547
548                 rcu_read_lock();
549                 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
550                         spin_lock_bh(&orig_node->ogm_cnt_lock);
551                         ret = batadv_orig_node_add_if(orig_node, max_if_num);
552                         spin_unlock_bh(&orig_node->ogm_cnt_lock);
553
554                         if (ret == -ENOMEM)
555                                 goto err;
556                 }
557                 rcu_read_unlock();
558         }
559
560         return 0;
561
562 err:
563         rcu_read_unlock();
564         return -ENOMEM;
565 }
566
567 static int batadv_orig_node_del_if(struct batadv_orig_node *orig_node,
568                                    int max_if_num, int del_if_num)
569 {
570         void *data_ptr = NULL;
571         int chunk_size;
572
573         /* last interface was removed */
574         if (max_if_num == 0)
575                 goto free_bcast_own;
576
577         chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS;
578         data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
579         if (!data_ptr)
580                 return -ENOMEM;
581
582         /* copy first part */
583         memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
584
585         /* copy second part */
586         memcpy((char *)data_ptr + del_if_num * chunk_size,
587                orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
588                (max_if_num - del_if_num) * chunk_size);
589
590 free_bcast_own:
591         kfree(orig_node->bcast_own);
592         orig_node->bcast_own = data_ptr;
593
594         if (max_if_num == 0)
595                 goto free_own_sum;
596
597         data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
598         if (!data_ptr)
599                 return -ENOMEM;
600
601         memcpy(data_ptr, orig_node->bcast_own_sum,
602                del_if_num * sizeof(uint8_t));
603
604         memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
605                orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
606                (max_if_num - del_if_num) * sizeof(uint8_t));
607
608 free_own_sum:
609         kfree(orig_node->bcast_own_sum);
610         orig_node->bcast_own_sum = data_ptr;
611
612         return 0;
613 }
614
615 int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
616                             int max_if_num)
617 {
618         struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
619         struct batadv_hashtable *hash = bat_priv->orig_hash;
620         struct hlist_head *head;
621         struct batadv_hard_iface *hard_iface_tmp;
622         struct batadv_orig_node *orig_node;
623         uint32_t i;
624         int ret;
625
626         /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
627          * if_num
628          */
629         for (i = 0; i < hash->size; i++) {
630                 head = &hash->table[i];
631
632                 rcu_read_lock();
633                 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
634                         spin_lock_bh(&orig_node->ogm_cnt_lock);
635                         ret = batadv_orig_node_del_if(orig_node, max_if_num,
636                                                       hard_iface->if_num);
637                         spin_unlock_bh(&orig_node->ogm_cnt_lock);
638
639                         if (ret == -ENOMEM)
640                                 goto err;
641                 }
642                 rcu_read_unlock();
643         }
644
645         /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
646         rcu_read_lock();
647         list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) {
648                 if (hard_iface_tmp->if_status == BATADV_IF_NOT_IN_USE)
649                         continue;
650
651                 if (hard_iface == hard_iface_tmp)
652                         continue;
653
654                 if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
655                         continue;
656
657                 if (hard_iface_tmp->if_num > hard_iface->if_num)
658                         hard_iface_tmp->if_num--;
659         }
660         rcu_read_unlock();
661
662         hard_iface->if_num = -1;
663         return 0;
664
665 err:
666         rcu_read_unlock();
667         return -ENOMEM;
668 }