1 /* 2 * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. 3 * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. 4 * 5 * This code is derived from software contributed to The DragonFly Project 6 * by Jeffrey M. Hsu. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of The DragonFly Project nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific, prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* 35 * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. 36 * 37 * License terms: all terms for the DragonFly license above plus the following: 38 * 39 * 4. All advertising materials mentioning features or use of this software 40 * must display the following acknowledgement: 41 * 42 * This product includes software developed by Jeffrey M. Hsu 43 * for the DragonFly Project. 44 * 45 * This requirement may be waived with permission from Jeffrey Hsu. 46 * This requirement will sunset and may be removed on July 8 2005, 47 * after which the standard DragonFly license (as shown above) will 48 * apply. 49 */ 50 51 /* 52 * Copyright (c) 1982, 1986, 1993, 1995 53 * The Regents of the University of California. All rights reserved. 54 * 55 * Redistribution and use in source and binary forms, with or without 56 * modification, are permitted provided that the following conditions 57 * are met: 58 * 1. Redistributions of source code must retain the above copyright 59 * notice, this list of conditions and the following disclaimer. 60 * 2. Redistributions in binary form must reproduce the above copyright 61 * notice, this list of conditions and the following disclaimer in the 62 * documentation and/or other materials provided with the distribution. 63 * 3. All advertising materials mentioning features or use of this software 64 * must display the following acknowledgement: 65 * This product includes software developed by the University of 66 * California, Berkeley and its contributors. 67 * 4. Neither the name of the University nor the names of its contributors 68 * may be used to endorse or promote products derived from this software 69 * without specific prior written permission. 70 * 71 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 72 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 74 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 77 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 78 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 79 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 80 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 81 * SUCH DAMAGE. 82 * 83 * @(#)tcp_seq.h 8.3 (Berkeley) 6/21/95 84 * $FreeBSD: src/sys/netinet/tcp_seq.h,v 1.11.2.7 2003/02/03 02:33:10 hsu Exp $ 85 * $DragonFly: src/sys/netinet/tcp_seq.h,v 1.9 2006/05/20 02:42:12 dillon Exp $ 86 */ 87 88 #ifndef _NETINET_TCP_SEQ_H_ 89 #define _NETINET_TCP_SEQ_H_ 90 91 #ifndef _NETINET_TCP_H_ 92 #include <netinet/tcp.h> 93 #endif 94 95 /* 96 * TCP sequence numbers are 32 bit integers operated 97 * on with modular arithmetic. These macros can be 98 * used to compare such integers. 99 */ 100 #define SEQ_LT(a,b) ((int)((a)-(b)) < 0) 101 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) 102 #define SEQ_GT(a,b) ((int)((a)-(b)) > 0) 103 #define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) 104 105 static __inline tcp_seq 106 seq_max(tcp_seq a, tcp_seq b) 107 { 108 return (SEQ_GT(a, b) ? a : b); 109 } 110 111 static __inline tcp_seq 112 seq_min(tcp_seq a, tcp_seq b) 113 { 114 return (SEQ_LT(a, b) ? a : b); 115 } 116 117 /* for modulo comparisons of timestamps */ 118 #define TSTMP_LT(a,b) ((int)((a)-(b)) < 0) 119 #define TSTMP_GT(a,b) ((int)((a)-(b)) > 0) 120 #define TSTMP_GEQ(a,b) ((int)((a)-(b)) >= 0) 121 122 /* 123 * TCP connection counts are 32 bit integers operated 124 * on with modular arithmetic. These macros can be 125 * used to compare such integers. 126 */ 127 #define CC_LT(a,b) ((int)((a)-(b)) < 0) 128 #define CC_LEQ(a,b) ((int)((a)-(b)) <= 0) 129 #define CC_GT(a,b) ((int)((a)-(b)) > 0) 130 #define CC_GEQ(a,b) ((int)((a)-(b)) >= 0) 131 132 /* Macro to increment a CC: skip 0 which has a special meaning */ 133 #define CC_INC(c) (++(c) == 0 ? ++(c) : (c)) 134 135 /* 136 * Macros to initialize tcp sequence numbers for 137 * send and receive from initial send and receive 138 * sequence numbers. 139 */ 140 #define tcp_rcvseqinit(tp) \ 141 (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1 142 143 #define tcp_sendseqinit(tp) \ 144 (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \ 145 (tp)->snd_recover = (tp)->iss 146 147 #define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * hz) 148 /* timestamp wrap-around time */ 149 150 #ifdef _KERNEL 151 extern tcp_cc tcp_ccgen; /* global connection count */ 152 #endif /* _KERNEL */ 153 #endif /* _NETINET_TCP_SEQ_H_ */ 154