netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RFC] tcp: fix ambiguity in the `before' relation
@ 2006-12-14 15:07 Gerrit Renker
  2006-12-20 18:31 ` David Miller
  2006-12-20 20:01 ` Christoph Hellwig
  0 siblings, 2 replies; 14+ messages in thread
From: Gerrit Renker @ 2006-12-14 15:07 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

While looking at DCCP sequence numbers, I stumbled over a problem with
the following definition of before in tcp.h:

static inline int before(__u32 seq1, __u32 seq2)
{
        return (__s32)(seq1-seq2) < 0;
}

Problem: This definition suffers from an an ambiguity, i.e. always
                   
           before(a, (a + 2^31) % 2^32)) = 1
           before((a + 2^31) % 2^32), a) = 1
 
         In text: when the difference between a and b amounts to 2^31,
         a is always considered `before' b, the function can not decide. 
         The reason is that implicitly 0 is `before' 1 ... 2^31-1 ... 2^31
      
Solution: There is a simple fix, by defining before in such a way that 
          0 is no longer `before' 2^31, i.e. 0 `before' 1 ... 2^31-1
          By not using the middle between 0 and 2^32, before can be made 
          unambiguous. 
          This is achieved by testing whether seq2-seq1 > 0 (using signed
          32-bit arithmetic).

I attach a patch to codify this. Also the `after' relation is basically 
a redefinition of `before', it is now defined as a macro after before.

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
---
 tcp.h |    9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)


diff --git a/include/net/tcp.h b/include/net/tcp.h
index c99774f..b7d8317 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -242,14 +242,9 @@ extern int tcp_memory_pressure;
 
 static inline int before(__u32 seq1, __u32 seq2)
 {
-        return (__s32)(seq1-seq2) < 0;
+        return (__s32)(seq2-seq1) > 0;
 }
-
-static inline int after(__u32 seq1, __u32 seq2)
-{
-	return (__s32)(seq2-seq1) < 0;
-}
-
+#define after(seq2, seq1) 	before(seq1, seq2)
 
 /* is s2<=s1<=s3 ? */
 static inline int between(__u32 seq1, __u32 seq2, __u32 seq3)



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

end of thread, other threads:[~2007-01-08  8:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-14 15:07 [PATCH][RFC] tcp: fix ambiguity in the `before' relation Gerrit Renker
2006-12-20 18:31 ` David Miller
2006-12-21 14:42   ` Gerrit Renker
2006-12-22  0:53   ` Herbert Xu
2007-01-03  8:56     ` Gerrit Renker
2007-01-04  0:15       ` Herbert Xu
2007-01-04 12:49         ` Gerrit Renker
2007-01-05  3:59           ` Herbert Xu
2007-01-05 11:51             ` Gerrit Renker
2007-01-05 12:01               ` Herbert Xu
2007-01-05 12:49                 ` Gerrit Renker
2007-01-05 20:34                   ` Herbert Xu
2007-01-08  8:58                     ` Gerrit Renker
2006-12-20 20:01 ` Christoph Hellwig

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).