[12/12] batman-adv: Add sequence number and duplicate checks for unicasts_safe

Message ID 1299086321-25116-13-git-send-email-linus.luessing@ascom.ch (mailing list archive)
State Rejected, archived
Headers

Commit Message

Linus Lüssing March 2, 2011, 5:18 p.m. UTC
  With the new redundant bonding mode a node might receive a unicast_safe
packet more than once. Therefore duplicate checks on any unicast_safe
packet need to be performed before further processing.

Signed-off-by: Linus Lüssing <linus.luessing@ascom.ch>
---
 originator.c |    3 +++
 routing.c    |   14 +++++++++++++-
 types.h      |    2 ++
 3 files changed, 18 insertions(+), 1 deletions(-)
  

Patch

diff --git a/originator.c b/originator.c
index 57cb5c9..3be8460 100644
--- a/originator.c
+++ b/originator.c
@@ -198,6 +198,7 @@  struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
 	INIT_LIST_HEAD(&orig_node->bond_list);
 	spin_lock_init(&orig_node->ogm_cnt_lock);
 	spin_lock_init(&orig_node->bcast_seqno_lock);
+	spin_lock_init(&orig_node->ucast_safe_seqno_lock);
 	spin_lock_init(&orig_node->neigh_list_lock);
 
 	/* extra reference for return */
@@ -209,6 +210,8 @@  struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
 	orig_node->hna_buff = NULL;
 	orig_node->bcast_seqno_state.seqno_reset = jiffies - 1
 					- msecs_to_jiffies(RESET_PROTECTION_MS);
+	orig_node->ucast_safe_seqno_state.seqno_reset = jiffies - 1
+					- msecs_to_jiffies(RESET_PROTECTION_MS);
 	orig_node->batman_seqno_reset = jiffies - 1
 					- msecs_to_jiffies(RESET_PROTECTION_MS);
 
diff --git a/routing.c b/routing.c
index a2c55fd..d19eb77 100644
--- a/routing.c
+++ b/routing.c
@@ -1440,13 +1440,25 @@  int recv_ucast_safe_packet(struct sk_buff *skb, struct hard_iface *recv_if)
 	struct unicast_packet_safe *unicast_packet;
 	struct orig_node *orig_node;
 	int hdr_size = sizeof(struct unicast_packet);
-	int bonding_mode;
+	int ret, bonding_mode;
 
 	if (check_unicast_packet(skb, hdr_size) < 0)
 		return NET_RX_DROP;
 
 	unicast_packet = (struct unicast_packet_safe *)skb->data;
 
+	orig_node = orig_hash_find(bat_priv, unicast_packet->orig);
+	if (!orig_node)
+		return NET_RX_DROP;
+
+	ret = check_duplicate(bat_priv, ntohl(unicast_packet->seqno),
+			      &orig_node->ucast_safe_seqno_state,
+			      &orig_node->ucast_safe_seqno_lock);
+
+	orig_node_free_ref(orig_node);
+	if (ret == NET_RX_DROP)
+		return NET_RX_DROP;
+
 	/* packet for me */
 	if (is_my_mac(unicast_packet->dest)) {
 		unicast_safe_to_unicast(skb);
diff --git a/types.h b/types.h
index cceff07..bfab0c7 100644
--- a/types.h
+++ b/types.h
@@ -93,11 +93,13 @@  struct orig_node {
 	struct bat_priv *bat_priv;
 	unsigned long last_frag_packet;
 	struct seqno_state bcast_seqno_state;
+	struct seqno_state ucast_safe_seqno_state;
 	spinlock_t ogm_cnt_lock; /* protects: bcast_own, bcast_own_sum,
 				  * neigh_node->real_bits,
 				  * neigh_node->real_packet_count */
 	spinlock_t bcast_seqno_lock; /* protects bcast_bits,
 				      *	 last_bcast_seqno */
+	spinlock_t ucast_safe_seqno_lock; /* protects ucast_safe_seqno_state */
 	atomic_t bond_candidates;
 	struct list_head bond_list;
 };