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