All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerrit Renker <acme@ghostprotocols.net>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH 11/31] [DCCP]: Make dccp_delta_seqno return signed numbers
Date: Tue, 20 Mar 2007 20:06:55 -0300	[thread overview]
Message-ID: <20070320230655.GZ17811@ghostprotocols.net> (raw)

Problem:
--------
 Using dccp_delta_seqno(a, b) produces unusable results when -- by accident
 or coincidence -- sequence number b precedes a.  If e.g. a and b are merely
 reordered and have a distance 1, their delta_seqno is 2^48-1, which would
 indicate a loss of 2^48-2 packets.

Fix:
----
 The fix is by using signed 48-bit arithmetic for dccp_delta_seqno, so that
 dccp_delta_seqno(a, b) returns:
  * > 0 if a is `before' b                OR
  *   0 if a == b                         OR
  * < 0 and > -2^47 if b is `before' a    OR
  * -2^47           if neither a `before' b  nor  b `before' a

 This implements http://www.mail-archive.com/dccp@vger.kernel.org/msg01153.html

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 net/dccp/dccp.h |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 82c618f..e6c95e9 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -113,9 +113,12 @@ static inline void dccp_inc_seqno(u64 *seqno)
 	*seqno = ADD48(*seqno, 1);
 }
 
-static inline u64 dccp_delta_seqno(u64 seqno1, u64 seqno2)
+/* signed mod-2^48 distance: pos. if seqno1 < seqno2, neg. if seqno1 > seqno2 */
+static inline s64 dccp_delta_seqno(const u64 seqno1, const u64 seqno2)
 {
-	return ((seqno2 << 16) - (seqno1 << 16)) >> 16;
+	u64 delta = SUB48(seqno2, seqno1);
+
+	return TO_SIGNED48(delta);
 }
 
 /* is seq1 < seq2 ? */
-- 
1.5.0.3


                 reply	other threads:[~2007-03-20 23:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070320230655.GZ17811@ghostprotocols.net \
    --to=acme@ghostprotocols.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.