xref: /netbsd-src/sys/netinet/tcp.h (revision f21799019721da45356f646d0d5820d71da39996)
1*f2179901Sroy /*	$NetBSD: tcp.h,v 1.37 2021/02/03 18:13:13 roy Exp $	*/
2cf92afd6Scgd 
361f28255Scgd /*
407b4f2abSmycroft  * Copyright (c) 1982, 1986, 1993
507b4f2abSmycroft  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  *
31cf92afd6Scgd  *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
3261f28255Scgd  */
3361f28255Scgd 
34f73530baSperry #ifndef _NETINET_TCP_H_
35f73530baSperry #define _NETINET_TCP_H_
36f73530baSperry 
37ff81b6d5Sbjh21 #include <sys/featuretest.h>
38ff81b6d5Sbjh21 
39ff81b6d5Sbjh21 #if defined(_NETBSD_SOURCE)
407c206e73Schristos #include <sys/types.h>
41ff81b6d5Sbjh21 
42450535e4Schristos typedef uint32_t tcp_seq;
4361f28255Scgd /*
4461f28255Scgd  * TCP header.
4561f28255Scgd  * Per RFC 793, September, 1981.
4654283920Skleink  * Updated by RFC 3168, September, 2001.
4761f28255Scgd  */
4861f28255Scgd struct tcphdr {
49450535e4Schristos 	uint16_t th_sport;		/* source port */
50450535e4Schristos 	uint16_t th_dport;		/* destination port */
5161f28255Scgd 	tcp_seq	  th_seq;		/* sequence number */
5261f28255Scgd 	tcp_seq	  th_ack;		/* acknowledgement number */
5361f28255Scgd #if BYTE_ORDER == LITTLE_ENDIAN
54f142d425Schristos 	/*LINTED non-portable bitfields*/
55450535e4Schristos 	uint8_t  th_x2:4,		/* (unused) */
5661f28255Scgd 		  th_off:4;		/* data offset */
5761f28255Scgd #endif
5861f28255Scgd #if BYTE_ORDER == BIG_ENDIAN
59f142d425Schristos 	/*LINTED non-portable bitfields*/
60450535e4Schristos 	uint8_t  th_off:4,		/* data offset */
6161f28255Scgd 		  th_x2:4;		/* (unused) */
6261f28255Scgd #endif
63450535e4Schristos 	uint8_t  th_flags;
6461aae00bSchristos #define	TH_FIN	  0x01		/* Final: Set on the last segment */
6561aae00bSchristos #define	TH_SYN	  0x02		/* Synchronization: New conn with dst port */
6661aae00bSchristos #define	TH_RST	  0x04		/* Reset: Announce to peer conn terminated */
6761aae00bSchristos #define	TH_PUSH	  0x08		/* Push: Immediately send, don't buffer seg */
6861aae00bSchristos #define	TH_ACK	  0x10		/* Acknowledge: Part of connection establish */
6961aae00bSchristos #define	TH_URG	  0x20		/* Urgent: send special marked segment now */
7061aae00bSchristos #define	TH_ECE	  0x40		/* ECN Echo */
7161aae00bSchristos #define	TH_CWR	  0x80		/* Congestion Window Reduced */
72450535e4Schristos 	uint16_t th_win;			/* window */
73450535e4Schristos 	uint16_t th_sum;			/* checksum */
74450535e4Schristos 	uint16_t th_urp;			/* urgent pointer */
751ca39e87Sroy };
76*f2179901Sroy #ifdef __CTASSERT
77*f2179901Sroy __CTASSERT(sizeof(struct tcphdr) == 20);
787a849d03Sroy #endif
7961f28255Scgd 
8061f28255Scgd #define	TCPOPT_EOL		0
8165dfd4ccSchristos #define	   TCPOLEN_EOL			1
8265dfd4ccSchristos #define	TCPOPT_PAD		0
8365dfd4ccSchristos #define	   TCPOLEN_PAD			1
8461f28255Scgd #define	TCPOPT_NOP		1
8565dfd4ccSchristos #define	   TCPOLEN_NOP			1
8661f28255Scgd #define	TCPOPT_MAXSEG		2
8707b4f2abSmycroft #define	   TCPOLEN_MAXSEG		4
8807b4f2abSmycroft #define	TCPOPT_WINDOW		3
8907b4f2abSmycroft #define	   TCPOLEN_WINDOW		3
9007b4f2abSmycroft #define	TCPOPT_SACK_PERMITTED	4		/* Experimental */
9107b4f2abSmycroft #define	   TCPOLEN_SACK_PERMITTED	2
9207b4f2abSmycroft #define	TCPOPT_SACK		5		/* Experimental */
9307b4f2abSmycroft #define	TCPOPT_TIMESTAMP	8
9407b4f2abSmycroft #define	   TCPOLEN_TIMESTAMP		10
9507b4f2abSmycroft #define	   TCPOLEN_TSTAMP_APPA		(TCPOLEN_TIMESTAMP+2) /* appendix A */
9607b4f2abSmycroft 
9707b4f2abSmycroft #define TCPOPT_TSTAMP_HDR	\
9807b4f2abSmycroft     (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
9961f28255Scgd 
100887b782bSjonathan #define	TCPOPT_SIGNATURE	19		/* Keyed MD5: RFC 2385 */
101887b782bSjonathan #define	   TCPOLEN_SIGNATURE		18
102fba9a3bdSriz #define    TCPOLEN_SIGLEN		(TCPOLEN_SIGNATURE+2) /* padding */
103887b782bSjonathan 
104ed8b840fSyamt #define MAX_TCPOPTLEN	40	/* max # bytes that go in options */
105ed8b840fSyamt 
10661f28255Scgd /*
10761f28255Scgd  * Default maximum segment size for TCP.
108f3e17479Srpaulo  * This is defined by RFC 1112 Sec 4.2.2.6.
10961f28255Scgd  */
110f3e17479Srpaulo #define	TCP_MSS		536
11161f28255Scgd 
1124175f869Srmind #define	TCP_MINMSS	216
1134175f869Srmind 
11407b4f2abSmycroft #define	TCP_MAXWIN	65535	/* largest value for (unscaled) window */
11507b4f2abSmycroft 
11607b4f2abSmycroft #define	TCP_MAX_WINSHIFT	14	/* maximum window shift */
11761f28255Scgd 
11825054b5cSmatt #define	TCP_MAXBURST	4	/* maximum segments in a burst */
11925054b5cSmatt 
120ff81b6d5Sbjh21 #endif /* _NETBSD_SOURCE */
121ff81b6d5Sbjh21 
12261f28255Scgd /*
12361f28255Scgd  * User-settable options (used with setsockopt).
12461f28255Scgd  */
125eeff1895Schristos #define	TCP_NODELAY	1	/* don't delay send to coalesce packets */
126eeff1895Schristos #define	TCP_MAXSEG	2	/* set maximum segment size */
127eeff1895Schristos #define	TCP_KEEPIDLE	3
128eeff1895Schristos #ifdef notyet
129eeff1895Schristos #define	TCP_NOPUSH	4	/* reserved for FreeBSD compat */
130eeff1895Schristos #endif
131eeff1895Schristos #define	TCP_KEEPINTVL	5
132eeff1895Schristos #define	TCP_KEEPCNT	6
133eeff1895Schristos #define	TCP_KEEPINIT	7
134eeff1895Schristos #ifdef notyet
135eeff1895Schristos #define	TCP_NOOPT	8	/* reserved for FreeBSD compat */
136eeff1895Schristos #endif
1371d14d022She #define	TCP_INFO	9	/* retrieve tcp_info structure */
138887b782bSjonathan #define	TCP_MD5SIG	0x10	/* use MD5 digests (RFC2385) */
139f3330397Srpaulo #define	TCP_CONGCTL	0x20	/* selected congestion control */
1409702e987Selad 
1411d14d022She #define	TCPI_OPT_TIMESTAMPS	0x01
1421d14d022She #define	TCPI_OPT_SACK		0x02
1431d14d022She #define	TCPI_OPT_WSCALE		0x04
1441d14d022She #define	TCPI_OPT_ECN		0x08
1451d14d022She #define	TCPI_OPT_TOE		0x10
1461d14d022She 
1471d14d022She /*
1481d14d022She  * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits
1491d14d022She  * the caller to query certain information about the state of a TCP
1501d14d022She  * connection.  We provide an overlapping set of fields with the Linux
1511d14d022She  * implementation, but since this is a fixed size structure, room has been
1521d14d022She  * left for growth.  In order to maximize potential future compatibility with
1531d14d022She  * the Linux API, the same variable names and order have been adopted, and
1541d14d022She  * padding left to make room for omitted fields in case they are added later.
1551d14d022She  *
1561d14d022She  * XXX: This is currently an unstable ABI/API, in that it is expected to
1571d14d022She  * change.
1581d14d022She  */
1591d14d022She struct tcp_info {
1601d14d022She 	uint8_t		tcpi_state; /* TCP FSM state. */
1611d14d022She 	uint8_t		__tcpi_ca_state;
1621d14d022She 	uint8_t		__tcpi_retransmits;
1631d14d022She 	uint8_t		__tcpi_probes;
1641d14d022She 	uint8_t		__tcpi_backoff;
1651d14d022She 	uint8_t		tcpi_options;	       /* Options enabled on conn. */
1661aeddccbSchristos 	/*LINTED: non-portable bitfield*/
1671d14d022She 	uint8_t		tcpi_snd_wscale:4,	/* RFC1323 send shift value. */
1681aeddccbSchristos 	/*LINTED: non-portable bitfield*/
1691d14d022She 			tcpi_rcv_wscale:4; /* RFC1323 recv shift value. */
1701d14d022She 
1711d14d022She 	uint32_t	tcpi_rto;		/* Retransmission timeout (usec). */
1721d14d022She 	uint32_t	__tcpi_ato;
1731d14d022She 	uint32_t	tcpi_snd_mss;		/* Max segment size for send. */
1741d14d022She 	uint32_t	tcpi_rcv_mss;		/* Max segment size for receive. */
1751d14d022She 
1761d14d022She 	uint32_t	__tcpi_unacked;
1771d14d022She 	uint32_t	__tcpi_sacked;
1781d14d022She 	uint32_t	__tcpi_lost;
1791d14d022She 	uint32_t	__tcpi_retrans;
1801d14d022She 	uint32_t	__tcpi_fackets;
1811d14d022She 
1821d14d022She 	/* Times; measurements in usecs. */
1831d14d022She 	uint32_t	__tcpi_last_data_sent;
1841d14d022She 	uint32_t	__tcpi_last_ack_sent;	/* Also unimpl. on Linux? */
1851d14d022She 	uint32_t	tcpi_last_data_recv;	/* Time since last recv data. */
1861d14d022She 	uint32_t	__tcpi_last_ack_recv;
1871d14d022She 
1881d14d022She 	/* Metrics; variable units. */
1891d14d022She 	uint32_t	__tcpi_pmtu;
1901d14d022She 	uint32_t	__tcpi_rcv_ssthresh;
1911d14d022She 	uint32_t	tcpi_rtt;		/* Smoothed RTT in usecs. */
1921d14d022She 	uint32_t	tcpi_rttvar;		/* RTT variance in usecs. */
1931d14d022She 	uint32_t	tcpi_snd_ssthresh;	/* Slow start threshold. */
1941d14d022She 	uint32_t	tcpi_snd_cwnd;		/* Send congestion window. */
1951d14d022She 	uint32_t	__tcpi_advmss;
1961d14d022She 	uint32_t	__tcpi_reordering;
1971d14d022She 
1981d14d022She 	uint32_t	__tcpi_rcv_rtt;
1991d14d022She 	uint32_t	tcpi_rcv_space;		/* Advertised recv window. */
2001d14d022She 
2011d14d022She 	/* FreeBSD/NetBSD extensions to tcp_info. */
2021d14d022She 	uint32_t	tcpi_snd_wnd;		/* Advertised send window. */
2031d14d022She 	uint32_t	tcpi_snd_bwnd;		/* No longer used. */
2041d14d022She 	uint32_t	tcpi_snd_nxt;		/* Next egress seqno */
2051d14d022She 	uint32_t	tcpi_rcv_nxt;		/* Next ingress seqno */
2061d14d022She 	uint32_t	tcpi_toe_tid;		/* HWTID for TOE endpoints */
2071d14d022She 	uint32_t	tcpi_snd_rexmitpack;	/* Retransmitted packets */
2081d14d022She 	uint32_t	tcpi_rcv_ooopack;	/* Out-of-order packets */
2091d14d022She 	uint32_t	tcpi_snd_zerowin;	/* Zero-sized windows sent */
2101d14d022She 
2111d14d022She 	/* Padding to grow without breaking ABI. */
2121d14d022She 	uint32_t	__tcpi_pad[26];		/* Padding. */
2131d14d022She };
2141d14d022She 
2159702e987Selad #endif /* !_NETINET_TCP_H_ */
216