From patchwork Fri Feb 11 23:21:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 746 Return-Path: Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 072D3154188 for ; Sat, 12 Feb 2011 00:21:53 +0100 (CET) Received: from sven-desktop.home.narfation.org (i59F6C012.versanet.de [89.246.192.18]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 30BE8940AE; Sat, 12 Feb 2011 00:21:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=mail; t=1297466504; bh=TwDxi0/65knIHo9dIpABKhUIYVVJ0i46hP+VvcSC/wY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; b=W9PaHRt8t/MfWnU91TLRh7VE2JOu9e1/+KPUJdvI08BKguHCf6c07SAvTMf4Ak2Jg avTP5xq8DErU2vCVl0Nz37aGGddCu3o+vGdMg5jCdYNOKBnl9iefEZih5ZqBleRFcL iL/uL57xYjs/sYnG6VXP4RYs1NYjCIgMq0mDMJQQ= From: Sven Eckelmann To: davem@davemloft.net Date: Sat, 12 Feb 2011 00:21:40 +0100 Message-Id: <1297466503-13246-2-git-send-email-sven@narfation.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1297466503-13246-1-git-send-email-sven@narfation.org> References: <1297466503-13246-1-git-send-email-sven@narfation.org> MIME-Version: 1.0 Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org Subject: [B.A.T.M.A.N.] [PATCH 1/4] 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: Fri, 11 Feb 2011 23:21:53 -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 it has to reserve two sequence numbers in a single fetch. The latter one can easily be done by increasing the value of the last used sequence number by 2 in a single step. 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 --- net/batman-adv/unicast.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c index cbf022c..9b2a222 100644 --- a/net/batman-adv/unicast.c +++ b/net/batman-adv/unicast.c @@ -226,6 +226,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; @@ -261,10 +262,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);