From patchwork Tue Feb 8 23:35:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 793 Return-Path: Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id AD0CF1540D2 for ; Wed, 9 Feb 2011 00:35:09 +0100 (CET) Received: from sven-desktop.home.narfation.org (i59F6B15E.versanet.de [89.246.177.94]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 7BA0B94060; Wed, 9 Feb 2011 00:35:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=mail; t=1297208146; bh=SHRK+5/OT6sSBTyyvp6cMY0Zpxpg0dqs8cd6SU1vykQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type: Content-Transfer-Encoding; b=W+JbDYYtDrLInXUWE3PskT971SmYeB8h8FYisDmFtrJB9jgvhk5N0ia2dQmCosbAH t61pjCC9oFJWWi1G8a2+q+fEtLq7hGiocE3uplr+r5WA4Bj55r/AbIHPK2y/SNsdAo 4pw8MAwWAU1OqXX3bDz5ZeFRaws/wATRjP5UPXMw= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 9 Feb 2011 00:35:02 +0100 Message-Id: <1297208102-4931-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 1.7.2.3 MIME-Version: 1.0 Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: Use successive sequence numbers for fragments X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Feb 2011 23:35:10 -0000 The two fragments of an unicast packet must have successive sequence numbers to allow the receiver side to detect matching fragments and merge them again. The current implementation doesn't provide that property because a sequence of two atomic_inc_return may be interleaved with another sequence which also changes the variable. The access to the fragment sequence number pool has either to be protected by correct locking or the access to the pool has to reserve two sequence numbers in a single access. The latter one can easily be done by increasing the value of the last used sequence number by 2 in a single access. The generated window of two currently unused sequence numbers can now be scattered across the two fragments. Reported-by: Linus Lüssing Signed-off-by: Sven Eckelmann --- batman-adv/unicast.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/batman-adv/unicast.c b/batman-adv/unicast.c index db62b66..29ad9b8 100644 --- a/batman-adv/unicast.c +++ b/batman-adv/unicast.c @@ -237,6 +237,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, int ucf_hdr_len = sizeof(struct unicast_frag_packet); int data_len = skb->len - uc_hdr_len; int large_tail = 0; + uint16_t seqno; if (!bat_priv->primary_if) goto dropped; @@ -272,10 +273,9 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, frag1->flags = UNI_FRAG_HEAD | large_tail; frag2->flags = large_tail; - frag1->seqno = htons((uint16_t)atomic_inc_return( - &batman_if->frag_seqno)); - frag2->seqno = htons((uint16_t)atomic_inc_return( - &batman_if->frag_seqno)); + seqno = atomic_add_return(2, &batman_if->frag_seqno); + frag1->seqno = htons(seqno - 1); + frag2->seqno = htons(seqno); send_skb_packet(skb, batman_if, dstaddr); send_skb_packet(frag_skb, batman_if, dstaddr);