xref: /titanic_52/usr/src/stand/lib/tcp/tcp_inet.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate /*
7*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1982, 1986 Regents of the University of California.
8*7c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
9*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
10*7c478bd9Sstevel@tonic-gate  */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #ifndef _TCP_INET_H
13*7c478bd9Sstevel@tonic-gate #define	_TCP_INET_H
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
18*7c478bd9Sstevel@tonic-gate extern "C" {
19*7c478bd9Sstevel@tonic-gate #endif
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate #include "tcp_sack.h"
22*7c478bd9Sstevel@tonic-gate 
23*7c478bd9Sstevel@tonic-gate /* TCP states */
24*7c478bd9Sstevel@tonic-gate #define	TCPS_ALL_ACKED		-7	/* Internal state for retransmissions */
25*7c478bd9Sstevel@tonic-gate #define	TCPS_CLOSED		-6
26*7c478bd9Sstevel@tonic-gate #define	TCPS_IDLE		-5	/* idle (opened, but not bound) */
27*7c478bd9Sstevel@tonic-gate #define	TCPS_BOUND		-4	/* bound, ready to connect or accept */
28*7c478bd9Sstevel@tonic-gate #define	TCPS_LISTEN		-3	/* listening for connection */
29*7c478bd9Sstevel@tonic-gate #define	TCPS_SYN_SENT		-2	/* active, have sent syn */
30*7c478bd9Sstevel@tonic-gate #define	TCPS_SYN_RCVD		-1	/* have received syn (and sent ours) */
31*7c478bd9Sstevel@tonic-gate /* states < TCPS_ESTABLISHED are those where connections not established */
32*7c478bd9Sstevel@tonic-gate #define	TCPS_ESTABLISHED	0	/* established */
33*7c478bd9Sstevel@tonic-gate #define	TCPS_CLOSE_WAIT		1	/* rcvd fin, waiting for close */
34*7c478bd9Sstevel@tonic-gate /* states > TCPS_CLOSE_WAIT are those where user has closed */
35*7c478bd9Sstevel@tonic-gate #define	TCPS_FIN_WAIT_1		2	/* have closed and sent fin */
36*7c478bd9Sstevel@tonic-gate #define	TCPS_CLOSING		3	/* closed, xchd FIN, await FIN ACK */
37*7c478bd9Sstevel@tonic-gate #define	TCPS_LAST_ACK		4	/* had fin and close; await FIN ACK */
38*7c478bd9Sstevel@tonic-gate /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
39*7c478bd9Sstevel@tonic-gate #define	TCPS_FIN_WAIT_2		5	/* have closed, fin is acked */
40*7c478bd9Sstevel@tonic-gate #define	TCPS_TIME_WAIT		6	/* in 2*msl quiet wait after close */
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * Internal flags used in conjunction with the packet header flags.
44*7c478bd9Sstevel@tonic-gate  * Used in tcp_rput_data to keep track of what needs to be done.
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate #define	TH_LIMIT_XMIT		0x0400	/* Limited xmit is needed */
47*7c478bd9Sstevel@tonic-gate #define	TH_XMIT_NEEDED		0x0800	/* Window opened - send queued data */
48*7c478bd9Sstevel@tonic-gate #define	TH_REXMIT_NEEDED	0x1000	/* Time expired for unacked data */
49*7c478bd9Sstevel@tonic-gate #define	TH_ACK_NEEDED		0x2000	/* Send an ack now. */
50*7c478bd9Sstevel@tonic-gate #define	TH_NEED_SACK_REXMIT	0x4000	/* Use SACK info to retransmission */
51*7c478bd9Sstevel@tonic-gate #define	TH_TIMER_NEEDED 0x8000	/* Start the delayed ack/push bit timer */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * Special Magic number used by TCP to issue a callback to recvfrom() in the
55*7c478bd9Sstevel@tonic-gate  * form of a dummy inetgram.
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate #define	TCP_CALLB_MAGIC_ID	0xFFFF
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * TCP sequence numbers are 32 bit integers operated
61*7c478bd9Sstevel@tonic-gate  * on with modular arithmetic.  These macros can be
62*7c478bd9Sstevel@tonic-gate  * used to compare such integers.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate #define	SEQ_LT(a, b)	((int32_t)((a)-(b)) < 0)
65*7c478bd9Sstevel@tonic-gate #define	SEQ_LEQ(a, b)	((int32_t)((a)-(b)) <= 0)
66*7c478bd9Sstevel@tonic-gate #define	SEQ_GT(a, b)	((int32_t)((a)-(b)) > 0)
67*7c478bd9Sstevel@tonic-gate #define	SEQ_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /* TCP Protocol header */
70*7c478bd9Sstevel@tonic-gate typedef	struct tcphdr_s {
71*7c478bd9Sstevel@tonic-gate 	uint8_t		th_lport[2];	/* Source port */
72*7c478bd9Sstevel@tonic-gate 	uint8_t		th_fport[2];	/* Destination port */
73*7c478bd9Sstevel@tonic-gate 	uint8_t		th_seq[4];	/* Sequence number */
74*7c478bd9Sstevel@tonic-gate 	uint8_t		th_ack[4];	/* Acknowledgement number */
75*7c478bd9Sstevel@tonic-gate 	uint8_t		th_offset_and_rsrvd[1]; /* Offset to the packet data */
76*7c478bd9Sstevel@tonic-gate 	uint8_t		th_flags[1];
77*7c478bd9Sstevel@tonic-gate 	uint8_t		th_win[2];	/* Allocation number */
78*7c478bd9Sstevel@tonic-gate 	uint8_t		th_sum[2];	/* TCP checksum */
79*7c478bd9Sstevel@tonic-gate 	uint8_t		th_urp[2];	/* Urgent pointer */
80*7c478bd9Sstevel@tonic-gate } tcph_t;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate #define	TCP_HDR_LENGTH(tcph) (((tcph)->th_offset_and_rsrvd[0] >>2) &(0xF << 2))
83*7c478bd9Sstevel@tonic-gate #define	TCP_MAX_COMBINED_HEADER_LENGTH	(60 + 60) /* Maxed out ip + tcp */
84*7c478bd9Sstevel@tonic-gate #define	TCP_MAX_IP_OPTIONS_LENGTH	(60 - IP_SIMPLE_HDR_LENGTH)
85*7c478bd9Sstevel@tonic-gate #define	TCP_MAX_HDR_LENGTH		60
86*7c478bd9Sstevel@tonic-gate #define	TCP_MAX_TCP_OPTIONS_LENGTH	(60 - sizeof (tcph_t))
87*7c478bd9Sstevel@tonic-gate #define	TCP_MIN_HEADER_LENGTH		20
88*7c478bd9Sstevel@tonic-gate #define	TCP_MAXWIN			65535
89*7c478bd9Sstevel@tonic-gate #define	TCP_PORT_LEN			sizeof (in_port_t)
90*7c478bd9Sstevel@tonic-gate #define	TCP_MAX_WINSHIFT		14
91*7c478bd9Sstevel@tonic-gate #define	TCP_MAX_LARGEWIN		(TCP_MAXWIN << TCP_MAX_WINSHIFT)
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate #define	TCPIP_HDR_LENGTH(mp, n)					\
94*7c478bd9Sstevel@tonic-gate 	(n) = IPH_HDR_LENGTH((mp)->b_rptr),			\
95*7c478bd9Sstevel@tonic-gate 	(n) += TCP_HDR_LENGTH((tcph_t *)&(mp)->b_rptr[(n)])
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate /* TCP Protocol header (used if the header is known to be 32-bit aligned) */
98*7c478bd9Sstevel@tonic-gate typedef	struct tcphdra_s {
99*7c478bd9Sstevel@tonic-gate 	in_port_t	tha_lport;	/* Source port */
100*7c478bd9Sstevel@tonic-gate 	in_port_t	tha_fport;	/* Destination port */
101*7c478bd9Sstevel@tonic-gate 	uint32_t	tha_seq;	/* Sequence number */
102*7c478bd9Sstevel@tonic-gate 	uint32_t	tha_ack;	/* Acknowledgement number */
103*7c478bd9Sstevel@tonic-gate 	uint8_t tha_offset_and_reserved; /* Offset to the packet data */
104*7c478bd9Sstevel@tonic-gate 	uint8_t		tha_flags;
105*7c478bd9Sstevel@tonic-gate 	uint16_t	tha_win;	/* Allocation number */
106*7c478bd9Sstevel@tonic-gate 	uint16_t	tha_sum;	/* TCP checksum */
107*7c478bd9Sstevel@tonic-gate 	uint16_t	tha_urp;	/* Urgent pointer */
108*7c478bd9Sstevel@tonic-gate } tcpha_t;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate typedef struct tcp_s {
111*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_time_wait_next; /* Next TCP in TIME_WAIT list */
112*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_time_wait_prev; /* Prev TCP in TIME_WAIT list */
113*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_max_swnd;		/* Maximum swnd we have seen */
114*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_suna;		/* Sender unacknowledged */
115*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_csuna;		/* Clear (no rexmits in window) suna */
116*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_snxt;		/* Senders next seq num */
117*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_swnd;		/* Senders window (relative to suna) */
118*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_mss;		/* Max segment size */
119*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_iss;		/* Initial send seq num */
120*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rnxt;		/* Seq we expect to recv next */
121*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rwnd;		/* Current receive window */
122*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rwnd_max;		/* Max receive window */
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_irs;		/* Initial recv seq num */
125*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_fss;		/* Final/fin send seq num */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_swl1;		/* These help us avoid using stale */
128*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_swl2;		/*  packets to update state */
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_cwnd;		/* Congestion window */
131*7c478bd9Sstevel@tonic-gate 	int32_t tcp_cwnd_cnt;		/* cwnd cnt in congestion avoidance */
132*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_cwnd_ssthresh;	/* Congestion window */
133*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_cwnd_max;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_snd_burst;		/* Send burst factor */
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_state;
138*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_rcv_ws;		/* My window scale power */
139*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_snd_ws;		/* Sender's window scale power */
140*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_ts_recent;	/* Timestamp of earliest unacked */
141*7c478bd9Sstevel@tonic-gate 					/*  data segment */
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_if_mtu;	/* Outgoing interface MTU. */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_rtt_sa;	/* Round trip smoothed average */
146*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_rtt_sd;	/* Round trip smoothed deviation */
147*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_rtt_update;		/* Round trip update(s) */
148*7c478bd9Sstevel@tonic-gate 	uint32_t 	tcp_ms_we_have_waited;	/* Total retrans time */
149*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_rto;	/* Round trip timeout */
150*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_rto_timeout;	/* RTT timeout time */
151*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_time_wait_expire;
152*7c478bd9Sstevel@tonic-gate 				/* time in hz when t/w expires */
153*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_last_rcv_lbolt;
154*7c478bd9Sstevel@tonic-gate 				/* lbolt on last packet, used for PAWS */
155*7c478bd9Sstevel@tonic-gate 	int	tcp_lingertime;		/* Close linger time (in seconds) */
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_first_timer_threshold;  /* When to prod IP */
158*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_second_timer_threshold; /* When to give up completely */
159*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_first_ctimer_threshold; /* 1st threshold when connecting */
160*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_second_ctimer_threshold; /* 2nd ... while connecting */
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rexmit_nxt;	/* Next rexmit seq num */
163*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rexmit_max;	/* Max retran seq num */
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_naglim;		/* Tunable nagle limit */
166*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_valid_bits;
167*7c478bd9Sstevel@tonic-gate #define	TCP_ISS_VALID	0x1	/* Is the tcp_iss seq num active? */
168*7c478bd9Sstevel@tonic-gate #define	TCP_FSS_VALID	0x2	/* Is the tcp_fss seq num active? */
169*7c478bd9Sstevel@tonic-gate #define	TCP_URG_VALID	0x4	/* Is the tcp_urg seq num active? */
170*7c478bd9Sstevel@tonic-gate #define	TCP_OFO_FIN_VALID 0x8	/* Has TCP received an out of order FIN? */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_xmit_hiwater;	/* Send buffer high water mark. */
173*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_xmit_lowater;	/* Send buffer low water mark. */
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	uchar_t	tcp_timer_backoff;	/* Backoff shift count. */
176*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_last_recv_time;	/* Last time we receive a segment. */
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	/* Fields arranged in approximate access order along main paths */
179*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_xmit_head;		/* Head of rexmit list */
180*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_xmit_last;		/* last valid data seen by tcp_wput */
181*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_unsent;		/* # of bytes in hand that are unsent */
182*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_xmit_tail;		/* Last rexmit data sent */
183*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_xmit_tail_unsent;	/* # of unsent bytes in xmit_tail */
184*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_rcv_list;		/* Queued until push or exceed */
185*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_rcv_last_tail;	/* tcp_rcv_push_wait. */
186*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rcv_cnt;		/* tcp_rcv_list is b_next chain. */
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rack;		/* Seq # we have acked */
189*7c478bd9Sstevel@tonic-gate 	uint32_t tcp_rack_cnt;		/* # of bytes we have deferred ack */
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_reass_head;	 /* Out of order reassembly list head */
192*7c478bd9Sstevel@tonic-gate 	mblk_t	*tcp_reass_tail;	 /* Out of order reassembly list tail */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 	tcp_sack_info_t	*tcp_sack_info;
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate #define	tcp_pipe	tcp_sack_info->tcp_pipe
197*7c478bd9Sstevel@tonic-gate #define	tcp_fack	tcp_sack_info->tcp_fack
198*7c478bd9Sstevel@tonic-gate #define	tcp_sack_snxt	tcp_sack_info->tcp_sack_snxt
199*7c478bd9Sstevel@tonic-gate #define	tcp_max_sack_blk	tcp_sack_info->tcp_max_sack_blk
200*7c478bd9Sstevel@tonic-gate #define	tcp_num_sack_blk	tcp_sack_info->tcp_num_sack_blk
201*7c478bd9Sstevel@tonic-gate #define	tcp_sack_list		tcp_sack_info->tcp_sack_list
202*7c478bd9Sstevel@tonic-gate #define	tcp_num_notsack_blk	tcp_sack_info->tcp_num_notsack_blk
203*7c478bd9Sstevel@tonic-gate #define	tcp_cnt_notsack_list	tcp_sack_info->tcp_cnt_notsack_list
204*7c478bd9Sstevel@tonic-gate #define	tcp_notsack_list		tcp_sack_info->tcp_notsack_list
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 	int tcp_conn_req_cnt_q0;	/* # of conn reqs in SYN_RCVD */
207*7c478bd9Sstevel@tonic-gate 	int tcp_conn_req_cnt_q;	/* # of conn reqs in ESTABLISHED */
208*7c478bd9Sstevel@tonic-gate 	int tcp_conn_req_max;	/* # of ESTABLISHED conn reqs allowed */
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 	int	tcp_iphc_len;		/* actual allocated buffer size */
211*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_hdr_len;		/* Byte len of combined TCP/IP hdr */
212*7c478bd9Sstevel@tonic-gate 	struct ip	*tcp_ipha;	/* IPv4 header in the buffer */
213*7c478bd9Sstevel@tonic-gate 	int	tcp_ip_hdr_len;		/* Byte len of our current IPvx hdr */
214*7c478bd9Sstevel@tonic-gate 	tcph_t	*tcp_tcph;		/* tcp header within combined hdr */
215*7c478bd9Sstevel@tonic-gate 	int32_t	tcp_tcp_hdr_len;	/* tcp header len within combined */
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 	uint16_t tcp_last_sent_len;	/* Record length for nagle */
218*7c478bd9Sstevel@tonic-gate 	uint16_t tcp_dupack_cnt;	/* # of consequtive duplicate acks */
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 	/*
221*7c478bd9Sstevel@tonic-gate 	 * Address family that app wishes returned addrsses to be in.
222*7c478bd9Sstevel@tonic-gate 	 * Currently taken from address family used in T_BIND_REQ, but
223*7c478bd9Sstevel@tonic-gate 	 * should really come from family used in original socket() call.
224*7c478bd9Sstevel@tonic-gate 	 * Value can be AF_INET or AF_INET6.
225*7c478bd9Sstevel@tonic-gate 	 */
226*7c478bd9Sstevel@tonic-gate 	uint_t	tcp_family;
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_ofo_fin_seq; /* Recv out of order FIN seq num */
229*7c478bd9Sstevel@tonic-gate 	uint32_t	tcp_cwr_snd_max;
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate 	uint32_t
232*7c478bd9Sstevel@tonic-gate 		tcp_fin_acked : 1,	/* Has our FIN been acked? */
233*7c478bd9Sstevel@tonic-gate 		tcp_fin_rcvd : 1,	/* Have we seen a FIN? */
234*7c478bd9Sstevel@tonic-gate 		tcp_fin_sent : 1,	/* Have we sent our FIN yet? */
235*7c478bd9Sstevel@tonic-gate 		tcp_useloopback : 1,	/* SO_USELOOPBACK "socket" option. */
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 		tcp_conn_def_q0: 1,	/* move from q0 to q deferred */
238*7c478bd9Sstevel@tonic-gate 		tcp_zero_win_probe: 1,	/* Zero win probing is in progress */
239*7c478bd9Sstevel@tonic-gate 		tcp_set_timer : 1,
240*7c478bd9Sstevel@tonic-gate 		tcp_active_open: 1,	/* This is a active open */
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 		tcp_timer_running: 1,	/* Retransmission timer running */
243*7c478bd9Sstevel@tonic-gate 		tcp_rexmit : 1,		/* TCP is retransmitting */
244*7c478bd9Sstevel@tonic-gate 		tcp_snd_sack_ok : 1,	/* Can use SACK for this connection */
245*7c478bd9Sstevel@tonic-gate 		tcp_ecn_ok : 1,		/* Can use ECN for this connection */
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate 		tcp_ecn_echo_on : 1,	/* Need to do ECN echo */
248*7c478bd9Sstevel@tonic-gate 		tcp_ecn_cwr_sent : 1,	/* ECN_CWR has been sent */
249*7c478bd9Sstevel@tonic-gate 		tcp_cwr : 1,		/* Cwnd has reduced recently */
250*7c478bd9Sstevel@tonic-gate 		tcp_snd_ts_ok  : 1,
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 		tcp_snd_ws_ok  : 1,
253*7c478bd9Sstevel@tonic-gate 		tcp_linger : 1,
254*7c478bd9Sstevel@tonic-gate 		tcp_dontdrop : 1,
255*7c478bd9Sstevel@tonic-gate 		tcp_junk_fill_thru_bit_31 : 13;
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 	char	*tcp_iphc;		/* Buffer holding tcp/ip hdr template */
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	in_addr_t	tcp_remote;	/* true remote address - needed for */
260*7c478bd9Sstevel@tonic-gate 					/* source routing. */
261*7c478bd9Sstevel@tonic-gate 	in_addr_t	tcp_bound_source;	/* IP address in bind_req */
262*7c478bd9Sstevel@tonic-gate 	/*
263*7c478bd9Sstevel@tonic-gate 	 * These fields contain the same information as tcp_tcph->th_*port.
264*7c478bd9Sstevel@tonic-gate 	 * However, the lookup functions can not use the header fields
265*7c478bd9Sstevel@tonic-gate 	 * since during IP option manipulation the tcp_tcph pointer
266*7c478bd9Sstevel@tonic-gate 	 * changes.
267*7c478bd9Sstevel@tonic-gate 	 */
268*7c478bd9Sstevel@tonic-gate 	union {
269*7c478bd9Sstevel@tonic-gate 		struct {
270*7c478bd9Sstevel@tonic-gate 			in_port_t	tcpu_fport;	/* Remote port */
271*7c478bd9Sstevel@tonic-gate 			in_port_t	tcpu_lport;	/* Local port */
272*7c478bd9Sstevel@tonic-gate 		} tcpu_ports1;
273*7c478bd9Sstevel@tonic-gate 		uint32_t		tcpu_ports2;	/* Rem port, */
274*7c478bd9Sstevel@tonic-gate 							/* local port */
275*7c478bd9Sstevel@tonic-gate 					/* Used for TCP_MATCH performance */
276*7c478bd9Sstevel@tonic-gate 	} tcp_tcpu;
277*7c478bd9Sstevel@tonic-gate #define	tcp_fport	tcp_tcpu.tcpu_ports1.tcpu_fport
278*7c478bd9Sstevel@tonic-gate #define	tcp_lport	tcp_tcpu.tcpu_ports1.tcpu_lport
279*7c478bd9Sstevel@tonic-gate #define	tcp_ports	tcp_tcpu.tcpu_ports2
280*7c478bd9Sstevel@tonic-gate 	/*
281*7c478bd9Sstevel@tonic-gate 	 * IP format that packets transmitted from this struct should use.
282*7c478bd9Sstevel@tonic-gate 	 * Value can be IPV4_VERSION or IPV6_VERSION.  Determines whether
283*7c478bd9Sstevel@tonic-gate 	 * IP+TCP header template above stores an IPv4 or IPv6 header.
284*7c478bd9Sstevel@tonic-gate 	 */
285*7c478bd9Sstevel@tonic-gate 	ushort_t	tcp_ipversion;
286*7c478bd9Sstevel@tonic-gate 	int		tcp_client_errno;
287*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_eager_next_q; /* next eager in ESTABLISHED state */
288*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_eager_last_q;	/* last eager in ESTABLISHED state */
289*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_eager_next_q0; /* next eager in SYN_RCVD state */
290*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_eager_prev_q0; /* prev eager in SYN_RCVD state */
291*7c478bd9Sstevel@tonic-gate 	struct tcp_s *tcp_listener;	/* Our listener */
292*7c478bd9Sstevel@tonic-gate } tcp_t;
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate /* External TCP functions. */
295*7c478bd9Sstevel@tonic-gate extern void tcp_socket_init(struct inetboot_socket *);
296*7c478bd9Sstevel@tonic-gate extern int tcp_connect(int);
297*7c478bd9Sstevel@tonic-gate extern int tcp_listen(int, int);
298*7c478bd9Sstevel@tonic-gate extern int tcp_bind(int);
299*7c478bd9Sstevel@tonic-gate extern int tcp_send(int, tcp_t *, const void *, int);
300*7c478bd9Sstevel@tonic-gate extern int tcp_opt_set(tcp_t *, int, int, const void *, socklen_t);
301*7c478bd9Sstevel@tonic-gate extern int tcp_accept(int, struct sockaddr *, socklen_t *);
302*7c478bd9Sstevel@tonic-gate extern int tcp_shutdown(int);
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate /* Exported for recvfrom */
305*7c478bd9Sstevel@tonic-gate extern void tcp_rcv_drain_sock(int);
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate /* Exported for stand/lib/sock/sock_test.c */
308*7c478bd9Sstevel@tonic-gate extern void tcp_time_wait_report(void);
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
311*7c478bd9Sstevel@tonic-gate }
312*7c478bd9Sstevel@tonic-gate #endif
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate #endif /* _TCP_INET_H */
315