Commit a73105b8 authored by Antonio Quartulli's avatar Antonio Quartulli Committed by Sven Eckelmann

batman-adv: improved client announcement mechanism

The client announcement mechanism informs every mesh node in the network
of any connected non-mesh client, in order to find the path towards that
client from any given point in the mesh.

The old implementation was based on the simple idea of appending a data
buffer to each OGM containing all the client MAC addresses the node is
serving. All other nodes can populate their global translation tables
(table which links client MAC addresses to node addresses) using this
MAC address buffer and linking it to the node's address contained in the
OGM. A node that wants to contact a client has to lookup the node the
client is connected to and its address in the global translation table.

It is easy to understand that this implementation suffers from several
issues:
 - big overhead (each and every OGM contains the entire list of
   connected clients)
 - high latencies for client route updates due to long OGM trip time and
   OGM losses

The new implementation addresses these issues by appending client
changes (new client joined or a client left) to the OGM instead of
filling it with all the client addresses each time. In this way nodes
can modify their global tables by means of "updates", thus reducing the
overhead within the OGMs.

To keep the entire network in sync each node maintains a translation
table version number (ttvn) and a translation table checksum. These
values are spread with the OGM to allow all the network participants to
determine whether or not they need to update their translation table
information.

When a translation table lookup is performed in order to send a packet
to a client attached to another node, the destination's ttvn is added to
the payload packet. Forwarding nodes can compare the packet's ttvn with
their destination's ttvn (this node could have a fresher information
than the source) and re-route the packet if necessary. This greatly
reduces the packet loss of clients roaming from one AP to the next.
Signed-off-by: default avatarAntonio Quartulli <ordex@autistici.org>
Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
parent 3b27ffb0
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
config BATMAN_ADV config BATMAN_ADV
tristate "B.A.T.M.A.N. Advanced Meshing Protocol" tristate "B.A.T.M.A.N. Advanced Meshing Protocol"
depends on NET depends on NET
select CRC16
default n default n
---help--- ---help---
......
...@@ -20,17 +20,12 @@ ...@@ -20,17 +20,12 @@
*/ */
#include "main.h" #include "main.h"
#include "translation-table.h"
#include "aggregation.h" #include "aggregation.h"
#include "send.h" #include "send.h"
#include "routing.h" #include "routing.h"
#include "hard-interface.h" #include "hard-interface.h"
/* calculate the size of the tt information for a given packet */
static int tt_len(const struct batman_packet *batman_packet)
{
return batman_packet->num_tt * ETH_ALEN;
}
/* return true if new_packet can be aggregated with forw_packet */ /* return true if new_packet can be aggregated with forw_packet */
static bool can_aggregate_with(const struct batman_packet *new_batman_packet, static bool can_aggregate_with(const struct batman_packet *new_batman_packet,
int packet_len, int packet_len,
...@@ -264,18 +259,20 @@ void receive_aggr_bat_packet(const struct ethhdr *ethhdr, ...@@ -264,18 +259,20 @@ void receive_aggr_bat_packet(const struct ethhdr *ethhdr,
batman_packet = (struct batman_packet *)packet_buff; batman_packet = (struct batman_packet *)packet_buff;
do { do {
/* network to host order for our 32bit seqno, and the /* network to host order for our 32bit seqno and the
orig_interval. */ orig_interval */
batman_packet->seqno = ntohl(batman_packet->seqno); batman_packet->seqno = ntohl(batman_packet->seqno);
batman_packet->tt_crc = ntohs(batman_packet->tt_crc);
tt_buff = packet_buff + buff_pos + BAT_PACKET_LEN; tt_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
receive_bat_packet(ethhdr, batman_packet,
tt_buff, tt_len(batman_packet),
if_incoming);
buff_pos += BAT_PACKET_LEN + tt_len(batman_packet); receive_bat_packet(ethhdr, batman_packet, tt_buff, if_incoming);
buff_pos += BAT_PACKET_LEN +
tt_len(batman_packet->tt_num_changes);
batman_packet = (struct batman_packet *) batman_packet = (struct batman_packet *)
(packet_buff + buff_pos); (packet_buff + buff_pos);
} while (aggregated_packet(buff_pos, packet_len, } while (aggregated_packet(buff_pos, packet_len,
batman_packet->num_tt)); batman_packet->tt_num_changes));
} }
...@@ -25,9 +25,11 @@ ...@@ -25,9 +25,11 @@
#include "main.h" #include "main.h"
/* is there another aggregated packet here? */ /* is there another aggregated packet here? */
static inline int aggregated_packet(int buff_pos, int packet_len, int num_tt) static inline int aggregated_packet(int buff_pos, int packet_len,
int tt_num_changes)
{ {
int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_tt * ETH_ALEN); int next_buff_pos = buff_pos + BAT_PACKET_LEN + (tt_num_changes *
sizeof(struct tt_change));
return (next_buff_pos <= packet_len) && return (next_buff_pos <= packet_len) &&
(next_buff_pos <= MAX_AGGREGATION_BYTES); (next_buff_pos <= MAX_AGGREGATION_BYTES);
......
...@@ -375,7 +375,7 @@ BAT_ATTR_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, TQ_MAX_VALUE, ...@@ -375,7 +375,7 @@ BAT_ATTR_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, TQ_MAX_VALUE,
static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth, static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth,
store_gw_bwidth); store_gw_bwidth);
#ifdef CONFIG_BATMAN_ADV_DEBUG #ifdef CONFIG_BATMAN_ADV_DEBUG
BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 3, NULL); BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 7, NULL);
#endif #endif
static struct bat_attribute *mesh_attrs[] = { static struct bat_attribute *mesh_attrs[] = {
......
...@@ -152,12 +152,6 @@ static void primary_if_select(struct bat_priv *bat_priv, ...@@ -152,12 +152,6 @@ static void primary_if_select(struct bat_priv *bat_priv,
batman_packet->ttl = TTL; batman_packet->ttl = TTL;
primary_if_update_addr(bat_priv); 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) static bool hardif_is_iface_up(const struct hard_iface *hard_iface)
...@@ -340,7 +334,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface, ...@@ -340,7 +334,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
batman_packet->flags = NO_FLAGS; batman_packet->flags = NO_FLAGS;
batman_packet->ttl = 2; batman_packet->ttl = 2;
batman_packet->tq = TQ_MAX_VALUE; 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; hard_iface->if_num = bat_priv->num_ifaces;
bat_priv->num_ifaces++; bat_priv->num_ifaces++;
...@@ -659,6 +654,10 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, ...@@ -659,6 +654,10 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
case BAT_VIS: case BAT_VIS:
ret = recv_vis_packet(skb, hard_iface); ret = recv_vis_packet(skb, hard_iface);
break; break;
/* Translation table query (request or response) */
case BAT_TT_QUERY:
ret = recv_tt_query(skb, hard_iface);
break;
default: default:
ret = NET_RX_DROP; ret = NET_RX_DROP;
} }
......
...@@ -86,6 +86,9 @@ int mesh_init(struct net_device *soft_iface) ...@@ -86,6 +86,9 @@ int mesh_init(struct net_device *soft_iface)
spin_lock_init(&bat_priv->forw_bcast_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_lhash_lock);
spin_lock_init(&bat_priv->tt_ghash_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_buff_lock);
spin_lock_init(&bat_priv->gw_list_lock); spin_lock_init(&bat_priv->gw_list_lock);
spin_lock_init(&bat_priv->vis_hash_lock); spin_lock_init(&bat_priv->vis_hash_lock);
spin_lock_init(&bat_priv->vis_list_lock); spin_lock_init(&bat_priv->vis_list_lock);
...@@ -96,14 +99,13 @@ int mesh_init(struct net_device *soft_iface) ...@@ -96,14 +99,13 @@ int mesh_init(struct net_device *soft_iface)
INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
INIT_HLIST_HEAD(&bat_priv->gw_list); INIT_HLIST_HEAD(&bat_priv->gw_list);
INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids); INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids);
INIT_LIST_HEAD(&bat_priv->tt_changes_list);
INIT_LIST_HEAD(&bat_priv->tt_req_list);
if (originator_init(bat_priv) < 1) if (originator_init(bat_priv) < 1)
goto err; goto err;
if (tt_local_init(bat_priv) < 1) if (tt_init(bat_priv) < 1)
goto err;
if (tt_global_init(bat_priv) < 1)
goto err; goto err;
tt_local_add(soft_iface, soft_iface->dev_addr); tt_local_add(soft_iface, soft_iface->dev_addr);
...@@ -137,8 +139,7 @@ void mesh_free(struct net_device *soft_iface) ...@@ -137,8 +139,7 @@ void mesh_free(struct net_device *soft_iface)
gw_node_purge(bat_priv); gw_node_purge(bat_priv);
originator_free(bat_priv); originator_free(bat_priv);
tt_local_free(bat_priv); tt_free(bat_priv);
tt_global_free(bat_priv);
softif_neigh_purge(bat_priv); softif_neigh_purge(bat_priv);
......
...@@ -46,11 +46,15 @@ ...@@ -46,11 +46,15 @@
/* sliding packet range of received originator messages in squence numbers /* sliding packet range of received originator messages in squence numbers
* (should be a multiple of our word size) */ * (should be a multiple of our word size) */
#define TQ_LOCAL_WINDOW_SIZE 64 #define TQ_LOCAL_WINDOW_SIZE 64
#define TT_REQUEST_TIMEOUT 3 /* seconds we have to keep pending tt_req */
#define TQ_GLOBAL_WINDOW_SIZE 5 #define TQ_GLOBAL_WINDOW_SIZE 5
#define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
#define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
#define TQ_TOTAL_BIDRECT_LIMIT 1 #define TQ_TOTAL_BIDRECT_LIMIT 1
#define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
#define NO_FLAGS 0 #define NO_FLAGS 0
#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
...@@ -96,7 +100,8 @@ enum mesh_state { ...@@ -96,7 +100,8 @@ enum mesh_state {
enum dbg_level { enum dbg_level {
DBG_BATMAN = 1 << 0, DBG_BATMAN = 1 << 0,
DBG_ROUTES = 1 << 1, /* route added / changed / deleted */ DBG_ROUTES = 1 << 1, /* route added / changed / deleted */
DBG_ALL = 3 DBG_TT = 1 << 2, /* translation table operations */
DBG_ALL = 7
}; };
......
...@@ -145,6 +145,7 @@ static void orig_node_free_rcu(struct rcu_head *rcu) ...@@ -145,6 +145,7 @@ static void orig_node_free_rcu(struct rcu_head *rcu)
tt_global_del_orig(orig_node->bat_priv, orig_node, tt_global_del_orig(orig_node->bat_priv, orig_node,
"originator timed out"); "originator timed out");
kfree(orig_node->tt_buff);
kfree(orig_node->bcast_own); kfree(orig_node->bcast_own);
kfree(orig_node->bcast_own_sum); kfree(orig_node->bcast_own_sum);
kfree(orig_node); kfree(orig_node);
...@@ -213,6 +214,7 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr) ...@@ -213,6 +214,7 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr)
spin_lock_init(&orig_node->ogm_cnt_lock); spin_lock_init(&orig_node->ogm_cnt_lock);
spin_lock_init(&orig_node->bcast_seqno_lock); spin_lock_init(&orig_node->bcast_seqno_lock);
spin_lock_init(&orig_node->neigh_list_lock); spin_lock_init(&orig_node->neigh_list_lock);
spin_lock_init(&orig_node->tt_buff_lock);
/* extra reference for return */ /* extra reference for return */
atomic_set(&orig_node->refcount, 2); atomic_set(&orig_node->refcount, 2);
...@@ -221,6 +223,8 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr) ...@@ -221,6 +223,8 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr)
memcpy(orig_node->orig, addr, ETH_ALEN); memcpy(orig_node->orig, addr, ETH_ALEN);
orig_node->router = NULL; orig_node->router = NULL;
orig_node->tt_buff = NULL; orig_node->tt_buff = NULL;
orig_node->tt_buff_len = 0;
atomic_set(&orig_node->tt_size, 0);
orig_node->bcast_seqno_reset = jiffies - 1 orig_node->bcast_seqno_reset = jiffies - 1
- msecs_to_jiffies(RESET_PROTECTION_MS); - msecs_to_jiffies(RESET_PROTECTION_MS);
orig_node->batman_seqno_reset = jiffies - 1 orig_node->batman_seqno_reset = jiffies - 1
...@@ -330,9 +334,7 @@ static bool purge_orig_node(struct bat_priv *bat_priv, ...@@ -330,9 +334,7 @@ static bool purge_orig_node(struct bat_priv *bat_priv,
if (purge_orig_neighbors(bat_priv, orig_node, if (purge_orig_neighbors(bat_priv, orig_node,
&best_neigh_node)) { &best_neigh_node)) {
update_routes(bat_priv, orig_node, update_routes(bat_priv, orig_node,
best_neigh_node, best_neigh_node);
orig_node->tt_buff,
orig_node->tt_buff_len);
} }
} }
......
...@@ -30,7 +30,8 @@ enum bat_packettype { ...@@ -30,7 +30,8 @@ enum bat_packettype {
BAT_UNICAST = 0x03, BAT_UNICAST = 0x03,
BAT_BCAST = 0x04, BAT_BCAST = 0x04,
BAT_VIS = 0x05, BAT_VIS = 0x05,
BAT_UNICAST_FRAG = 0x06 BAT_UNICAST_FRAG = 0x06,
BAT_TT_QUERY = 0x07
}; };
/* this file is included by batctl which needs these defines */ /* this file is included by batctl which needs these defines */
...@@ -63,6 +64,25 @@ enum unicast_frag_flags { ...@@ -63,6 +64,25 @@ enum unicast_frag_flags {
UNI_FRAG_LARGETAIL = 1 << 1 UNI_FRAG_LARGETAIL = 1 << 1
}; };
/* TT_QUERY subtypes */
#define TT_QUERY_TYPE_MASK 0x3
enum tt_query_packettype {
TT_REQUEST = 0,
TT_RESPONSE = 1
};
/* TT_QUERY flags */
enum tt_query_flags {
TT_FULL_TABLE = 1 << 2
};
/* TT_CHANGE flags */
enum tt_change_flags {
TT_CHANGE_DEL = 0x01,
TT_CLIENT_ROAM = 0x02
};
struct batman_packet { struct batman_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
...@@ -73,8 +93,9 @@ struct batman_packet { ...@@ -73,8 +93,9 @@ struct batman_packet {
uint8_t prev_sender[6]; uint8_t prev_sender[6];
uint8_t gw_flags; /* flags related to gateway class */ uint8_t gw_flags; /* flags related to gateway class */
uint8_t tq; uint8_t tq;
uint8_t num_tt; uint8_t tt_num_changes;
uint8_t reserved; uint8_t ttvn; /* translation table version number */
uint16_t tt_crc;
} __packed; } __packed;
#define BAT_PACKET_LEN sizeof(struct batman_packet) #define BAT_PACKET_LEN sizeof(struct batman_packet)
...@@ -112,7 +133,7 @@ struct unicast_packet { ...@@ -112,7 +133,7 @@ struct unicast_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t ttl; uint8_t ttl;
uint8_t reserved; uint8_t ttvn; /* destination translation table version number */
uint8_t dest[6]; uint8_t dest[6];
} __packed; } __packed;
...@@ -120,7 +141,7 @@ struct unicast_frag_packet { ...@@ -120,7 +141,7 @@ struct unicast_frag_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t ttl; uint8_t ttl;
uint8_t reserved; uint8_t ttvn; /* destination translation table version number */
uint8_t dest[6]; uint8_t dest[6];
uint8_t flags; uint8_t flags;
uint8_t align; uint8_t align;
...@@ -150,4 +171,32 @@ struct vis_packet { ...@@ -150,4 +171,32 @@ struct vis_packet {
uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */ uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
} __packed; } __packed;
struct tt_query_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
uint8_t ttl;
/* the flag field is a combination of:
* - TT_REQUEST or TT_RESPONSE
* - TT_FULL_TABLE */
uint8_t flags;
uint8_t dst[ETH_ALEN];
uint8_t src[ETH_ALEN];
/* the ttvn field is:
* if TT_REQUEST: ttvn that triggered the
* request
* if TT_RESPONSE: new ttvn for the src
* orig_node */
uint8_t ttvn;
/* tt_data field is:
* if TT_REQUEST: crc associated with the
* ttvn
* if TT_RESPONSE: table_size */
uint16_t tt_data;
} __packed;
struct tt_change {
uint8_t flags;
uint8_t addr[ETH_ALEN];
} __packed;
#endif /* _NET_BATMAN_ADV_PACKET_H_ */ #endif /* _NET_BATMAN_ADV_PACKET_H_ */
This diff is collapsed.
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
void slide_own_bcast_window(struct hard_iface *hard_iface); void slide_own_bcast_window(struct hard_iface *hard_iface);
void receive_bat_packet(const struct ethhdr *ethhdr, void receive_bat_packet(const struct ethhdr *ethhdr,
struct batman_packet *batman_packet, struct batman_packet *batman_packet,
const unsigned char *tt_buff, int tt_buff_len, const unsigned char *tt_buff,
struct hard_iface *if_incoming); struct hard_iface *if_incoming);
void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node, void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node,
struct neigh_node *neigh_node, const unsigned char *tt_buff, struct neigh_node *neigh_node);
int tt_buff_len);
int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if); int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if); int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if); int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
...@@ -37,6 +36,7 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if); ...@@ -37,6 +36,7 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if); 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_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_bat_packet(struct sk_buff *skb, struct hard_iface *recv_if);
int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if);
struct neigh_node *find_router(struct bat_priv *bat_priv, struct neigh_node *find_router(struct bat_priv *bat_priv,
struct orig_node *orig_node, struct orig_node *orig_node,
const struct hard_iface *recv_if); const struct hard_iface *recv_if);
......
...@@ -120,7 +120,7 @@ static void send_packet_to_if(struct forw_packet *forw_packet, ...@@ -120,7 +120,7 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
/* adjust all flags and log packets */ /* adjust all flags and log packets */
while (aggregated_packet(buff_pos, while (aggregated_packet(buff_pos,
forw_packet->packet_len, forw_packet->packet_len,
batman_packet->num_tt)) { batman_packet->tt_num_changes)) {
/* we might have aggregated direct link packets with an /* we might have aggregated direct link packets with an
* ordinary base packet */ * ordinary base packet */
...@@ -135,17 +135,17 @@ static void send_packet_to_if(struct forw_packet *forw_packet, ...@@ -135,17 +135,17 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
"Forwarding")); "Forwarding"));
bat_dbg(DBG_BATMAN, bat_priv, bat_dbg(DBG_BATMAN, bat_priv,
"%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d," "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d,"
" IDF %s) on interface %s [%pM]\n", " IDF %s, hvn %d) on interface %s [%pM]\n",
fwd_str, (packet_num > 0 ? "aggregated " : ""), fwd_str, (packet_num > 0 ? "aggregated " : ""),
batman_packet->orig, ntohl(batman_packet->seqno), batman_packet->orig, ntohl(batman_packet->seqno),
batman_packet->tq, batman_packet->ttl, batman_packet->tq, batman_packet->ttl,
(batman_packet->flags & DIRECTLINK ? (batman_packet->flags & DIRECTLINK ?
"on" : "off"), "on" : "off"),
hard_iface->net_dev->name, batman_packet->ttvn, hard_iface->net_dev->name,
hard_iface->net_dev->dev_addr); hard_iface->net_dev->dev_addr);
buff_pos += sizeof(*batman_packet) + buff_pos += sizeof(*batman_packet) +
(batman_packet->num_tt * ETH_ALEN); tt_len(batman_packet->tt_num_changes);
packet_num++; packet_num++;
batman_packet = (struct batman_packet *) batman_packet = (struct batman_packet *)
(forw_packet->skb->data + buff_pos); (forw_packet->skb->data + buff_pos);
...@@ -213,25 +213,18 @@ static void send_packet(struct forw_packet *forw_packet) ...@@ -213,25 +213,18 @@ static void send_packet(struct forw_packet *forw_packet)
rcu_read_unlock(); rcu_read_unlock();
} }
static void rebuild_batman_packet(struct bat_priv *bat_priv, static void realloc_packet_buffer(struct hard_iface *hard_iface,
struct hard_iface *hard_iface) int new_len)
{ {
int new_len;
unsigned char *new_buff; unsigned char *new_buff;
struct batman_packet *batman_packet; struct batman_packet *batman_packet;
new_len = sizeof(*batman_packet) + (bat_priv->num_local_tt * ETH_ALEN);
new_buff = kmalloc(new_len, GFP_ATOMIC); new_buff = kmalloc(new_len, GFP_ATOMIC);
/* keep old buffer if kmalloc should fail */ /* keep old buffer if kmalloc should fail */
if (new_buff) { if (new_buff) {
memcpy(new_buff, hard_iface->packet_buff, memcpy(new_buff, hard_iface->packet_buff,
sizeof(*batman_packet)); sizeof(*batman_packet));
batman_packet = (struct batman_packet *)new_buff;
batman_packet->num_tt = tt_local_fill_buffer(bat_priv,
new_buff + sizeof(*batman_packet),
new_len - sizeof(*batman_packet));
kfree(hard_iface->packet_buff); kfree(hard_iface->packet_buff);
hard_iface->packet_buff = new_buff; hard_iface->packet_buff = new_buff;
...@@ -239,6 +232,46 @@ static void rebuild_batman_packet(struct bat_priv *bat_priv, ...@@ -239,6 +232,46 @@ static void rebuild_batman_packet(struct bat_priv *bat_priv,
} }
} }
/* when calling this function (hard_iface == primary_if) has to be true */
static void prepare_packet_buffer(struct bat_priv *bat_priv,
struct hard_iface *hard_iface)
{
int new_len;
struct batman_packet *batman_packet;
new_len = BAT_PACKET_LEN +
tt_len((uint8_t)atomic_read(&bat_priv->tt_local_changes));
/* if we have too many changes for one packet don't send any
* and wait for the tt table request which will be fragmented */
if (new_len > hard_iface->soft_iface->mtu)
new_len = BAT_PACKET_LEN;
realloc_packet_buffer(hard_iface, new_len);
batman_packet = (struct batman_packet *)hard_iface->packet_buff;
atomic_set(&bat_priv->tt_crc, tt_local_crc(bat_priv));
/* reset the sending counter */
atomic_set(&bat_priv->tt_ogm_append_cnt, TT_OGM_APPEND_MAX);
batman_packet->tt_num_changes = tt_changes_fill_buffer(bat_priv,
hard_iface->packet_buff + BAT_PACKET_LEN,
hard_iface->packet_len - BAT_PACKET_LEN);
}
static void reset_packet_buffer(struct bat_priv *bat_priv,
struct hard_iface *hard_iface)
{
struct batman_packet *batman_packet;
realloc_packet_buffer(hard_iface, BAT_PACKET_LEN);
batman_packet = (struct batman_packet *)hard_iface->packet_buff;
batman_packet->tt_num_changes = 0;
}
void schedule_own_packet(struct hard_iface *hard_iface) void schedule_own_packet(struct hard_iface *hard_iface)
{ {
struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
...@@ -264,14 +297,22 @@ void schedule_own_packet(struct hard_iface *hard_iface) ...@@ -264,14 +297,22 @@ void schedule_own_packet(struct hard_iface *hard_iface)
if (hard_iface->if_status == IF_TO_BE_ACTIVATED) if (hard_iface->if_status == IF_TO_BE_ACTIVATED)
hard_iface->if_status = IF_ACTIVE; hard_iface->if_status = IF_ACTIVE;
/* if local tt has changed and interface is a primary interface */ if (hard_iface == primary_if) {
if ((atomic_read(&bat_priv->tt_local_changed)) && /* if at least one change happened */
(hard_iface == primary_if)) if (atomic_read(&bat_priv->tt_local_changes) > 0) {
rebuild_batman_packet(bat_priv, hard_iface); prepare_packet_buffer(bat_priv, hard_iface);
/* Increment the TTVN only once per OGM interval */
atomic_inc(&bat_priv->ttvn);
}
/* if the changes have been sent enough times */
if (!atomic_dec_not_zero(&bat_priv->tt_ogm_append_cnt))
reset_packet_buffer(bat_priv, hard_iface);
}
/** /**
* NOTE: packet_buff might just have been re-allocated in * NOTE: packet_buff might just have been re-allocated in
* rebuild_batman_packet() * prepare_packet_buffer() or in reset_packet_buffer()
*/ */
batman_packet = (struct batman_packet *)hard_iface->packet_buff; batman_packet = (struct batman_packet *)hard_iface->packet_buff;
...@@ -279,6 +320,9 @@ void schedule_own_packet(struct hard_iface *hard_iface) ...@@ -279,6 +320,9 @@ void schedule_own_packet(struct hard_iface *hard_iface)
batman_packet->seqno = batman_packet->seqno =
htonl((uint32_t)atomic_read(&hard_iface->seqno)); htonl((uint32_t)atomic_read(&hard_iface->seqno));
batman_packet->ttvn = atomic_read(&bat_priv->ttvn);
batman_packet->tt_crc = htons((uint16_t)atomic_read(&bat_priv->tt_crc));
if (vis_server == VIS_TYPE_SERVER_SYNC) if (vis_server == VIS_TYPE_SERVER_SYNC)
batman_packet->flags |= VIS_SERVER; batman_packet->flags |= VIS_SERVER;
else else
...@@ -307,13 +351,14 @@ void schedule_own_packet(struct hard_iface *hard_iface) ...@@ -307,13 +351,14 @@ void schedule_own_packet(struct hard_iface *hard_iface)
void schedule_forward_packet(struct orig_node *orig_node, void schedule_forward_packet(struct orig_node *orig_node,
const struct ethhdr *ethhdr, const struct ethhdr *ethhdr,
struct batman_packet *batman_packet, struct batman_packet *batman_packet,
int directlink, int tt_buff_len, int directlink,
struct hard_iface *if_incoming) struct hard_iface *if_incoming)
{ {
struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
struct neigh_node *router; struct neigh_node *router;
uint8_t in_tq, in_ttl, tq_avg = 0; uint8_t in_tq, in_ttl, tq_avg = 0;
unsigned long send_time; unsigned long send_time;
uint8_t tt_num_changes;
if (batman_packet->ttl <= 1) { if (batman_packet->ttl <= 1) {
bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n"); bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
...@@ -324,6 +369,7 @@ void schedule_forward_packet(struct orig_node *orig_node, ...@@ -324,6 +369,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
in_tq = batman_packet->tq; in_tq = batman_packet->tq;
in_ttl = batman_packet->ttl; in_ttl = batman_packet->ttl;
tt_num_changes = batman_packet->tt_num_changes;
batman_packet->ttl--; batman_packet->ttl--;
memcpy(batman_packet->prev_sender, ethhdr->h_source, ETH_ALEN); memcpy(batman_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
...@@ -356,6 +402,7 @@ void schedule_forward_packet(struct orig_node *orig_node, ...@@ -356,6 +402,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
batman_packet->ttl); batman_packet->ttl);
batman_packet->seqno = htonl(batman_packet->seqno); batman_packet->seqno = htonl(batman_packet->seqno);
batman_packet->tt_crc = htons(batman_packet->tt_crc);
/* switch of primaries first hop flag when forwarding */ /* switch of primaries first hop flag when forwarding */
batman_packet->flags &= ~PRIMARIES_FIRST_HOP; batman_packet->flags &= ~PRIMARIES_FIRST_HOP;
...@@ -367,7 +414,7 @@ void schedule_forward_packet(struct orig_node *orig_node, ...@@ -367,7 +414,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
send_time = forward_send_time(); send_time = forward_send_time();
add_bat_packet_to_list(bat_priv, add_bat_packet_to_list(bat_priv,
(unsigned char *)batman_packet, (unsigned char *)batman_packet,
sizeof(*batman_packet) + tt_buff_len, sizeof(*batman_packet) + tt_len(tt_num_changes),
if_incoming, 0, send_time); if_incoming, 0, send_time);
} }
......
...@@ -28,7 +28,7 @@ void schedule_own_packet(struct hard_iface *hard_iface); ...@@ -28,7 +28,7 @@ void schedule_own_packet(struct hard_iface *hard_iface);
void schedule_forward_packet(struct orig_node *orig_node, void schedule_forward_packet(struct orig_node *orig_node,
const struct ethhdr *ethhdr, const struct ethhdr *ethhdr,
struct batman_packet *batman_packet, struct batman_packet *batman_packet,
int directlink, int tt_buff_len, int directlink,
struct hard_iface *if_outgoing); struct hard_iface *if_outgoing);
int add_bcast_packet_to_list(struct bat_priv *bat_priv, int add_bcast_packet_to_list(struct bat_priv *bat_priv,
const struct sk_buff *skb); const struct sk_buff *skb);
......
...@@ -534,7 +534,7 @@ static int interface_set_mac_addr(struct net_device *dev, void *p) ...@@ -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 */ /* only modify transtable if it has been initialised before */
if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) { if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
tt_local_remove(bat_priv, dev->dev_addr, tt_local_remove(bat_priv, dev->dev_addr,
"mac address changed"); "mac address changed");
tt_local_add(dev, addr->sa_data); tt_local_add(dev, addr->sa_data);
} }
...@@ -592,7 +592,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface) ...@@ -592,7 +592,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
if (curr_softif_neigh) if (curr_softif_neigh)
goto dropped; goto dropped;
/* TODO: check this for locks */ /* Register the client MAC in the transtable */
tt_local_add(soft_iface, ethhdr->h_source); tt_local_add(soft_iface, ethhdr->h_source);
if (is_multicast_ether_addr(ethhdr->h_dest)) { if (is_multicast_ether_addr(ethhdr->h_dest)) {
...@@ -830,7 +830,12 @@ struct net_device *softif_create(const char *name) ...@@ -830,7 +830,12 @@ struct net_device *softif_create(const char *name)
atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
atomic_set(&bat_priv->bcast_seqno, 1); atomic_set(&bat_priv->bcast_seqno, 1);
atomic_set(&bat_priv->tt_local_changed, 0); atomic_set(&bat_priv->ttvn, 0);
atomic_set(&bat_priv->tt_local_changes, 0);
atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
bat_priv->tt_buff = NULL;
bat_priv->tt_buff_len = 0;
bat_priv->primary_if = NULL; bat_priv->primary_if = NULL;
bat_priv->num_ifaces = 0; bat_priv->num_ifaces = 0;
......
This diff is collapsed.
...@@ -22,23 +22,43 @@ ...@@ -22,23 +22,43 @@
#ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ #ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
#define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ #define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
int tt_local_init(struct bat_priv *bat_priv); int tt_len(int changes_num);
int tt_changes_fill_buffer(struct bat_priv *bat_priv,
unsigned char *buff, int buff_len);
int tt_init(struct bat_priv *bat_priv);
void tt_local_add(struct net_device *soft_iface, const uint8_t *addr); void tt_local_add(struct net_device *soft_iface, const uint8_t *addr);
void tt_local_remove(struct bat_priv *bat_priv, void tt_local_remove(struct bat_priv *bat_priv,
const uint8_t *addr, const char *message); const uint8_t *addr, const char *message);
int tt_local_fill_buffer(struct bat_priv *bat_priv,
unsigned char *buff, int buff_len);
int tt_local_seq_print_text(struct seq_file *seq, void *offset); int tt_local_seq_print_text(struct seq_file *seq, void *offset);
void tt_local_free(struct bat_priv *bat_priv);
int tt_global_init(struct bat_priv *bat_priv);
void tt_global_add_orig(struct bat_priv *bat_priv, void tt_global_add_orig(struct bat_priv *bat_priv,
struct orig_node *orig_node, struct orig_node *orig_node,
const unsigned char *tt_buff, int tt_buff_len); 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);
int tt_global_seq_print_text(struct seq_file *seq, void *offset); int tt_global_seq_print_text(struct seq_file *seq, void *offset);
void tt_global_del_orig(struct bat_priv *bat_priv, void tt_global_del_orig(struct bat_priv *bat_priv,
struct orig_node *orig_node, const char *message); struct orig_node *orig_node, const char *message);
void tt_global_free(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);
struct orig_node *transtable_search(struct bat_priv *bat_priv, struct orig_node *transtable_search(struct bat_priv *bat_priv,
const uint8_t *addr); const uint8_t *addr);
void tt_save_orig_buffer(struct bat_priv *bat_priv, struct orig_node *orig_node,
const unsigned char *tt_buff, uint8_t tt_num_changes);
uint16_t tt_local_crc(struct bat_priv *bat_priv);
uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node);
void tt_free(struct bat_priv *bat_priv);
int send_tt_request(struct bat_priv *bat_priv,
struct orig_node *dst_orig_node, uint8_t hvn,
uint16_t tt_crc, bool full_table);
bool send_tt_response(struct bat_priv *bat_priv,
struct tt_query_packet *tt_request);
void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node,
uint16_t tt_num_changes, uint8_t ttvn,
struct tt_change *tt_change);
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);
#endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */ #endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
...@@ -75,8 +75,12 @@ struct orig_node { ...@@ -75,8 +75,12 @@ struct orig_node {
unsigned long batman_seqno_reset; unsigned long batman_seqno_reset;
uint8_t gw_flags; uint8_t gw_flags;
uint8_t flags; uint8_t flags;
atomic_t last_ttvn; /* last seen translation table version number */
uint16_t tt_crc;
unsigned char *tt_buff; unsigned char *tt_buff;
int16_t tt_buff_len; int16_t tt_buff_len;
spinlock_t tt_buff_lock; /* protects tt_buff */
atomic_t tt_size;
uint32_t last_real_seqno; uint32_t last_real_seqno;
uint8_t last_ttl; uint8_t last_ttl;
unsigned long bcast_bits[NUM_WORDS]; unsigned long bcast_bits[NUM_WORDS];
...@@ -94,6 +98,7 @@ struct orig_node { ...@@ -94,6 +98,7 @@ struct orig_node {
spinlock_t ogm_cnt_lock; spinlock_t ogm_cnt_lock;
/* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */ /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
spinlock_t bcast_seqno_lock; spinlock_t bcast_seqno_lock;
spinlock_t tt_list_lock; /* protects tt_list */
atomic_t bond_candidates; atomic_t bond_candidates;
struct list_head bond_list; struct list_head bond_list;
}; };
...@@ -145,6 +150,9 @@ struct bat_priv { ...@@ -145,6 +150,9 @@ struct bat_priv {
atomic_t bcast_seqno; atomic_t bcast_seqno;
atomic_t bcast_queue_left; atomic_t bcast_queue_left;
atomic_t batman_queue_left; atomic_t batman_queue_left;
atomic_t ttvn; /* tranlation table version number */
atomic_t tt_ogm_append_cnt;
atomic_t tt_local_changes; /* changes registered in a OGM interval */
char num_ifaces; char num_ifaces;
struct debug_log *debug_log; struct debug_log *debug_log;
struct kobject *mesh_obj; struct kobject *mesh_obj;
...@@ -153,22 +161,30 @@ struct bat_priv { ...@@ -153,22 +161,30 @@ struct bat_priv {
struct hlist_head forw_bcast_list; struct hlist_head forw_bcast_list;
struct hlist_head gw_list; struct hlist_head gw_list;
struct hlist_head softif_neigh_vids; struct hlist_head softif_neigh_vids;
struct list_head tt_changes_list; /* tracks changes in a OGM int */
struct list_head vis_send_list; struct list_head vis_send_list;
struct hashtable_t *orig_hash; struct hashtable_t *orig_hash;
struct hashtable_t *tt_local_hash; struct hashtable_t *tt_local_hash;
struct hashtable_t *tt_global_hash; struct hashtable_t *tt_global_hash;
struct list_head tt_req_list; /* list of pending tt_requests */
struct hashtable_t *vis_hash; struct hashtable_t *vis_hash;
spinlock_t forw_bat_list_lock; /* protects forw_bat_list */ spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
spinlock_t forw_bcast_list_lock; /* protects */ 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_lhash_lock; /* protects tt_local_hash */
spinlock_t tt_ghash_lock; /* protects tt_global_hash */ spinlock_t tt_ghash_lock; /* protects tt_global_hash */
spinlock_t tt_req_list_lock; /* protects tt_req_list */
spinlock_t gw_list_lock; /* protects gw_list and curr_gw */ spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
spinlock_t vis_hash_lock; /* protects vis_hash */ spinlock_t vis_hash_lock; /* protects vis_hash */
spinlock_t vis_list_lock; /* protects vis_info::recv_list */ spinlock_t vis_list_lock; /* protects vis_info::recv_list */
spinlock_t softif_neigh_lock; /* protects soft-interface neigh list */ spinlock_t softif_neigh_lock; /* protects soft-interface neigh list */
spinlock_t softif_neigh_vid_lock; /* protects soft-interface vid list */ spinlock_t softif_neigh_vid_lock; /* protects soft-interface vid list */
int16_t num_local_tt; atomic_t num_local_tt;
atomic_t tt_local_changed; /* Checksum of the local table, recomputed before sending a new OGM */
atomic_t tt_crc;
unsigned char *tt_buff;
int16_t tt_buff_len;
spinlock_t tt_buff_lock; /* protects tt_buff */
struct delayed_work tt_work; struct delayed_work tt_work;
struct delayed_work orig_work; struct delayed_work orig_work;
struct delayed_work vis_work; struct delayed_work vis_work;
...@@ -202,9 +218,22 @@ struct tt_local_entry { ...@@ -202,9 +218,22 @@ struct tt_local_entry {
struct tt_global_entry { struct tt_global_entry {
uint8_t addr[ETH_ALEN]; uint8_t addr[ETH_ALEN];
struct orig_node *orig_node; struct orig_node *orig_node;
uint8_t ttvn;
/* entry in the global table */
struct hlist_node hash_entry; struct hlist_node hash_entry;
}; };
struct tt_change_node {
struct list_head list;
struct tt_change change;
};
struct tt_req_node {
uint8_t addr[ETH_ALEN];
unsigned long issued_at;
struct list_head list;
};
/** /**
* forw_packet - structure for forw_list maintaining packets to be * forw_packet - structure for forw_list maintaining packets to be
* send/forwarded * send/forwarded
......
...@@ -325,6 +325,9 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv) ...@@ -325,6 +325,9 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
unicast_packet->ttl = TTL; unicast_packet->ttl = TTL;
/* copy the destination for faster routing */ /* copy the destination for faster routing */
memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
/* set the destination tt version number */
unicast_packet->ttvn =
(uint8_t)atomic_read(&orig_node->last_ttvn);
if (atomic_read(&bat_priv->fragmentation) && if (atomic_read(&bat_priv->fragmentation) &&
data_len + sizeof(*unicast_packet) > data_len + sizeof(*unicast_packet) >
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment