b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batman-adv: modify TT_RESPONSE-full-table format
@ 2011-05-29 23:05 Antonio Quartulli
  2011-05-30 13:46 ` Marek Lindner
  0 siblings, 1 reply; 13+ messages in thread
From: Antonio Quartulli @ 2011-05-29 23:05 UTC (permalink / raw)
  To: B.A.T.M.A.N

In case of TT_REQUEST for a full table, the related TT_RESPONSE now
carries a set of tt_change structures instead of pure MACs.
This helps to keep the TT_RESPONSE format extensible. In particular, the
flag field can be used for later purposes.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 translation-table.c |   99 +++++++++++++++++++++++++--------------------------
 1 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index f04ab9b..3f30460 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -1012,6 +1012,7 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 	struct neigh_node *neigh_node = NULL;
 	struct hard_iface *primary_if = NULL;
 	struct tt_global_entry *tt_global_entry;
+	struct tt_change *tt_change;
 	struct hlist_node *node;
 	struct hlist_head *head;
 	struct hashtable_t *hash;
@@ -1086,14 +1087,14 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) *
-								ETH_ALEN;
+						sizeof(struct tt_change);
 		if (sizeof(struct tt_query_packet) + tt_len >
 						primary_if->soft_iface->mtu) {
 			tt_len = primary_if->soft_iface->mtu -
 						sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
+			tt_len -= tt_len % sizeof(struct tt_change);
 		}
-		tt_tot = tt_len / ETH_ALEN;
+		tt_tot = tt_len / sizeof(struct tt_change);
 
 		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
 				    tt_len + ETH_HLEN);
@@ -1106,7 +1107,8 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		tt_response->ttvn = (uint8_t)
 			atomic_read(&req_dst_orig_node->last_ttvn);
 
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
+		tt_change = (struct tt_change *)(skb->data +
+			  sizeof(struct tt_query_packet));
 		/* Fill the packet with the orig_node's local table */
 		hash = bat_priv->tt_global_hash;
 		tt_count = 0;
@@ -1120,10 +1122,13 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 					break;
 				if (tt_global_entry->orig_node ==
 				    req_dst_orig_node) {
-					memcpy(tt_buff + tt_count * ETH_ALEN,
+					memcpy(tt_change->addr,
 					       tt_global_entry->addr,
 					       ETH_ALEN);
+					tt_change->flags = TT_CHANGE_ADD;
+
 					tt_count++;
+					tt_change++;
 				}
 			}
 		}
@@ -1173,6 +1178,7 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 	struct orig_node *orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
 	struct tt_local_entry *tt_local_entry;
+	struct tt_change *tt_change;
 	struct hard_iface *primary_if = NULL;
 	struct hlist_node *node;
 	struct hlist_head *head;
@@ -1238,14 +1244,14 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&bat_priv->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) *
-								ETH_ALEN;
+						sizeof(struct tt_change);
 		if (sizeof(struct tt_query_packet) + tt_len >
 				primary_if->soft_iface->mtu) {
 			tt_len = primary_if->soft_iface->mtu -
 				sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
+			tt_len -= tt_len % sizeof(struct tt_change);
 		}
-		tt_tot = tt_len / ETH_ALEN;
+		tt_tot = tt_len / sizeof(struct tt_change);
 
 		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
 				    tt_len + ETH_HLEN);
@@ -1255,7 +1261,8 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		skb_reserve(skb, ETH_HLEN);
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
+		tt_change = (struct tt_change *)(skb->data +
+			    sizeof(struct tt_query_packet));
 		/* Fill the packet with the local table */
 		tt_response->ttvn =
 			(uint8_t)atomic_read(&bat_priv->ttvn);
@@ -1270,10 +1277,12 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 					head, hash_entry) {
 				if (tt_count == tt_tot)
 					break;
-				memcpy(tt_buff + tt_count * ETH_ALEN,
-					tt_local_entry->addr,
-						ETH_ALEN);
+				memcpy(tt_change->addr, tt_local_entry->addr,
+				       ETH_ALEN);
+				tt_change->flags = TT_CHANGE_ADD;
+
 				tt_count++;
+				tt_change++;
 			}
 		}
 		rcu_read_unlock();
@@ -1323,23 +1332,30 @@ bool send_tt_response(struct bat_priv *bat_priv,
 		return send_other_tt_response(bat_priv, tt_request);
 }
 
-/* Substitute the TT response source's table with the newone carried by the
- * packet */
-static void _tt_fill_gtable(struct bat_priv *bat_priv,
-			    struct orig_node *orig_node, unsigned char *tt_buff,
-			    uint16_t table_size, uint8_t ttvn)
+static void _tt_update_changes(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node,
+			       struct tt_change *tt_change,
+			       uint16_t tt_num_changes, uint8_t ttvn)
 {
-	int count;
-	unsigned char *tt_ptr;
-
-	for (count = 0; count < table_size; count++) {
-		tt_ptr = tt_buff + (count * ETH_ALEN);
+	int i;
 
-		/* If we fail to allocate a new entry we return immediatly */
-		if (!tt_global_add(bat_priv, orig_node, tt_ptr, ttvn, false))
-			return;
+	for (i = 0; i < tt_num_changes; i++) {
+		if ((tt_change + i)->flags & TT_CHANGE_DEL)
+			tt_global_del(bat_priv, orig_node,
+				      (tt_change + i)->addr,
+				      "tt removed by changes",
+				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+		else
+			if (!tt_global_add(bat_priv, orig_node,
+					   (tt_change + i)->addr, ttvn, false))
+				/* In case of problem while storing a
+				 * global_entry, we stop the updating
+				 * procedure without committing the
+				 * ttvn change. This will avoid to send
+				 * corrupted data on tt_request
+				 */
+				return;
 	}
-	atomic_set(&orig_node->last_ttvn, ttvn);
 }
 
 static void tt_fill_gtable(struct bat_priv *bat_priv,
@@ -1354,11 +1370,9 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	/* Purge the old table first.. */
 	tt_global_del_orig(bat_priv, orig_node, "Received full table");
 
-	_tt_fill_gtable(bat_priv, orig_node,
-		((unsigned char *)tt_response) +
-		sizeof(struct tt_query_packet),
-		tt_response->tt_data,
-		tt_response->ttvn);
+	_tt_update_changes(bat_priv, orig_node,
+			   (struct tt_change *)(tt_response + 1),
+			   tt_response->tt_data, tt_response->ttvn);
 
 	spin_lock_bh(&orig_node->tt_buff_lock);
 	kfree(orig_node->tt_buff);
@@ -1366,6 +1380,8 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	orig_node->tt_buff = NULL;
 	spin_unlock_bh(&orig_node->tt_buff_lock);
 
+	atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
+
 out:
 	if (orig_node)
 		orig_node_free_ref(orig_node);
@@ -1375,25 +1391,8 @@ 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)
 {
-	int i;
-
-	for (i = 0; i < tt_num_changes; i++) {
-		if ((tt_change + i)->flags & TT_CHANGE_DEL)
-			tt_global_del(bat_priv, orig_node,
-				      (tt_change + i)->addr,
-				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
-		else
-			if (!tt_global_add(bat_priv, orig_node,
-					   (tt_change + i)->addr, ttvn, false))
-				/* In case of problem while storing a
-				 * global_entry, we stop the updating
-				 * procedure without committing the
-				 * ttvn change. This will avoid to send
-				 * corrupted data on tt_request
-				 */
-				return;
-	}
+	_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
+			   ttvn);
 
 	tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change,
 			    tt_num_changes);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCH] batman-adv: modify TT_RESPONSE-full-table format
  2011-05-29 23:05 [B.A.T.M.A.N.] [PATCH] batman-adv: modify TT_RESPONSE-full-table format Antonio Quartulli
@ 2011-05-30 13:46 ` Marek Lindner
  2011-05-30 18:40   ` [B.A.T.M.A.N.] [PATCHv3] " Antonio Quartulli
  0 siblings, 1 reply; 13+ messages in thread
From: Marek Lindner @ 2011-05-30 13:46 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Marek Lindner

From: Antonio Quartulli <ordex@autistici.org>

In case of TT_REQUEST for a full table, the related TT_RESPONSE now
carries a set of tt_change structures instead of pure MACs.
This helps to keep the TT_RESPONSE format extensible. In particular, the
flag field can be used for later purposes.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
Merged full table write into a single function.

 translation-table.c |  278 +++++++++++++++++++++++++--------------------------
 1 files changed, 135 insertions(+), 143 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index f04ab9b..8a5df7a 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -493,7 +493,7 @@ static void tt_changes_list_free(struct bat_priv *bat_priv)
 	spin_unlock_bh(&bat_priv->tt_changes_list_lock);
 }
 
-/* caller must hold orig_node recount */
+/* 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, bool roaming)
 {
@@ -938,6 +938,76 @@ unlock:
 	return tt_req_node;
 }
 
+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;
+
+	return (tt_global_entry->orig_node == orig_node);
+}
+
+static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
+					      struct hashtable_t *hash,
+					      struct hard_iface *primary_if,
+					      int (*valid_cb)(const void *,
+							      const void *),
+					      void *cb_data)
+{
+	struct tt_local_entry *tt_local_entry;
+	struct tt_query_packet *tt_response;
+	struct tt_change *tt_change;
+	struct hlist_node *node;
+	struct hlist_head *head;
+	struct sk_buff *skb = NULL;
+	uint16_t tt_tot, tt_count;
+	ssize_t tt_query_size = sizeof(struct tt_query_packet);
+	int i;
+
+	if (sizeof(struct tt_query_packet) + tt_len >
+						primary_if->soft_iface->mtu) {
+		tt_len = primary_if->soft_iface->mtu - tt_query_size;
+		tt_len -= tt_len % sizeof(struct tt_change);
+	}
+	tt_tot = tt_len / sizeof(struct tt_change);
+
+	skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN);
+	if (!skb)
+		goto out;
+
+	skb_reserve(skb, ETH_HLEN);
+	tt_response = (struct tt_query_packet *)skb_put(skb,
+						     tt_query_size + tt_len);
+	tt_response->ttvn = ttvn;
+	tt_response->tt_data = htons(tt_tot);
+
+	tt_change = (struct tt_change *)(skb->data + tt_query_size);
+	tt_count = 0;
+
+	rcu_read_lock();
+	for (i = 0; i < hash->size; i++) {
+		head = &hash->table[i];
+
+		hlist_for_each_entry_rcu(tt_local_entry, node,
+					 head, hash_entry) {
+			if (tt_count == tt_tot)
+				break;
+
+			if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data)))
+				continue;
+
+			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
+			tt_change->flags = TT_CHANGE_ADD;
+
+			tt_count++;
+			tt_change++;
+		}
+	}
+	rcu_read_unlock();
+
+out:
+	return skb;
+}
+
 int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node,
 		    uint8_t ttvn, uint16_t tt_crc, bool full_table)
 {
@@ -1006,20 +1076,16 @@ out:
 }
 
 static bool send_other_tt_response(struct bat_priv *bat_priv,
-				  struct tt_query_packet *tt_request)
+				   struct tt_query_packet *tt_request)
 {
 	struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
 	struct hard_iface *primary_if = NULL;
-	struct tt_global_entry *tt_global_entry;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t orig_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t orig_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1077,6 +1143,7 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		/* Copy the last orig_node's OGM buffer */
@@ -1086,48 +1153,17 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-						primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-						sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_global_hash,
+					     primary_if, tt_global_valid_entry,
+					     req_dst_orig_node);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_response->ttvn = (uint8_t)
-			atomic_read(&req_dst_orig_node->last_ttvn);
-
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the orig_node's local table */
-		hash = bat_priv->tt_global_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_global_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				if (tt_global_entry->orig_node ==
-				    req_dst_orig_node) {
-					memcpy(tt_buff + tt_count * ETH_ALEN,
-					       tt_global_entry->addr,
-					       ETH_ALEN);
-					tt_count++;
-				}
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1135,7 +1171,6 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1168,20 +1203,16 @@ out:
 
 }
 static bool send_my_tt_response(struct bat_priv *bat_priv,
-			       struct tt_query_packet *tt_request)
+				struct tt_query_packet *tt_request)
 {
 	struct orig_node *orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
-	struct tt_local_entry *tt_local_entry;
 	struct hard_iface *primary_if = NULL;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t my_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t my_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1231,6 +1262,7 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		memcpy(tt_buff, bat_priv->tt_buff,
@@ -1238,45 +1270,16 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&bat_priv->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-				primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-				sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&bat_priv->ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_local_hash,
+					     primary_if, NULL, NULL);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the local table */
-		tt_response->ttvn =
-			(uint8_t)atomic_read(&bat_priv->ttvn);
-
-		hash = bat_priv->tt_local_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_local_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				memcpy(tt_buff + tt_count * ETH_ALEN,
-					tt_local_entry->addr,
-						ETH_ALEN);
-				tt_count++;
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1284,7 +1287,6 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1323,57 +1325,10 @@ bool send_tt_response(struct bat_priv *bat_priv,
 		return send_other_tt_response(bat_priv, tt_request);
 }
 
-/* Substitute the TT response source's table with the newone carried by the
- * packet */
-static void _tt_fill_gtable(struct bat_priv *bat_priv,
-			    struct orig_node *orig_node, unsigned char *tt_buff,
-			    uint16_t table_size, uint8_t ttvn)
-{
-	int count;
-	unsigned char *tt_ptr;
-
-	for (count = 0; count < table_size; count++) {
-		tt_ptr = tt_buff + (count * ETH_ALEN);
-
-		/* If we fail to allocate a new entry we return immediatly */
-		if (!tt_global_add(bat_priv, orig_node, tt_ptr, ttvn, false))
-			return;
-	}
-	atomic_set(&orig_node->last_ttvn, ttvn);
-}
-
-static void tt_fill_gtable(struct bat_priv *bat_priv,
-			   struct tt_query_packet *tt_response)
-{
-	struct orig_node *orig_node = NULL;
-
-	orig_node = orig_hash_find(bat_priv, tt_response->src);
-	if (!orig_node)
-		goto out;
-
-	/* Purge the old table first.. */
-	tt_global_del_orig(bat_priv, orig_node, "Received full table");
-
-	_tt_fill_gtable(bat_priv, orig_node,
-		((unsigned char *)tt_response) +
-		sizeof(struct tt_query_packet),
-		tt_response->tt_data,
-		tt_response->ttvn);
-
-	spin_lock_bh(&orig_node->tt_buff_lock);
-	kfree(orig_node->tt_buff);
-	orig_node->tt_buff_len = 0;
-	orig_node->tt_buff = NULL;
-	spin_unlock_bh(&orig_node->tt_buff_lock);
-
-out:
-	if (orig_node)
-		orig_node_free_ref(orig_node);
-}
-
-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)
+static void _tt_update_changes(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node,
+			       struct tt_change *tt_change,
+			       uint16_t tt_num_changes, uint8_t ttvn)
 {
 	int i;
 
@@ -1394,6 +1349,43 @@ void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node,
 				 */
 				return;
 	}
+}
+
+static void tt_fill_gtable(struct bat_priv *bat_priv,
+			   struct tt_query_packet *tt_response)
+{
+	struct orig_node *orig_node = NULL;
+
+	orig_node = orig_hash_find(bat_priv, tt_response->src);
+	if (!orig_node)
+		goto out;
+
+	/* Purge the old table first.. */
+	tt_global_del_orig(bat_priv, orig_node, "Received full table");
+
+	_tt_update_changes(bat_priv, orig_node,
+			   (struct tt_change *)(tt_response + 1),
+			   tt_response->tt_data, tt_response->ttvn);
+
+	spin_lock_bh(&orig_node->tt_buff_lock);
+	kfree(orig_node->tt_buff);
+	orig_node->tt_buff_len = 0;
+	orig_node->tt_buff = NULL;
+	spin_unlock_bh(&orig_node->tt_buff_lock);
+
+	atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
+
+out:
+	if (orig_node)
+		orig_node_free_ref(orig_node);
+}
+
+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)
+{
+	_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
+			   ttvn);
 
 	tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change,
 			    tt_num_changes);
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format
  2011-05-30 13:46 ` Marek Lindner
