batman-adv: split routing API data structure in subobjects
[linux-2.6-microblaze.git] / net / batman-adv / hard-interface.c
index 0a7deaf..1f90808 100644 (file)
@@ -23,9 +23,9 @@
 #include <linux/byteorder/generic.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/if.h>
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>
-#include <linux/if.h>
 #include <linux/kernel.h>
 #include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
-#include <net/net_namespace.h>
 
+#include "bat_v.h"
 #include "bridge_loop_avoidance.h"
 #include "debugfs.h"
 #include "distributed-arp-table.h"
 #include "gateway_client.h"
+#include "log.h"
 #include "originator.h"
 #include "packet.h"
 #include "send.h"
@@ -121,6 +122,7 @@ static bool batadv_mutual_parents(const struct net_device *dev1,
 static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
 {
        struct net_device *parent_dev;
+       struct net *net = dev_net(net_dev);
        bool ret;
 
        /* check if this is a batman-adv mesh interface */
@@ -133,7 +135,7 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
                return false;
 
        /* recurse over the parent device */
-       parent_dev = __dev_get_by_index(&init_net, dev_get_iflink(net_dev));
+       parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev));
        /* if we got a NULL parent_dev there is something broken.. */
        if (WARN(!parent_dev, "Cannot find parent device"))
                return false;
@@ -146,22 +148,22 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
        return ret;
 }
 
-static int batadv_is_valid_iface(const struct net_device *net_dev)
+static bool batadv_is_valid_iface(const struct net_device *net_dev)
 {
        if (net_dev->flags & IFF_LOOPBACK)
-               return 0;
+               return false;
 
        if (net_dev->type != ARPHRD_ETHER)
-               return 0;
+               return false;
 
        if (net_dev->addr_len != ETH_ALEN)
-               return 0;
+               return false;
 
        /* no batman over batman */
        if (batadv_is_on_batman_iface(net_dev))
-               return 0;
+               return false;
 
-       return 1;
+       return true;
 }
 
 /**
@@ -236,8 +238,8 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,
 
        ASSERT_RTNL();
 
-       if (new_hard_iface && !kref_get_unless_zero(&new_hard_iface->refcount))
-               new_hard_iface = NULL;
+       if (new_hard_iface)
+               kref_get(&new_hard_iface->refcount);
 
        curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
        rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
@@ -245,7 +247,7 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,
        if (!new_hard_iface)
                goto out;
 
-       bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface);
+       bat_priv->algo_ops->iface.primary_set(new_hard_iface);
        batadv_primary_if_update_addr(bat_priv, curr_hard_iface);
 
 out:
@@ -392,7 +394,7 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
 
        bat_priv = netdev_priv(hard_iface->soft_iface);
 
-       bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
+       bat_priv->algo_ops->iface.update_mac(hard_iface);
        hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;
 
        /* the first active interface becomes our primary interface or
@@ -407,8 +409,8 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
 
        batadv_update_min_mtu(hard_iface->soft_iface);
 
-       if (bat_priv->bat_algo_ops->bat_iface_activate)
-               bat_priv->bat_algo_ops->bat_iface_activate(hard_iface);
+       if (bat_priv->algo_ops->iface.activate)
+               bat_priv->algo_ops->iface.activate(hard_iface);
 
 out:
        if (primary_if)
@@ -456,7 +458,7 @@ static int batadv_master_del_slave(struct batadv_hard_iface *slave,
 }
 
 int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
-                                  const char *iface_name)
+                                  struct net *net, const char *iface_name)
 {
        struct batadv_priv *bat_priv;
        struct net_device *soft_iface, *master;
@@ -467,13 +469,12 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
        if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
                goto out;
 
-       if (!kref_get_unless_zero(&hard_iface->refcount))
-               goto out;
+       kref_get(&hard_iface->refcount);
 
-       soft_iface = dev_get_by_name(&init_net, iface_name);
+       soft_iface = dev_get_by_name(net, iface_name);
 
        if (!soft_iface) {
-               soft_iface = batadv_softif_create(iface_name);
+               soft_iface = batadv_softif_create(net, iface_name);
 
                if (!soft_iface) {
                        ret = -ENOMEM;
@@ -507,7 +508,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
        if (ret)
                goto err_dev;
 
-       ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
+       ret = bat_priv->algo_ops->iface.enable(hard_iface);
        if (ret < 0)
                goto err_upper;
 
@@ -516,12 +517,13 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
        hard_iface->if_status = BATADV_IF_INACTIVE;
        ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
        if (ret < 0) {
-               bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
+               bat_priv->algo_ops->iface.disable(hard_iface);
                bat_priv->num_ifaces--;
                hard_iface->if_status = BATADV_IF_NOT_IN_USE;
                goto err_upper;
        }
 
+       kref_get(&hard_iface->refcount);
        hard_iface->batman_adv_ptype.type = ethertype;
        hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
        hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
@@ -553,9 +555,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 
        batadv_hardif_recalc_extra_skbroom(soft_iface);
 
-       /* begin scheduling originator messages on that interface */
-       batadv_schedule_bat_ogm(hard_iface);
-
 out:
        return 0;
 
@@ -583,6 +582,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
        batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
                    hard_iface->net_dev->name);
        dev_remove_pack(&hard_iface->batman_adv_ptype);
+       batadv_hardif_put(hard_iface);
 
        bat_priv->num_ifaces--;
        batadv_orig_hash_del_if(hard_iface, bat_priv->num_ifaces);
@@ -598,7 +598,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
                        batadv_hardif_put(new_if);
        }
 
-       bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
+       bat_priv->algo_ops->iface.disable(hard_iface);
        hard_iface->if_status = BATADV_IF_NOT_IN_USE;
 
        /* delete all references to this hard_iface */
@@ -652,8 +652,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 
        ASSERT_RTNL();
 
-       ret = batadv_is_valid_iface(net_dev);
-       if (ret != 1)
+       if (!batadv_is_valid_iface(net_dev))
                goto out;
 
        dev_hold(net_dev);
@@ -686,6 +685,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
        if (batadv_is_wifi_netdev(net_dev))
                hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
 
+       batadv_v_hardif_init(hard_iface);
+
        /* extra reference for return */
        kref_init(&hard_iface->refcount);
        kref_get(&hard_iface->refcount);
@@ -782,7 +783,7 @@ static int batadv_hard_if_event(struct notifier_block *this,
                batadv_check_known_mac_addr(hard_iface->net_dev);
 
                bat_priv = netdev_priv(hard_iface->soft_iface);
-               bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
+               bat_priv->algo_ops->iface.update_mac(hard_iface);
 
                primary_if = batadv_primary_if_get_selected(bat_priv);
                if (!primary_if)