diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2007-03-20 11:26:51 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:26:42 -0400 |
commit | 6b811d43f6cc9eccdfc011a99f8571df2abc46d1 (patch) | |
tree | 58e7f27415faf9ad6761bab6e51a7003139190f9 /net/dccp/dccp.h | |
parent | 8b5be26831b973d8013e8b4c9860d9694310cdc6 (diff) |
[DCCP]: 48-bit sequence number arithmetic
This patch
* organizes the sequence arithmetic functions into one corner of dccp.h
* performs a small modification of dccp_set_seqno to make it more widely reusable
(now it is safe to use any number, since it performs modulo-2^48 assignment)
* adds functions and generic macros for 48-bit sequence arithmetic:
--48 bit complement
--modulo-48 addition and modulo-48 subtraction
--dccp_inc_seqno now a special case of add48
Constants renamed following a suggestion by Arnaldo.
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/dccp.h')
-rw-r--r-- | net/dccp/dccp.h | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h index e33a9edb4036..a2c20a265b25 100644 --- a/net/dccp/dccp.h +++ b/net/dccp/dccp.h | |||
@@ -92,6 +92,32 @@ extern int sysctl_dccp_feat_send_ack_vector; | |||
92 | extern int sysctl_dccp_feat_send_ndp_count; | 92 | extern int sysctl_dccp_feat_send_ndp_count; |
93 | extern int sysctl_dccp_tx_qlen; | 93 | extern int sysctl_dccp_tx_qlen; |
94 | 94 | ||
95 | /* | ||
96 | * 48-bit sequence number arithmetic (signed and unsigned) | ||
97 | */ | ||
98 | #define INT48_MIN 0x800000000000LL /* 2^47 */ | ||
99 | #define UINT48_MAX 0xFFFFFFFFFFFFLL /* 2^48 - 1 */ | ||
100 | #define COMPLEMENT48(x) (0x1000000000000LL - (x)) /* 2^48 - x */ | ||
101 | #define TO_SIGNED48(x) (((x) < INT48_MIN)? (x) : -COMPLEMENT48( (x))) | ||
102 | #define TO_UNSIGNED48(x) (((x) >= 0)? (x) : COMPLEMENT48(-(x))) | ||
103 | #define ADD48(a, b) (((a) + (b)) & UINT48_MAX) | ||
104 | #define SUB48(a, b) ADD48((a), COMPLEMENT48(b)) | ||
105 | |||
106 | static inline void dccp_set_seqno(u64 *seqno, u64 value) | ||
107 | { | ||
108 | *seqno = value & UINT48_MAX; | ||
109 | } | ||
110 | |||
111 | static inline void dccp_inc_seqno(u64 *seqno) | ||
112 | { | ||
113 | *seqno = ADD48(*seqno, 1); | ||
114 | } | ||
115 | |||
116 | static inline u64 dccp_delta_seqno(u64 seqno1, u64 seqno2) | ||
117 | { | ||
118 | return ((seqno2 << 16) - (seqno1 << 16)) >> 16; | ||
119 | } | ||
120 | |||
95 | /* is seq1 < seq2 ? */ | 121 | /* is seq1 < seq2 ? */ |
96 | static inline int before48(const u64 seq1, const u64 seq2) | 122 | static inline int before48(const u64 seq1, const u64 seq2) |
97 | { | 123 | { |
@@ -313,26 +339,7 @@ static inline int dccp_packet_without_ack(const struct sk_buff *skb) | |||
313 | return type == DCCP_PKT_DATA || type == DCCP_PKT_REQUEST; | 339 | return type == DCCP_PKT_DATA || type == DCCP_PKT_REQUEST; |
314 | } | 340 | } |
315 | 341 | ||
316 | #define DCCP_MAX_SEQNO ((((u64)1) << 48) - 1) | 342 | #define DCCP_PKT_WITHOUT_ACK_SEQ (UINT48_MAX << 2) |
317 | #define DCCP_PKT_WITHOUT_ACK_SEQ (DCCP_MAX_SEQNO << 2) | ||
318 | |||
319 | static inline void dccp_set_seqno(u64 *seqno, u64 value) | ||
320 | { | ||
321 | if (value > DCCP_MAX_SEQNO) | ||
322 | value -= DCCP_MAX_SEQNO + 1; | ||
323 | *seqno = value; | ||
324 | } | ||
325 | |||
326 | static inline u64 dccp_delta_seqno(u64 seqno1, u64 seqno2) | ||
327 | { | ||
328 | return ((seqno2 << 16) - (seqno1 << 16)) >> 16; | ||
329 | } | ||
330 | |||
331 | static inline void dccp_inc_seqno(u64 *seqno) | ||
332 | { | ||
333 | if (++*seqno > DCCP_MAX_SEQNO) | ||
334 | *seqno = 0; | ||
335 | } | ||
336 | 343 | ||
337 | static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss) | 344 | static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss) |
338 | { | 345 | { |