@ 2011-05-30 18:40   ` Antonio Quartulli
  2011-05-30 21:37     ` [B.A.T.M.A.N.] [PATCHv4] " Antonio Quartulli
  2011-06-01  5:34     ` [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format Andrew Lunn
  0 siblings, 2 replies; 13+ messages in thread
From: Antonio Quartulli @ 2011-05-30 18:40 UTC (permalink / raw)
  To: B.A.T.M.A.N; +Cc: Marek Lindner

In case of TT_REQUEST for a full table, the related TT_RESPONSE now
carries a set of tt_change structures instead of pure MACs.
This helps to keep the TT_RESPONSE format extensible. In particular, the
flag field can be used for later purposes.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 translation-table.c |  255 +++++++++++++++++++++++++--------------------------
 1 files changed, 125 insertions(+), 130 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index f04ab9b..1c50122 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -493,7 +493,7 @@ static void tt_changes_list_free(struct bat_priv *bat_priv)
 	spin_unlock_bh(&bat_priv->tt_changes_list_lock);
 }
 
-/* caller must hold orig_node recount */
+/* 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, bool roaming)
 {
@@ -938,6 +938,79 @@ unlock:
 	return tt_req_node;
 }
 
+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_GLOBAL_ROAM)
+		return 0;
+
+	return (tt_global_entry->orig_node == orig_node);
+}
+
+static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
+					      struct hashtable_t *hash,
+					      struct hard_iface *primary_if,
+					      int (*valid_cb)(const void *,
+							      const void *),
+					      void *cb_data)
+{
+	struct tt_local_entry *tt_local_entry;
+	struct tt_query_packet *tt_response;
+	struct tt_change *tt_change;
+	struct hlist_node *node;
+	struct hlist_head *head;
+	struct sk_buff *skb = NULL;
+	uint16_t tt_tot, tt_count;
+	ssize_t tt_query_size = sizeof(struct tt_query_packet);
+	int i;
+
+	if (sizeof(struct tt_query_packet) + tt_len >
+						primary_if->soft_iface->mtu) {
+		tt_len = primary_if->soft_iface->mtu - tt_query_size;
+		tt_len -= tt_len % sizeof(struct tt_change);
+	}
+	tt_tot = tt_len / sizeof(struct tt_change);
+
+	skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN);
+	if (!skb)
+		goto out;
+
+	skb_reserve(skb, ETH_HLEN);
+	tt_response = (struct tt_query_packet *)skb_put(skb,
+						     tt_query_size + tt_len);
+	tt_response->ttvn = ttvn;
+	tt_response->tt_data = htons(tt_tot);
+
+	tt_change = (struct tt_change *)(skb->data + tt_query_size);
+	tt_count = 0;
+
+	rcu_read_lock();
+	for (i = 0; i < hash->size; i++) {
+		head = &hash->table[i];
+
+		hlist_for_each_entry_rcu(tt_local_entry, node,
+					 head, hash_entry) {
+			if (tt_count == tt_tot)
+				break;
+
+			if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data)))
+				continue;
+
+			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
+			tt_change->flags = TT_CHANGE_ADD;
+
+			tt_count++;
+			tt_change++;
+		}
+	}
+	rcu_read_unlock();
+
+out:
+	return skb;
+}
+
 int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node,
 		    uint8_t ttvn, uint16_t tt_crc, bool full_table)
 {
@@ -1006,20 +1079,16 @@ out:
 }
 
 static bool send_other_tt_response(struct bat_priv *bat_priv,
-				  struct tt_query_packet *tt_request)
+				   struct tt_query_packet *tt_request)
 {
 	struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
 	struct hard_iface *primary_if = NULL;
-	struct tt_global_entry *tt_global_entry;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t orig_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t orig_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1077,6 +1146,7 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		/* Copy the last orig_node's OGM buffer */
@@ -1086,48 +1156,17 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-						primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-						sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_global_hash,
+					     primary_if, tt_global_valid_entry,
+					     req_dst_orig_node);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_response->ttvn = (uint8_t)
-			atomic_read(&req_dst_orig_node->last_ttvn);
-
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the orig_node's local table */
-		hash = bat_priv->tt_global_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_global_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				if (tt_global_entry->orig_node ==
-				    req_dst_orig_node) {
-					memcpy(tt_buff + tt_count * ETH_ALEN,
-					       tt_global_entry->addr,
-					       ETH_ALEN);
-					tt_count++;
-				}
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1135,7 +1174,6 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1168,20 +1206,16 @@ out:
 
 }
 static bool send_my_tt_response(struct bat_priv *bat_priv,
-			       struct tt_query_packet *tt_request)
+				struct tt_query_packet *tt_request)
 {
 	struct orig_node *orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
-	struct tt_local_entry *tt_local_entry;
 	struct hard_iface *primary_if = NULL;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t my_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t my_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1231,6 +1265,7 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		memcpy(tt_buff, bat_priv->tt_buff,
@@ -1238,45 +1273,16 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&bat_priv->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-				primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-				sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&bat_priv->ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_local_hash,
+					     primary_if, NULL, NULL);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the local table */
-		tt_response->ttvn =
-			(uint8_t)atomic_read(&bat_priv->ttvn);
-
-		hash = bat_priv->tt_local_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_local_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				memcpy(tt_buff + tt_count * ETH_ALEN,
-					tt_local_entry->addr,
-						ETH_ALEN);
-				tt_count++;
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1284,7 +1290,6 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1323,23 +1328,30 @@ bool send_tt_response(struct bat_priv *bat_priv,
 		return send_other_tt_response(bat_priv, tt_request);
 }
 
-/* Substitute the TT response source's table with the newone carried by the
- * packet */
-static void _tt_fill_gtable(struct bat_priv *bat_priv,
-			    struct orig_node *orig_node, unsigned char *tt_buff,
-			    uint16_t table_size, uint8_t ttvn)
+static void _tt_update_changes(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node,
+			       struct tt_change *tt_change,
+			       uint16_t tt_num_changes, uint8_t ttvn)
 {
-	int count;
-	unsigned char *tt_ptr;
-
-	for (count = 0; count < table_size; count++) {
-		tt_ptr = tt_buff + (count * ETH_ALEN);
+	int i;
 
-		/* If we fail to allocate a new entry we return immediatly */
-		if (!tt_global_add(bat_priv, orig_node, tt_ptr, ttvn, false))
-			return;
+	for (i = 0; i < tt_num_changes; i++) {
+		if ((tt_change + i)->flags & TT_CHANGE_DEL)
+			tt_global_del(bat_priv, orig_node,
+				      (tt_change + i)->addr,
+				      "tt removed by changes",
+				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+		else
+			if (!tt_global_add(bat_priv, orig_node,
+					   (tt_change + i)->addr, ttvn, false))
+				/* In case of problem while storing a
+				 * global_entry, we stop the updating
+				 * procedure without committing the
+				 * ttvn change. This will avoid to send
+				 * corrupted data on tt_request
+				 */
+				return;
 	}
-	atomic_set(&orig_node->last_ttvn, ttvn);
 }
 
 static void tt_fill_gtable(struct bat_priv *bat_priv,
@@ -1354,11 +1366,9 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	/* Purge the old table first.. */
 	tt_global_del_orig(bat_priv, orig_node, "Received full table");
 
-	_tt_fill_gtable(bat_priv, orig_node,
-		((unsigned char *)tt_response) +
-		sizeof(struct tt_query_packet),
-		tt_response->tt_data,
-		tt_response->ttvn);
+	_tt_update_changes(bat_priv, orig_node,
+			   (struct tt_change *)(tt_response + 1),
+			   tt_response->tt_data, tt_response->ttvn);
 
 	spin_lock_bh(&orig_node->tt_buff_lock);
 	kfree(orig_node->tt_buff);
@@ -1366,6 +1376,8 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	orig_node->tt_buff = NULL;
 	spin_unlock_bh(&orig_node->tt_buff_lock);
 
+	atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
+
 out:
 	if (orig_node)
 		orig_node_free_ref(orig_node);
@@ -1375,25 +1387,8 @@ 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)
 {
-	int i;
-
-	for (i = 0; i < tt_num_changes; i++) {
-		if ((tt_change + i)->flags & TT_CHANGE_DEL)
-			tt_global_del(bat_priv, orig_node,
-				      (tt_change + i)->addr,
-				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
-		else
-			if (!tt_global_add(bat_priv, orig_node,
-					   (tt_change + i)->addr, ttvn, false))
-				/* In case of problem while storing a
-				 * global_entry, we stop the updating
-				 * procedure without committing the
-				 * ttvn change. This will avoid to send
-				 * corrupted data on tt_request
-				 */
-				return;
-	}
+	_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
+			   ttvn);
 
 	tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change,
 			    tt_num_changes);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCHv4] batman-adv: modify TT_RESPONSE-full-table format
  2011-05-30 18:40   ` [B.A.T.M.A.N.] [PATCHv3] " Antonio Quartulli
@ 2011-05-30 21:37     ` Antonio Quartulli
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 1/2] " Antonio Quartulli
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 " Antonio Quartulli
  2011-06-01  5:34     ` [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format Andrew Lunn
  1 sibling, 2 replies; 13+ messages in thread
From: Antonio Quartulli @ 2011-05-30 21:37 UTC (permalink / raw)
  To: B.A.T.M.A.N; +Cc: Marek Lindner

In case of TT_REQUEST for a full table, the related TT_RESPONSE now
carries a set of tt_change structures instead of pure MACs.
This helps to keep the TT_RESPONSE format extensible. In particular, the
flag field can be used for later purposes.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 main.h              |    5 -
 packet.h            |   12 ++-
 translation-table.c |  255 +++++++++++++++++++++++++--------------------------
 types.h             |    5 -
 4 files changed, 136 insertions(+), 141 deletions(-)

diff --git a/main.h b/main.h
index 582e387..faf6391 100644
--- a/main.h
+++ b/main.h
@@ -55,11 +55,6 @@
 
 #define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
 
-/* Transtable change flags */
-#define TT_CHANGE_ADD   0x00
-#define TT_CHANGE_DEL   0x01
-#define TT_CHANGE_ROAM  0x02
-
 /* Transtable global entry flags */
 #define TT_GLOBAL_ROAM  0x01
 
diff --git a/packet.h b/packet.h
index ae212c7..8f33177 100644
--- a/packet.h
+++ b/packet.h
@@ -54,11 +54,16 @@
 #define UNI_FRAG_HEAD 0x01
 #define UNI_FRAG_LARGETAIL 0x02
 
-/* TT flags */
+/* TT_QUERY flags */
 #define TT_RESPONSE     0x01
 #define TT_REQUEST      0x02
 #define TT_FULL_TABLE   0x04
 
+/* TT_CHANGE flags */
+#define TT_CHANGE_ADD   0x00
+#define TT_CHANGE_DEL   0x01
+#define TT_CHANGE_ROAM  0x02
+
 struct batman_packet {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
@@ -180,4 +185,9 @@ struct roam_adv_packet {
 	uint8_t  client[ETH_ALEN];
 } __packed;
 
+struct tt_change {
+	uint8_t flags;
+	uint8_t addr[ETH_ALEN];
+};
+
 #endif /* _NET_BATMAN_ADV_PACKET_H_ */
diff --git a/translation-table.c b/translation-table.c
index f04ab9b..1c50122 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -493,7 +493,7 @@ static void tt_changes_list_free(struct bat_priv *bat_priv)
 	spin_unlock_bh(&bat_priv->tt_changes_list_lock);
 }
 
-/* caller must hold orig_node recount */
+/* 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, bool roaming)
 {
@@ -938,6 +938,79 @@ unlock:
 	return tt_req_node;
 }
 
+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_GLOBAL_ROAM)
+		return 0;
+
+	return (tt_global_entry->orig_node == orig_node);
+}
+
+static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
+					      struct hashtable_t *hash,
+					      struct hard_iface *primary_if,
+					      int (*valid_cb)(const void *,
+							      const void *),
+					      void *cb_data)
+{
+	struct tt_local_entry *tt_local_entry;
+	struct tt_query_packet *tt_response;
+	struct tt_change *tt_change;
+	struct hlist_node *node;
+	struct hlist_head *head;
+	struct sk_buff *skb = NULL;
+	uint16_t tt_tot, tt_count;
+	ssize_t tt_query_size = sizeof(struct tt_query_packet);
+	int i;
+
+	if (sizeof(struct tt_query_packet) + tt_len >
+						primary_if->soft_iface->mtu) {
+		tt_len = primary_if->soft_iface->mtu - tt_query_size;
+		tt_len -= tt_len % sizeof(struct tt_change);
+	}
+	tt_tot = tt_len / sizeof(struct tt_change);
+
+	skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN);
+	if (!skb)
+		goto out;
+
+	skb_reserve(skb, ETH_HLEN);
+	tt_response = (struct tt_query_packet *)skb_put(skb,
+						     tt_query_size + tt_len);
+	tt_response->ttvn = ttvn;
+	tt_response->tt_data = htons(tt_tot);
+
+	tt_change = (struct tt_change *)(skb->data + tt_query_size);
+	tt_count = 0;
+
+	rcu_read_lock();
+	for (i = 0; i < hash->size; i++) {
+		head = &hash->table[i];
+
+		hlist_for_each_entry_rcu(tt_local_entry, node,
+					 head, hash_entry) {
+			if (tt_count == tt_tot)
+				break;
+
+			if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data)))
+				continue;
+
+			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
+			tt_change->flags = TT_CHANGE_ADD;
+
+			tt_count++;
+			tt_change++;
+		}
+	}
+	rcu_read_unlock();
+
+out:
+	return skb;
+}
+
 int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node,
 		    uint8_t ttvn, uint16_t tt_crc, bool full_table)
 {
@@ -1006,20 +1079,16 @@ out:
 }
 
 static bool send_other_tt_response(struct bat_priv *bat_priv,
-				  struct tt_query_packet *tt_request)
+				   struct tt_query_packet *tt_request)
 {
 	struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
 	struct hard_iface *primary_if = NULL;
-	struct tt_global_entry *tt_global_entry;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t orig_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t orig_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1077,6 +1146,7 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		/* Copy the last orig_node's OGM buffer */
@@ -1086,48 +1156,17 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-						primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-						sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_global_hash,
+					     primary_if, tt_global_valid_entry,
+					     req_dst_orig_node);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_response->ttvn = (uint8_t)
-			atomic_read(&req_dst_orig_node->last_ttvn);
-
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the orig_node's local table */
-		hash = bat_priv->tt_global_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_global_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				if (tt_global_entry->orig_node ==
-				    req_dst_orig_node) {
-					memcpy(tt_buff + tt_count * ETH_ALEN,
-					       tt_global_entry->addr,
-					       ETH_ALEN);
-					tt_count++;
-				}
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1135,7 +1174,6 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1168,20 +1206,16 @@ out:
 
 }
 static bool send_my_tt_response(struct bat_priv *bat_priv,
-			       struct tt_query_packet *tt_request)
+				struct tt_query_packet *tt_request)
 {
 	struct orig_node *orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
-	struct tt_local_entry *tt_local_entry;
 	struct hard_iface *primary_if = NULL;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t my_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t my_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1231,6 +1265,7 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		memcpy(tt_buff, bat_priv->tt_buff,
@@ -1238,45 +1273,16 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&bat_priv->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-				primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-				sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&bat_priv->ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_local_hash,
+					     primary_if, NULL, NULL);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the local table */
-		tt_response->ttvn =
-			(uint8_t)atomic_read(&bat_priv->ttvn);
-
-		hash = bat_priv->tt_local_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_local_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				memcpy(tt_buff + tt_count * ETH_ALEN,
-					tt_local_entry->addr,
-						ETH_ALEN);
-				tt_count++;
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1284,7 +1290,6 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1323,23 +1328,30 @@ bool send_tt_response(struct bat_priv *bat_priv,
 		return send_other_tt_response(bat_priv, tt_request);
 }
 
-/* Substitute the TT response source's table with the newone carried by the
- * packet */
-static void _tt_fill_gtable(struct bat_priv *bat_priv,
-			    struct orig_node *orig_node, unsigned char *tt_buff,
-			    uint16_t table_size, uint8_t ttvn)
+static void _tt_update_changes(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node,
+			       struct tt_change *tt_change,
+			       uint16_t tt_num_changes, uint8_t ttvn)
 {
-	int count;
-	unsigned char *tt_ptr;
-
-	for (count = 0; count < table_size; count++) {
-		tt_ptr = tt_buff + (count * ETH_ALEN);
+	int i;
 
-		/* If we fail to allocate a new entry we return immediatly */
-		if (!tt_global_add(bat_priv, orig_node, tt_ptr, ttvn, false))
-			return;
+	for (i = 0; i < tt_num_changes; i++) {
+		if ((tt_change + i)->flags & TT_CHANGE_DEL)
+			tt_global_del(bat_priv, orig_node,
+				      (tt_change + i)->addr,
+				      "tt removed by changes",
+				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+		else
+			if (!tt_global_add(bat_priv, orig_node,
+					   (tt_change + i)->addr, ttvn, false))
+				/* In case of problem while storing a
+				 * global_entry, we stop the updating
+				 * procedure without committing the
+				 * ttvn change. This will avoid to send
+				 * corrupted data on tt_request
+				 */
+				return;
 	}
-	atomic_set(&orig_node->last_ttvn, ttvn);
 }
 
 static void tt_fill_gtable(struct bat_priv *bat_priv,
@@ -1354,11 +1366,9 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	/* Purge the old table first.. */
 	tt_global_del_orig(bat_priv, orig_node, "Received full table");
 
-	_tt_fill_gtable(bat_priv, orig_node,
-		((unsigned char *)tt_response) +
-		sizeof(struct tt_query_packet),
-		tt_response->tt_data,
-		tt_response->ttvn);
+	_tt_update_changes(bat_priv, orig_node,
+			   (struct tt_change *)(tt_response + 1),
+			   tt_response->tt_data, tt_response->ttvn);
 
 	spin_lock_bh(&orig_node->tt_buff_lock);
 	kfree(orig_node->tt_buff);
@@ -1366,6 +1376,8 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	orig_node->tt_buff = NULL;
 	spin_unlock_bh(&orig_node->tt_buff_lock);
 
+	atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
+
 out:
 	if (orig_node)
 		orig_node_free_ref(orig_node);
@@ -1375,25 +1387,8 @@ 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)
 {
-	int i;
-
-	for (i = 0; i < tt_num_changes; i++) {
-		if ((tt_change + i)->flags & TT_CHANGE_DEL)
-			tt_global_del(bat_priv, orig_node,
-				      (tt_change + i)->addr,
-				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
-		else
-			if (!tt_global_add(bat_priv, orig_node,
-					   (tt_change + i)->addr, ttvn, false))
-				/* In case of problem while storing a
-				 * global_entry, we stop the updating
-				 * procedure without committing the
-				 * ttvn change. This will avoid to send
-				 * corrupted data on tt_request
-				 */
-				return;
-	}
+	_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
+			   ttvn);
 
 	tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change,
 			    tt_num_changes);
diff --git a/types.h b/types.h
index 8c9b5da..11e8569 100644
--- a/types.h
+++ b/types.h
@@ -109,11 +109,6 @@ struct orig_node {
 	struct list_head bond_list;
 };
 
-struct tt_change {
-	uint8_t flags;
-	uint8_t addr[ETH_ALEN];
-};
-
 struct gw_node {
 	struct hlist_node list;
 	struct orig_node *orig_node;
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCHv5 1/2] batman-adv: modify TT_RESPONSE-full-table format
  2011-05-30 21:37     ` [B.A.T.M.A.N.] [PATCHv4] " Antonio Quartulli
@ 2011-05-30 23:25       ` Antonio Quartulli
  2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 " Antonio Quartulli
  2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations Antonio Quartulli
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 " Antonio Quartulli
  1 sibling, 2 replies; 13+ messages in thread
From: Antonio Quartulli @ 2011-05-30 23:25 UTC (permalink / raw)
  To: B.A.T.M.A.N; +Cc: Marek Lindner

In case of TT_REQUEST for a full table, the related TT_RESPONSE now
carries a set of tt_change structures instead of pure MACs.
This helps to keep the TT_RESPONSE format extensible. In particular, the
flag field can be used for later purposes.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
PATCHv4 has been splitted in 'v5 1/2' and 'v5 2/2' in order to make it a bit easier to
be backported and merged with the related parent patch.

 translation-table.c |  255 +++++++++++++++++++++++++--------------------------
 1 files changed, 125 insertions(+), 130 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index f04ab9b..1c50122 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -493,7 +493,7 @@ static void tt_changes_list_free(struct bat_priv *bat_priv)
 	spin_unlock_bh(&bat_priv->tt_changes_list_lock);
 }
 
-/* caller must hold orig_node recount */
+/* 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, bool roaming)
 {
@@ -938,6 +938,79 @@ unlock:
 	return tt_req_node;
 }
 
+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_GLOBAL_ROAM)
+		return 0;
+
+	return (tt_global_entry->orig_node == orig_node);
+}
+
+static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
+					      struct hashtable_t *hash,
+					      struct hard_iface *primary_if,
+					      int (*valid_cb)(const void *,
+							      const void *),
+					      void *cb_data)
+{
+	struct tt_local_entry *tt_local_entry;
+	struct tt_query_packet *tt_response;
+	struct tt_change *tt_change;
+	struct hlist_node *node;
+	struct hlist_head *head;
+	struct sk_buff *skb = NULL;
+	uint16_t tt_tot, tt_count;
+	ssize_t tt_query_size = sizeof(struct tt_query_packet);
+	int i;
+
+	if (sizeof(struct tt_query_packet) + tt_len >
+						primary_if->soft_iface->mtu) {
+		tt_len = primary_if->soft_iface->mtu - tt_query_size;
+		tt_len -= tt_len % sizeof(struct tt_change);
+	}
+	tt_tot = tt_len / sizeof(struct tt_change);
+
+	skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN);
+	if (!skb)
+		goto out;
+
+	skb_reserve(skb, ETH_HLEN);
+	tt_response = (struct tt_query_packet *)skb_put(skb,
+						     tt_query_size + tt_len);
+	tt_response->ttvn = ttvn;
+	tt_response->tt_data = htons(tt_tot);
+
+	tt_change = (struct tt_change *)(skb->data + tt_query_size);
+	tt_count = 0;
+
+	rcu_read_lock();
+	for (i = 0; i < hash->size; i++) {
+		head = &hash->table[i];
+
+		hlist_for_each_entry_rcu(tt_local_entry, node,
+					 head, hash_entry) {
+			if (tt_count == tt_tot)
+				break;
+
+			if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data)))
+				continue;
+
+			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
+			tt_change->flags = TT_CHANGE_ADD;
+
+			tt_count++;
+			tt_change++;
+		}
+	}
+	rcu_read_unlock();
+
+out:
+	return skb;
+}
+
 int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node,
 		    uint8_t ttvn, uint16_t tt_crc, bool full_table)
 {
@@ -1006,20 +1079,16 @@ out:
 }
 
 static bool send_other_tt_response(struct bat_priv *bat_priv,
-				  struct tt_query_packet *tt_request)
+				   struct tt_query_packet *tt_request)
 {
 	struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
 	struct hard_iface *primary_if = NULL;
-	struct tt_global_entry *tt_global_entry;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t orig_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t orig_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1077,6 +1146,7 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		/* Copy the last orig_node's OGM buffer */
@@ -1086,48 +1156,17 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-						primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-						sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_global_hash,
+					     primary_if, tt_global_valid_entry,
+					     req_dst_orig_node);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_response->ttvn = (uint8_t)
-			atomic_read(&req_dst_orig_node->last_ttvn);
-
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the orig_node's local table */
-		hash = bat_priv->tt_global_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_global_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				if (tt_global_entry->orig_node ==
-				    req_dst_orig_node) {
-					memcpy(tt_buff + tt_count * ETH_ALEN,
-					       tt_global_entry->addr,
-					       ETH_ALEN);
-					tt_count++;
-				}
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1135,7 +1174,6 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1168,20 +1206,16 @@ out:
 
 }
 static bool send_my_tt_response(struct bat_priv *bat_priv,
-			       struct tt_query_packet *tt_request)
+				struct tt_query_packet *tt_request)
 {
 	struct orig_node *orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
-	struct tt_local_entry *tt_local_entry;
 	struct hard_iface *primary_if = NULL;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t my_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t my_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1231,6 +1265,7 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		memcpy(tt_buff, bat_priv->tt_buff,
@@ -1238,45 +1273,16 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&bat_priv->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-				primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-				sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&bat_priv->ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_local_hash,
+					     primary_if, NULL, NULL);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the local table */
-		tt_response->ttvn =
-			(uint8_t)atomic_read(&bat_priv->ttvn);
-
-		hash = bat_priv->tt_local_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_local_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				memcpy(tt_buff + tt_count * ETH_ALEN,
-					tt_local_entry->addr,
-						ETH_ALEN);
-				tt_count++;
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1284,7 +1290,6 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1323,23 +1328,30 @@ bool send_tt_response(struct bat_priv *bat_priv,
 		return send_other_tt_response(bat_priv, tt_request);
 }
 
-/* Substitute the TT response source's table with the newone carried by the
- * packet */
-static void _tt_fill_gtable(struct bat_priv *bat_priv,
-			    struct orig_node *orig_node, unsigned char *tt_buff,
-			    uint16_t table_size, uint8_t ttvn)
+static void _tt_update_changes(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node,
+			       struct tt_change *tt_change,
+			       uint16_t tt_num_changes, uint8_t ttvn)
 {
-	int count;
-	unsigned char *tt_ptr;
-
-	for (count = 0; count < table_size; count++) {
-		tt_ptr = tt_buff + (count * ETH_ALEN);
+	int i;
 
-		/* If we fail to allocate a new entry we return immediatly */
-		if (!tt_global_add(bat_priv, orig_node, tt_ptr, ttvn, false))
-			return;
+	for (i = 0; i < tt_num_changes; i++) {
+		if ((tt_change + i)->flags & TT_CHANGE_DEL)
+			tt_global_del(bat_priv, orig_node,
+				      (tt_change + i)->addr,
+				      "tt removed by changes",
+				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+		else
+			if (!tt_global_add(bat_priv, orig_node,
+					   (tt_change + i)->addr, ttvn, false))
+				/* In case of problem while storing a
+				 * global_entry, we stop the updating
+				 * procedure without committing the
+				 * ttvn change. This will avoid to send
+				 * corrupted data on tt_request
+				 */
+				return;
 	}
-	atomic_set(&orig_node->last_ttvn, ttvn);
 }
 
 static void tt_fill_gtable(struct bat_priv *bat_priv,
@@ -1354,11 +1366,9 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	/* Purge the old table first.. */
 	tt_global_del_orig(bat_priv, orig_node, "Received full table");
 
-	_tt_fill_gtable(bat_priv, orig_node,
-		((unsigned char *)tt_response) +
-		sizeof(struct tt_query_packet),
-		tt_response->tt_data,
-		tt_response->ttvn);
+	_tt_update_changes(bat_priv, orig_node,
+			   (struct tt_change *)(tt_response + 1),
+			   tt_response->tt_data, tt_response->ttvn);
 
 	spin_lock_bh(&orig_node->tt_buff_lock);
 	kfree(orig_node->tt_buff);
@@ -1366,6 +1376,8 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	orig_node->tt_buff = NULL;
 	spin_unlock_bh(&orig_node->tt_buff_lock);
 
+	atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
+
 out:
 	if (orig_node)
 		orig_node_free_ref(orig_node);
@@ -1375,25 +1387,8 @@ 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)
 {
-	int i;
-
-	for (i = 0; i < tt_num_changes; i++) {
-		if ((tt_change + i)->flags & TT_CHANGE_DEL)
-			tt_global_del(bat_priv, orig_node,
-				      (tt_change + i)->addr,
-				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
-		else
-			if (!tt_global_add(bat_priv, orig_node,
-					   (tt_change + i)->addr, ttvn, false))
-				/* In case of problem while storing a
-				 * global_entry, we stop the updating
-				 * procedure without committing the
-				 * ttvn change. This will avoid to send
-				 * corrupted data on tt_request
-				 */
-				return;
-	}
+	_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
+			   ttvn);
 
 	tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change,
 			    tt_num_changes);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCHv5 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations
  2011-05-30 21:37     ` [B.A.T.M.A.N.] [PATCHv4] " Antonio Quartulli
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 1/2] " Antonio Quartulli
@ 2011-05-30 23:25       ` Antonio Quartulli
  2011-06-01  5:41         ` Andrew Lunn
  1 sibling, 1 reply; 13+ messages in thread
From: Antonio Quartulli @ 2011-05-30 23:25 UTC (permalink / raw)
  To: B.A.T.M.A.N

struct tt_change is sent over the wire so need to be in packet.h as well
as all the TT_CHANGE_* flags. TT_GLOBAL/CHANGE_ROAM as been renamed to
TT_CLIENT_ROAM so that both tt_global_entry and tt_change can use the
same same flag.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 main.h              |   10 +---------
 packet.h            |   11 ++++++++++-
 translation-table.c |   18 +++++++++---------
 types.h             |    5 -----
 4 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/main.h b/main.h
index 582e387..82cf523 100644
--- a/main.h
+++ b/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_GLOBAL_ROAM_TIMEOUT 600
+#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,14 +55,6 @@
 
 #define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
 
-/* Transtable change flags */
-#define TT_CHANGE_ADD   0x00
-#define TT_CHANGE_DEL   0x01
-#define TT_CHANGE_ROAM  0x02
-
-/* Transtable global entry flags */
-#define TT_GLOBAL_ROAM  0x01
-
 #define ROAMING_MAX_TIME 20 /* Time in which a client can roam at most
 			     * ROAMING_MAX_COUNT times */
 #define ROAMING_MAX_COUNT 5
diff --git a/packet.h b/packet.h
index ae212c7..5e3e778 100644
--- a/packet.h
+++ b/packet.h
@@ -54,11 +54,15 @@
 #define UNI_FRAG_HEAD 0x01
 #define UNI_FRAG_LARGETAIL 0x02
 
-/* TT flags */
+/* TT_QUERY flags */
 #define TT_RESPONSE     0x01
 #define TT_REQUEST      0x02
 #define TT_FULL_TABLE   0x04
 
+/* TT_CHANGE flags */
+#define TT_CHANGE_DEL   0x01
+#define TT_CLIENT_ROAM  0x02
+
 struct batman_packet {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
@@ -180,4 +184,9 @@ struct roam_adv_packet {
 	uint8_t  client[ETH_ALEN];
 } __packed;
 
+struct tt_change {
+	uint8_t flags;
+	uint8_t addr[ETH_ALEN];
+};
+
 #endif /* _NET_BATMAN_ADV_PACKET_H_ */
diff --git a/translation-table.c b/translation-table.c
index 1c50122..bcbd39b 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -156,7 +156,7 @@ static void tt_local_event(struct bat_priv *bat_priv, uint8_t op,
 
 	tt_change_node->change.flags = op;
 	if (roaming)
-		tt_change_node->change.flags |= TT_GLOBAL_ROAM;
+		tt_change_node->change.flags |= TT_CLIENT_ROAM;
 
 	memcpy(tt_change_node->change.addr, addr, ETH_ALEN);
 
@@ -204,7 +204,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
 	if (!tt_local_entry)
 		goto out;
 
-	tt_local_event(bat_priv, TT_CHANGE_ADD, addr, false);
+	tt_local_event(bat_priv, 0, addr, false);
 
 	bat_dbg(DBG_TT, bat_priv,
 		"Creating new local tt entry: %pM (ttvn: %d)\n", addr,
@@ -665,7 +665,7 @@ void tt_global_del(struct bat_priv *bat_priv,
 
 	if (tt_global_entry->orig_node == orig_node) {
 		if (roaming) {
-			tt_global_entry->flags |= TT_GLOBAL_ROAM;
+			tt_global_entry->flags |= TT_CLIENT_ROAM;
 			tt_global_entry->roam_at = jiffies;
 			goto out;
 		}
@@ -724,10 +724,10 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
 		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_GLOBAL_ROAM))
+			if (!(tt_global_entry->flags & TT_CLIENT_ROAM))
 				continue;
 			if (!is_out_of_time(tt_global_entry->roam_at,
-					    TT_GLOBAL_ROAM_TIMEOUT * 1000))
+					    TT_CLIENT_ROAM_TIMEOUT * 1000))
 				continue;
 
 			bat_dbg(DBG_TT, bat_priv, "Deleting global "
@@ -818,7 +818,7 @@ uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node)
 				 * consistency only. They don't have to be
 				 * taken into account while computing the
 				 * global crc */
-				if (tt_global_entry->flags & TT_GLOBAL_ROAM)
+				if (tt_global_entry->flags & TT_CLIENT_ROAM)
 					continue;
 				total_one = 0;
 				for (j = 0; j < ETH_ALEN; j++)
@@ -943,7 +943,7 @@ 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_GLOBAL_ROAM)
+	if (tt_global_entry->flags & TT_CLIENT_ROAM)
 		return 0;
 
 	return (tt_global_entry->orig_node == orig_node);
@@ -999,7 +999,7 @@ static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
 				continue;
 
 			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
-			tt_change->flags = TT_CHANGE_ADD;
+			tt_change->flags = 0;
 
 			tt_count++;
 			tt_change++;
@@ -1340,7 +1340,7 @@ static void _tt_update_changes(struct bat_priv *bat_priv,
 			tt_global_del(bat_priv, orig_node,
 				      (tt_change + i)->addr,
 				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+				      (tt_change + i)->flags & TT_CLIENT_ROAM);
 		else
 			if (!tt_global_add(bat_priv, orig_node,
 					   (tt_change + i)->addr, ttvn, false))
diff --git a/types.h b/types.h
index 8c9b5da..11e8569 100644
--- a/types.h
+++ b/types.h
@@ -109,11 +109,6 @@ struct orig_node {
 	struct list_head bond_list;
 };
 
-struct tt_change {
-	uint8_t flags;
-	uint8_t addr[ETH_ALEN];
-};
-
 struct gw_node {
 	struct hlist_node list;
 	struct orig_node *orig_node;
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format
  2011-05-30 18:40   ` [B.A.T.M.A.N.] [PATCHv3] " Antonio Quartulli
  2011-05-30 21:37     ` [B.A.T.M.A.N.] [PATCHv4] " Antonio Quartulli
@ 2011-06-01  5:34     ` Andrew Lunn
  2011-06-01  6:19       ` Antonio Quartulli
  1 sibling, 1 reply; 13+ messages in thread
From: Andrew Lunn @ 2011-06-01  5:34 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking; +Cc: Marek Lindner

> +	ssize_t tt_query_size = sizeof(struct tt_query_packet);
> +	int i;
> +
> +	if (sizeof(struct tt_query_packet) + tt_len >
> +						primary_if->soft_iface->mtu) {
> +		tt_len = primary_if->soft_iface->mtu - tt_query_size;
> +		tt_len -= tt_len % sizeof(struct tt_change);
> +	}

Hi Antonio

This first struck me as being asymmetric. Then i say that
tt_query_size is sizeof(struct tt_query_packet). So use it in the if
statement, and then symmetry is restored and probably the indentation
looks better.

      Andrew

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv5 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 " Antonio Quartulli
@ 2011-06-01  5:41         ` Andrew Lunn
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Lunn @ 2011-06-01  5:41 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

> -	tt_local_event(bat_priv, TT_CHANGE_ADD, addr, false);
> +	tt_local_event(bat_priv, 0, addr, false);

Hi Antonio

i find TT_CHANGE_ADD much more descriptive than 0. Could you add back
a macro here rather than a hard coded value? TT_NO_FLAGS?

  Andrew

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format
  2011-06-01  5:34     ` [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format Andrew Lunn
@ 2011-06-01  6:19       ` Antonio Quartulli
  0 siblings, 0 replies; 13+ messages in thread
From: Antonio Quartulli @ 2011-06-01  6:19 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On mer, giu 01, 2011 at 07:34:25 +0200, Andrew Lunn wrote:
> > +	ssize_t tt_query_size = sizeof(struct tt_query_packet);
> > +	int i;
> > +
> > +	if (sizeof(struct tt_query_packet) + tt_len >
> > +						primary_if->soft_iface->mtu) {
> > +		tt_len = primary_if->soft_iface->mtu - tt_query_size;
> > +		tt_len -= tt_len % sizeof(struct tt_change);
> > +	}
> 
> Hi Antonio
> 
> This first struck me as being asymmetric. Then i say that
> tt_query_size is sizeof(struct tt_query_packet). So use it in the if
> statement, and then symmetry is restored and probably the indentation
> looks better.

Oh, thanks Andrew! I'm going to fix it

> 
>       Andrew

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCHv6 1/2] batman-adv: modify TT_RESPONSE-full-table format
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 1/2] " Antonio Quartulli
@ 2011-06-04 16:36         ` Antonio Quartulli
  2011-06-05 20:08           ` Marek Lindner
  2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations Antonio Quartulli
  1 sibling, 1 reply; 13+ messages in thread
From: Antonio Quartulli @ 2011-06-04 16:36 UTC (permalink / raw)
  To: B.A.T.M.A.N; +Cc: Marek Lindner

In case of TT_REQUEST for a full table, the related TT_RESPONSE now
carries a set of tt_change structures instead of pure MACs.
This helps to keep the TT_RESPONSE format extensible. In particular, the
flag field can be used for later purposes.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---

Thanks Andrew. I fixed the asymmetry in the if-loop as suggested in:
http://www.mail-archive.com/b.a.t.m.a.n@lists.open-mesh.org/msg04792.html

 translation-table.c |  254 +++++++++++++++++++++++++--------------------------
 1 files changed, 124 insertions(+), 130 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index f04ab9b..67ea01a 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -493,7 +493,7 @@ static void tt_changes_list_free(struct bat_priv *bat_priv)
 	spin_unlock_bh(&bat_priv->tt_changes_list_lock);
 }
 
