|
@@ -25,22 +25,21 @@
|
|
|
#include "send.h"
|
|
|
#include "translation-table.h"
|
|
|
#include "routing.h"
|
|
|
+#include "bat_sysfs.h"
|
|
|
+#include "originator.h"
|
|
|
#include "hash.h"
|
|
|
|
|
|
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
|
|
-
|
|
|
-static char avail_ifs;
|
|
|
-static char active_ifs;
|
|
|
+#include <linux/if_arp.h>
|
|
|
|
|
|
-static void hardif_free_interface(struct rcu_head *rcu);
|
|
|
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
|
|
|
|
|
-static struct batman_if *get_batman_if_by_name(char *name)
|
|
|
+struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
|
|
|
{
|
|
|
struct batman_if *batman_if;
|
|
|
|
|
|
rcu_read_lock();
|
|
|
list_for_each_entry_rcu(batman_if, &if_list, list) {
|
|
|
- if (strncmp(batman_if->dev, name, IFNAMSIZ) == 0)
|
|
|
+ if (batman_if->net_dev == net_dev)
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
@@ -51,23 +50,90 @@ out:
|
|
|
return batman_if;
|
|
|
}
|
|
|
|
|
|
-int hardif_min_mtu(void)
|
|
|
+static int is_valid_iface(struct net_device *net_dev)
|
|
|
+{
|
|
|
+ if (net_dev->flags & IFF_LOOPBACK)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ if (net_dev->type != ARPHRD_ETHER)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ if (net_dev->addr_len != ETH_ALEN)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ /* no batman over batman */
|
|
|
+#ifdef HAVE_NET_DEVICE_OPS
|
|
|
+ if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
|
|
|
+ return 0;
|
|
|
+#else
|
|
|
+ if (net_dev->hard_start_xmit == interface_tx)
|
|
|
+ return 0;
|
|
|
+#endif
|
|
|
+
|
|
|
+ /* Device is being bridged */
|
|
|
+ /* if (net_dev->br_port != NULL)
|
|
|
+ return 0; */
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+static struct batman_if *get_active_batman_if(void)
|
|
|
{
|
|
|
struct batman_if *batman_if;
|
|
|
- /* allow big frames if all devices are capable to do so
|
|
|
- * (have MTU > 1500 + BAT_HEADER_LEN) */
|
|
|
- int min_mtu = ETH_DATA_LEN;
|
|
|
|
|
|
+ /* TODO: should check interfaces belonging to bat_priv */
|
|
|
rcu_read_lock();
|
|
|
list_for_each_entry_rcu(batman_if, &if_list, list) {
|
|
|
- if ((batman_if->if_active == IF_ACTIVE) ||
|
|
|
- (batman_if->if_active == IF_TO_BE_ACTIVATED))
|
|
|
- min_mtu = MIN(batman_if->net_dev->mtu - BAT_HEADER_LEN,
|
|
|
- min_mtu);
|
|
|
+ if (batman_if->if_status == IF_ACTIVE)
|
|
|
+ goto out;
|
|
|
}
|
|
|
+
|
|
|
+ batman_if = NULL;
|
|
|
+
|
|
|
+out:
|
|
|
rcu_read_unlock();
|
|
|
+ return batman_if;
|
|
|
+}
|
|
|
|
|
|
- return min_mtu;
|
|
|
+static void set_primary_if(struct bat_priv *bat_priv,
|
|
|
+ struct batman_if *batman_if)
|
|
|
+{
|
|
|
+ struct batman_packet *batman_packet;
|
|
|
+
|
|
|
+ bat_priv->primary_if = batman_if;
|
|
|
+
|
|
|
+ if (!bat_priv->primary_if)
|
|
|
+ return;
|
|
|
+
|
|
|
+ set_main_if_addr(batman_if->net_dev->dev_addr);
|
|
|
+
|
|
|
+ batman_packet = (struct batman_packet *)(batman_if->packet_buff);
|
|
|
+ batman_packet->flags = 0;
|
|
|
+ batman_packet->ttl = TTL;
|
|
|
+
|
|
|
+ /***
|
|
|
+ * hacky trick to make sure that we send the HNA information via
|
|
|
+ * our new primary interface
|
|
|
+ */
|
|
|
+ atomic_set(&hna_local_changed, 1);
|
|
|
+}
|
|
|
+
|
|
|
+static bool hardif_is_iface_up(struct batman_if *batman_if)
|
|
|
+{
|
|
|
+ if (batman_if->net_dev->flags & IFF_UP)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+static void update_mac_addresses(struct batman_if *batman_if)
|
|
|
+{
|
|
|
+ addr_to_string(batman_if->addr_str, batman_if->net_dev->dev_addr);
|
|
|
+
|
|
|
+ memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig,
|
|
|
+ batman_if->net_dev->dev_addr, ETH_ALEN);
|
|
|
+ memcpy(((struct batman_packet *)(batman_if->packet_buff))->prev_sender,
|
|
|
+ batman_if->net_dev->dev_addr, ETH_ALEN);
|
|
|
}
|
|
|
|
|
|
static void check_known_mac_addr(uint8_t *addr)
|
|
@@ -76,8 +142,8 @@ static void check_known_mac_addr(uint8_t *addr)
|
|
|
|
|
|
rcu_read_lock();
|
|
|
list_for_each_entry_rcu(batman_if, &if_list, list) {
|
|
|
- if ((batman_if->if_active != IF_ACTIVE) &&
|
|
|
- (batman_if->if_active != IF_TO_BE_ACTIVATED))
|
|
|
+ if ((batman_if->if_status != IF_ACTIVE) &&
|
|
|
+ (batman_if->if_status != IF_TO_BE_ACTIVATED))
|
|
|
continue;
|
|
|
|
|
|
if (!compare_orig(batman_if->net_dev->dev_addr, addr))
|
|
@@ -90,6 +156,25 @@ static void check_known_mac_addr(uint8_t *addr)
|
|
|
rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
+int hardif_min_mtu(void)
|
|
|
+{
|
|
|
+ struct batman_if *batman_if;
|
|
|
+ /* allow big frames if all devices are capable to do so
|
|
|
+ * (have MTU > 1500 + BAT_HEADER_LEN) */
|
|
|
+ int min_mtu = ETH_DATA_LEN;
|
|
|
+
|
|
|
+ rcu_read_lock();
|
|
|
+ list_for_each_entry_rcu(batman_if, &if_list, list) {
|
|
|
+ if ((batman_if->if_status == IF_ACTIVE) ||
|
|
|
+ (batman_if->if_status == IF_TO_BE_ACTIVATED))
|
|
|
+ min_mtu = MIN(batman_if->net_dev->mtu - BAT_HEADER_LEN,
|
|
|
+ min_mtu);
|
|
|
+ }
|
|
|
+ rcu_read_unlock();
|
|
|
+
|
|
|
+ return min_mtu;
|
|
|
+}
|
|
|
+
|
|
|
/* adjusts the MTU if a new interface with a smaller MTU appeared. */
|
|
|
void update_min_mtu(void)
|
|
|
{
|
|
@@ -100,322 +185,246 @@ void update_min_mtu(void)
|
|
|
soft_device->mtu = min_mtu;
|
|
|
}
|
|
|
|
|
|
-/* checks if the interface is up. (returns 1 if it is) */
|
|
|
-static int hardif_is_interface_up(char *dev)
|
|
|
+static void hardif_activate_interface(struct bat_priv *bat_priv,
|
|
|
+ struct batman_if *batman_if)
|
|
|
{
|
|
|
- struct net_device *net_dev;
|
|
|
+ if (batman_if->if_status != IF_INACTIVE)
|
|
|
+ return;
|
|
|
|
|
|
- /**
|
|
|
- * if we already have an interface in our interface list and
|
|
|
- * the current interface is not the primary interface and
|
|
|
- * the primary interface is not up and
|
|
|
- * the primary interface has never been up - don't activate any
|
|
|
- * secondary interface !
|
|
|
- */
|
|
|
+ dev_hold(batman_if->net_dev);
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
- if ((!list_empty(&if_list)) &&
|
|
|
- strncmp(((struct batman_if *)if_list.next)->dev, dev, IFNAMSIZ) &&
|
|
|
- !(((struct batman_if *)if_list.next)->if_active == IF_ACTIVE) &&
|
|
|
- !(((struct batman_if *)if_list.next)->if_active == IF_TO_BE_ACTIVATED) &&
|
|
|
- (!main_if_was_up())) {
|
|
|
- rcu_read_unlock();
|
|
|
- goto end;
|
|
|
- }
|
|
|
- rcu_read_unlock();
|
|
|
+ update_mac_addresses(batman_if);
|
|
|
+ batman_if->if_status = IF_TO_BE_ACTIVATED;
|
|
|
|
|
|
-#ifdef __NET_NET_NAMESPACE_H
|
|
|
- net_dev = dev_get_by_name(&init_net, dev);
|
|
|
-#else
|
|
|
- net_dev = dev_get_by_name(dev);
|
|
|
-#endif
|
|
|
- if (!net_dev)
|
|
|
- goto end;
|
|
|
+ /**
|
|
|
+ * the first active interface becomes our primary interface or
|
|
|
+ * the next active interface after the old primay interface was removed
|
|
|
+ */
|
|
|
+ if (!bat_priv->primary_if)
|
|
|
+ set_primary_if(bat_priv, batman_if);
|
|
|
|
|
|
- if (!(net_dev->flags & IFF_UP))
|
|
|
- goto failure;
|
|
|
+ printk(KERN_INFO "batman-adv:Interface activated: %s\n",
|
|
|
+ batman_if->dev);
|
|
|
|
|
|
- dev_put(net_dev);
|
|
|
- return 1;
|
|
|
+ if (atomic_read(&module_state) == MODULE_INACTIVE)
|
|
|
+ activate_module();
|
|
|
|
|
|
-failure:
|
|
|
- dev_put(net_dev);
|
|
|
-end:
|
|
|
- return 0;
|
|
|
+ update_min_mtu();
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
-/* deactivates the interface. */
|
|
|
-void hardif_deactivate_interface(struct batman_if *batman_if)
|
|
|
+static void hardif_deactivate_interface(struct batman_if *batman_if)
|
|
|
{
|
|
|
- if (batman_if->if_active != IF_ACTIVE)
|
|
|
+ if ((batman_if->if_status != IF_ACTIVE) &&
|
|
|
+ (batman_if->if_status != IF_TO_BE_ACTIVATED))
|
|
|
return;
|
|
|
|
|
|
- /**
|
|
|
- * batman_if->net_dev has been acquired by dev_get_by_name() in
|
|
|
- * proc_interfaces_write() and has to be unreferenced.
|
|
|
- */
|
|
|
-
|
|
|
- if (batman_if->net_dev)
|
|
|
- dev_put(batman_if->net_dev);
|
|
|
+ dev_put(batman_if->net_dev);
|
|
|
|
|
|
- batman_if->if_active = IF_INACTIVE;
|
|
|
- active_ifs--;
|
|
|
+ batman_if->if_status = IF_INACTIVE;
|
|
|
|
|
|
printk(KERN_INFO "batman-adv:Interface deactivated: %s\n",
|
|
|
- batman_if->dev);
|
|
|
+ batman_if->dev);
|
|
|
+
|
|
|
+ update_min_mtu();
|
|
|
}
|
|
|
|
|
|
-/* (re)activate given interface. */
|
|
|
-static void hardif_activate_interface(struct batman_if *batman_if)
|
|
|
+int hardif_enable_interface(struct batman_if *batman_if)
|
|
|
{
|
|
|
- if (batman_if->if_active != IF_INACTIVE)
|
|
|
- return;
|
|
|
-
|
|
|
-#ifdef __NET_NET_NAMESPACE_H
|
|
|
- batman_if->net_dev = dev_get_by_name(&init_net, batman_if->dev);
|
|
|
-#else
|
|
|
- batman_if->net_dev = dev_get_by_name(batman_if->dev);
|
|
|
-#endif
|
|
|
- if (!batman_if->net_dev)
|
|
|
- goto dev_err;
|
|
|
+ /* FIXME: each batman_if will be attached to a softif */
|
|
|
+ struct bat_priv *bat_priv = netdev_priv(soft_device);
|
|
|
+ struct batman_packet *batman_packet;
|
|
|
|
|
|
- check_known_mac_addr(batman_if->net_dev->dev_addr);
|
|
|
+ if (batman_if->if_status != IF_NOT_IN_USE)
|
|
|
+ goto out;
|
|
|
|
|
|
- addr_to_string(batman_if->addr_str, batman_if->net_dev->dev_addr);
|
|
|
+ batman_if->packet_len = BAT_PACKET_LEN;
|
|
|
+ batman_if->packet_buff = kmalloc(batman_if->packet_len, GFP_ATOMIC);
|
|
|
|
|
|
- memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig,
|
|
|
- batman_if->net_dev->dev_addr, ETH_ALEN);
|
|
|
- memcpy(((struct batman_packet *)(batman_if->packet_buff))->prev_sender,
|
|
|
- batman_if->net_dev->dev_addr, ETH_ALEN);
|
|
|
+ if (!batman_if->packet_buff) {
|
|
|
+ printk(KERN_ERR "batman-adv:Can't add interface packet (%s): out of memory\n",
|
|
|
+ batman_if->dev);
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
|
|
|
- batman_if->if_active = IF_TO_BE_ACTIVATED;
|
|
|
- active_ifs++;
|
|
|
+ batman_packet = (struct batman_packet *)(batman_if->packet_buff);
|
|
|
+ batman_packet->packet_type = BAT_PACKET;
|
|
|
+ batman_packet->version = COMPAT_VERSION;
|
|
|
+ batman_packet->flags = 0;
|
|
|
+ batman_packet->ttl = 2;
|
|
|
+ batman_packet->tq = TQ_MAX_VALUE;
|
|
|
+ batman_packet->num_hna = 0;
|
|
|
|
|
|
- /* save the mac address if it is our primary interface */
|
|
|
- if (batman_if->if_num == 0)
|
|
|
- set_main_if_addr(batman_if->net_dev->dev_addr);
|
|
|
+ batman_if->if_num = bat_priv->num_ifaces;
|
|
|
+ bat_priv->num_ifaces++;
|
|
|
+ batman_if->if_status = IF_INACTIVE;
|
|
|
+ orig_hash_add_if(batman_if, bat_priv->num_ifaces);
|
|
|
|
|
|
- printk(KERN_INFO "batman-adv:Interface activated: %s\n",
|
|
|
- batman_if->dev);
|
|
|
+ atomic_set(&batman_if->seqno, 1);
|
|
|
+ printk(KERN_INFO "batman-adv:Adding interface: %s\n", batman_if->dev);
|
|
|
|
|
|
- return;
|
|
|
+ if (hardif_is_iface_up(batman_if))
|
|
|
+ hardif_activate_interface(bat_priv, batman_if);
|
|
|
+ else
|
|
|
+ printk(KERN_ERR "batman-adv:Not using interface %s (retrying later): interface not active\n", batman_if->dev);
|
|
|
|
|
|
-dev_err:
|
|
|
- batman_if->net_dev = NULL;
|
|
|
-}
|
|
|
+ /* begin scheduling originator messages on that interface */
|
|
|
+ schedule_own_packet(batman_if);
|
|
|
|
|
|
-static void hardif_free_interface(struct rcu_head *rcu)
|
|
|
-{
|
|
|
- struct batman_if *batman_if = container_of(rcu, struct batman_if, rcu);
|
|
|
+out:
|
|
|
+ return 0;
|
|
|
|
|
|
- kfree(batman_if->packet_buff);
|
|
|
- kfree(batman_if->dev);
|
|
|
- kfree(batman_if);
|
|
|
+err:
|
|
|
+ return -ENOMEM;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * called by
|
|
|
- * - echo '' > /proc/.../interfaces
|
|
|
- * - modprobe -r batman-adv-core
|
|
|
- */
|
|
|
-/* removes and frees all interfaces */
|
|
|
-void hardif_remove_interfaces(void)
|
|
|
+void hardif_disable_interface(struct batman_if *batman_if)
|
|
|
{
|
|
|
- struct batman_if *batman_if = NULL;
|
|
|
-
|
|
|
- avail_ifs = 0;
|
|
|
-
|
|
|
- /* no lock needed - we don't delete somewhere else */
|
|
|
- list_for_each_entry(batman_if, &if_list, list) {
|
|
|
-
|
|
|
- list_del_rcu(&batman_if->list);
|
|
|
+ /* FIXME: each batman_if will be attached to a softif */
|
|
|
+ struct bat_priv *bat_priv = netdev_priv(soft_device);
|
|
|
|
|
|
- /* first deactivate interface */
|
|
|
- if (batman_if->if_active != IF_INACTIVE)
|
|
|
- hardif_deactivate_interface(batman_if);
|
|
|
-
|
|
|
- call_rcu(&batman_if->rcu, hardif_free_interface);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static int resize_orig(struct orig_node *orig_node, int if_num)
|
|
|
-{
|
|
|
- void *data_ptr;
|
|
|
+ if (batman_if->if_status == IF_ACTIVE)
|
|
|
+ hardif_deactivate_interface(batman_if);
|
|
|
|
|
|
- data_ptr = kmalloc((if_num + 1) * sizeof(TYPE_OF_WORD) * NUM_WORDS,
|
|
|
- GFP_ATOMIC);
|
|
|
- if (!data_ptr) {
|
|
|
- printk(KERN_ERR "batman-adv:Can't resize orig: out of memory\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ if (batman_if->if_status != IF_INACTIVE)
|
|
|
+ return;
|
|
|
|
|
|
- memcpy(data_ptr, orig_node->bcast_own,
|
|
|
- if_num * sizeof(TYPE_OF_WORD) * NUM_WORDS);
|
|
|
- kfree(orig_node->bcast_own);
|
|
|
- orig_node->bcast_own = data_ptr;
|
|
|
+ printk(KERN_INFO "batman-adv:Removing interface: %s\n", batman_if->dev);
|
|
|
+ bat_priv->num_ifaces--;
|
|
|
+ orig_hash_del_if(batman_if, bat_priv->num_ifaces);
|
|
|
|
|
|
- data_ptr = kmalloc((if_num + 1) * sizeof(uint8_t), GFP_ATOMIC);
|
|
|
- if (!data_ptr) {
|
|
|
- printk(KERN_ERR "batman-adv:Can't resize orig: out of memory\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ if (batman_if == bat_priv->primary_if)
|
|
|
+ set_primary_if(bat_priv, get_active_batman_if());
|
|
|
|
|
|
- memcpy(data_ptr, orig_node->bcast_own_sum, if_num * sizeof(uint8_t));
|
|
|
- kfree(orig_node->bcast_own_sum);
|
|
|
- orig_node->bcast_own_sum = data_ptr;
|
|
|
+ kfree(batman_if->packet_buff);
|
|
|
+ batman_if->packet_buff = NULL;
|
|
|
+ batman_if->if_status = IF_NOT_IN_USE;
|
|
|
|
|
|
- return 0;
|
|
|
+ if ((atomic_read(&module_state) == MODULE_ACTIVE) &&
|
|
|
+ (bat_priv->num_ifaces == 0))
|
|
|
+ deactivate_module();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-/* adds an interface the interface list and activate it, if possible */
|
|
|
-int hardif_add_interface(char *dev, int if_num)
|
|
|
+static struct batman_if *hardif_add_interface(struct net_device *net_dev)
|
|
|
{
|
|
|
struct batman_if *batman_if;
|
|
|
- struct batman_packet *batman_packet;
|
|
|
- struct orig_node *orig_node;
|
|
|
- unsigned long flags;
|
|
|
- HASHIT(hashit);
|
|
|
+ int ret;
|
|
|
|
|
|
- batman_if = kmalloc(sizeof(struct batman_if), GFP_KERNEL);
|
|
|
+ ret = is_valid_iface(net_dev);
|
|
|
+ if (ret != 1)
|
|
|
+ goto out;
|
|
|
|
|
|
+ batman_if = kmalloc(sizeof(struct batman_if), GFP_ATOMIC);
|
|
|
if (!batman_if) {
|
|
|
- printk(KERN_ERR "batman-adv:Can't add interface (%s): out of memory\n", dev);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- batman_if->net_dev = NULL;
|
|
|
-
|
|
|
- if ((if_num == 0) && (num_hna > 0))
|
|
|
- batman_if->packet_len = BAT_PACKET_LEN + num_hna * ETH_ALEN;
|
|
|
- else
|
|
|
- batman_if->packet_len = BAT_PACKET_LEN;
|
|
|
-
|
|
|
- batman_if->packet_buff = kmalloc(batman_if->packet_len, GFP_KERNEL);
|
|
|
-
|
|
|
- if (!batman_if->packet_buff) {
|
|
|
- printk(KERN_ERR "batman-adv:Can't add interface packet (%s): out of memory\n", dev);
|
|
|
+ printk(KERN_ERR "batman-adv:Can't add interface (%s): out of memory\n",
|
|
|
+ net_dev->name);
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
|
- batman_if->if_num = if_num;
|
|
|
- batman_if->dev = dev;
|
|
|
- batman_if->if_active = IF_INACTIVE;
|
|
|
- INIT_RCU_HEAD(&batman_if->rcu);
|
|
|
+ batman_if->dev = kstrdup(net_dev->name, GFP_ATOMIC);
|
|
|
+ if (!batman_if->dev)
|
|
|
+ goto free_if;
|
|
|
|
|
|
- printk(KERN_INFO "batman-adv:Adding interface: %s\n", dev);
|
|
|
- avail_ifs++;
|
|
|
+ ret = sysfs_add_hardif(&batman_if->hardif_obj, net_dev);
|
|
|
+ if (ret)
|
|
|
+ goto free_dev;
|
|
|
|
|
|
+ batman_if->if_num = -1;
|
|
|
+ batman_if->net_dev = net_dev;
|
|
|
+ batman_if->if_status = IF_NOT_IN_USE;
|
|
|
+ INIT_RCU_HEAD(&batman_if->rcu);
|
|
|
INIT_LIST_HEAD(&batman_if->list);
|
|
|
|
|
|
- batman_packet = (struct batman_packet *)(batman_if->packet_buff);
|
|
|
- batman_packet->packet_type = BAT_PACKET;
|
|
|
- batman_packet->version = COMPAT_VERSION;
|
|
|
- batman_packet->flags = 0x00;
|
|
|
- batman_packet->ttl = (batman_if->if_num > 0 ? 2 : TTL);
|
|
|
- batman_packet->flags = 0;
|
|
|
- batman_packet->tq = TQ_MAX_VALUE;
|
|
|
- batman_packet->num_hna = 0;
|
|
|
-
|
|
|
- if (batman_if->packet_len != BAT_PACKET_LEN) {
|
|
|
- unsigned char *hna_buff;
|
|
|
- int hna_len;
|
|
|
-
|
|
|
- hna_buff = batman_if->packet_buff + BAT_PACKET_LEN;
|
|
|
- hna_len = batman_if->packet_len - BAT_PACKET_LEN;
|
|
|
- batman_packet->num_hna = hna_local_fill_buffer(hna_buff,
|
|
|
- hna_len);
|
|
|
- }
|
|
|
-
|
|
|
- atomic_set(&batman_if->seqno, 1);
|
|
|
+ check_known_mac_addr(batman_if->net_dev->dev_addr);
|
|
|
+ list_add_tail_rcu(&batman_if->list, &if_list);
|
|
|
+ return batman_if;
|
|
|
|
|
|
- /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
|
|
|
- * if_num */
|
|
|
- spin_lock_irqsave(&orig_hash_lock, flags);
|
|
|
+free_dev:
|
|
|
+ kfree(batman_if->dev);
|
|
|
+free_if:
|
|
|
+ kfree(batman_if);
|
|
|
+out:
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
|
|
|
- while (hash_iterate(orig_hash, &hashit)) {
|
|
|
- orig_node = hashit.bucket->data;
|
|
|
- if (resize_orig(orig_node, if_num) == -1) {
|
|
|
- spin_unlock_irqrestore(&orig_hash_lock, flags);
|
|
|
- goto out;
|
|
|
- }
|
|
|
- }
|
|
|
+static void hardif_free_interface(struct rcu_head *rcu)
|
|
|
+{
|
|
|
+ struct batman_if *batman_if = container_of(rcu, struct batman_if, rcu);
|
|
|
|
|
|
- spin_unlock_irqrestore(&orig_hash_lock, flags);
|
|
|
+ /* delete all references to this batman_if */
|
|
|
+ purge_orig(NULL);
|
|
|
+ purge_outstanding_packets(batman_if);
|
|
|
|
|
|
- if (!hardif_is_interface_up(batman_if->dev))
|
|
|
- printk(KERN_ERR "batman-adv:Not using interface %s (retrying later): interface not active\n", batman_if->dev);
|
|
|
- else
|
|
|
- hardif_activate_interface(batman_if);
|
|
|
+ kfree(batman_if->dev);
|
|
|
+ kfree(batman_if);
|
|
|
+}
|
|
|
|
|
|
- list_add_tail_rcu(&batman_if->list, &if_list);
|
|
|
+static void hardif_remove_interface(struct batman_if *batman_if)
|
|
|
+{
|
|
|
+ /* first deactivate interface */
|
|
|
+ if (batman_if->if_status != IF_NOT_IN_USE)
|
|
|
+ hardif_disable_interface(batman_if);
|
|
|
|
|
|
- /* begin sending originator messages on that interface */
|
|
|
- schedule_own_packet(batman_if);
|
|
|
- return 1;
|
|
|
+ if (batman_if->if_status != IF_NOT_IN_USE)
|
|
|
+ return;
|
|
|
|
|
|
-out:
|
|
|
- kfree(batman_if->packet_buff);
|
|
|
- kfree(batman_if);
|
|
|
- kfree(dev);
|
|
|
- return -1;
|
|
|
+ batman_if->if_status = IF_TO_BE_REMOVED;
|
|
|
+ list_del_rcu(&batman_if->list);
|
|
|
+ sysfs_del_hardif(&batman_if->hardif_obj);
|
|
|
+ call_rcu(&batman_if->rcu, hardif_free_interface);
|
|
|
}
|
|
|
|
|
|
-char hardif_get_active_if_num(void)
|
|
|
+void hardif_remove_interfaces(void)
|
|
|
{
|
|
|
- return active_ifs;
|
|
|
+ struct batman_if *batman_if, *batman_if_tmp;
|
|
|
+
|
|
|
+ list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list)
|
|
|
+ hardif_remove_interface(batman_if);
|
|
|
}
|
|
|
|
|
|
static int hard_if_event(struct notifier_block *this,
|
|
|
- unsigned long event, void *ptr)
|
|
|
+ unsigned long event, void *ptr)
|
|
|
{
|
|
|
- struct net_device *dev = (struct net_device *)ptr;
|
|
|
- struct batman_if *batman_if = get_batman_if_by_name(dev->name);
|
|
|
+ struct net_device *net_dev = (struct net_device *)ptr;
|
|
|
+ struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
|
|
|
+ /* FIXME: each batman_if will be attached to a softif */
|
|
|
+ struct bat_priv *bat_priv = netdev_priv(soft_device);
|
|
|
+
|
|
|
+ if (!batman_if)
|
|
|
+ batman_if = hardif_add_interface(net_dev);
|
|
|
|
|
|
if (!batman_if)
|
|
|
goto out;
|
|
|
|
|
|
switch (event) {
|
|
|
+ case NETDEV_REGISTER:
|
|
|
+ break;
|
|
|
+ case NETDEV_UP:
|
|
|
+ hardif_activate_interface(bat_priv, batman_if);
|
|
|
+ break;
|
|
|
case NETDEV_GOING_DOWN:
|
|
|
case NETDEV_DOWN:
|
|
|
- case NETDEV_UNREGISTER:
|
|
|
hardif_deactivate_interface(batman_if);
|
|
|
break;
|
|
|
- case NETDEV_UP:
|
|
|
- hardif_activate_interface(batman_if);
|
|
|
- if ((atomic_read(&module_state) == MODULE_INACTIVE) &&
|
|
|
- (hardif_get_active_if_num() > 0)) {
|
|
|
- activate_module();
|
|
|
- }
|
|
|
+ case NETDEV_UNREGISTER:
|
|
|
+ hardif_remove_interface(batman_if);
|
|
|
+ break;
|
|
|
+ case NETDEV_CHANGENAME:
|
|
|
+ break;
|
|
|
+ case NETDEV_CHANGEADDR:
|
|
|
+ check_known_mac_addr(batman_if->net_dev->dev_addr);
|
|
|
+ update_mac_addresses(batman_if);
|
|
|
+ if (batman_if == bat_priv->primary_if)
|
|
|
+ set_primary_if(bat_priv, batman_if);
|
|
|
break;
|
|
|
- /* NETDEV_CHANGEADDR - mac address change - what are we doing here ? */
|
|
|
default:
|
|
|
break;
|
|
|
};
|
|
|
|
|
|
- update_min_mtu();
|
|
|
-
|
|
|
out:
|
|
|
return NOTIFY_DONE;
|
|
|
}
|
|
|
|
|
|
-/* find batman interface by netdev. assumes rcu_read_lock on */
|
|
|
-static struct batman_if *find_batman_if(struct net_device *dev)
|
|
|
-{
|
|
|
- struct batman_if *batman_if;
|
|
|
-
|
|
|
- rcu_read_lock();
|
|
|
- list_for_each_entry_rcu(batman_if, &if_list, list) {
|
|
|
- if (batman_if->net_dev == dev) {
|
|
|
- rcu_read_unlock();
|
|
|
- return batman_if;
|
|
|
- }
|
|
|
- }
|
|
|
- rcu_read_unlock();
|
|
|
- return NULL;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
/* receive a packet with the batman ethertype coming on a hard
|
|
|
* interface */
|
|
|
int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
|
|
@@ -444,12 +453,12 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
|
|
|
|| !skb_mac_header(skb)))
|
|
|
goto err_free;
|
|
|
|
|
|
- batman_if = find_batman_if(skb->dev);
|
|
|
+ batman_if = get_batman_if_by_netdev(skb->dev);
|
|
|
if (!batman_if)
|
|
|
goto err_free;
|
|
|
|
|
|
/* discard frames on not active interfaces */
|
|
|
- if (batman_if->if_active != IF_ACTIVE)
|
|
|
+ if (batman_if->if_status != IF_ACTIVE)
|
|
|
goto err_free;
|
|
|
|
|
|
stats = (struct net_device_stats *)dev_get_stats(skb->dev);
|