tcp.h revision 149403
1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)tcp.h 8.1 (Berkeley) 6/10/93 3050477Speter * $FreeBSD: head/sys/netinet/tcp.h 149403 2005-08-24 02:47:16Z ps $ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_TCP_H_ 342169Spaul#define _NETINET_TCP_H_ 352169Spaul 36104343Smike#include <sys/cdefs.h> 37104343Smike 38104342Smike#if __BSD_VISIBLE 39104342Smike 4037622Sbdetypedef u_int32_t tcp_seq; 416247Swollman 4255679Sshin#define tcp6_seq tcp_seq /* for KAME src sync over BSD*'s */ 4355679Sshin#define tcp6hdr tcphdr /* for KAME src sync over BSD*'s */ 4455679Sshin 451541Srgrimes/* 461541Srgrimes * TCP header. 471541Srgrimes * Per RFC 793, September, 1981. 481541Srgrimes */ 491541Srgrimesstruct tcphdr { 501541Srgrimes u_short th_sport; /* source port */ 511541Srgrimes u_short th_dport; /* destination port */ 521541Srgrimes tcp_seq th_seq; /* sequence number */ 531541Srgrimes tcp_seq th_ack; /* acknowledgement number */ 548876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN 5536767Sbde u_int th_x2:4, /* (unused) */ 561541Srgrimes th_off:4; /* data offset */ 571541Srgrimes#endif 588876Srgrimes#if BYTE_ORDER == BIG_ENDIAN 5936767Sbde u_int th_off:4, /* data offset */ 601541Srgrimes th_x2:4; /* (unused) */ 611541Srgrimes#endif 621541Srgrimes u_char th_flags; 631541Srgrimes#define TH_FIN 0x01 641541Srgrimes#define TH_SYN 0x02 651541Srgrimes#define TH_RST 0x04 661541Srgrimes#define TH_PUSH 0x08 671541Srgrimes#define TH_ACK 0x10 681541Srgrimes#define TH_URG 0x20 6970826Srwatson#define TH_ECE 0x40 7070826Srwatson#define TH_CWR 0x80 7170854Srwatson#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR) 726348Swollman 731541Srgrimes u_short th_win; /* window */ 741541Srgrimes u_short th_sum; /* checksum */ 751541Srgrimes u_short th_urp; /* urgent pointer */ 761541Srgrimes}; 771541Srgrimes 781541Srgrimes#define TCPOPT_EOL 0 791541Srgrimes#define TCPOPT_NOP 1 801541Srgrimes#define TCPOPT_MAXSEG 2 811541Srgrimes#define TCPOLEN_MAXSEG 4 821541Srgrimes#define TCPOPT_WINDOW 3 831541Srgrimes#define TCPOLEN_WINDOW 3 841541Srgrimes#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ 851541Srgrimes#define TCPOLEN_SACK_PERMITTED 2 861541Srgrimes#define TCPOPT_SACK 5 /* Experimental */ 87130989Sps#define TCPOLEN_SACK 8 /* 2*sizeof(tcp_seq) */ 881541Srgrimes#define TCPOPT_TIMESTAMP 8 891541Srgrimes#define TCPOLEN_TIMESTAMP 10 901541Srgrimes#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ 916247Swollman#define TCPOPT_TSTAMP_HDR \ 921541Srgrimes (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) 931541Srgrimes 94130989Sps#define MAX_TCPOPTLEN 40 /* Absolute maximum TCP options len */ 95130989Sps 96125680Sbms#define TCPOPT_SIGNATURE 19 /* Keyed MD5: RFC 2385 */ 97125680Sbms#define TCPOLEN_SIGNATURE 18 986247Swollman 99130989Sps/* Option definitions */ 100130989Sps#define TCPOPT_SACK_PERMIT_HDR \ 101130989Sps(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK_PERMITTED<<8|TCPOLEN_SACK_PERMITTED) 102130989Sps#define TCPOPT_SACK_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK<<8) 103130989Sps/* Miscellaneous constants */ 104149403Sps#define MAX_SACK_BLKS 6 /* Max # SACK blocks stored at receiver side */ 105146552Sps#define TCP_MAX_SACK 4 /* MAX # SACKs sent in any segment */ 106130989Sps 107130989Sps 1081541Srgrimes/* 1091541Srgrimes * Default maximum segment size for TCP. 110124258Sandre * With an IP MTU of 576, this is 536, 1111541Srgrimes * but 512 is probably more convenient. 1121541Srgrimes * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)). 1131541Srgrimes */ 1141541Srgrimes#define TCP_MSS 512 115124258Sandre/* 116124290Sandre * TCP_MINMSS is defined to be 216 which is fine for the smallest 117124290Sandre * link MTU (256 bytes, AX.25 packet radio) in the Internet. 118124258Sandre * However it is very unlikely to come across such low MTU interfaces 119124258Sandre * these days (anno dato 2003). 120124258Sandre * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments. 121124258Sandre * Setting this to "0" disables the minmss check. 122124258Sandre */ 123124290Sandre#define TCP_MINMSS 216 124124258Sandre/* 125124258Sandre * TCP_MINMSSOVERLOAD is defined to be 1000 which should cover any type 126124258Sandre * of interactive TCP session. 127124258Sandre * See tcp_subr.c tcp_minmssoverload SYSCTL declaration and tcp_input.c 128124258Sandre * for more comments. 129124258Sandre * Setting this to "0" disables the minmssoverload check. 130124258Sandre */ 131124437Sandre#define TCP_MINMSSOVERLOAD 0 /* XXX: Disabled until refined */ 1321541Srgrimes 13352904Sshin/* 13452904Sshin * Default maximum segment size for TCP6. 13552904Sshin * With an IP6 MSS of 1280, this is 1220, 13652904Sshin * but 1024 is probably more convenient. (xxx kazu in doubt) 13752904Sshin * This should be defined as MIN(1024, IP6_MSS - sizeof (struct tcpip6hdr)) 13852904Sshin */ 13952904Sshin#define TCP6_MSS 1024 14052904Sshin 1411541Srgrimes#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ 1426247Swollman#define TTCP_CLIENT_SND_WND 4096 /* dflt send window for T/TCP client */ 1431541Srgrimes 1441541Srgrimes#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ 1451541Srgrimes 146133874Srwatson#define TCP_MAXBURST 4 /* maximum segments in a burst */ 14760067Sjlemon 1486247Swollman#define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */ 1496247Swollman#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr)) 1506247Swollman /* max space left for options */ 151104342Smike#endif /* __BSD_VISIBLE */ 1526247Swollman 1531541Srgrimes/* 1541541Srgrimes * User-settable options (used with setsockopt). 1551541Srgrimes */ 1561541Srgrimes#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ 157104342Smike#if __BSD_VISIBLE 1581541Srgrimes#define TCP_MAXSEG 0x02 /* set maximum segment size */ 1596247Swollman#define TCP_NOPUSH 0x04 /* don't push last block of write */ 1606247Swollman#define TCP_NOOPT 0x08 /* don't use TCP options */ 161125890Sbms#define TCP_MD5SIG 0x10 /* use MD5 digests (RFC2385) */ 162138118Srwatson#define TCP_INFO 0x20 /* retrieve tcp_info structure */ 163138118Srwatson 164138118Srwatson#define TCPI_OPT_TIMESTAMPS 0x01 165138118Srwatson#define TCPI_OPT_SACK 0x02 166138118Srwatson#define TCPI_OPT_WSCALE 0x04 167138118Srwatson#define TCPI_OPT_ECN 0x08 168138118Srwatson 169138118Srwatson/* 170138118Srwatson * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits 171138118Srwatson * the caller to query certain information about the state of a TCP 172138118Srwatson * connection. We provide an overlapping set of fields with the Linux 173138118Srwatson * implementation, but since this is a fixed size structure, room has been 174138118Srwatson * left for growth. In order to maximize potential future compatibility with 175138118Srwatson * the Linux API, the same variable names and order have been adopted, and 176138118Srwatson * padding left to make room for omitted fields in case they are added later. 177138118Srwatson * 178138118Srwatson * XXX: This is currently an unstable ABI/API, in that it is expected to 179138118Srwatson * change. 180138118Srwatson */ 181138118Srwatsonstruct tcp_info { 182138118Srwatson u_int8_t tcpi_state; /* TCP FSM state. */ 183138118Srwatson u_int8_t __tcpi_ca_state; 184138118Srwatson u_int8_t __tcpi_retransmits; 185138118Srwatson u_int8_t __tcpi_probes; 186138118Srwatson u_int8_t __tcpi_backoff; 187138118Srwatson u_int8_t tcpi_options; /* Options enabled on conn. */ 188138118Srwatson u_int8_t tcpi_snd_wscale:4, /* RFC1323 send shift value. */ 189138118Srwatson tcpi_rcv_wscale:4; /* RFC1323 recv shift value. */ 190138118Srwatson 191138118Srwatson u_int32_t __tcpi_rto; 192138118Srwatson u_int32_t __tcpi_ato; 193138118Srwatson u_int32_t __tcpi_snd_mss; 194138118Srwatson u_int32_t __tcpi_rcv_mss; 195138118Srwatson 196138118Srwatson u_int32_t __tcpi_unacked; 197138118Srwatson u_int32_t __tcpi_sacked; 198138118Srwatson u_int32_t __tcpi_lost; 199138118Srwatson u_int32_t __tcpi_retrans; 200138118Srwatson u_int32_t __tcpi_fackets; 201138118Srwatson 202138118Srwatson /* Times; measurements in usecs. */ 203138118Srwatson u_int32_t __tcpi_last_data_sent; 204138118Srwatson u_int32_t __tcpi_last_ack_sent; /* Also unimpl. on Linux? */ 205138118Srwatson u_int32_t __tcpi_last_data_recv; 206138118Srwatson u_int32_t __tcpi_last_ack_recv; 207138118Srwatson 208138118Srwatson /* Metrics; variable units. */ 209138118Srwatson u_int32_t __tcpi_pmtu; 210138118Srwatson u_int32_t __tcpi_rcv_ssthresh; 211138118Srwatson u_int32_t __tcpi_rtt; 212138118Srwatson u_int32_t __tcpi_rttvar; 213138118Srwatson u_int32_t tcpi_snd_ssthresh; /* Slow start threshold. */ 214138118Srwatson u_int32_t tcpi_snd_cwnd; /* Send congestion window. */ 215138118Srwatson u_int32_t __tcpi_advmss; 216138118Srwatson u_int32_t __tcpi_reordering; 217138118Srwatson 218138118Srwatson u_int32_t __tcpi_rcv_rtt; 219138136Srwatson u_int32_t tcpi_rcv_space; /* Advertised recv window. */ 220138118Srwatson 221138118Srwatson /* FreeBSD extensions to tcp_info. */ 222138118Srwatson u_int32_t tcpi_snd_wnd; /* Advertised send window. */ 223138118Srwatson u_int32_t tcpi_snd_bwnd; /* Bandwidth send window. */ 224138118Srwatson 225138118Srwatson /* Padding to grow without breaking ABI. */ 226138118Srwatson u_int32_t __tcpi_pad[32]; /* Padding. */ 227138118Srwatson}; 228104342Smike#endif 2292169Spaul 230104342Smike#endif /* !_NETINET_TCP_H_ */ 231