-/* caller must hold orig_node recount */
+/* 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, bool roaming)
 {
@@ -938,6 +938,78 @@ unlock:
 	return tt_req_node;
 }
 
+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_GLOBAL_ROAM)
+		return 0;
+
+	return (tt_global_entry->orig_node == orig_node);
+}
+
+static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
+					      struct hashtable_t *hash,
+					      struct hard_iface *primary_if,
+					      int (*valid_cb)(const void *,
+							      const void *),
+					      void *cb_data)
+{
+	struct tt_local_entry *tt_local_entry;
+	struct tt_query_packet *tt_response;
+	struct tt_change *tt_change;
+	struct hlist_node *node;
+	struct hlist_head *head;
+	struct sk_buff *skb = NULL;
+	uint16_t tt_tot, tt_count;
+	ssize_t tt_query_size = sizeof(struct tt_query_packet);
+	int i;
+
+	if (tt_query_size + tt_len > primary_if->soft_iface->mtu) {
+		tt_len = primary_if->soft_iface->mtu - tt_query_size;
+		tt_len -= tt_len % sizeof(struct tt_change);
+	}
+	tt_tot = tt_len / sizeof(struct tt_change);
+
+	skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN);
+	if (!skb)
+		goto out;
+
+	skb_reserve(skb, ETH_HLEN);
+	tt_response = (struct tt_query_packet *)skb_put(skb,
+						     tt_query_size + tt_len);
+	tt_response->ttvn = ttvn;
+	tt_response->tt_data = htons(tt_tot);
+
+	tt_change = (struct tt_change *)(skb->data + tt_query_size);
+	tt_count = 0;
+
+	rcu_read_lock();
+	for (i = 0; i < hash->size; i++) {
+		head = &hash->table[i];
+
+		hlist_for_each_entry_rcu(tt_local_entry, node,
+					 head, hash_entry) {
+			if (tt_count == tt_tot)
+				break;
+
+			if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data)))
+				continue;
+
+			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
+			tt_change->flags = TT_CHANGE_ADD;
+
+			tt_count++;
+			tt_change++;
+		}
+	}
+	rcu_read_unlock();
+
+out:
+	return skb;
+}
+
 int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node,
 		    uint8_t ttvn, uint16_t tt_crc, bool full_table)
 {
@@ -1006,20 +1078,16 @@ out:
 }
 
 static bool send_other_tt_response(struct bat_priv *bat_priv,
-				  struct tt_query_packet *tt_request)
+				   struct tt_query_packet *tt_request)
 {
 	struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
 	struct hard_iface *primary_if = NULL;
-	struct tt_global_entry *tt_global_entry;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t orig_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t orig_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1077,6 +1145,7 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		/* Copy the last orig_node's OGM buffer */
@@ -1086,48 +1155,17 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-						primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-						sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_global_hash,
+					     primary_if, tt_global_valid_entry,
+					     req_dst_orig_node);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_response->ttvn = (uint8_t)
-			atomic_read(&req_dst_orig_node->last_ttvn);
-
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the orig_node's local table */
-		hash = bat_priv->tt_global_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_global_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				if (tt_global_entry->orig_node ==
-				    req_dst_orig_node) {
-					memcpy(tt_buff + tt_count * ETH_ALEN,
-					       tt_global_entry->addr,
-					       ETH_ALEN);
-					tt_count++;
-				}
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1135,7 +1173,6 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1168,20 +1205,16 @@ out:
 
 }
 static bool send_my_tt_response(struct bat_priv *bat_priv,
-			       struct tt_query_packet *tt_request)
+				struct tt_query_packet *tt_request)
 {
 	struct orig_node *orig_node = NULL;
 	struct neigh_node *neigh_node = NULL;
-	struct tt_local_entry *tt_local_entry;
 	struct hard_iface *primary_if = NULL;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	struct hashtable_t *hash;
-	uint8_t my_ttvn, req_ttvn;
-	int i, ret = false;
+	uint8_t my_ttvn, req_ttvn, ttvn;
+	int ret = false;
 	unsigned char *tt_buff;
 	bool full_table;
-	uint16_t tt_len, tt_tot, tt_count;
+	uint16_t tt_len, tt_tot;
 	struct sk_buff *skb = NULL;
 	struct tt_query_packet *tt_response;
 
@@ -1231,6 +1264,7 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		tt_response = (struct tt_query_packet *)skb_put(skb,
 				sizeof(struct tt_query_packet) + tt_len);
 		tt_response->ttvn = req_ttvn;
+		tt_response->tt_data = htons(tt_tot);
 
 		tt_buff = skb->data + sizeof(struct tt_query_packet);
 		memcpy(tt_buff, bat_priv->tt_buff,
@@ -1238,45 +1272,16 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 		spin_unlock_bh(&bat_priv->tt_buff_lock);
 	} else {
 		tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) *
-								ETH_ALEN;
-		if (sizeof(struct tt_query_packet) + tt_len >
-				primary_if->soft_iface->mtu) {
-			tt_len = primary_if->soft_iface->mtu -
-				sizeof(struct tt_query_packet);
-			tt_len -= tt_len % ETH_ALEN;
-		}
-		tt_tot = tt_len / ETH_ALEN;
+						sizeof(struct tt_change);
+		ttvn = (uint8_t)atomic_read(&bat_priv->ttvn);
 
-		skb = dev_alloc_skb(sizeof(struct tt_query_packet) +
-				    tt_len + ETH_HLEN);
+		skb = tt_response_fill_table(tt_len, ttvn,
+					     bat_priv->tt_local_hash,
+					     primary_if, NULL, NULL);
 		if (!skb)
 			goto out;
 
-		skb_reserve(skb, ETH_HLEN);
-		tt_response = (struct tt_query_packet *)skb_put(skb,
-				sizeof(struct tt_query_packet) + tt_len);
-		tt_buff = skb->data + sizeof(struct tt_query_packet);
-		/* Fill the packet with the local table */
-		tt_response->ttvn =
-			(uint8_t)atomic_read(&bat_priv->ttvn);
-
-		hash = bat_priv->tt_local_hash;
-		tt_count = 0;
-		rcu_read_lock();
-		for (i = 0; i < hash->size; i++) {
-			head = &hash->table[i];
-
-			hlist_for_each_entry_rcu(tt_local_entry, node,
-					head, hash_entry) {
-				if (tt_count == tt_tot)
-					break;
-				memcpy(tt_buff + tt_count * ETH_ALEN,
-					tt_local_entry->addr,
-						ETH_ALEN);
-				tt_count++;
-			}
-		}
-		rcu_read_unlock();
+		tt_response = (struct tt_query_packet *)skb->data;
 	}
 
 	tt_response->packet_type = BAT_TT_QUERY;
@@ -1284,7 +1289,6 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
 	tt_response->ttl = TTL;
 	memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
 	memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
-	tt_response->tt_data = htons(tt_tot);
 	tt_response->flags = TT_RESPONSE;
 
 	if (full_table)
@@ -1323,23 +1327,30 @@ bool send_tt_response(struct bat_priv *bat_priv,
 		return send_other_tt_response(bat_priv, tt_request);
 }
 
-/* Substitute the TT response source's table with the newone carried by the
- * packet */
-static void _tt_fill_gtable(struct bat_priv *bat_priv,
-			    struct orig_node *orig_node, unsigned char *tt_buff,
-			    uint16_t table_size, uint8_t ttvn)
+static void _tt_update_changes(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node,
+			       struct tt_change *tt_change,
+			       uint16_t tt_num_changes, uint8_t ttvn)
 {
-	int count;
-	unsigned char *tt_ptr;
-
-	for (count = 0; count < table_size; count++) {
-		tt_ptr = tt_buff + (count * ETH_ALEN);
+	int i;
 
-		/* If we fail to allocate a new entry we return immediatly */
-		if (!tt_global_add(bat_priv, orig_node, tt_ptr, ttvn, false))
-			return;
+	for (i = 0; i < tt_num_changes; i++) {
+		if ((tt_change + i)->flags & TT_CHANGE_DEL)
+			tt_global_del(bat_priv, orig_node,
+				      (tt_change + i)->addr,
+				      "tt removed by changes",
+				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+		else
+			if (!tt_global_add(bat_priv, orig_node,
+					   (tt_change + i)->addr, ttvn, false))
+				/* In case of problem while storing a
+				 * global_entry, we stop the updating
+				 * procedure without committing the
+				 * ttvn change. This will avoid to send
+				 * corrupted data on tt_request
+				 */
+				return;
 	}
-	atomic_set(&orig_node->last_ttvn, ttvn);
 }
 
 static void tt_fill_gtable(struct bat_priv *bat_priv,
@@ -1354,11 +1365,9 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	/* Purge the old table first.. */
 	tt_global_del_orig(bat_priv, orig_node, "Received full table");
 
-	_tt_fill_gtable(bat_priv, orig_node,
-		((unsigned char *)tt_response) +
-		sizeof(struct tt_query_packet),
-		tt_response->tt_data,
-		tt_response->ttvn);
+	_tt_update_changes(bat_priv, orig_node,
+			   (struct tt_change *)(tt_response + 1),
+			   tt_response->tt_data, tt_response->ttvn);
 
 	spin_lock_bh(&orig_node->tt_buff_lock);
 	kfree(orig_node->tt_buff);
@@ -1366,6 +1375,8 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 	orig_node->tt_buff = NULL;
 	spin_unlock_bh(&orig_node->tt_buff_lock);
 
+	atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
+
 out:
 	if (orig_node)
 		orig_node_free_ref(orig_node);
@@ -1375,25 +1386,8 @@ 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)
 {
-	int i;
-
-	for (i = 0; i < tt_num_changes; i++) {
-		if ((tt_change + i)->flags & TT_CHANGE_DEL)
-			tt_global_del(bat_priv, orig_node,
-				      (tt_change + i)->addr,
-				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
-		else
-			if (!tt_global_add(bat_priv, orig_node,
-					   (tt_change + i)->addr, ttvn, false))
-				/* In case of problem while storing a
-				 * global_entry, we stop the updating
-				 * procedure without committing the
-				 * ttvn change. This will avoid to send
-				 * corrupted data on tt_request
-				 */
-				return;
-	}
+	_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
+			   ttvn);
 
 	tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change,
 			    tt_num_changes);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [B.A.T.M.A.N.] [PATCHv6 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations
  2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 1/2] " Antonio Quartulli
  2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 " Antonio Quartulli
@ 2011-06-04 16:36         ` Antonio Quartulli
  2011-06-05 20:27           ` Marek Lindner
  1 sibling, 1 reply; 13+ messages in thread
From: Antonio Quartulli @ 2011-06-04 16:36 UTC (permalink / raw)
  To: B.A.T.M.A.N

struct tt_change is sent over the wire so need to be in packet.h as well
as all the TT_CHANGE_* flags. TT_GLOBAL/CHANGE_ROAM as been renamed to
TT_CLIENT_ROAM so that both tt_global_entry and tt_change can use the
same same flag.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
Thanks Andrew. I added a NO_FLAGS define in main.h as suggested in:
http://www.mail-archive.com/b.a.t.m.a.n@lists.open-mesh.org/msg04793.html

 main.h              |   12 +++---------
 packet.h            |   11 ++++++++++-
 translation-table.c |   22 +++++++++++-----------
 types.h             |    5 -----
 4 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/main.h b/main.h
index 582e387..e058ac5 100644
--- a/main.h
+++ b/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_GLOBAL_ROAM_TIMEOUT 600
+#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,18 +55,12 @@
 
 #define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
 
-/* Transtable change flags */
-#define TT_CHANGE_ADD   0x00
-#define TT_CHANGE_DEL   0x01
-#define TT_CHANGE_ROAM  0x02
-
-/* Transtable global entry flags */
-#define TT_GLOBAL_ROAM  0x01
-
 #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)
 
 #define LOG_BUF_LEN 8192	  /* has to be a power of 2 */
diff --git a/packet.h b/packet.h
index ae212c7..5e3e778 100644
--- a/packet.h
+++ b/packet.h
@@ -54,11 +54,15 @@
 #define UNI_FRAG_HEAD 0x01
 #define UNI_FRAG_LARGETAIL 0x02
 
-/* TT flags */
+/* TT_QUERY flags */
 #define TT_RESPONSE     0x01
 #define TT_REQUEST      0x02
 #define TT_FULL_TABLE   0x04
 
+/* TT_CHANGE flags */
+#define TT_CHANGE_DEL   0x01
+#define TT_CLIENT_ROAM  0x02
+
 struct batman_packet {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
@@ -180,4 +184,9 @@ struct roam_adv_packet {
 	uint8_t  client[ETH_ALEN];
 } __packed;
 
+struct tt_change {
+	uint8_t flags;
+	uint8_t addr[ETH_ALEN];
+};
+
 #endif /* _NET_BATMAN_ADV_PACKET_H_ */
diff --git a/translation-table.c b/translation-table.c
index 67ea01a..d2a9f80 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -156,7 +156,7 @@ static void tt_local_event(struct bat_priv *bat_priv, uint8_t op,
 
 	tt_change_node->change.flags = op;
 	if (roaming)
-		tt_change_node->change.flags |= TT_GLOBAL_ROAM;
+		tt_change_node->change.flags |= TT_CLIENT_ROAM;
 
 	memcpy(tt_change_node->change.addr, addr, ETH_ALEN);
 
@@ -204,7 +204,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
 	if (!tt_local_entry)
 		goto out;
 
-	tt_local_event(bat_priv, TT_CHANGE_ADD, addr, false);
+	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,
@@ -515,7 +515,7 @@ 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 = 0x00;
+		tt_global_entry->flags = NO_FLAGS;
 		tt_global_entry->roam_at = 0;
 		atomic_set(&tt_global_entry->refcount, 2);
 
@@ -533,7 +533,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
 			atomic_inc(&orig_node->tt_size);
 		}
 		tt_global_entry->ttvn = ttvn;
-		tt_global_entry->flags = 0x00;
+		tt_global_entry->flags = NO_FLAGS;
 		tt_global_entry->roam_at = 0;
 	}
 
@@ -665,7 +665,7 @@ void tt_global_del(struct bat_priv *bat_priv,
 
 	if (tt_global_entry->orig_node == orig_node) {
 		if (roaming) {
-			tt_global_entry->flags |= TT_GLOBAL_ROAM;
+			tt_global_entry->flags |= TT_CLIENT_ROAM;
 			tt_global_entry->roam_at = jiffies;
 			goto out;
 		}
@@ -724,10 +724,10 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
 		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_GLOBAL_ROAM))
+			if (!(tt_global_entry->flags & TT_CLIENT_ROAM))
 				continue;
 			if (!is_out_of_time(tt_global_entry->roam_at,
-					    TT_GLOBAL_ROAM_TIMEOUT * 1000))
+					    TT_CLIENT_ROAM_TIMEOUT * 1000))
 				continue;
 
 			bat_dbg(DBG_TT, bat_priv, "Deleting global "
@@ -818,7 +818,7 @@ uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node)
 				 * consistency only. They don't have to be
 				 * taken into account while computing the
 				 * global crc */
-				if (tt_global_entry->flags & TT_GLOBAL_ROAM)
+				if (tt_global_entry->flags & TT_CLIENT_ROAM)
 					continue;
 				total_one = 0;
 				for (j = 0; j < ETH_ALEN; j++)
@@ -943,7 +943,7 @@ 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_GLOBAL_ROAM)
+	if (tt_global_entry->flags & TT_CLIENT_ROAM)
 		return 0;
 
 	return (tt_global_entry->orig_node == orig_node);
@@ -998,7 +998,7 @@ static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
 				continue;
 
 			memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN);
-			tt_change->flags = TT_CHANGE_ADD;
+			tt_change->flags = NO_FLAGS;
 
 			tt_count++;
 			tt_change++;
@@ -1339,7 +1339,7 @@ static void _tt_update_changes(struct bat_priv *bat_priv,
 			tt_global_del(bat_priv, orig_node,
 				      (tt_change + i)->addr,
 				      "tt removed by changes",
-				      (tt_change + i)->flags & TT_CHANGE_ROAM);
+				      (tt_change + i)->flags & TT_CLIENT_ROAM);
 		else
 			if (!tt_global_add(bat_priv, orig_node,
 					   (tt_change + i)->addr, ttvn, false))
diff --git a/types.h b/types.h
index 8c9b5da..11e8569 100644
--- a/types.h
+++ b/types.h
@@ -109,11 +109,6 @@ struct orig_node {
 	struct list_head bond_list;
 };
 
