xref: /csrg-svn/sys/netinet/tcp.h (revision 4575)
1*4575Swnj /* tcp.h 1.4 81/10/21 */
24573Swnj 
34573Swnj /*
44573Swnj  * Tcp header (fits over ip header).
54573Swnj  */
64573Swnj struct th {
74573Swnj 	struct	th *t_next;		/* -> next tcp on rcv chain */
84573Swnj 	struct	th *t_prev;		/* -> prev tcp on rcv chain */
94573Swnj 	u_char	t_x1;			/* (unused) */
104573Swnj 	u_char	t_pr;			/* protocol */
114573Swnj 	u_short	t_len;			/* seg length */
124573Swnj 	struct	socket t_s;		/* source internet address */
134573Swnj 	struct	socket t_d;		/* destination internet address */
144573Swnj 	u_short	t_src;			/* source port */
154573Swnj 	u_short	t_dst;			/* destination port */
164573Swnj 	seq_t	t_seq;			/* sequence number */
174573Swnj 	seq_t	t_ackno;		/* acknowledgement number */
184573Swnj #define	t_end(x) (x->t_seq + x->t_len - 1)
194573Swnj 	u_char
204573Swnj 		t_x2:4,			/* (unused) */
214573Swnj 		t_off:4;		/* data offset */
22*4575Swnj 	u_char	th_flags;
23*4575Swnj #define	TH_FIN	001
24*4575Swnj #define	TH_SYN	002
25*4575Swnj #define	TH_RST	004
26*4575Swnj #define	TH_EOL	010
27*4575Swnj #define	TH_ACK	020
28*4575Swnj #define	TH_URG	040
294573Swnj 	u_short	t_win;			/* window */
304573Swnj 	u_short	t_sum;			/* checksum */
314573Swnj 	u_short	t_urp;			/* urgent pointer */
324499Swnj };
334499Swnj 
344573Swnj /*
354573Swnj  * Tcp control block.
364573Swnj  */
374573Swnj struct tcb {
384573Swnj 	struct	th *t_rcv_next;		/* first el on rcv queue */
394573Swnj 	struct	th *t_rcv_prev;		/* last el on rcv queue */
404573Swnj 	struct	tcb *t_tcb_next;	/* next tcb */
414573Swnj 	struct	tcb *t_tcb_prev;	/* next tcb */
424573Swnj 	struct	ucb *t_ucb;		/* ucb */
434573Swnj 	struct	mbuf *t_rcv_unack;	/* unacked message queue */
444573Swnj 	seq_t	iss;			/* initial send seq # */
454573Swnj 	seq_t	irs;			/* initial recv seq # */
464573Swnj 	seq_t	rcv_urp;		/* rcv urgent pointer */
474573Swnj 	seq_t	rcv_nxt;		/* next seq # to rcv */
484573Swnj 	seq_t	rcv_end;		/* rcv eol pointer */
494573Swnj 	seq_t	snd_off;		/* seq # of first datum in send buf */
504573Swnj 	seq_t	seq_fin;		/* seq # of FIN sent */
514573Swnj 	seq_t	snd_end;		/* send eol pointer */
524573Swnj 	seq_t	snd_urp;		/* snd urgent pointer */
534573Swnj 	seq_t	snd_lst;		/* seq # of last sent datum */
544573Swnj 	seq_t	snd_nxt;		/* seq # of next datum to send */
554573Swnj 	seq_t	snd_una;		/* seq # of first unacked datum */
564573Swnj 	seq_t	snd_wl;			/* seq # of last sent window */
574573Swnj 	seq_t	snd_hi;			/* highest seq # sent */
584573Swnj 	seq_t	snd_wnd;		/* send window max */
594573Swnj 	seq_t	t_rexmt_val;		/* val saved in rexmt timer */
604573Swnj 	seq_t	t_rtl_val;		/* val saved in rexmt too long timer */
614573Swnj 	seq_t	t_xmt_val;		/* seq # sent when xmt timer started */
624499Swnj 
634573Swnj 	/* various flags and state variables */
644499Swnj 
65*4575Swnj 	u_short	tc_flags;
66*4575Swnj #define	TC_ACK_DUE	0x0001		/* must we send ACK */
67*4575Swnj #define	TC_CANCELLED	0x0002		/* retransmit timer cancelled */
68*4575Swnj #define	TC_DROPPED_TXT	0x0004		/* dropped incoming data */
69*4575Swnj #define	TC_FIN_RCVD	0x0008		/* FIN received */
70*4575Swnj #define	TC_FORCE_ONE	0x0010		/* force sending of one byte */
71*4575Swnj #define	TC_NEW_WINDOW	0x0020		/* received new window size */
72*4575Swnj #define	TC_REXMT	0x0040		/* this msg is a retransmission */
73*4575Swnj #define	TC_SND_FIN	0x0080		/* FIN should be sent */
74*4575Swnj #define	TC_SND_RST	0x0100		/* RST should be sent */
75*4575Swnj #define	TC_SND_URG	0x0200		/* urgent data to send */
76*4575Swnj #define	TC_SYN_ACKED	0x0400		/* SYN has been ACKed */
77*4575Swnj #define	TC_SYN_RCVD	0x0800		/* SYN has been received */
78*4575Swnj #define	TC_USR_CLOSED	0x1000		/* user has closed connection */
79*4575Swnj #define	TC_WAITED_2_ML	0x2000		/* wait time for FIN ACK is up */
80*4575Swnj #define	TC_NET_KEEP	0x4000		/* don't free this net input */
81*4575Swnj #define	TC_USR_ABORT	0x8000		/* user has closed and does not expect
824573Swnj 					   to receive any more data */
83*4575Swnj 
844573Swnj 	u_short	t_lport;		/* local port */
854573Swnj 	u_short	t_fport;		/* foreign port */
864573Swnj 	u_char	t_state;		/* state of this connection */
874573Swnj 	u_char	t_xmtime;		/* current rexmt time */
884499Swnj 
894573Swnj 	/* timers */
904499Swnj 
914573Swnj 	u_char	t_init;			/* initialization too long */
924573Swnj 	u_char	t_rexmt;		/* retransmission */
934573Swnj 	u_char	t_rexmttl;		/* retransmit too long */
944573Swnj 	u_char	t_persist;		/* retransmit persistance */
954573Swnj 	u_char	t_finack;		/* fin acknowledged */
964573Swnj 	u_char	t_xmt;			/* round trip transmission time */
974573Swnj };
984499Swnj 
994573Swnj #define	ISSINCR		128		/* increment for iss each second */
1004573Swnj #define	TCPROTO		6		/* TCP-4 protocol number */
1014573Swnj #define	TCPSIZE		20		/* size of TCP leader (bytes) */
1024573Swnj #define	T_2ML		10		/* 2*maximum packet lifetime */
1034573Swnj #define	T_PERS		5		/* persist time */
1044573Swnj #define	T_INIT		30		/* init too long timeout */
1054573Swnj #define	T_REXMT		1		/* base for retransmission time */
1064573Swnj #define	T_REXMTTL	30		/* retransmit too long timeout */
1074573Swnj #define	T_REMAX		30		/* maximum retransmission time */
1084573Swnj #define	ACTIVE		1		/* active open */
1094573Swnj #define	PASSIVE		0		/* passive open */
1104499Swnj 
1114573Swnj /*
1124573Swnj  * Tcp debugging record.
1134573Swnj  */
1144573Swnj struct t_debug {
1154573Swnj 	long	t_tod;			/* time of day */
1164573Swnj 	struct	tcb *t_tcb;		/* -> tcb */
1174573Swnj 	char	t_old;			/* old state */
1184573Swnj 	char	t_inp;			/* input */
1194573Swnj 	char	t_tim;			/* timer id */
1204573Swnj 	char	t_new;			/* new state */
1214573Swnj 	seq_t	t_sno;			/* seq_t number */
1224573Swnj 	seq_t	t_ano;			/* acknowledgement */
1234573Swnj 	u_short	t_wno;			/* window */
1244573Swnj 	u_short	t_lno;			/* length */
1254573Swnj 	u_char	t_flg;			/* message flags */
1264573Swnj };
1274499Swnj 
1284573Swnj /*
1294573Swnj  * Tcp machine predicates
1304573Swnj  */
1314573Swnj #define	ack_ok(x, y) \
132*4575Swnj     (((y)->th_flags&TH_ACK)==0 || \
133*4575Swnj       ((x)->iss < (y)->t_ackno && (y)->t_ackno <= (x)->snd_hi))
1344499Swnj 
1354573Swnj #define	syn_ok(x, y) \
136*4575Swnj     ((y)->th_flags&TH_SYN)
1374499Swnj 
1384573Swnj #define	ack_fin(x, y) \
1394573Swnj     ((x)->seq_fin > (x)->iss && (y)->t_ackno > (x)->seq_fin)
1404499Swnj 
1414573Swnj #define	rcv_empty(x) \
142*4575Swnj     (((x)->tc_flags&TC_USR_ABORT) || \
1434573Swnj       ((x)->t_ucb->uc_rbuf == NULL && (x)->t_rcv_next == (x)->t_rcv_prev))
144