xref: /csrg-svn/sys/netinet/tcp_var.h (revision 5076)
1*5076Swnj /*	tcp_var.h	4.8	81/11/25	*/
24808Swnj 
34808Swnj /*
44808Swnj  * Kernel variables for tcp.
54808Swnj  */
64808Swnj 
74808Swnj /*
84901Swnj  * Tcp+ip header, after ip options removed.
94901Swnj  */
104901Swnj struct tcpiphdr {
114901Swnj 	struct 	ipovly ti_i;		/* overlaid ip structure */
124901Swnj 	struct	tcphdr ti_t;		/* tcp header */
134901Swnj };
144901Swnj #define	ti_next		ti_i.ih_next
154901Swnj #define	ti_prev		ti_i.ih_prev
164901Swnj #define	ti_x1		ti_i.ih_x1
174901Swnj #define	ti_pr		ti_i.ih_pr
184901Swnj #define	ti_len		ti_i.ih_len
194901Swnj #define	ti_src		ti_i.ih_src
204901Swnj #define	ti_dst		ti_i.ih_dst
214901Swnj #define	ti_sport	ti_t.th_sport
224901Swnj #define	ti_dport	ti_t.th_dport
234901Swnj #define	ti_seq		ti_t.th_seq
244901Swnj #define	ti_ackno	ti_t.th_ackno
254901Swnj #define	ti_x2		ti_t.th_x2
264901Swnj #define	ti_off		ti_t.th_off
274901Swnj #define	ti_flags	ti_t.th_flags
284901Swnj #define	ti_win		ti_t.th_win
294901Swnj #define	ti_sum		ti_t.th_sum
304901Swnj #define	ti_urp		ti_t.th_urp
314901Swnj 
324901Swnj /*
335067Swnj  * TCP sequence numbers are 32 bit integers operated
345067Swnj  * on with modular arithmetic.  These macros can be
355067Swnj  * used to compare such integers.
365067Swnj  */
375067Swnj #define	SEQ_LT(a,b)	((int)((a)-(b)) < 0)
385067Swnj #define	SEQ_LEQ(a,b)	((int)((a)-(b)) <= 0)
395067Swnj #define	SEQ_GT(a,b)	((int)((a)-(b)) > 0)
405067Swnj #define	SEQ_GEQ(a,b)	((int)((a)-(b)) >= 0)
415067Swnj 
425067Swnj /*
435067Swnj  * Definitions of the TCP timers.  These timers are counted
445067Swnj  * down PR_SLOWHZ times a second.
455067Swnj  */
46*5076Swnj #define	TCPT_NTIMERS	4
475067Swnj 
48*5076Swnj #define	TCPT_REXMT	0		/* retransmit */
49*5076Swnj #define	TCPT_2MSL	1		/* 2*msl quiet time timer */
50*5076Swnj #define	TCPT_PERSIST	2		/* retransmit persistance */
515067Swnj #define	TCPT_KEEP	3		/* keep alive */
525067Swnj 
535067Swnj /*
544808Swnj  * Tcp control block.
554808Swnj  */
564881Swnj struct tcpcb {
57*5076Swnj 	struct	tcpiphdr *seg_next;	/* sequencing queue */
58*5076Swnj 	struct	tcpiphdr *seg_prev;
59*5076Swnj 	int	t_state;		/* state of this connection */
60*5076Swnj 	int	seqcnt;			/* count of chars in seq queue */
615067Swnj 	short	t_timers[TCPT_NTIMERS];	/* tcp timers */
62*5076Swnj 	short	t_options;		/* connection options: */
635067Swnj #define	TO_PUSH		0x01			/* push mode */
645067Swnj #define	TO_URG		0x02			/* urgent mode */
655067Swnj #define	TO_KEEP		0x04			/* use keep-alives */
665067Swnj 	u_char	t_flags;
675067Swnj #define	TF_OWEACK	0x01			/* owe ack to peer */
68*5076Swnj #define	TF_DELACK	0x02			/* delaying ack to peer */
694881Swnj 	struct	tcpiphdr *t_template;	/* skeletal packet for transmit */
705067Swnj 	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
714808Swnj /*
725067Swnj  * The following fields are used as in the protocol specification.
735067Swnj  * See RFC783, Dec. 1981, page 21.
744808Swnj  */
755067Swnj /* send sequence variables */
765067Swnj 	tcp_seq	snd_una;		/* send unacknowledged */
775067Swnj 	tcp_seq	snd_nxt;		/* send next */
785067Swnj 	u_short	snd_wnd;		/* send window */
795067Swnj 	tcp_seq	snd_up;			/* send urgent pointer */
805067Swnj 	tcp_seq	snd_wl1;		/* window update seg seq number */
815067Swnj 	tcp_seq	snd_wl2;		/* window update seg ack number */
825067Swnj 	tcp_seq	iss;			/* initial send sequence number */
835067Swnj /* receive sequence variables */
845067Swnj 	tcp_seq	rcv_nxt;		/* receive next */
855067Swnj 	u_short	rcv_wnd;		/* receive window */
865067Swnj 	tcp_seq	rcv_up;			/* receive urgent pointer */
875067Swnj 	tcp_seq	irs;			/* initial receive sequence number */
885067Swnj /*
895067Swnj  * Additional variables for this implementation.
905067Swnj  */
91*5076Swnj /* receive variables */
92*5076Swnj 	tcp_seq	rcv_adv;		/* advertised window */
935067Swnj /* retransmit variables */
94*5076Swnj 	tcp_seq	snd_max;		/* highest sequence number sent */
95*5076Swnj 					   used to recognize retransmits */
965067Swnj };
974808Swnj 
984881Swnj #define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
994881Swnj #define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
1004881Swnj 
1014808Swnj #define	ISSINCR		128		/* increment for iss each second */
1024808Swnj 
103*5076Swnj #define	TCP_TTL		60		/* time to live for TCP segs */
1044808Swnj /*
1055067Swnj  * TCPSC constants give various timeouts in ``slow-clock'' ticks.
1064808Swnj  */
107*5076Swnj #define	TCPSC_MSL	(120*PR_SLOWHZ)		/* max seg lifetime */
108*5076Swnj #define	TCPSC_REXMT	(  1*PR_SLOWHZ)		/* base retransmit time */
109*5076Swnj #define	TCPSC_KEEP	(240*PR_SLOWHZ)		/* keep alive */
110*5076Swnj #define	TCPSC_PERSIST	(  5*PR_SLOWHZ)		/* retransmit persistance */
1114808Swnj 
112*5076Swnj #define	TCPSC_KEEPTTL	(  4*TCPSC_KEEP)	/* keep alive too long */
113*5076Swnj #define	TCPSC_2MSL	(  2*TCPSC_MSL)		/* 2*msl quiet time timer */
1145067Swnj 
115*5076Swnj #define	TCPSC_TOOLONG	(480*PR_SLOWHZ)
116*5076Swnj 
1174926Swnj struct	tcpstat {
1184926Swnj 	int	tcps_badsum;
1194926Swnj 	int	tcps_badoff;
1204926Swnj 	int	tcps_hdrops;
1214926Swnj 	int	tcps_badsegs;
1224926Swnj 	int	tcps_unack;
1234926Swnj };
1244926Swnj 
1254808Swnj #ifdef KERNEL
1265067Swnj tcp_seq	tcp_iss;		/* tcp initial send seq # */
1275067Swnj struct	inpcb tcb;		/* head of queue of active tcpcb's */
1285067Swnj struct	tcpstat tcpstat;	/* tcp statistics */
1294808Swnj #endif
1304881Swnj struct	tcpiphdr *tcp_template();
1314808Swnj #endif
1324808Swnj 
1335067Swnj #ifdef	TCPTIMERS
1345067Swnj char *tcptimers[] =
1355067Swnj     { "INIT", "REXMT", "REXMTTL", "KEEP", "KEEPTTL", "PERSIST", "2MSL" };
1365067Swnj #endif
137