-struct tt_change {
-	uint8_t flags;
-	uint8_t addr[ETH_ALEN];
-};
-
 struct gw_node {
 	struct hlist_node list;
 	struct orig_node *orig_node;
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv6 1/2] batman-adv: modify TT_RESPONSE-full-table format
  2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 " Antonio Quartulli
@ 2011-06-05 20:08           ` Marek Lindner
  0 siblings, 0 replies; 13+ messages in thread
From: Marek Lindner @ 2011-06-05 20:08 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Saturday, June 04, 2011 06:36:32 PM Antonio Quartulli wrote:
> In case of TT_REQUEST for a full table, the related TT_RESPONSE now
> carries a set of tt_change structures instead of pure MACs.
> This helps to keep the TT_RESPONSE format extensible. In particular, the
> flag field can be used for later purposes.

Applied in revision e455c1c.

Thanks,
Marek

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv6 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations
  2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations Antonio Quartulli
@ 2011-06-05 20:27           ` Marek Lindner
  0 siblings, 0 replies; 13+ messages in thread
From: Marek Lindner @ 2011-06-05 20:27 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Saturday, June 04, 2011 06:36:33 PM Antonio Quartulli wrote:
> struct tt_change is sent over the wire so need to be in packet.h as well
> as all the TT_CHANGE_* flags. TT_GLOBAL/CHANGE_ROAM as been renamed to
> TT_CLIENT_ROAM so that both tt_global_entry and tt_change can use the
> same same flag.

Applied in revision 78491cb.

Thanks,
Marek

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-06-05 20:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-29 23:05 [B.A.T.M.A.N.] [PATCH] batman-adv: modify TT_RESPONSE-full-table format Antonio Quartulli
2011-05-30 13:46 ` Marek Lindner
2011-05-30 18:40   ` [B.A.T.M.A.N.] [PATCHv3] " Antonio Quartulli
2011-05-30 21:37     ` [B.A.T.M.A.N.] [PATCHv4] " Antonio Quartulli
2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 1/2] " Antonio Quartulli
2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 " Antonio Quartulli
2011-06-05 20:08           ` Marek Lindner
2011-06-04 16:36         ` [B.A.T.M.A.N.] [PATCHv6 2/2] batman-adv: rename and move TT_* flags/structs to the proper locations Antonio Quartulli
2011-06-05 20:27           ` Marek Lindner
2011-05-30 23:25       ` [B.A.T.M.A.N.] [PATCHv5 " Antonio Quartulli
2011-06-01  5:41         ` Andrew Lunn
2011-06-01  5:34     ` [B.A.T.M.A.N.] [PATCHv3] batman-adv: modify TT_RESPONSE-full-table format Andrew Lunn
2011-06-01  6:19       ` Antonio Quartulli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).