[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit eac56465b88cc9ad3b964a9f0a02be3d3a136ddf
Merge: 1b9c4134c126aa8ae00a57672d4a4eaecc436b54 43676ab590c3f8686fd047d34c3e33803eef71f0
Author: David S. Miller <davem(a)davemloft.net>
Date: Mon Jun 20 12:59:37 2011 -0700
Merge branch 'batman-adv/next' of git://git.open-mesh.org/ecsv/linux-merge
diff --combined net/batman-adv/hard-interface.c
index abb4901,55b5def..db7aacf
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@@ -152,12 -152,6 +152,6 @@@ static void primary_if_select(struct ba
batman_packet->ttl = TTL;
primary_if_update_addr(bat_priv);
-
- /***
- * hacky trick to make sure that we send the TT information via
- * our new primary interface
- */
- atomic_set(&bat_priv->tt_local_changed, 1);
}
static bool hardif_is_iface_up(const struct hard_iface *hard_iface)
@@@ -340,7 -334,8 +334,8 @@@ int hardif_enable_interface(struct hard
batman_packet->flags = NO_FLAGS;
batman_packet->ttl = 2;
batman_packet->tq = TQ_MAX_VALUE;
- batman_packet->num_tt = 0;
+ batman_packet->tt_num_changes = 0;
+ batman_packet->ttvn = 0;
hard_iface->if_num = bat_priv->num_ifaces;
bat_priv->num_ifaces++;
@@@ -568,7 -563,7 +563,7 @@@ static int hard_if_event(struct notifie
break;
default:
break;
- };
+ }
hardif_put:
hardif_free_ref(hard_iface);
@@@ -659,6 -654,14 +654,14 @@@ static int batman_skb_recv(struct sk_bu
case BAT_VIS:
ret = recv_vis_packet(skb, hard_iface);
break;
+ /* Translation table query (request or response) */
+ case BAT_TT_QUERY:
+ ret = recv_tt_query(skb, hard_iface);
+ break;
+ /* Roaming advertisement */
+ case BAT_ROAM_ADV:
+ ret = recv_roam_adv(skb, hard_iface);
+ break;
default:
ret = NET_RX_DROP;
}
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit 43676ab590c3f8686fd047d34c3e33803eef71f0
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Tue Apr 26 21:31:45 2011 +0200
batman-adv: improved gateway tq-based selection
If a client issues a DHCPREQUEST for renewal, the packet is dropped
if the old destination (the old gateway for the client) TQ is smaller
than the current best gateway TQ less GW_THRESHOLD
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 6381864..8b25b52 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -25,11 +25,17 @@
#include "gateway_common.h"
#include "hard-interface.h"
#include "originator.h"
+#include "routing.h"
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <linux/if_vlan.h>
+/* This is the offset of the options field in a dhcp packet starting at
+ * the beginning of the dhcp header */
+#define DHCP_OPTIONS_OFFSET 240
+#define DHCP_REQUEST 3
+
static void gw_node_free_ref(struct gw_node *gw_node)
{
if (atomic_dec_and_test(&gw_node->refcount))
@@ -509,14 +515,75 @@ out:
return ret;
}
-int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb)
+static bool is_type_dhcprequest(struct sk_buff *skb, int header_len)
+{
+ int ret = false;
+ unsigned char *p;
+ int pkt_len;
+
+ if (skb_linearize(skb) < 0)
+ goto out;
+
+ pkt_len = skb_headlen(skb);
+
+ if (pkt_len < header_len + DHCP_OPTIONS_OFFSET + 1)
+ goto out;
+
+ p = skb->data + header_len + DHCP_OPTIONS_OFFSET;
+ pkt_len -= header_len + DHCP_OPTIONS_OFFSET + 1;
+
+ /* Access the dhcp option lists. Each entry is made up by:
+ * - octect 1: option type
+ * - octect 2: option data len (only if type != 255 and 0)
+ * - octect 3: option data */
+ while (*p != 255 && !ret) {
+ /* p now points to the first octect: option type */
+ if (*p == 53) {
+ /* type 53 is the message type option.
+ * Jump the len octect and go to the data octect */
+ if (pkt_len < 2)
+ goto out;
+ p += 2;
+
+ /* check if the message type is what we need */
+ if (*p == DHCP_REQUEST)
+ ret = true;
+ break;
+ } else if (*p == 0) {
+ /* option type 0 (padding), just go forward */
+ if (pkt_len < 1)
+ goto out;
+ pkt_len--;
+ p++;
+ } else {
+ /* This is any other option. So we get the length... */
+ if (pkt_len < 1)
+ goto out;
+ pkt_len--;
+ p++;
+
+ /* ...and then we jump over the data */
+ if (pkt_len < *p)
+ goto out;
+ pkt_len -= *p;
+ p += (*p);
+ }
+ }
+out:
+ return ret;
+}
+
+int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb,
+ struct orig_node *old_gw)
{
struct ethhdr *ethhdr;
struct iphdr *iphdr;
struct ipv6hdr *ipv6hdr;
struct udphdr *udphdr;
struct gw_node *curr_gw;
+ struct neigh_node *neigh_curr = NULL, *neigh_old = NULL;
unsigned int header_len = 0;
+ int ret = 1;
if (atomic_read(&bat_priv->gw_mode) == GW_MODE_OFF)
return 0;
@@ -584,7 +651,30 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb)
if (!curr_gw)
return 0;
+ /* If old_gw != NULL then this packet is unicast.
+ * So, at this point we have to check the message type: if it is a
+ * DHCPREQUEST we have to decide whether to drop it or not */
+ if (old_gw && curr_gw->orig_node != old_gw) {
+ if (is_type_dhcprequest(skb, header_len)) {
+ /* If the dhcp packet has been sent to a different gw,
+ * we have to evaluate whether the old gw is still
+ * reliable enough */
+ neigh_curr = find_router(bat_priv, curr_gw->orig_node,
+ NULL);
+ neigh_old = find_router(bat_priv, old_gw, NULL);
+ if (!neigh_curr || !neigh_old)
+ goto free_neigh;
+ if (neigh_curr->tq_avg - neigh_old->tq_avg <
+ GW_THRESHOLD)
+ ret = -1;
+ }
+ }
+free_neigh:
+ if (neigh_old)
+ neigh_node_free_ref(neigh_old);
+ if (neigh_curr)
+ neigh_node_free_ref(neigh_curr);
if (curr_gw)
gw_node_free_ref(curr_gw);
- return 1;
+ return ret;
}
diff --git a/net/batman-adv/gateway_client.h b/net/batman-adv/gateway_client.h
index 1ce8c60..b9b983c 100644
--- a/net/batman-adv/gateway_client.h
+++ b/net/batman-adv/gateway_client.h
@@ -31,6 +31,7 @@ void gw_node_update(struct bat_priv *bat_priv,
void gw_node_delete(struct bat_priv *bat_priv, struct orig_node *orig_node);
void gw_node_purge(struct bat_priv *bat_priv);
int gw_client_seq_print_text(struct seq_file *seq, void *offset);
-int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb);
+int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb,
+ struct orig_node *old_gw);
#endif /* _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ */
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index f9e0e17..4f293b5 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -91,7 +91,6 @@ enum mesh_state {
#define BCAST_QUEUE_LEN 256
#define BATMAN_QUEUE_LEN 256
-
enum uev_action {
UEV_ADD = 0,
UEV_DEL,
@@ -102,6 +101,8 @@ enum uev_type {
UEV_GW = 0
};
+#define GW_THRESHOLD 50
+
/*
* Debug Messages
*/
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 3371ece..2dcdbb7 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -30,6 +30,7 @@
#include "gateway_common.h"
#include "gateway_client.h"
#include "bat_sysfs.h"
+#include "originator.h"
#include <linux/slab.h>
#include <linux/ethtool.h>
#include <linux/etherdevice.h>
@@ -561,6 +562,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
struct bcast_packet *bcast_packet;
struct vlan_ethhdr *vhdr;
struct softif_neigh *curr_softif_neigh = NULL;
+ struct orig_node *orig_node = NULL;
int data_len = skb->len, ret;
short vid = -1;
bool do_bcast = false;
@@ -595,8 +597,10 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
/* Register the client MAC in the transtable */
tt_local_add(soft_iface, ethhdr->h_source);
- if (is_multicast_ether_addr(ethhdr->h_dest)) {
- ret = gw_is_target(bat_priv, skb);
+ orig_node = transtable_search(bat_priv, ethhdr->h_dest);
+ if (is_multicast_ether_addr(ethhdr->h_dest) ||
+ (orig_node && orig_node->gw_flags)) {
+ ret = gw_is_target(bat_priv, skb, orig_node);
if (ret < 0)
goto dropped;
@@ -656,6 +660,8 @@ end:
softif_neigh_free_ref(curr_softif_neigh);
if (primary_if)
hardif_free_ref(primary_if);
+ if (orig_node)
+ orig_node_free_ref(orig_node);
return NETDEV_TX_OK;
}
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit 19595e054d35820e026caac314414e435287e3ae
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Sun Jun 12 11:58:58 2011 +0200
batman-adv: throw uevent in userspace on gateway add/change/del event
In case of new default gw, changing the default gw or deleting the default gw a
uevent is triggered with type=gw, action=add/change/del and
data={GW_ORIG_ADDRESS} (if any).
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 0350c0c..6381864 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -179,6 +179,7 @@ void gw_election(struct bat_priv *bat_priv)
{
struct gw_node *curr_gw = NULL, *next_gw = NULL;
struct neigh_node *router = NULL;
+ char gw_addr[18] = { '\0' };
/**
* The batman daemon checks here if we already passed a full originator
@@ -200,6 +201,8 @@ void gw_election(struct bat_priv *bat_priv)
goto out;
if (next_gw) {
+ sprintf(gw_addr, "%pM", next_gw->orig_node->orig);
+
router = orig_node_get_router(next_gw->orig_node);
if (!router) {
gw_deselect(bat_priv);
@@ -210,12 +213,14 @@ void gw_election(struct bat_priv *bat_priv)
if ((curr_gw) && (!next_gw)) {
bat_dbg(DBG_BATMAN, bat_priv,
"Removing selected gateway - no gateway in range\n");
+ throw_uevent(bat_priv, UEV_GW, UEV_DEL, NULL);
} else if ((!curr_gw) && (next_gw)) {
bat_dbg(DBG_BATMAN, bat_priv,
"Adding route to gateway %pM (gw_flags: %i, tq: %i)\n",
next_gw->orig_node->orig,
next_gw->orig_node->gw_flags,
router->tq_avg);
+ throw_uevent(bat_priv, UEV_GW, UEV_ADD, gw_addr);
} else {
bat_dbg(DBG_BATMAN, bat_priv,
"Changing route to gateway %pM "
@@ -223,6 +228,7 @@ void gw_election(struct bat_priv *bat_priv)
next_gw->orig_node->orig,
next_gw->orig_node->gw_flags,
router->tq_avg);
+ throw_uevent(bat_priv, UEV_GW, UEV_CHANGE, gw_addr);
}
gw_select(bat_priv, next_gw);
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit c6bda689c2c94788e1e567463ce861d1f135857f
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Tue Apr 26 18:26:01 2011 +0200
batman-adv: add wrapper function to throw uevent in userspace
Using throw_uevent() is now possible to trigger uevent signal that can
be recognised in userspace. Uevents will be triggered through the
/devices/virtual/net/{MESH_IFACE} kobject.
A triggered uevent has three properties:
- type: the event class. Who generates the event (only 'gw' is currently
defined). Corresponds to the BATTYPE uevent variable.
- action: the associated action with the event ('add'/'change'/'del' are
currently defined). Corresponds to the BATACTION uevent variable.
- data: any useful data for the userspace. Corresponds to the BATDATA
uevent variable.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/bat_sysfs.c b/net/batman-adv/bat_sysfs.c
index 63738ec..cd15deb 100644
--- a/net/batman-adv/bat_sysfs.c
+++ b/net/batman-adv/bat_sysfs.c
@@ -40,6 +40,20 @@ static struct bat_priv *kobj_to_batpriv(struct kobject *obj)
return netdev_priv(net_dev);
}
+#define UEV_TYPE_VAR "BATTYPE="
+#define UEV_ACTION_VAR "BATACTION="
+#define UEV_DATA_VAR "BATDATA="
+
+static char *uev_action_str[] = {
+ "add",
+ "del",
+ "change"
+};
+
+static char *uev_type_str[] = {
+ "gw"
+};
+
/* Use this, if you have customized show and store functions */
#define BAT_ATTR(_name, _mode, _show, _store) \
struct bat_attribute bat_attr_##_name = { \
@@ -601,3 +615,60 @@ void sysfs_del_hardif(struct kobject **hardif_obj)
kobject_put(*hardif_obj);
*hardif_obj = NULL;
}
+
+int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
+ enum uev_action action, const char *data)
+{
+ int ret = -1;
+ struct hard_iface *primary_if = NULL;
+ struct kobject *bat_kobj;
+ char *uevent_env[4] = { NULL, NULL, NULL, NULL };
+
+ primary_if = primary_if_get_selected(bat_priv);
+ if (!primary_if)
+ goto out;
+
+ bat_kobj = &primary_if->soft_iface->dev.kobj;
+
+ uevent_env[0] = kmalloc(strlen(UEV_TYPE_VAR) +
+ strlen(uev_type_str[type]) + 1,
+ GFP_ATOMIC);
+ if (!uevent_env[0])
+ goto out;
+
+ sprintf(uevent_env[0], "%s%s", UEV_TYPE_VAR, uev_type_str[type]);
+
+ uevent_env[1] = kmalloc(strlen(UEV_ACTION_VAR) +
+ strlen(uev_action_str[action]) + 1,
+ GFP_ATOMIC);
+ if (!uevent_env[1])
+ goto out;
+
+ sprintf(uevent_env[1], "%s%s", UEV_ACTION_VAR, uev_action_str[action]);
+
+ /* If the event is DEL, ignore the data field */
+ if (action != UEV_DEL) {
+ uevent_env[2] = kmalloc(strlen(UEV_DATA_VAR) +
+ strlen(data) + 1, GFP_ATOMIC);
+ if (!uevent_env[2])
+ goto out;
+
+ sprintf(uevent_env[2], "%s%s", UEV_DATA_VAR, data);
+ }
+
+ ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
+out:
+ kfree(uevent_env[0]);
+ kfree(uevent_env[1]);
+ kfree(uevent_env[2]);
+
+ if (primary_if)
+ hardif_free_ref(primary_if);
+
+ if (ret)
+ bat_dbg(DBG_BATMAN, bat_priv, "Impossible to send "
+ "uevent for (%s,%s,%s) event (err: %d)\n",
+ uev_type_str[type], uev_action_str[action],
+ (action == UEV_DEL ? "NULL" : data), ret);
+ return ret;
+}
diff --git a/net/batman-adv/bat_sysfs.h b/net/batman-adv/bat_sysfs.h
index 02f1fa7..a3f75a7 100644
--- a/net/batman-adv/bat_sysfs.h
+++ b/net/batman-adv/bat_sysfs.h
@@ -38,5 +38,7 @@ int sysfs_add_meshif(struct net_device *dev);
void sysfs_del_meshif(struct net_device *dev);
int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev);
void sysfs_del_hardif(struct kobject **hardif_obj);
+int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
+ enum uev_action action, const char *data);
#endif /* _NET_BATMAN_ADV_SYSFS_H_ */
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 8eae05e..f9e0e17 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -91,6 +91,17 @@ enum mesh_state {
#define BCAST_QUEUE_LEN 256
#define BATMAN_QUEUE_LEN 256
+
+enum uev_action {
+ UEV_ADD = 0,
+ UEV_DEL,
+ UEV_CHANGE
+};
+
+enum uev_type {
+ UEV_GW = 0
+};
+
/*
* Debug Messages
*/
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit 7683fdc1e88644ee8108a1f33faba80545f0024d
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Wed Apr 27 14:28:07 2011 +0200
batman-adv: protect the local and the global trans-tables with rcu
The local and the global translation-tables are now lock free and rcu
protected.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Acked-by: Simon Wunderlich <siwu(a)hrz.tu-chemnitz.de>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 3318ee2..c2b06b7 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -84,8 +84,6 @@ int mesh_init(struct net_device *soft_iface)
spin_lock_init(&bat_priv->forw_bat_list_lock);
spin_lock_init(&bat_priv->forw_bcast_list_lock);
- spin_lock_init(&bat_priv->tt_lhash_lock);
- spin_lock_init(&bat_priv->tt_ghash_lock);
spin_lock_init(&bat_priv->tt_changes_list_lock);
spin_lock_init(&bat_priv->tt_req_list_lock);
spin_lock_init(&bat_priv->tt_roam_list_lock);
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 05d50ca..0ce090c 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -90,9 +90,7 @@ static void update_transtable(struct bat_priv *bat_priv,
/* Even if we received the crc into the OGM, we prefer
* to recompute it to spot any possible inconsistency
* in the global table */
- spin_lock_bh(&bat_priv->tt_ghash_lock);
orig_node->tt_crc = tt_global_crc(bat_priv, orig_node);
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
/* Roaming phase is over: tables are in sync again. I can
* unset the flag */
orig_node->tt_poss_change = false;
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index d516d85..5f1fcd5 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -80,6 +80,9 @@ static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv,
if (!compare_eth(tt_local_entry, data))
continue;
+ if (!atomic_inc_not_zero(&tt_local_entry->refcount))
+ continue;
+
tt_local_entry_tmp = tt_local_entry;
break;
}
@@ -109,6 +112,9 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv,
if (!compare_eth(tt_global_entry, data))
continue;
+ if (!atomic_inc_not_zero(&tt_global_entry->refcount))
+ continue;
+
tt_global_entry_tmp = tt_global_entry;
break;
}
@@ -125,8 +131,20 @@ static bool is_out_of_time(unsigned long starting_time, unsigned long timeout)
return time_after(jiffies, deadline);
}
+static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry)
+{
+ if (atomic_dec_and_test(&tt_local_entry->refcount))
+ kfree_rcu(tt_local_entry, rcu);
+}
+
+static void tt_global_entry_free_ref(struct tt_global_entry *tt_global_entry)
+{
+ if (atomic_dec_and_test(&tt_global_entry->refcount))
+ kfree_rcu(tt_global_entry, rcu);
+}
+
static void tt_local_event(struct bat_priv *bat_priv, uint8_t op,
- const uint8_t *addr, uint8_t roaming)
+ const uint8_t *addr, bool roaming)
{
struct tt_change_node *tt_change_node;
@@ -171,21 +189,19 @@ static int tt_local_init(struct bat_priv *bat_priv)
void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
{
struct bat_priv *bat_priv = netdev_priv(soft_iface);
- struct tt_local_entry *tt_local_entry;
- struct tt_global_entry *tt_global_entry;
- uint8_t roam_addr[ETH_ALEN];
+ struct tt_local_entry *tt_local_entry = NULL;
+ struct tt_global_entry *tt_global_entry = NULL;
- spin_lock_bh(&bat_priv->tt_lhash_lock);
tt_local_entry = tt_local_hash_find(bat_priv, addr);
if (tt_local_entry) {
tt_local_entry->last_seen = jiffies;
- goto unlock;
+ goto out;
}
tt_local_entry = kmalloc(sizeof(*tt_local_entry), GFP_ATOMIC);
if (!tt_local_entry)
- goto unlock;
+ goto out;
tt_local_event(bat_priv, NO_FLAGS, addr, false);
@@ -195,6 +211,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
memcpy(tt_local_entry->addr, addr, ETH_ALEN);
tt_local_entry->last_seen = jiffies;
+ atomic_set(&tt_local_entry->refcount, 2);
/* the batman interface mac address should never be purged */
if (compare_eth(addr, soft_iface->dev_addr))
@@ -204,30 +221,26 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig,
tt_local_entry, &tt_local_entry->hash_entry);
+
atomic_inc(&bat_priv->num_local_tt);
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
/* remove address from global hash if present */
- spin_lock_bh(&bat_priv->tt_ghash_lock);
-
tt_global_entry = tt_global_hash_find(bat_priv, addr);
/* Check whether it is a roaming! */
if (tt_global_entry) {
- memcpy(roam_addr, tt_global_entry->addr, ETH_ALEN);
/* This node is probably going to update its tt table */
tt_global_entry->orig_node->tt_poss_change = true;
_tt_global_del(bat_priv, tt_global_entry,
"local tt received");
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
send_roam_adv(bat_priv, tt_global_entry->addr,
- tt_global_entry->orig_node);
- } else
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
-
- return;
-unlock:
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
+ tt_global_entry->orig_node);
+ }
+out:
+ if (tt_local_entry)
+ tt_local_entry_free_ref(tt_local_entry);
+ if (tt_global_entry)
+ tt_global_entry_free_ref(tt_global_entry);
}
int tt_changes_fill_buffer(struct bat_priv *bat_priv,
@@ -309,8 +322,6 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset)
"announced via TT (TTVN: %u):\n",
net_dev->name, (uint8_t)atomic_read(&bat_priv->ttvn));
- spin_lock_bh(&bat_priv->tt_lhash_lock);
-
buf_size = 1;
/* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */
for (i = 0; i < hash->size; i++) {
@@ -324,7 +335,6 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset)
buff = kmalloc(buf_size, GFP_ATOMIC);
if (!buff) {
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
ret = -ENOMEM;
goto out;
}
@@ -344,8 +354,6 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset)
rcu_read_unlock();
}
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
-
seq_printf(seq, "%s", buff);
kfree(buff);
out:
@@ -354,15 +362,6 @@ out:
return ret;
}
-static void tt_local_entry_free(struct hlist_node *node, void *arg)
-{
- struct bat_priv *bat_priv = arg;
- void *data = container_of(node, struct tt_local_entry, hash_entry);
-
- kfree(data);
- atomic_dec(&bat_priv->num_local_tt);
-}
-
static void tt_local_del(struct bat_priv *bat_priv,
struct tt_local_entry *tt_local_entry,
const char *message)
@@ -375,23 +374,24 @@ static void tt_local_del(struct bat_priv *bat_priv,
hash_remove(bat_priv->tt_local_hash, compare_ltt, choose_orig,
tt_local_entry->addr);
- tt_local_entry_free(&tt_local_entry->hash_entry, bat_priv);
+ tt_local_entry_free_ref(tt_local_entry);
}
void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr,
const char *message, bool roaming)
{
- struct tt_local_entry *tt_local_entry;
+ struct tt_local_entry *tt_local_entry = NULL;
- spin_lock_bh(&bat_priv->tt_lhash_lock);
tt_local_entry = tt_local_hash_find(bat_priv, addr);
- if (tt_local_entry) {
- tt_local_event(bat_priv, TT_CHANGE_DEL, tt_local_entry->addr,
- roaming);
- tt_local_del(bat_priv, tt_local_entry, message);
- }
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
+ if (!tt_local_entry)
+ goto out;
+
+ tt_local_event(bat_priv, TT_CHANGE_DEL, tt_local_entry->addr, roaming);
+ tt_local_del(bat_priv, tt_local_entry, message);
+out:
+ if (tt_local_entry)
+ tt_local_entry_free_ref(tt_local_entry);
}
static void tt_local_purge(struct bat_priv *bat_priv)
@@ -400,40 +400,45 @@ static void tt_local_purge(struct bat_priv *bat_priv)
struct tt_local_entry *tt_local_entry;
struct hlist_node *node, *node_tmp;
struct hlist_head *head;
+ spinlock_t *list_lock; /* protects write access to the hash lists */
int i;
- spin_lock_bh(&bat_priv->tt_lhash_lock);
-
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+ spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_local_entry, node, node_tmp,
head, hash_entry) {
if (tt_local_entry->never_purge)
continue;
if (!is_out_of_time(tt_local_entry->last_seen,
- TT_LOCAL_TIMEOUT * 1000))
+ TT_LOCAL_TIMEOUT * 1000))
continue;
tt_local_event(bat_priv, TT_CHANGE_DEL,
tt_local_entry->addr, false);
- tt_local_del(bat_priv, tt_local_entry,
- "address timed out");
+ atomic_dec(&bat_priv->num_local_tt);
+ bat_dbg(DBG_TT, bat_priv, "Deleting local "
+ "tt entry (%pM): timed out\n",
+ tt_local_entry->addr);
+ hlist_del_rcu(node);
+ tt_local_entry_free_ref(tt_local_entry);
}
+ spin_unlock_bh(list_lock);
}
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
}
static void tt_local_table_free(struct bat_priv *bat_priv)
{
struct hashtable_t *hash;
- int i;
spinlock_t *list_lock; /* protects write access to the hash lists */
- struct hlist_head *head;
- struct hlist_node *node, *node_tmp;
struct tt_local_entry *tt_local_entry;
+ struct hlist_node *node, *node_tmp;
+ struct hlist_head *head;
+ int i;
if (!bat_priv->tt_local_hash)
return;
@@ -448,7 +453,7 @@ static void tt_local_table_free(struct bat_priv *bat_priv)
hlist_for_each_entry_safe(tt_local_entry, node, node_tmp,
head, hash_entry) {
hlist_del_rcu(node);
- kfree(tt_local_entry);
+ tt_local_entry_free_ref(tt_local_entry);
}
spin_unlock_bh(list_lock);
}
@@ -492,10 +497,9 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
const unsigned char *tt_addr, uint8_t ttvn, bool roaming)
{
struct tt_global_entry *tt_global_entry;
- struct tt_local_entry *tt_local_entry;
struct orig_node *orig_node_tmp;
+ int ret = 0;
- spin_lock_bh(&bat_priv->tt_ghash_lock);
tt_global_entry = tt_global_hash_find(bat_priv, tt_addr);
if (!tt_global_entry) {
@@ -503,7 +507,8 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
kmalloc(sizeof(*tt_global_entry),
GFP_ATOMIC);
if (!tt_global_entry)
- goto unlock;
+ goto out;
+
memcpy(tt_global_entry->addr, tt_addr, ETH_ALEN);
/* Assign the new orig_node */
atomic_inc(&orig_node->refcount);
@@ -511,10 +516,12 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
tt_global_entry->ttvn = ttvn;
tt_global_entry->flags = NO_FLAGS;
tt_global_entry->roam_at = 0;
- atomic_inc(&orig_node->tt_size);
+ atomic_set(&tt_global_entry->refcount, 2);
+
hash_add(bat_priv->tt_global_hash, compare_gtt,
choose_orig, tt_global_entry,
&tt_global_entry->hash_entry);
+ atomic_inc(&orig_node->tt_size);
} else {
if (tt_global_entry->orig_node != orig_node) {
atomic_dec(&tt_global_entry->orig_node->tt_size);
@@ -529,25 +536,18 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
tt_global_entry->roam_at = 0;
}
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
-
bat_dbg(DBG_TT, bat_priv,
"Creating new global tt entry: %pM (via %pM)\n",
tt_global_entry->addr, orig_node->orig);
/* remove address from local hash if present */
- spin_lock_bh(&bat_priv->tt_lhash_lock);
- tt_local_entry = tt_local_hash_find(bat_priv, tt_addr);
-
- if (tt_local_entry)
- tt_local_remove(bat_priv, tt_global_entry->addr,
- "global tt received", roaming);
-
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
- return 1;
-unlock:
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
- return 0;
+ tt_local_remove(bat_priv, tt_global_entry->addr,
+ "global tt received", roaming);
+ ret = 1;
+out:
+ if (tt_global_entry)
+ tt_global_entry_free_ref(tt_global_entry);
+ return ret;
}
int tt_global_seq_print_text(struct seq_file *seq, void *offset)
@@ -584,8 +584,6 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
seq_printf(seq, " %-13s %s %-15s %s\n",
"Client", "(TTVN)", "Originator", "(Curr TTVN)");
- spin_lock_bh(&bat_priv->tt_ghash_lock);
-
buf_size = 1;
/* Estimate length for: " * xx:xx:xx:xx:xx:xx (ttvn) via
* xx:xx:xx:xx:xx:xx (cur_ttvn)\n"*/
@@ -600,10 +598,10 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
buff = kmalloc(buf_size, GFP_ATOMIC);
if (!buff) {
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
ret = -ENOMEM;
goto out;
}
+
buff[0] = '\0';
pos = 0;
@@ -625,8 +623,6 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
rcu_read_unlock();
}
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
-
seq_printf(seq, "%s", buff);
kfree(buff);
out:
@@ -640,7 +636,7 @@ static void _tt_global_del(struct bat_priv *bat_priv,
const char *message)
{
if (!tt_global_entry)
- return;
+ goto out;
bat_dbg(DBG_TT, bat_priv,
"Deleting global tt entry %pM (via %pM): %s\n",
@@ -648,31 +644,35 @@ static void _tt_global_del(struct bat_priv *bat_priv,
message);
atomic_dec(&tt_global_entry->orig_node->tt_size);
+
hash_remove(bat_priv->tt_global_hash, compare_gtt, choose_orig,
tt_global_entry->addr);
- kfree(tt_global_entry);
+out:
+ if (tt_global_entry)
+ tt_global_entry_free_ref(tt_global_entry);
}
void tt_global_del(struct bat_priv *bat_priv,
struct orig_node *orig_node, const unsigned char *addr,
const char *message, bool roaming)
{
- struct tt_global_entry *tt_global_entry;
+ struct tt_global_entry *tt_global_entry = NULL;
- spin_lock_bh(&bat_priv->tt_ghash_lock);
tt_global_entry = tt_global_hash_find(bat_priv, addr);
+ if (!tt_global_entry)
+ goto out;
- if (tt_global_entry && tt_global_entry->orig_node == orig_node) {
+ if (tt_global_entry->orig_node == orig_node) {
if (roaming) {
tt_global_entry->flags |= TT_CLIENT_ROAM;
tt_global_entry->roam_at = jiffies;
goto out;
}
- atomic_dec(&orig_node->tt_size);
_tt_global_del(bat_priv, tt_global_entry, message);
}
out:
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
+ if (tt_global_entry)
+ tt_global_entry_free_ref(tt_global_entry);
}
void tt_global_del_orig(struct bat_priv *bat_priv,
@@ -683,30 +683,28 @@ void tt_global_del_orig(struct bat_priv *bat_priv,
struct hashtable_t *hash = bat_priv->tt_global_hash;
struct hlist_node *node, *safe;
struct hlist_head *head;
+ spinlock_t *list_lock; /* protects write access to the hash lists */
- if (!bat_priv->tt_global_hash)
- return;
-
- spin_lock_bh(&bat_priv->tt_ghash_lock);
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+ spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_global_entry, node, safe,
head, hash_entry) {
- if (tt_global_entry->orig_node == orig_node)
- _tt_global_del(bat_priv, tt_global_entry,
- message);
+ if (tt_global_entry->orig_node == orig_node) {
+ bat_dbg(DBG_TT, bat_priv,
+ "Deleting global tt entry %pM "
+ "(via %pM): originator time out\n",
+ tt_global_entry->addr,
+ tt_global_entry->orig_node->orig);
+ hlist_del_rcu(node);
+ tt_global_entry_free_ref(tt_global_entry);
+ }
}
+ spin_unlock_bh(list_lock);
}
atomic_set(&orig_node->tt_size, 0);
-
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
-}
-
-static void tt_global_entry_free(struct hlist_node *node, void *arg)
-{
- void *data = container_of(node, struct tt_global_entry, hash_entry);
- kfree(data);
}
static void tt_global_roam_purge(struct bat_priv *bat_priv)
@@ -715,13 +713,14 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
struct tt_global_entry *tt_global_entry;
struct hlist_node *node, *node_tmp;
struct hlist_head *head;
+ spinlock_t *list_lock; /* protects write access to the hash lists */
int i;
- spin_lock_bh(&bat_priv->tt_ghash_lock);
-
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+ spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_global_entry, node, node_tmp,
head, hash_entry) {
if (!(tt_global_entry->flags & TT_CLIENT_ROAM))
@@ -730,20 +729,47 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
TT_CLIENT_ROAM_TIMEOUT * 1000))
continue;
- _tt_global_del(bat_priv, tt_global_entry,
- "Roaming timeout");
+ bat_dbg(DBG_TT, bat_priv, "Deleting global "
+ "tt entry (%pM): Roaming timeout\n",
+ tt_global_entry->addr);
+ atomic_dec(&tt_global_entry->orig_node->tt_size);
+ hlist_del_rcu(node);
+ tt_global_entry_free_ref(tt_global_entry);
}
+ spin_unlock_bh(list_lock);
}
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
}
static void tt_global_table_free(struct bat_priv *bat_priv)
{
+ struct hashtable_t *hash;
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct tt_global_entry *tt_global_entry;
+ struct hlist_node *node, *node_tmp;
+ struct hlist_head *head;
+ int i;
+
if (!bat_priv->tt_global_hash)
return;
- hash_delete(bat_priv->tt_global_hash, tt_global_entry_free, NULL);
+ hash = bat_priv->tt_global_hash;
+
+ for (i = 0; i < hash->size; i++) {
+ head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+
+ spin_lock_bh(list_lock);
+ hlist_for_each_entry_safe(tt_global_entry, node, node_tmp,
+ head, hash_entry) {
+ hlist_del_rcu(node);
+ tt_global_entry_free_ref(tt_global_entry);
+ }
+ spin_unlock_bh(list_lock);
+ }
+
+ hash_destroy(hash);
+
bat_priv->tt_global_hash = NULL;
}
@@ -753,19 +779,19 @@ struct orig_node *transtable_search(struct bat_priv *bat_priv,
struct tt_global_entry *tt_global_entry;
struct orig_node *orig_node = NULL;
- spin_lock_bh(&bat_priv->tt_ghash_lock);
tt_global_entry = tt_global_hash_find(bat_priv, addr);
if (!tt_global_entry)
goto out;
if (!atomic_inc_not_zero(&tt_global_entry->orig_node->refcount))
- goto out;
+ goto free_tt;
orig_node = tt_global_entry->orig_node;
+free_tt:
+ tt_global_entry_free_ref(tt_global_entry);
out:
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
return orig_node;
}
@@ -828,7 +854,6 @@ uint16_t tt_local_crc(struct bat_priv *bat_priv)
tt_local_entry->addr[j]);
total ^= total_one;
}
-
rcu_read_unlock();
}
@@ -1371,15 +1396,17 @@ void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node,
bool is_my_client(struct bat_priv *bat_priv, const uint8_t *addr)
{
- struct tt_local_entry *tt_local_entry;
+ struct tt_local_entry *tt_local_entry = NULL;
+ bool ret = false;
- spin_lock_bh(&bat_priv->tt_lhash_lock);
tt_local_entry = tt_local_hash_find(bat_priv, addr);
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
-
+ if (!tt_local_entry)
+ goto out;
+ ret = true;
+out:
if (tt_local_entry)
- return true;
- return false;
+ tt_local_entry_free_ref(tt_local_entry);
+ return ret;
}
void handle_tt_response(struct bat_priv *bat_priv,
@@ -1416,9 +1443,7 @@ void handle_tt_response(struct bat_priv *bat_priv,
spin_unlock_bh(&bat_priv->tt_req_list_lock);
/* Recalculate the CRC for this orig_node and store it */
- spin_lock_bh(&bat_priv->tt_ghash_lock);
orig_node->tt_crc = tt_global_crc(bat_priv, orig_node);
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
/* Roaming phase is over: tables are in sync again. I can
* unset the flag */
orig_node->tt_poss_change = false;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 9c84fa9..11e8569 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -184,8 +184,6 @@ struct bat_priv {
spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
spinlock_t forw_bcast_list_lock; /* protects */
spinlock_t tt_changes_list_lock; /* protects tt_changes */
- spinlock_t tt_lhash_lock; /* protects tt_local_hash */
- spinlock_t tt_ghash_lock; /* protects tt_global_hash */
spinlock_t tt_req_list_lock; /* protects tt_req_list */
spinlock_t tt_roam_list_lock; /* protects tt_roam_list */
spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
@@ -226,6 +224,8 @@ struct tt_local_entry {
uint8_t addr[ETH_ALEN];
unsigned long last_seen;
char never_purge;
+ atomic_t refcount;
+ struct rcu_head rcu;
struct hlist_node hash_entry;
};
@@ -235,6 +235,8 @@ struct tt_global_entry {
uint8_t ttvn;
uint8_t flags; /* only TT_GLOBAL_ROAM is used */
unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
+ atomic_t refcount;
+ struct rcu_head rcu;
struct hlist_node hash_entry; /* entry in the global table */
};
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index 355c6e5..8a1b985 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -665,11 +665,12 @@ next:
hash = bat_priv->tt_local_hash;
- spin_lock_bh(&bat_priv->tt_lhash_lock);
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
- hlist_for_each_entry(tt_local_entry, node, head, hash_entry) {
+ rcu_read_lock();
+ hlist_for_each_entry_rcu(tt_local_entry, node, head,
+ hash_entry) {
entry = (struct vis_info_entry *)
skb_put(info->skb_packet,
sizeof(*entry));
@@ -678,14 +679,12 @@ next:
entry->quality = 0; /* 0 means TT */
packet->entries++;
- if (vis_packet_full(info)) {
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
- return 0;
- }
+ if (vis_packet_full(info))
+ goto unlock;
}
+ rcu_read_unlock();
}
- spin_unlock_bh(&bat_priv->tt_lhash_lock);
return 0;
unlock:
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit cc47f66e6b9ec7e7d465f74739a6fc9844593894
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Wed Apr 27 14:27:57 2011 +0200
batman-adv: improved roaming mechanism
With the current client announcement implementation, in case of roaming,
an update is triggered on the new AP serving the client. At that point
the new information is spread around by means of the OGM broadcasting
mechanism. Until this operations is not executed, no node is able to
correctly route traffic towards the client. This obviously causes packet
drops and introduces a delay in the time needed by the client to recover
its connections.
A new packet type called ROAMING_ADVERTISEMENT is added to account this
issue.
This message is sent in case of roaming from the new AP serving the
client to the old one and will contain the client MAC address. In this
way an out-of-OGM update is immediately committed, so that the old node
can update its global translation table. Traffic reaching this node will
then be redirected to the correct destination utilising the fresher
information. Thus reducing the packet drops and the connection recovery
delay.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index d40426c..55b5def 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -658,6 +658,10 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
case BAT_TT_QUERY:
ret = recv_tt_query(skb, hard_iface);
break;
+ /* Roaming advertisement */
+ case BAT_ROAM_ADV:
+ ret = recv_roam_adv(skb, hard_iface);
+ break;
default:
ret = NET_RX_DROP;
}
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 49a5e64..3318ee2 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -88,6 +88,7 @@ int mesh_init(struct net_device *soft_iface)
spin_lock_init(&bat_priv->tt_ghash_lock);
spin_lock_init(&bat_priv->tt_changes_list_lock);
spin_lock_init(&bat_priv->tt_req_list_lock);
+ spin_lock_init(&bat_priv->tt_roam_list_lock);
spin_lock_init(&bat_priv->tt_buff_lock);
spin_lock_init(&bat_priv->gw_list_lock);
spin_lock_init(&bat_priv->vis_hash_lock);
@@ -101,6 +102,7 @@ int mesh_init(struct net_device *soft_iface)
INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids);
INIT_LIST_HEAD(&bat_priv->tt_changes_list);
INIT_LIST_HEAD(&bat_priv->tt_req_list);
+ INIT_LIST_HEAD(&bat_priv->tt_roam_list);
if (originator_init(bat_priv) < 1)
goto err;
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 6f53a1d..8eae05e 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -42,7 +42,7 @@
* -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */
#define PURGE_TIMEOUT 200
#define TT_LOCAL_TIMEOUT 3600 /* in seconds */
-
+#define TT_CLIENT_ROAM_TIMEOUT 600
/* sliding packet range of received originator messages in squence numbers
* (should be a multiple of our word size) */
#define TQ_LOCAL_WINDOW_SIZE 64
@@ -55,6 +55,10 @@
#define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
+#define ROAMING_MAX_TIME 20 /* Time in which a client can roam at most
+ * ROAMING_MAX_COUNT times */
+#define ROAMING_MAX_COUNT 5
+
#define NO_FLAGS 0
#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 25e7e50..338b3c5 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -219,6 +219,7 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr)
/* extra reference for return */
atomic_set(&orig_node->refcount, 2);
+ orig_node->tt_poss_change = false;
orig_node->bat_priv = bat_priv;
memcpy(orig_node->orig, addr, ETH_ALEN);
orig_node->router = NULL;
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 407dd2e..c5f081d 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -31,7 +31,8 @@ enum bat_packettype {
BAT_BCAST = 0x04,
BAT_VIS = 0x05,
BAT_UNICAST_FRAG = 0x06,
- BAT_TT_QUERY = 0x07
+ BAT_TT_QUERY = 0x07,
+ BAT_ROAM_ADV = 0x08
};
/* this file is included by batctl which needs these defines */
@@ -194,6 +195,16 @@ struct tt_query_packet {
uint16_t tt_data;
} __packed;
+struct roam_adv_packet {
+ uint8_t packet_type;
+ uint8_t version;
+ uint8_t ttl;
+ uint8_t reserved;
+ uint8_t dst[ETH_ALEN];
+ uint8_t src[ETH_ALEN];
+ uint8_t client[ETH_ALEN];
+} __packed;
+
struct tt_change {
uint8_t flags;
uint8_t addr[ETH_ALEN];
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 8b0f833..05d50ca 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -93,6 +93,9 @@ static void update_transtable(struct bat_priv *bat_priv,
spin_lock_bh(&bat_priv->tt_ghash_lock);
orig_node->tt_crc = tt_global_crc(bat_priv, orig_node);
spin_unlock_bh(&bat_priv->tt_ghash_lock);
+ /* Roaming phase is over: tables are in sync again. I can
+ * unset the flag */
+ orig_node->tt_poss_change = false;
} else {
/* if we missed more than one change or our tables are not
* in sync anymore -> request fresh tt data */
@@ -1252,6 +1255,54 @@ out:
return NET_RX_DROP;
}
+int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if)
+{
+ struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
+ struct roam_adv_packet *roam_adv_packet;
+ struct orig_node *orig_node;
+ struct ethhdr *ethhdr;
+
+ /* drop packet if it has not necessary minimum size */
+ if (unlikely(!pskb_may_pull(skb, sizeof(struct roam_adv_packet))))
+ goto out;
+
+ ethhdr = (struct ethhdr *)skb_mac_header(skb);
+
+ /* packet with unicast indication but broadcast recipient */
+ if (is_broadcast_ether_addr(ethhdr->h_dest))
+ goto out;
+
+ /* packet with broadcast sender address */
+ if (is_broadcast_ether_addr(ethhdr->h_source))
+ goto out;
+
+ roam_adv_packet = (struct roam_adv_packet *)skb->data;
+
+ if (!is_my_mac(roam_adv_packet->dst))
+ return route_unicast_packet(skb, recv_if);
+
+ orig_node = orig_hash_find(bat_priv, roam_adv_packet->src);
+ if (!orig_node)
+ goto out;
+
+ bat_dbg(DBG_TT, bat_priv, "Received ROAMING_ADV from %pM "
+ "(client %pM)\n", roam_adv_packet->src,
+ roam_adv_packet->client);
+
+ tt_global_add(bat_priv, orig_node, roam_adv_packet->client,
+ atomic_read(&orig_node->last_ttvn) + 1, true);
+
+ /* Roaming phase starts: I have new information but the ttvn has not
+ * been incremented yet. This flag will make me check all the incoming
+ * packets for the correct destination. */
+ bat_priv->tt_poss_change = true;
+
+ orig_node_free_ref(orig_node);
+out:
+ /* returning NET_RX_DROP will make the caller function kfree the skb */
+ return NET_RX_DROP;
+}
+
/* find a suitable router for this originator, and use
* bonding if possible. increases the found neighbors
* refcount.*/
@@ -1445,6 +1496,7 @@ static int check_unicast_ttvn(struct bat_priv *bat_priv,
struct ethhdr *ethhdr;
struct hard_iface *primary_if;
struct unicast_packet *unicast_packet;
+ bool tt_poss_change;
/* I could need to modify it */
if (skb_cow(skb, sizeof(struct unicast_packet)) < 0)
@@ -1452,27 +1504,28 @@ static int check_unicast_ttvn(struct bat_priv *bat_priv,
unicast_packet = (struct unicast_packet *)skb->data;
- if (is_my_mac(unicast_packet->dest))
+ if (is_my_mac(unicast_packet->dest)) {
+ tt_poss_change = bat_priv->tt_poss_change;
curr_ttvn = (uint8_t)atomic_read(&bat_priv->ttvn);
- else {
+ } else {
orig_node = orig_hash_find(bat_priv, unicast_packet->dest);
if (!orig_node)
return 0;
curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
+ tt_poss_change = orig_node->tt_poss_change;
orig_node_free_ref(orig_node);
}
/* Check whether I have to reroute the packet */
- if (seq_before(unicast_packet->ttvn, curr_ttvn)) {
+ if (seq_before(unicast_packet->ttvn, curr_ttvn) || tt_poss_change) {
/* Linearize the skb before accessing it */
if (skb_linearize(skb) < 0)
return 0;
ethhdr = (struct ethhdr *)(skb->data +
sizeof(struct unicast_packet));
-
orig_node = transtable_search(bat_priv, ethhdr->h_dest);
if (!orig_node) {
diff --git a/net/batman-adv/routing.h b/net/batman-adv/routing.h
index e77d464..fb14e95 100644
--- a/net/batman-adv/routing.h
+++ b/net/batman-adv/routing.h
@@ -37,6 +37,7 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_bat_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if);
+int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if);
struct neigh_node *find_router(struct bat_priv *bat_priv,
struct orig_node *orig_node,
const struct hard_iface *recv_if);
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 6b14075..7a2f082 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -303,6 +303,7 @@ void schedule_own_packet(struct hard_iface *hard_iface)
prepare_packet_buffer(bat_priv, hard_iface);
/* Increment the TTVN only once per OGM interval */
atomic_inc(&bat_priv->ttvn);
+ bat_priv->tt_poss_change = false;
}
/* if the changes have been sent enough times */
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index c288d93..3371ece 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -534,7 +534,7 @@ static int interface_set_mac_addr(struct net_device *dev, void *p)
/* only modify transtable if it has been initialised before */
if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
tt_local_remove(bat_priv, dev->dev_addr,
- "mac address changed");
+ "mac address changed", false);
tt_local_add(dev, addr->sa_data);
}
@@ -836,6 +836,7 @@ struct net_device *softif_create(const char *name)
bat_priv->tt_buff = NULL;
bat_priv->tt_buff_len = 0;
+ bat_priv->tt_poss_change = false;
bat_priv->primary_if = NULL;
bat_priv->num_ifaces = 0;
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 597cd1a..d516d85 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -126,7 +126,7 @@ static bool is_out_of_time(unsigned long starting_time, unsigned long timeout)
}
static void tt_local_event(struct bat_priv *bat_priv, uint8_t op,
- const uint8_t *addr)
+ const uint8_t *addr, uint8_t roaming)
{
struct tt_change_node *tt_change_node;
@@ -136,6 +136,9 @@ static void tt_local_event(struct bat_priv *bat_priv, uint8_t op,
return;
tt_change_node->change.flags = op;
+ if (roaming)
+ tt_change_node->change.flags |= TT_CLIENT_ROAM;
+
memcpy(tt_change_node->change.addr, addr, ETH_ALEN);
spin_lock_bh(&bat_priv->tt_changes_list_lock);
@@ -170,6 +173,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
struct bat_priv *bat_priv = netdev_priv(soft_iface);
struct tt_local_entry *tt_local_entry;
struct tt_global_entry *tt_global_entry;
+ uint8_t roam_addr[ETH_ALEN];
spin_lock_bh(&bat_priv->tt_lhash_lock);
tt_local_entry = tt_local_hash_find(bat_priv, addr);
@@ -183,7 +187,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
if (!tt_local_entry)
goto unlock;
- tt_local_event(bat_priv, NO_FLAGS, addr);
+ tt_local_event(bat_priv, NO_FLAGS, addr, false);
bat_dbg(DBG_TT, bat_priv,
"Creating new local tt entry: %pM (ttvn: %d)\n", addr,
@@ -208,11 +212,19 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
tt_global_entry = tt_global_hash_find(bat_priv, addr);
- if (tt_global_entry)
+ /* Check whether it is a roaming! */
+ if (tt_global_entry) {
+ memcpy(roam_addr, tt_global_entry->addr, ETH_ALEN);
+ /* This node is probably going to update its tt table */
+ tt_global_entry->orig_node->tt_poss_change = true;
_tt_global_del(bat_priv, tt_global_entry,
"local tt received");
+ spin_unlock_bh(&bat_priv->tt_ghash_lock);
+ send_roam_adv(bat_priv, tt_global_entry->addr,
+ tt_global_entry->orig_node);
+ } else
+ spin_unlock_bh(&bat_priv->tt_ghash_lock);
- spin_unlock_bh(&bat_priv->tt_ghash_lock);
return;
unlock:
spin_unlock_bh(&bat_priv->tt_lhash_lock);
@@ -367,7 +379,7 @@ static void tt_local_del(struct bat_priv *bat_priv,
}
void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr,
- const char *message)
+ const char *message, bool roaming)
{
struct tt_local_entry *tt_local_entry;
@@ -375,7 +387,8 @@ void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr,
tt_local_entry = tt_local_hash_find(bat_priv, addr);
if (tt_local_entry) {
- tt_local_event(bat_priv, TT_CHANGE_DEL, tt_local_entry->addr);
+ tt_local_event(bat_priv, TT_CHANGE_DEL, tt_local_entry->addr,
+ roaming);
tt_local_del(bat_priv, tt_local_entry, message);
}
spin_unlock_bh(&bat_priv->tt_lhash_lock);
@@ -404,7 +417,7 @@ static void tt_local_purge(struct bat_priv *bat_priv)
continue;
tt_local_event(bat_priv, TT_CHANGE_DEL,
- tt_local_entry->addr);
+ tt_local_entry->addr, false);
tt_local_del(bat_priv, tt_local_entry,
"address timed out");
}
@@ -476,7 +489,7 @@ static void tt_changes_list_free(struct bat_priv *bat_priv)
/* caller must hold orig_node refcount */
int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
- const unsigned char *tt_addr, uint8_t ttvn)
+ const unsigned char *tt_addr, uint8_t ttvn, bool roaming)
{
struct tt_global_entry *tt_global_entry;
struct tt_local_entry *tt_local_entry;
@@ -496,6 +509,8 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
atomic_inc(&orig_node->refcount);
tt_global_entry->orig_node = orig_node;
tt_global_entry->ttvn = ttvn;
+ tt_global_entry->flags = NO_FLAGS;
+ tt_global_entry->roam_at = 0;
atomic_inc(&orig_node->tt_size);
hash_add(bat_priv->tt_global_hash, compare_gtt,
choose_orig, tt_global_entry,
@@ -506,10 +521,12 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
orig_node_tmp = tt_global_entry->orig_node;
atomic_inc(&orig_node->refcount);
tt_global_entry->orig_node = orig_node;
- tt_global_entry->ttvn = ttvn;
orig_node_free_ref(orig_node_tmp);
atomic_inc(&orig_node->tt_size);
}
+ tt_global_entry->ttvn = ttvn;
+ tt_global_entry->flags = NO_FLAGS;
+ tt_global_entry->roam_at = 0;
}
spin_unlock_bh(&bat_priv->tt_ghash_lock);
@@ -523,8 +540,9 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
tt_local_entry = tt_local_hash_find(bat_priv, tt_addr);
if (tt_local_entry)
- tt_local_del(bat_priv, tt_local_entry,
- "global tt received");
+ tt_local_remove(bat_priv, tt_global_entry->addr,
+ "global tt received", roaming);
+
spin_unlock_bh(&bat_priv->tt_lhash_lock);
return 1;
unlock:
@@ -637,7 +655,7 @@ static void _tt_global_del(struct bat_priv *bat_priv,
void tt_global_del(struct bat_priv *bat_priv,
struct orig_node *orig_node, const unsigned char *addr,
- const char *message)
+ const char *message, bool roaming)
{
struct tt_global_entry *tt_global_entry;
@@ -645,9 +663,15 @@ void tt_global_del(struct bat_priv *bat_priv,
tt_global_entry = tt_global_hash_find(bat_priv, addr);
if (tt_global_entry && tt_global_entry->orig_node == orig_node) {
+ if (roaming) {
+ tt_global_entry->flags |= TT_CLIENT_ROAM;
+ tt_global_entry->roam_at = jiffies;
+ goto out;
+ }
atomic_dec(&orig_node->tt_size);
_tt_global_del(bat_priv, tt_global_entry, message);
}
+out:
spin_unlock_bh(&bat_priv->tt_ghash_lock);
}
@@ -685,6 +709,35 @@ static void tt_global_entry_free(struct hlist_node *node, void *arg)
kfree(data);
}
+static void tt_global_roam_purge(struct bat_priv *bat_priv)
+{
+ struct hashtable_t *hash = bat_priv->tt_global_hash;
+ struct tt_global_entry *tt_global_entry;
+ struct hlist_node *node, *node_tmp;
+ struct hlist_head *head;
+ int i;
+
+ spin_lock_bh(&bat_priv->tt_ghash_lock);
+
+ for (i = 0; i < hash->size; i++) {
+ head = &hash->table[i];
+
+ hlist_for_each_entry_safe(tt_global_entry, node, node_tmp,
+ head, hash_entry) {
+ if (!(tt_global_entry->flags & TT_CLIENT_ROAM))
+ continue;
+ if (!is_out_of_time(tt_global_entry->roam_at,
+ TT_CLIENT_ROAM_TIMEOUT * 1000))
+ continue;
+
+ _tt_global_del(bat_priv, tt_global_entry,
+ "Roaming timeout");
+ }
+ }
+
+ spin_unlock_bh(&bat_priv->tt_ghash_lock);
+}
+
static void tt_global_table_free(struct bat_priv *bat_priv)
{
if (!bat_priv->tt_global_hash)
@@ -734,6 +787,12 @@ uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node)
head, hash_entry) {
if (compare_eth(tt_global_entry->orig_node,
orig_node)) {
+ /* Roaming clients are in the global table for
+ * consistency only. They don't have to be
+ * taken into account while computing the
+ * global crc */
+ if (tt_global_entry->flags & TT_CLIENT_ROAM)
+ continue;
total_one = 0;
for (j = 0; j < ETH_ALEN; j++)
total_one = crc16_byte(total_one,
@@ -858,6 +917,9 @@ static int tt_global_valid_entry(const void *entry_ptr, const void *data_ptr)
const struct tt_global_entry *tt_global_entry = entry_ptr;
const struct orig_node *orig_node = data_ptr;
+ if (tt_global_entry->flags & TT_CLIENT_ROAM)
+ return 0;
+
return (tt_global_entry->orig_node == orig_node);
}
@@ -1251,10 +1313,11 @@ static void _tt_update_changes(struct bat_priv *bat_priv,
if ((tt_change + i)->flags & TT_CHANGE_DEL)
tt_global_del(bat_priv, orig_node,
(tt_change + i)->addr,
- "tt removed by changes");
+ "tt removed by changes",
+ (tt_change + i)->flags & TT_CLIENT_ROAM);
else
if (!tt_global_add(bat_priv, orig_node,
- (tt_change + i)->addr, ttvn))
+ (tt_change + i)->addr, ttvn, false))
/* In case of problem while storing a
* global_entry, we stop the updating
* procedure without committing the
@@ -1356,6 +1419,9 @@ void handle_tt_response(struct bat_priv *bat_priv,
spin_lock_bh(&bat_priv->tt_ghash_lock);
orig_node->tt_crc = tt_global_crc(bat_priv, orig_node);
spin_unlock_bh(&bat_priv->tt_ghash_lock);
+ /* Roaming phase is over: tables are in sync again. I can
+ * unset the flag */
+ orig_node->tt_poss_change = false;
out:
if (orig_node)
orig_node_free_ref(orig_node);
@@ -1374,16 +1440,134 @@ int tt_init(struct bat_priv *bat_priv)
return 1;
}
-void tt_free(struct bat_priv *bat_priv)
+static void tt_roam_list_free(struct bat_priv *bat_priv)
{
- cancel_delayed_work_sync(&bat_priv->tt_work);
+ struct tt_roam_node *node, *safe;
- tt_local_table_free(bat_priv);
- tt_global_table_free(bat_priv);
- tt_req_list_free(bat_priv);
- tt_changes_list_free(bat_priv);
+ spin_lock_bh(&bat_priv->tt_roam_list_lock);
- kfree(bat_priv->tt_buff);
+ list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) {
+ list_del(&node->list);
+ kfree(node);
+ }
+
+ spin_unlock_bh(&bat_priv->tt_roam_list_lock);
+}
+
+static void tt_roam_purge(struct bat_priv *bat_priv)
+{
+ struct tt_roam_node *node, *safe;
+
+ spin_lock_bh(&bat_priv->tt_roam_list_lock);
+ list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) {
+ if (!is_out_of_time(node->first_time,
+ ROAMING_MAX_TIME * 1000))
+ continue;
+
+ list_del(&node->list);
+ kfree(node);
+ }
+ spin_unlock_bh(&bat_priv->tt_roam_list_lock);
+}
+
+/* This function checks whether the client already reached the
+ * maximum number of possible roaming phases. In this case the ROAMING_ADV
+ * will not be sent.
+ *
+ * returns true if the ROAMING_ADV can be sent, false otherwise */
+static bool tt_check_roam_count(struct bat_priv *bat_priv,
+ uint8_t *client)
+{
+ struct tt_roam_node *tt_roam_node;
+ bool ret = false;
+
+ spin_lock_bh(&bat_priv->tt_roam_list_lock);
+ /* The new tt_req will be issued only if I'm not waiting for a
+ * reply from the same orig_node yet */
+ list_for_each_entry(tt_roam_node, &bat_priv->tt_roam_list, list) {
+ if (!compare_eth(tt_roam_node->addr, client))
+ continue;
+
+ if (is_out_of_time(tt_roam_node->first_time,
+ ROAMING_MAX_TIME * 1000))
+ continue;
+
+ if (!atomic_dec_not_zero(&tt_roam_node->counter))
+ /* Sorry, you roamed too many times! */
+ goto unlock;
+ ret = true;
+ break;
+ }
+
+ if (!ret) {
+ tt_roam_node = kmalloc(sizeof(*tt_roam_node), GFP_ATOMIC);
+ if (!tt_roam_node)
+ goto unlock;
+
+ tt_roam_node->first_time = jiffies;
+ atomic_set(&tt_roam_node->counter, ROAMING_MAX_COUNT - 1);
+ memcpy(tt_roam_node->addr, client, ETH_ALEN);
+
+ list_add(&tt_roam_node->list, &bat_priv->tt_roam_list);
+ ret = true;
+ }
+
+unlock:
+ spin_unlock_bh(&bat_priv->tt_roam_list_lock);
+ return ret;
+}
+
+void send_roam_adv(struct bat_priv *bat_priv, uint8_t *client,
+ struct orig_node *orig_node)
+{
+ struct neigh_node *neigh_node = NULL;
+ struct sk_buff *skb = NULL;
+ struct roam_adv_packet *roam_adv_packet;
+ int ret = 1;
+ struct hard_iface *primary_if;
+
+ /* before going on we have to check whether the client has
+ * already roamed to us too many times */
+ if (!tt_check_roam_count(bat_priv, client))
+ goto out;
+
+ skb = dev_alloc_skb(sizeof(struct roam_adv_packet) + ETH_HLEN);
+ if (!skb)
+ goto out;
+
+ skb_reserve(skb, ETH_HLEN);
+
+ roam_adv_packet = (struct roam_adv_packet *)skb_put(skb,
+ sizeof(struct roam_adv_packet));
+
+ roam_adv_packet->packet_type = BAT_ROAM_ADV;
+ roam_adv_packet->version = COMPAT_VERSION;
+ roam_adv_packet->ttl = TTL;
+ primary_if = primary_if_get_selected(bat_priv);
+ if (!primary_if)
+ goto out;
+ memcpy(roam_adv_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN);
+ hardif_free_ref(primary_if);
+ memcpy(roam_adv_packet->dst, orig_node->orig, ETH_ALEN);
+ memcpy(roam_adv_packet->client, client, ETH_ALEN);
+
+ neigh_node = orig_node_get_router(orig_node);
+ if (!neigh_node)
+ goto out;
+
+ bat_dbg(DBG_TT, bat_priv,
+ "Sending ROAMING_ADV to %pM (client %pM) via %pM\n",
+ orig_node->orig, client, neigh_node->addr);
+
+ send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr);
+ ret = 0;
+
+out:
+ if (neigh_node)
+ neigh_node_free_ref(neigh_node);
+ if (ret)
+ kfree_skb(skb);
+ return;
}
static void tt_purge(struct work_struct *work)
@@ -1394,7 +1578,22 @@ static void tt_purge(struct work_struct *work)
container_of(delayed_work, struct bat_priv, tt_work);
tt_local_purge(bat_priv);
+ tt_global_roam_purge(bat_priv);
tt_req_purge(bat_priv);
+ tt_roam_purge(bat_priv);
tt_start_timer(bat_priv);
}
+
+void tt_free(struct bat_priv *bat_priv)
+{
+ cancel_delayed_work_sync(&bat_priv->tt_work);
+
+ tt_local_table_free(bat_priv);
+ tt_global_table_free(bat_priv);
+ tt_req_list_free(bat_priv);
+ tt_changes_list_free(bat_priv);
+ tt_roam_list_free(bat_priv);
+
+ kfree(bat_priv->tt_buff);
+}
diff --git a/net/batman-adv/translation-table.h b/net/batman-adv/translation-table.h
index 51f7e30..1cd2d39 100644
--- a/net/batman-adv/translation-table.h
+++ b/net/batman-adv/translation-table.h
@@ -28,20 +28,20 @@ int tt_changes_fill_buffer(struct bat_priv *bat_priv,
int tt_init(struct bat_priv *bat_priv);
void tt_local_add(struct net_device *soft_iface, const uint8_t *addr);
void tt_local_remove(struct bat_priv *bat_priv,
- const uint8_t *addr, const char *message);
+ const uint8_t *addr, const char *message, bool roaming);
int tt_local_seq_print_text(struct seq_file *seq, void *offset);
void tt_global_add_orig(struct bat_priv *bat_priv,
struct orig_node *orig_node,
const unsigned char *tt_buff, int tt_buff_len);
int tt_global_add(struct bat_priv *bat_priv,
struct orig_node *orig_node, const unsigned char *addr,
- uint8_t ttvn);
+ uint8_t ttvn, bool roaming);
int tt_global_seq_print_text(struct seq_file *seq, void *offset);
void tt_global_del_orig(struct bat_priv *bat_priv,
struct orig_node *orig_node, const char *message);
void tt_global_del(struct bat_priv *bat_priv,
struct orig_node *orig_node, const unsigned char *addr,
- const char *message);
+ const char *message, bool roaming);
struct orig_node *transtable_search(struct bat_priv *bat_priv,
const uint8_t *addr);
void tt_save_orig_buffer(struct bat_priv *bat_priv, struct orig_node *orig_node,
@@ -60,5 +60,7 @@ void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node,
bool is_my_client(struct bat_priv *bat_priv, const uint8_t *addr);
void handle_tt_response(struct bat_priv *bat_priv,
struct tt_query_packet *tt_response);
+void send_roam_adv(struct bat_priv *bat_priv, uint8_t *client,
+ struct orig_node *orig_node);
#endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 3b642a9..9c84fa9 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -81,6 +81,12 @@ struct orig_node {
int16_t tt_buff_len;
spinlock_t tt_buff_lock; /* protects tt_buff */
atomic_t tt_size;
+ /* The tt_poss_change flag is used to detect an ongoing roaming phase.
+ * If true, then I sent a Roaming_adv to this orig_node and I have to
+ * inspect every packet directed to it to check whether it is still
+ * the true destination or not. This flag will be reset to false as
+ * soon as I receive a new TTVN from this orig_node */
+ bool tt_poss_change;
uint32_t last_real_seqno;
uint8_t last_ttl;
unsigned long bcast_bits[NUM_WORDS];
@@ -153,6 +159,12 @@ struct bat_priv {
atomic_t ttvn; /* tranlation table version number */
atomic_t tt_ogm_append_cnt;
atomic_t tt_local_changes; /* changes registered in a OGM interval */
+ /* The tt_poss_change flag is used to detect an ongoing roaming phase.
+ * If true, then I received a Roaming_adv and I have to inspect every
+ * packet directed to me to check whether I am still the true
+ * destination or not. This flag will be reset to false as soon as I
+ * increase my TTVN */
+ bool tt_poss_change;
char num_ifaces;
struct debug_log *debug_log;
struct kobject *mesh_obj;
@@ -167,6 +179,7 @@ struct bat_priv {
struct hashtable_t *tt_local_hash;
struct hashtable_t *tt_global_hash;
struct list_head tt_req_list; /* list of pending tt_requests */
+ struct list_head tt_roam_list;
struct hashtable_t *vis_hash;
spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
spinlock_t forw_bcast_list_lock; /* protects */
@@ -174,6 +187,7 @@ struct bat_priv {
spinlock_t tt_lhash_lock; /* protects tt_local_hash */
spinlock_t tt_ghash_lock; /* protects tt_global_hash */
spinlock_t tt_req_list_lock; /* protects tt_req_list */
+ spinlock_t tt_roam_list_lock; /* protects tt_roam_list */
spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
spinlock_t vis_hash_lock; /* protects vis_hash */
spinlock_t vis_list_lock; /* protects vis_info::recv_list */
@@ -219,8 +233,9 @@ struct tt_global_entry {
uint8_t addr[ETH_ALEN];
struct orig_node *orig_node;
uint8_t ttvn;
- /* entry in the global table */
- struct hlist_node hash_entry;
+ uint8_t flags; /* only TT_GLOBAL_ROAM is used */
+ unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
+ struct hlist_node hash_entry; /* entry in the global table */
};
struct tt_change_node {
@@ -234,6 +249,13 @@ struct tt_req_node {
struct list_head list;
};
+struct tt_roam_node {
+ uint8_t addr[ETH_ALEN];
+ atomic_t counter;
+ unsigned long first_time;
+ struct list_head list;
+};
+
/**
* forw_packet - structure for forw_list maintaining packets to be
* send/forwarded
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit 2265c141086474bbae55a5bb3afa1ebb78ccaa7c
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Wed Apr 27 00:22:00 2011 +0200
batman-adv: gateway election code refactoring
The gateway election mechanism has been a little revised. Now the
gw_election is trigered by an atomic_t flag (gw_reselect) which is set
to 1 in case of election needed, avoding to set curr_gw to NULL.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 7248de2..0350c0c 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -20,6 +20,7 @@
*/
#include "main.h"
+#include "bat_sysfs.h"
#include "gateway_client.h"
#include "gateway_common.h"
#include "hard-interface.h"
@@ -97,40 +98,19 @@ static void gw_select(struct bat_priv *bat_priv, struct gw_node *new_gw_node)
void gw_deselect(struct bat_priv *bat_priv)
{
- gw_select(bat_priv, NULL);
+ atomic_set(&bat_priv->gw_reselect, 1);
}
-void gw_election(struct bat_priv *bat_priv)
+static struct gw_node *gw_get_best_gw_node(struct bat_priv *bat_priv)
{
- struct hlist_node *node;
- struct gw_node *gw_node, *curr_gw = NULL, *curr_gw_tmp = NULL;
struct neigh_node *router;
- uint8_t max_tq = 0;
+ struct hlist_node *node;
+ struct gw_node *gw_node, *curr_gw = NULL;
uint32_t max_gw_factor = 0, tmp_gw_factor = 0;
+ uint8_t max_tq = 0;
int down, up;
- /**
- * The batman daemon checks here if we already passed a full originator
- * cycle in order to make sure we don't choose the first gateway we
- * hear about. This check is based on the daemon's uptime which we
- * don't have.
- **/
- if (atomic_read(&bat_priv->gw_mode) != GW_MODE_CLIENT)
- return;
-
- curr_gw = gw_get_selected_gw_node(bat_priv);
- if (curr_gw)
- goto out;
-
rcu_read_lock();
- if (hlist_empty(&bat_priv->gw_list)) {
- bat_dbg(DBG_BATMAN, bat_priv,
- "Removing selected gateway - "
- "no gateway in range\n");
- gw_deselect(bat_priv);
- goto unlock;
- }
-
hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) {
if (gw_node->deleted)
continue;
@@ -139,6 +119,9 @@ void gw_election(struct bat_priv *bat_priv)
if (!router)
continue;
+ if (!atomic_inc_not_zero(&gw_node->refcount))
+ goto next;
+
switch (atomic_read(&bat_priv->gw_sel_class)) {
case 1: /* fast connection */
gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags,
@@ -151,8 +134,12 @@ void gw_election(struct bat_priv *bat_priv)
if ((tmp_gw_factor > max_gw_factor) ||
((tmp_gw_factor == max_gw_factor) &&
- (router->tq_avg > max_tq)))
- curr_gw_tmp = gw_node;
+ (router->tq_avg > max_tq))) {
+ if (curr_gw)
+ gw_node_free_ref(curr_gw);
+ curr_gw = gw_node;
+ atomic_inc(&curr_gw->refcount);
+ }
break;
default: /**
@@ -163,8 +150,12 @@ void gw_election(struct bat_priv *bat_priv)
* soon as a better gateway appears which has
* $routing_class more tq points)
**/
- if (router->tq_avg > max_tq)
- curr_gw_tmp = gw_node;
+ if (router->tq_avg > max_tq) {
+ if (curr_gw)
+ gw_node_free_ref(curr_gw);
+ curr_gw = gw_node;
+ atomic_inc(&curr_gw->refcount);
+ }
break;
}
@@ -174,42 +165,75 @@ void gw_election(struct bat_priv *bat_priv)
if (tmp_gw_factor > max_gw_factor)
max_gw_factor = tmp_gw_factor;
+ gw_node_free_ref(gw_node);
+
+next:
neigh_node_free_ref(router);
}
+ rcu_read_unlock();
- if (curr_gw != curr_gw_tmp) {
- router = orig_node_get_router(curr_gw_tmp->orig_node);
- if (!router)
- goto unlock;
+ return curr_gw;
+}
- if ((curr_gw) && (!curr_gw_tmp))
- bat_dbg(DBG_BATMAN, bat_priv,
- "Removing selected gateway - "
- "no gateway in range\n");
- else if ((!curr_gw) && (curr_gw_tmp))
- bat_dbg(DBG_BATMAN, bat_priv,
- "Adding route to gateway %pM "
- "(gw_flags: %i, tq: %i)\n",
- curr_gw_tmp->orig_node->orig,
- curr_gw_tmp->orig_node->gw_flags,
- router->tq_avg);
- else
- bat_dbg(DBG_BATMAN, bat_priv,
- "Changing route to gateway %pM "
- "(gw_flags: %i, tq: %i)\n",
- curr_gw_tmp->orig_node->orig,
- curr_gw_tmp->orig_node->gw_flags,
- router->tq_avg);
+void gw_election(struct bat_priv *bat_priv)
+{
+ struct gw_node *curr_gw = NULL, *next_gw = NULL;
+ struct neigh_node *router = NULL;
- neigh_node_free_ref(router);
- gw_select(bat_priv, curr_gw_tmp);
+ /**
+ * The batman daemon checks here if we already passed a full originator
+ * cycle in order to make sure we don't choose the first gateway we
+ * hear about. This check is based on the daemon's uptime which we
+ * don't have.
+ **/
+ if (atomic_read(&bat_priv->gw_mode) != GW_MODE_CLIENT)
+ goto out;
+
+ if (!atomic_dec_not_zero(&bat_priv->gw_reselect))
+ goto out;
+
+ curr_gw = gw_get_selected_gw_node(bat_priv);
+
+ next_gw = gw_get_best_gw_node(bat_priv);
+
+ if (curr_gw == next_gw)
+ goto out;
+
+ if (next_gw) {
+ router = orig_node_get_router(next_gw->orig_node);
+ if (!router) {
+ gw_deselect(bat_priv);
+ goto out;
+ }
}
-unlock:
- rcu_read_unlock();
+ if ((curr_gw) && (!next_gw)) {
+ bat_dbg(DBG_BATMAN, bat_priv,
+ "Removing selected gateway - no gateway in range\n");
+ } else if ((!curr_gw) && (next_gw)) {
+ bat_dbg(DBG_BATMAN, bat_priv,
+ "Adding route to gateway %pM (gw_flags: %i, tq: %i)\n",
+ next_gw->orig_node->orig,
+ next_gw->orig_node->gw_flags,
+ router->tq_avg);
+ } else {
+ bat_dbg(DBG_BATMAN, bat_priv,
+ "Changing route to gateway %pM "
+ "(gw_flags: %i, tq: %i)\n",
+ next_gw->orig_node->orig,
+ next_gw->orig_node->gw_flags,
+ router->tq_avg);
+ }
+
+ gw_select(bat_priv, next_gw);
+
out:
if (curr_gw)
gw_node_free_ref(curr_gw);
+ if (next_gw)
+ gw_node_free_ref(next_gw);
+ if (router)
+ neigh_node_free_ref(router);
}
void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node)
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index c2b06b7..e367e69 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -113,6 +113,7 @@ int mesh_init(struct net_device *soft_iface)
if (vis_init(bat_priv) < 1)
goto err;
+ atomic_set(&bat_priv->gw_reselect, 0);
atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
goto end;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 11e8569..85cf122 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -201,6 +201,7 @@ struct bat_priv {
struct delayed_work orig_work;
struct delayed_work vis_work;
struct gw_node __rcu *curr_gw; /* rcu protected pointer */
+ atomic_t gw_reselect;
struct hard_iface __rcu *primary_if; /* rcu protected pointer */
struct vis_info *my_vis_info;
};
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit db69ecfcb0d4df4d6449172186a8dd20836275ed
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Wed Jun 15 15:17:21 2011 +0200
batman-adv: Keep interface_tx as local function
interface_tx is not used outside of soft-interface.c and thus doesn't
need to be declared inside soft-interface.h
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index b8d3f248..0fc997e 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -553,7 +553,7 @@ static int interface_change_mtu(struct net_device *dev, int new_mtu)
return 0;
}
-int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
+static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
{
struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
struct bat_priv *bat_priv = netdev_priv(soft_iface);
diff --git a/net/batman-adv/soft-interface.h b/net/batman-adv/soft-interface.h
index c24906d..001546f 100644
--- a/net/batman-adv/soft-interface.h
+++ b/net/batman-adv/soft-interface.h
@@ -25,7 +25,6 @@
int my_skb_head_push(struct sk_buff *skb, unsigned int len);
int softif_neigh_seq_print_text(struct seq_file *seq, void *offset);
void softif_neigh_purge(struct bat_priv *bat_priv);
-int interface_tx(struct sk_buff *skb, struct net_device *soft_iface);
void interface_rx(struct net_device *soft_iface,
struct sk_buff *skb, struct hard_iface *recv_if,
int hdr_size);
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit 3b27ffb00fbe9d9189715ea13ce8712e2f0cb0c5
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Sat May 28 14:51:06 2011 +0200
batman-adv: Unify the first 3 bytes in each packet
The amount of duplicated code in the receive and routing code can be
reduced when all headers provide the packet type, version and ttl in the
same first bytes.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 9f77086..6ddbfd8 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -34,7 +34,7 @@ enum bat_packettype {
};
/* this file is included by batctl which needs these defines */
-#define COMPAT_VERSION 12
+#define COMPAT_VERSION 14
enum batman_flags {
PRIMARIES_FIRST_HOP = 1 << 4,
@@ -66,15 +66,15 @@ enum unicast_frag_flags {
struct batman_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
+ uint8_t ttl;
uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
- uint8_t tq;
uint32_t seqno;
uint8_t orig[6];
uint8_t prev_sender[6];
- uint8_t ttl;
- uint8_t num_tt;
uint8_t gw_flags; /* flags related to gateway class */
- uint8_t align;
+ uint8_t tq;
+ uint8_t num_tt;
+ uint8_t reserved;
} __packed;
#define BAT_PACKET_LEN sizeof(struct batman_packet)
@@ -82,12 +82,13 @@ struct batman_packet {
struct icmp_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t msg_type; /* see ICMP message types above */
uint8_t ttl;
+ uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6];
uint8_t orig[6];
uint16_t seqno;
uint8_t uid;
+ uint8_t reserved;
} __packed;
#define BAT_RR_LEN 16
@@ -97,8 +98,8 @@ struct icmp_packet {
struct icmp_packet_rr {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t msg_type; /* see ICMP message types above */
uint8_t ttl;
+ uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6];
uint8_t orig[6];
uint16_t seqno;
@@ -110,16 +111,19 @@ struct icmp_packet_rr {
struct unicast_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t dest[6];
uint8_t ttl;
+ uint8_t reserved;
+ uint8_t dest[6];
} __packed;
struct unicast_frag_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t dest[6];
uint8_t ttl;
+ uint8_t reserved;
+ uint8_t dest[6];
uint8_t flags;
+ uint8_t align;
uint8_t orig[6];
uint16_t seqno;
} __packed;
@@ -127,18 +131,20 @@ struct unicast_frag_packet {
struct bcast_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t orig[6];
uint8_t ttl;
+ uint8_t reserved;
uint32_t seqno;
+ uint8_t orig[6];
} __packed;
struct vis_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
+ uint8_t ttl; /* TTL */
uint8_t vis_type; /* which type of vis-participant sent this? */
- uint8_t entries; /* number of entries behind this struct */
uint32_t seqno; /* sequence number */
- uint8_t ttl; /* TTL */
+ uint8_t entries; /* number of entries behind this struct */
+ uint8_t reserved;
uint8_t vis_orig[6]; /* originator that announces its neighbors */
uint8_t target_orig[6]; /* who should receive this packet */
uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
--
LinuxNextTracking
11 years, 7 months
[linux-next] LinuxNextTracking branch, master, updated. next-20110624
by batman@open-mesh.org
The following commit has been merged in the master branch:
commit b2c44a53836559b5e2823aa215c979c33bc9e2db
Author: David Howells <dhowells(a)redhat.com>
Date: Wed Jun 15 09:41:36 2011 +0200
batman-adv: count_real_packets() in batman-adv assumes char is signed
count_real_packets() in batman-adv assumes char is signed, and returns -1
through it:
net/batman-adv/routing.c: In function 'receive_bat_packet':
net/batman-adv/routing.c:739: warning: comparison is always false due to limited range of data type
Use int instead.
Signed-off-by: David Howells <dhowells(a)redhat.com>
[sven(a)narfation.org: Rebase on top of current version]
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
diff --git a/net/batman-adv/bitarray.c b/net/batman-adv/bitarray.c
index 700ee4f..3659a25 100644
--- a/net/batman-adv/bitarray.c
+++ b/net/batman-adv/bitarray.c
@@ -26,8 +26,8 @@
/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
-uint8_t get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
- uint32_t curr_seqno)
+int get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
+ uint32_t curr_seqno)
{
int32_t diff, word_offset, word_num;
diff --git a/net/batman-adv/bitarray.h b/net/batman-adv/bitarray.h
index e32eb2d..277c037 100644
--- a/net/batman-adv/bitarray.h
+++ b/net/batman-adv/bitarray.h
@@ -26,8 +26,8 @@
/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
-uint8_t get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
- uint32_t curr_seqno);
+int get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
+ uint32_t curr_seqno);
/* turn corresponding bit on, so we can remember that we got the packet */
void bit_mark(unsigned long *seq_bits, int32_t n);
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 934f1f2..d5ce644 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -361,7 +361,7 @@ static void update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
const struct batman_packet *batman_packet,
struct hard_iface *if_incoming,
const unsigned char *tt_buff, int tt_buff_len,
- char is_duplicate)
+ int is_duplicate)
{
struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
struct neigh_node *router = NULL;
@@ -528,7 +528,7 @@ static int window_protected(struct bat_priv *bat_priv,
* -1 the packet is old and has been received while the seqno window
* was protected. Caller should drop it.
*/
-static char count_real_packets(const struct ethhdr *ethhdr,
+static int count_real_packets(const struct ethhdr *ethhdr,
const struct batman_packet *batman_packet,
const struct hard_iface *if_incoming)
{
@@ -536,7 +536,7 @@ static char count_real_packets(const struct ethhdr *ethhdr,
struct orig_node *orig_node;
struct neigh_node *tmp_neigh_node;
struct hlist_node *node;
- char is_duplicate = 0;
+ int is_duplicate = 0;
int32_t seq_diff;
int need_update = 0;
int set_mark, ret = -1;
@@ -605,7 +605,7 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
char has_directlink_flag;
char is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
char is_broadcast = 0, is_bidirectional, is_single_hop_neigh;
- char is_duplicate;
+ int is_duplicate;
uint32_t if_incoming_seqno;
/* Silently drop when the batman packet is actually not a
--
LinuxNextTracking
11 years, 7 months