batman-adv: send GW_DEL event in case of soft-iface destruction
[firefly-linux-kernel-4.4.55.git] / net / batman-adv / hard-interface.c
1 /* Copyright (C) 2007-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 "hard-interface.h"
23 #include "soft-interface.h"
24 #include "send.h"
25 #include "translation-table.h"
26 #include "routing.h"
27 #include "sysfs.h"
28 #include "originator.h"
29 #include "hash.h"
30 #include "bridge_loop_avoidance.h"
31 #include "gateway_client.h"
32
33 #include <linux/if_arp.h>
34 #include <linux/if_ether.h>
35
36 void batadv_hardif_free_rcu(struct rcu_head *rcu)
37 {
38         struct batadv_hard_iface *hard_iface;
39
40         hard_iface = container_of(rcu, struct batadv_hard_iface, rcu);
41         dev_put(hard_iface->net_dev);
42         kfree(hard_iface);
43 }
44
45 struct batadv_hard_iface *
46 batadv_hardif_get_by_netdev(const struct net_device *net_dev)
47 {
48         struct batadv_hard_iface *hard_iface;
49
50         rcu_read_lock();
51         list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
52                 if (hard_iface->net_dev == net_dev &&
53                     atomic_inc_not_zero(&hard_iface->refcount))
54                         goto out;
55         }
56
57         hard_iface = NULL;
58
59 out:
60         rcu_read_unlock();
61         return hard_iface;
62 }
63
64 /**
65  * batadv_is_on_batman_iface - check if a device is a batman iface descendant
66  * @net_dev: the device to check
67  *
68  * If the user creates any virtual device on top of a batman-adv interface, it
69  * is important to prevent this new interface to be used to create a new mesh
70  * network (this behaviour would lead to a batman-over-batman configuration).
71  * This function recursively checks all the fathers of the device passed as
72  * argument looking for a batman-adv soft interface.
73  *
74  * Returns true if the device is descendant of a batman-adv mesh interface (or
75  * if it is a batman-adv interface itself), false otherwise
76  */
77 static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
78 {
79         struct net_device *parent_dev;
80         bool ret;
81
82         /* check if this is a batman-adv mesh interface */
83         if (batadv_softif_is_valid(net_dev))
84                 return true;
85
86         /* no more parents..stop recursion */
87         if (net_dev->iflink == net_dev->ifindex)
88                 return false;
89
90         /* recurse over the parent device */
91         parent_dev = dev_get_by_index(&init_net, net_dev->iflink);
92         /* if we got a NULL parent_dev there is something broken.. */
93         if (WARN(!parent_dev, "Cannot find parent device"))
94                 return false;
95
96         ret = batadv_is_on_batman_iface(parent_dev);
97
98         if (parent_dev)
99                 dev_put(parent_dev);
100         return ret;
101 }
102
103 static int batadv_is_valid_iface(const struct net_device *net_dev)
104 {
105         if (net_dev->flags & IFF_LOOPBACK)
106                 return 0;
107
108         if (net_dev->type != ARPHRD_ETHER)
109                 return 0;
110
111         if (net_dev->addr_len != ETH_ALEN)
112                 return 0;
113
114         /* no batman over batman */
115         if (batadv_is_on_batman_iface(net_dev))
116                 return 0;
117
118         return 1;
119 }
120
121 /**
122  * batadv_is_wifi_netdev - check if the given net_device struct is a wifi
123  *  interface
124  * @net_device: the device to check
125  *
126  * Returns true if the net device is a 802.11 wireless device, false otherwise.
127  */
128 static bool batadv_is_wifi_netdev(struct net_device *net_device)
129 {
130 #ifdef CONFIG_WIRELESS_EXT
131         /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
132          * check for wireless_handlers != NULL
133          */
134         if (net_device->wireless_handlers)
135                 return true;
136 #endif
137
138         /* cfg80211 drivers have to set ieee80211_ptr */
139         if (net_device->ieee80211_ptr)
140                 return true;
141
142         return false;
143 }
144
145 /**
146  * batadv_is_wifi_iface - check if the given interface represented by ifindex
147  *  is a wifi interface
148  * @ifindex: interface index to check
149  *
150  * Returns true if the interface represented by ifindex is a 802.11 wireless
151  * device, false otherwise.
152  */
153 bool batadv_is_wifi_iface(int ifindex)
154 {
155         struct net_device *net_device = NULL;
156         bool ret = false;
157
158         if (ifindex == BATADV_NULL_IFINDEX)
159                 goto out;
160
161         net_device = dev_get_by_index(&init_net, ifindex);
162         if (!net_device)
163                 goto out;
164
165         ret = batadv_is_wifi_netdev(net_device);
166
167 out:
168         if (net_device)
169                 dev_put(net_device);
170         return ret;
171 }
172
173 static struct batadv_hard_iface *
174 batadv_hardif_get_active(const struct net_device *soft_iface)
175 {
176         struct batadv_hard_iface *hard_iface;
177
178         rcu_read_lock();
179         list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
180                 if (hard_iface->soft_iface != soft_iface)
181                         continue;
182
183                 if (hard_iface->if_status == BATADV_IF_ACTIVE &&
184                     atomic_inc_not_zero(&hard_iface->refcount))
185                         goto out;
186         }
187
188         hard_iface = NULL;
189
190 out:
191         rcu_read_unlock();
192         return hard_iface;
193 }
194
195 static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
196                                           struct batadv_hard_iface *oldif)
197 {
198         struct batadv_hard_iface *primary_if;
199
200         primary_if = batadv_primary_if_get_selected(bat_priv);
201         if (!primary_if)
202                 goto out;
203
204         batadv_dat_init_own_addr(bat_priv, primary_if);
205         batadv_bla_update_orig_address(bat_priv, primary_if, oldif);
206 out:
207         if (primary_if)
208                 batadv_hardif_free_ref(primary_if);
209 }
210
211 static void batadv_primary_if_select(struct batadv_priv *bat_priv,
212                                      struct batadv_hard_iface *new_hard_iface)
213 {
214         struct batadv_hard_iface *curr_hard_iface;
215
216         ASSERT_RTNL();
217
218         if (new_hard_iface && !atomic_inc_not_zero(&new_hard_iface->refcount))
219                 new_hard_iface = NULL;
220
221         curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
222         rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
223
224         if (!new_hard_iface)
225                 goto out;
226
227         bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface);
228         batadv_primary_if_update_addr(bat_priv, curr_hard_iface);
229
230 out:
231         if (curr_hard_iface)
232                 batadv_hardif_free_ref(curr_hard_iface);
233 }
234
235 static bool
236 batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
237 {
238         if (hard_iface->net_dev->flags & IFF_UP)
239                 return true;
240
241         return false;
242 }
243
244 static void batadv_check_known_mac_addr(const struct net_device *net_dev)
245 {
246         const struct batadv_hard_iface *hard_iface;
247
248         rcu_read_lock();
249         list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
250                 if ((hard_iface->if_status != BATADV_IF_ACTIVE) &&
251                     (hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED))
252                         continue;
253
254                 if (hard_iface->net_dev == net_dev)
255                         continue;
256
257                 if (!batadv_compare_eth(hard_iface->net_dev->dev_addr,
258                                         net_dev->dev_addr))
259                         continue;
260
261                 pr_warn("The newly added mac address (%pM) already exists on: %s\n",
262                         net_dev->dev_addr, hard_iface->net_dev->name);
263                 pr_warn("It is strongly recommended to keep mac addresses unique to avoid problems!\n");
264         }
265         rcu_read_unlock();
266 }
267
268 int batadv_hardif_min_mtu(struct net_device *soft_iface)
269 {
270         struct batadv_priv *bat_priv = netdev_priv(soft_iface);
271         const struct batadv_hard_iface *hard_iface;
272         int min_mtu = ETH_DATA_LEN;
273
274         rcu_read_lock();
275         list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
276                 if ((hard_iface->if_status != BATADV_IF_ACTIVE) &&
277                     (hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED))
278                         continue;
279
280                 if (hard_iface->soft_iface != soft_iface)
281                         continue;
282
283                 min_mtu = min_t(int, hard_iface->net_dev->mtu, min_mtu);
284         }
285         rcu_read_unlock();
286
287         atomic_set(&bat_priv->packet_size_max, min_mtu);
288
289         if (atomic_read(&bat_priv->fragmentation) == 0)
290                 goto out;
291
292         /* with fragmentation enabled the maximum size of internally generated
293          * packets such as translation table exchanges or tvlv containers, etc
294          * has to be calculated
295          */
296         min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
297         min_mtu -= sizeof(struct batadv_frag_packet);
298         min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
299         atomic_set(&bat_priv->packet_size_max, min_mtu);
300
301         /* with fragmentation enabled we can fragment external packets easily */
302         min_mtu = min_t(int, min_mtu, ETH_DATA_LEN);
303
304 out:
305         return min_mtu - batadv_max_header_len();
306 }
307
308 /* adjusts the MTU if a new interface with a smaller MTU appeared. */
309 void batadv_update_min_mtu(struct net_device *soft_iface)
310 {
311         soft_iface->mtu = batadv_hardif_min_mtu(soft_iface);
312
313         /* Check if the local translate table should be cleaned up to match a
314          * new (and smaller) MTU.
315          */
316         batadv_tt_local_resize_to_mtu(soft_iface);
317 }
318
319 static void
320 batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
321 {
322         struct batadv_priv *bat_priv;
323         struct batadv_hard_iface *primary_if = NULL;
324
325         if (hard_iface->if_status != BATADV_IF_INACTIVE)
326                 goto out;
327
328         bat_priv = netdev_priv(hard_iface->soft_iface);
329
330         bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
331         hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;
332
333         /* the first active interface becomes our primary interface or
334          * the next active interface after the old primary interface was removed
335          */
336         primary_if = batadv_primary_if_get_selected(bat_priv);
337         if (!primary_if)
338                 batadv_primary_if_select(bat_priv, hard_iface);
339
340         batadv_info(hard_iface->soft_iface, "Interface activated: %s\n",
341                     hard_iface->net_dev->name);
342
343         batadv_update_min_mtu(hard_iface->soft_iface);
344
345 out:
346         if (primary_if)
347                 batadv_hardif_free_ref(primary_if);
348 }
349
350 static void
351 batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
352 {
353         if ((hard_iface->if_status != BATADV_IF_ACTIVE) &&
354             (hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED))
355                 return;
356
357         hard_iface->if_status = BATADV_IF_INACTIVE;
358
359         batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
360                     hard_iface->net_dev->name);
361
362         batadv_update_min_mtu(hard_iface->soft_iface);
363 }
364
365 /**
366  * batadv_master_del_slave - remove hard_iface from the current master interface
367  * @slave: the interface enslaved in another master
368  * @master: the master from which slave has to be removed
369  *
370  * Invoke ndo_del_slave on master passing slave as argument. In this way slave
371  * is free'd and master can correctly change its internal state.
372  * Return 0 on success, a negative value representing the error otherwise
373  */
374 static int batadv_master_del_slave(struct batadv_hard_iface *slave,
375                                    struct net_device *master)
376 {
377         int ret;
378
379         if (!master)
380                 return 0;
381
382         ret = -EBUSY;
383         if (master->netdev_ops->ndo_del_slave)
384                 ret = master->netdev_ops->ndo_del_slave(master, slave->net_dev);
385
386         return ret;
387 }
388
389 int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
390                                    const char *iface_name)
391 {
392         struct batadv_priv *bat_priv;
393         struct net_device *soft_iface, *master;
394         __be16 ethertype = htons(ETH_P_BATMAN);
395         int max_header_len = batadv_max_header_len();
396         int ret;
397
398         if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
399                 goto out;
400
401         if (!atomic_inc_not_zero(&hard_iface->refcount))
402                 goto out;
403
404         soft_iface = dev_get_by_name(&init_net, iface_name);
405
406         if (!soft_iface) {
407                 soft_iface = batadv_softif_create(iface_name);
408
409                 if (!soft_iface) {
410                         ret = -ENOMEM;
411                         goto err;
412                 }
413
414                 /* dev_get_by_name() increases the reference counter for us */
415                 dev_hold(soft_iface);
416         }
417
418         if (!batadv_softif_is_valid(soft_iface)) {
419                 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
420                        soft_iface->name);
421                 ret = -EINVAL;
422                 goto err_dev;
423         }
424
425         /* check if the interface is enslaved in another virtual one and
426          * in that case unlink it first
427          */
428         master = netdev_master_upper_dev_get(hard_iface->net_dev);
429         ret = batadv_master_del_slave(hard_iface, master);
430         if (ret)
431                 goto err_dev;
432
433         hard_iface->soft_iface = soft_iface;
434         bat_priv = netdev_priv(hard_iface->soft_iface);
435
436         ret = netdev_master_upper_dev_link(hard_iface->net_dev, soft_iface);
437         if (ret)
438                 goto err_dev;
439
440         ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
441         if (ret < 0)
442                 goto err_upper;
443
444         hard_iface->if_num = bat_priv->num_ifaces;
445         bat_priv->num_ifaces++;
446         hard_iface->if_status = BATADV_IF_INACTIVE;
447         ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
448         if (ret < 0) {
449                 bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
450                 bat_priv->num_ifaces--;
451                 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
452                 goto err_upper;
453         }
454
455         hard_iface->batman_adv_ptype.type = ethertype;
456         hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
457         hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
458         dev_add_pack(&hard_iface->batman_adv_ptype);
459
460         batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
461                     hard_iface->net_dev->name);
462
463         if (atomic_read(&bat_priv->fragmentation) &&
464             hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
465                 batadv_info(hard_iface->soft_iface,
466                             "The MTU of interface %s is too small (%i) to handle the transport of batman-adv packets. Packets going over this interface will be fragmented on layer2 which could impact the performance. Setting the MTU to %i would solve the problem.\n",
467                             hard_iface->net_dev->name, hard_iface->net_dev->mtu,
468                             ETH_DATA_LEN + max_header_len);
469
470         if (!atomic_read(&bat_priv->fragmentation) &&
471             hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
472                 batadv_info(hard_iface->soft_iface,
473                             "The MTU of interface %s is too small (%i) to handle the transport of batman-adv packets. If you experience problems getting traffic through try increasing the MTU to %i.\n",
474                             hard_iface->net_dev->name, hard_iface->net_dev->mtu,
475                             ETH_DATA_LEN + max_header_len);
476
477         if (batadv_hardif_is_iface_up(hard_iface))
478                 batadv_hardif_activate_interface(hard_iface);
479         else
480                 batadv_err(hard_iface->soft_iface,
481                            "Not using interface %s (retrying later): interface not active\n",
482                            hard_iface->net_dev->name);
483
484         /* begin scheduling originator messages on that interface */
485         batadv_schedule_bat_ogm(hard_iface);
486
487 out:
488         return 0;
489
490 err_upper:
491         netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface);
492 err_dev:
493         hard_iface->soft_iface = NULL;
494         dev_put(soft_iface);
495 err:
496         batadv_hardif_free_ref(hard_iface);
497         return ret;
498 }
499
500 void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
501                                      enum batadv_hard_if_cleanup autodel)
502 {
503         struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
504         struct batadv_hard_iface *primary_if = NULL;
505
506         if (hard_iface->if_status == BATADV_IF_ACTIVE)
507                 batadv_hardif_deactivate_interface(hard_iface);
508
509         if (hard_iface->if_status != BATADV_IF_INACTIVE)
510                 goto out;
511
512         batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
513                     hard_iface->net_dev->name);
514         dev_remove_pack(&hard_iface->batman_adv_ptype);
515
516         bat_priv->num_ifaces--;
517         batadv_orig_hash_del_if(hard_iface, bat_priv->num_ifaces);
518
519         primary_if = batadv_primary_if_get_selected(bat_priv);
520         if (hard_iface == primary_if) {
521                 struct batadv_hard_iface *new_if;
522
523                 new_if = batadv_hardif_get_active(hard_iface->soft_iface);
524                 batadv_primary_if_select(bat_priv, new_if);
525
526                 if (new_if)
527                         batadv_hardif_free_ref(new_if);
528         }
529
530         bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
531         hard_iface->if_status = BATADV_IF_NOT_IN_USE;
532
533         /* delete all references to this hard_iface */
534         batadv_purge_orig_ref(bat_priv);
535         batadv_purge_outstanding_packets(bat_priv, hard_iface);
536         dev_put(hard_iface->soft_iface);
537
538         /* nobody uses this interface anymore */
539         if (!bat_priv->num_ifaces) {
540                 batadv_gw_check_client_stop(bat_priv);
541
542                 if (autodel == BATADV_IF_CLEANUP_AUTO)
543                         batadv_softif_destroy_sysfs(hard_iface->soft_iface);
544         }
545
546         netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
547         hard_iface->soft_iface = NULL;
548         batadv_hardif_free_ref(hard_iface);
549
550 out:
551         if (primary_if)
552                 batadv_hardif_free_ref(primary_if);
553 }
554
555 /**
556  * batadv_hardif_remove_interface_finish - cleans up the remains of a hardif
557  * @work: work queue item
558  *
559  * Free the parts of the hard interface which can not be removed under
560  * rtnl lock (to prevent deadlock situations).
561  */
562 static void batadv_hardif_remove_interface_finish(struct work_struct *work)
563 {
564         struct batadv_hard_iface *hard_iface;
565
566         hard_iface = container_of(work, struct batadv_hard_iface,
567                                   cleanup_work);
568
569         batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
570         batadv_hardif_free_ref(hard_iface);
571 }
572
573 static struct batadv_hard_iface *
574 batadv_hardif_add_interface(struct net_device *net_dev)
575 {
576         struct batadv_hard_iface *hard_iface;
577         int ret;
578
579         ASSERT_RTNL();
580
581         ret = batadv_is_valid_iface(net_dev);
582         if (ret != 1)
583                 goto out;
584
585         dev_hold(net_dev);
586
587         hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
588         if (!hard_iface)
589                 goto release_dev;
590
591         ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
592         if (ret)
593                 goto free_if;
594
595         hard_iface->if_num = -1;
596         hard_iface->net_dev = net_dev;
597         hard_iface->soft_iface = NULL;
598         hard_iface->if_status = BATADV_IF_NOT_IN_USE;
599         INIT_LIST_HEAD(&hard_iface->list);
600         INIT_WORK(&hard_iface->cleanup_work,
601                   batadv_hardif_remove_interface_finish);
602
603         hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
604         if (batadv_is_wifi_netdev(net_dev))
605                 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
606
607         /* extra reference for return */
608         atomic_set(&hard_iface->refcount, 2);
609
610         batadv_check_known_mac_addr(hard_iface->net_dev);
611         list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
612
613         return hard_iface;
614
615 free_if:
616         kfree(hard_iface);
617 release_dev:
618         dev_put(net_dev);
619 out:
620         return NULL;
621 }
622
623 static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
624 {
625         ASSERT_RTNL();
626
627         /* first deactivate interface */
628         if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
629                 batadv_hardif_disable_interface(hard_iface,
630                                                 BATADV_IF_CLEANUP_AUTO);
631
632         if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
633                 return;
634
635         hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
636         queue_work(batadv_event_workqueue, &hard_iface->cleanup_work);
637 }
638
639 void batadv_hardif_remove_interfaces(void)
640 {
641         struct batadv_hard_iface *hard_iface, *hard_iface_tmp;
642
643         rtnl_lock();
644         list_for_each_entry_safe(hard_iface, hard_iface_tmp,
645                                  &batadv_hardif_list, list) {
646                 list_del_rcu(&hard_iface->list);
647                 batadv_hardif_remove_interface(hard_iface);
648         }
649         rtnl_unlock();
650 }
651
652 static int batadv_hard_if_event(struct notifier_block *this,
653                                 unsigned long event, void *ptr)
654 {
655         struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
656         struct batadv_hard_iface *hard_iface;
657         struct batadv_hard_iface *primary_if = NULL;
658         struct batadv_priv *bat_priv;
659
660         if (batadv_softif_is_valid(net_dev) && event == NETDEV_REGISTER) {
661                 batadv_sysfs_add_meshif(net_dev);
662                 bat_priv = netdev_priv(net_dev);
663                 batadv_softif_create_vlan(bat_priv, BATADV_NO_FLAGS);
664                 return NOTIFY_DONE;
665         }
666
667         hard_iface = batadv_hardif_get_by_netdev(net_dev);
668         if (!hard_iface && event == NETDEV_REGISTER)
669                 hard_iface = batadv_hardif_add_interface(net_dev);
670
671         if (!hard_iface)
672                 goto out;
673
674         switch (event) {
675         case NETDEV_UP:
676                 batadv_hardif_activate_interface(hard_iface);
677                 break;
678         case NETDEV_GOING_DOWN:
679         case NETDEV_DOWN:
680                 batadv_hardif_deactivate_interface(hard_iface);
681                 break;
682         case NETDEV_UNREGISTER:
683                 list_del_rcu(&hard_iface->list);
684
685                 batadv_hardif_remove_interface(hard_iface);
686                 break;
687         case NETDEV_CHANGEMTU:
688                 if (hard_iface->soft_iface)
689                         batadv_update_min_mtu(hard_iface->soft_iface);
690                 break;
691         case NETDEV_CHANGEADDR:
692                 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
693                         goto hardif_put;
694
695                 batadv_check_known_mac_addr(hard_iface->net_dev);
696
697                 bat_priv = netdev_priv(hard_iface->soft_iface);
698                 bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
699
700                 primary_if = batadv_primary_if_get_selected(bat_priv);
701                 if (!primary_if)
702                         goto hardif_put;
703
704                 if (hard_iface == primary_if)
705                         batadv_primary_if_update_addr(bat_priv, NULL);
706                 break;
707         default:
708                 break;
709         }
710
711 hardif_put:
712         batadv_hardif_free_ref(hard_iface);
713 out:
714         if (primary_if)
715                 batadv_hardif_free_ref(primary_if);
716         return NOTIFY_DONE;
717 }
718
719 struct notifier_block batadv_hard_if_notifier = {
720         .notifier_call = batadv_hard_if_event,
721 };