tcp_seq.h revision 6247
136285Sbrian/*
236285Sbrian * Copyright (c) 1982, 1986, 1993
336285Sbrian *	The Regents of the University of California.  All rights reserved.
436285Sbrian *
536285Sbrian * Redistribution and use in source and binary forms, with or without
636285Sbrian * modification, are permitted provided that the following conditions
736285Sbrian * are met:
836285Sbrian * 1. Redistributions of source code must retain the above copyright
936285Sbrian *    notice, this list of conditions and the following disclaimer.
1036285Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1136285Sbrian *    notice, this list of conditions and the following disclaimer in the
1236285Sbrian *    documentation and/or other materials provided with the distribution.
1336285Sbrian * 3. All advertising materials mentioning features or use of this software
1436285Sbrian *    must display the following acknowledgement:
1536285Sbrian *	This product includes software developed by the University of
1636285Sbrian *	California, Berkeley and its contributors.
1736285Sbrian * 4. Neither the name of the University nor the names of its contributors
1836285Sbrian *    may be used to endorse or promote products derived from this software
1936285Sbrian *    without specific prior written permission.
2036285Sbrian *
2136285Sbrian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2236285Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2336285Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2436285Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2536285Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2649472Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2736285Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2836285Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2936285Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3036285Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3136285Sbrian * SUCH DAMAGE.
3236285Sbrian *
3349472Sbrian *	@(#)tcp_seq.h	8.1 (Berkeley) 6/10/93
3449472Sbrian * $Id: tcp_seq.h,v 1.3 1994/08/21 05:27:37 paul Exp $
3549472Sbrian */
3649472Sbrian
3749472Sbrian#ifndef _NETINET_TCP_SEQ_H_
3849472Sbrian#define _NETINET_TCP_SEQ_H_
3949472Sbrian/*
4036285Sbrian * TCP sequence numbers are 32 bit integers operated
4137007Sbrian * on with modular arithmetic.  These macros can be
4236285Sbrian * used to compare such integers.
4337007Sbrian */
4437007Sbrian#define	SEQ_LT(a,b)	((int)((a)-(b)) < 0)
4537007Sbrian#define	SEQ_LEQ(a,b)	((int)((a)-(b)) <= 0)
4637007Sbrian#define	SEQ_GT(a,b)	((int)((a)-(b)) > 0)
4737007Sbrian#define	SEQ_GEQ(a,b)	((int)((a)-(b)) >= 0)
4836285Sbrian
4936285Sbrian/* for modulo comparisons of timestamps */
5036285Sbrian#define TSTMP_LT(a,b)	((int)((a)-(b)) < 0)
5136285Sbrian#define TSTMP_GEQ(a,b)	((int)((a)-(b)) >= 0)
5236285Sbrian
5336285Sbrian#ifdef TTCP
5436285Sbrian/*
5536285Sbrian * TCP connection counts are 32 bit integers operated
5636285Sbrian * on with modular arithmetic.  These macros can be
5736285Sbrian * used to compare such integers.
5836285Sbrian */
5936285Sbrian#define	CC_LT(a,b)	((int)((a)-(b)) < 0)
6037007Sbrian#define	CC_LEQ(a,b)	((int)((a)-(b)) <= 0)
6136285Sbrian#define	CC_GT(a,b)	((int)((a)-(b)) > 0)
6236285Sbrian#define	CC_GEQ(a,b)	((int)((a)-(b)) >= 0)
6336285Sbrian
6436285Sbrian/* Macro to increment a CC: skip 0 which has a special meaning */
6536285Sbrian#define CC_INC(c)	(++(c) == 0 ? ++(c) : (c))
6636285Sbrian#endif
6736285Sbrian
6836285Sbrian/*
6936285Sbrian * Macros to initialize tcp sequence numbers for
7036285Sbrian * send and receive from initial send and receive
7136285Sbrian * sequence numbers.
7236285Sbrian */
7336285Sbrian#define	tcp_rcvseqinit(tp) \
7436285Sbrian	(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
7536285Sbrian
7636285Sbrian#define	tcp_sendseqinit(tp) \
7736285Sbrian	(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
7844468Sbrian	    (tp)->iss
7944468Sbrian
8036285Sbrian#define	TCP_ISSINCR	(125*1024)	/* increment for tcp_iss each second */
8136285Sbrian
8236285Sbrian#define TCP_PAWS_IDLE	(24 * 24 * 60 * 60 * PR_SLOWHZ)
8336285Sbrian					/* timestamp wrap-around time */
8436285Sbrian
8536285Sbrian#ifdef KERNEL
8638174Sbriantcp_seq	tcp_iss;		/* tcp initial send seq # */
8738174Sbrian#ifdef TTCP
8836285Sbriantcp_cc	tcp_ccgen;		/* global connection count */
8936285Sbrian#endif
9036285Sbrian#endif
9136285Sbrian#endif
9236285Sbrian