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$ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_TCP_H_ 342169Spaul#define _NETINET_TCP_H_ 352169Spaul 36104343Smike#include <sys/cdefs.h> 37230953Sed#include <sys/types.h> 38104343Smike 39104342Smike#if __BSD_VISIBLE 40104342Smike 4137622Sbdetypedef u_int32_t tcp_seq; 426247Swollman 4355679Sshin#define tcp6_seq tcp_seq /* for KAME src sync over BSD*'s */ 4455679Sshin#define tcp6hdr tcphdr /* for KAME src sync over BSD*'s */ 4555679Sshin 461541Srgrimes/* 471541Srgrimes * TCP header. 481541Srgrimes * Per RFC 793, September, 1981. 491541Srgrimes */ 501541Srgrimesstruct tcphdr { 511541Srgrimes u_short th_sport; /* source port */ 521541Srgrimes u_short th_dport; /* destination port */ 531541Srgrimes tcp_seq th_seq; /* sequence number */ 541541Srgrimes tcp_seq th_ack; /* acknowledgement number */ 558876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN 56203343Sluigi u_char th_x2:4, /* (unused) */ 571541Srgrimes th_off:4; /* data offset */ 581541Srgrimes#endif 598876Srgrimes#if BYTE_ORDER == BIG_ENDIAN 60203343Sluigi u_char th_off:4, /* data offset */ 611541Srgrimes th_x2:4; /* (unused) */ 621541Srgrimes#endif 631541Srgrimes u_char th_flags; 641541Srgrimes#define TH_FIN 0x01 651541Srgrimes#define TH_SYN 0x02 661541Srgrimes#define TH_RST 0x04 671541Srgrimes#define TH_PUSH 0x08 681541Srgrimes#define TH_ACK 0x10 691541Srgrimes#define TH_URG 0x20 7070826Srwatson#define TH_ECE 0x40 7170826Srwatson#define TH_CWR 0x80 72155817Sandre#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECE|TH_CWR) 73169997Sandre#define PRINT_TH_FLAGS "\20\1FIN\2SYN\3RST\4PUSH\5ACK\6URG\7ECE\10CWR" 746348Swollman 751541Srgrimes u_short th_win; /* window */ 761541Srgrimes u_short th_sum; /* checksum */ 771541Srgrimes u_short th_urp; /* urgent pointer */ 781541Srgrimes}; 791541Srgrimes 801541Srgrimes#define TCPOPT_EOL 0 81167606Sandre#define TCPOLEN_EOL 1 82177986Sandre#define TCPOPT_PAD 0 /* padding after EOL */ 83177986Sandre#define TCPOLEN_PAD 1 841541Srgrimes#define TCPOPT_NOP 1 85167606Sandre#define TCPOLEN_NOP 1 861541Srgrimes#define TCPOPT_MAXSEG 2 871541Srgrimes#define TCPOLEN_MAXSEG 4 881541Srgrimes#define TCPOPT_WINDOW 3 891541Srgrimes#define TCPOLEN_WINDOW 3 90167606Sandre#define TCPOPT_SACK_PERMITTED 4 911541Srgrimes#define TCPOLEN_SACK_PERMITTED 2 92167606Sandre#define TCPOPT_SACK 5 93167606Sandre#define TCPOLEN_SACKHDR 2 94130989Sps#define TCPOLEN_SACK 8 /* 2*sizeof(tcp_seq) */ 951541Srgrimes#define TCPOPT_TIMESTAMP 8 961541Srgrimes#define TCPOLEN_TIMESTAMP 10 971541Srgrimes#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ 98168904Sandre#define TCPOPT_SIGNATURE 19 /* Keyed MD5: RFC 2385 */ 99125680Sbms#define TCPOLEN_SIGNATURE 18 1006247Swollman 101130989Sps/* Miscellaneous constants */ 102149403Sps#define MAX_SACK_BLKS 6 /* Max # SACK blocks stored at receiver side */ 103146552Sps#define TCP_MAX_SACK 4 /* MAX # SACKs sent in any segment */ 104130989Sps 105130989Sps 1061541Srgrimes/* 107212653Sandre * The default maximum segment size (MSS) to be used for new TCP connections 108212653Sandre * when path MTU discovery is not enabled. 109212653Sandre * 110212653Sandre * RFC879 derives the default MSS from the largest datagram size hosts are 111212653Sandre * minimally required to handle directly or through IP reassembly minus the 112212653Sandre * size of the IP and TCP header. With IPv6 the minimum MTU is specified 113212653Sandre * in RFC2460. 114212653Sandre * 115212653Sandre * For IPv4 the MSS is 576 - sizeof(struct tcpiphdr) 116212653Sandre * For IPv6 the MSS is IPV6_MMTU - sizeof(struct ip6_hdr) - sizeof(struct tcphdr) 117212653Sandre * 118212653Sandre * We use explicit numerical definition here to avoid header pollution. 1191541Srgrimes */ 120212653Sandre#define TCP_MSS 536 121212653Sandre#define TCP6_MSS 1220 122212653Sandre 123124258Sandre/* 124212731Sandre * Limit the lowest MSS we accept for path MTU discovery and the TCP SYN MSS 125212731Sandre * option. Allowing low values of MSS can consume significant resources and 126212731Sandre * be used to mount a resource exhaustion attack. 127212653Sandre * Connections requesting lower MSS values will be rounded up to this value 128212731Sandre * and the IP_DF flag will be cleared to allow fragmentation along the path. 129212653Sandre * 130212653Sandre * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments. Setting 131212653Sandre * it to "0" disables the minmss check. 132212653Sandre * 133212731Sandre * The default value is fine for TCP across the Internet's smallest official 134212731Sandre * link MTU (256 bytes for AX.25 packet radio). However, a connection is very 135212731Sandre * unlikely to come across such low MTU interfaces these days (anno domini 2003). 136124258Sandre */ 137124290Sandre#define TCP_MINMSS 216 1381541Srgrimes 1391541Srgrimes#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ 1406247Swollman#define TTCP_CLIENT_SND_WND 4096 /* dflt send window for T/TCP client */ 1411541Srgrimes 1421541Srgrimes#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ 1431541Srgrimes 144133874Srwatson#define TCP_MAXBURST 4 /* maximum segments in a burst */ 14560067Sjlemon 1466247Swollman#define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */ 1476247Swollman#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr)) 1486247Swollman /* max space left for options */ 149104342Smike#endif /* __BSD_VISIBLE */ 1506247Swollman 1511541Srgrimes/* 152247525Sjhb * User-settable options (used with setsockopt). These are discrete 153247525Sjhb * values and are not masked together. Some values appear to be 154247525Sjhb * bitmasks for historical reasons. 1551541Srgrimes */ 156247525Sjhb#define TCP_NODELAY 1 /* don't delay send to coalesce packets */ 157104342Smike#if __BSD_VISIBLE 158247525Sjhb#define TCP_MAXSEG 2 /* set maximum segment size */ 159247525Sjhb#define TCP_NOPUSH 4 /* don't push last block of write */ 160247525Sjhb#define TCP_NOOPT 8 /* don't use TCP options */ 161247525Sjhb#define TCP_MD5SIG 16 /* use MD5 digests (RFC2385) */ 162247525Sjhb#define TCP_INFO 32 /* retrieve tcp_info structure */ 163247525Sjhb#define TCP_CONGESTION 64 /* get/set congestion control algorithm */ 164247525Sjhb#define TCP_KEEPINIT 128 /* N, time to establish connection */ 165247525Sjhb#define TCP_KEEPIDLE 256 /* L,N,X start keeplives after this period */ 166247525Sjhb#define TCP_KEEPINTVL 512 /* L,N interval between keepalives */ 167247525Sjhb#define TCP_KEEPCNT 1024 /* L,N number of keepalives before close */ 168138118Srwatson 169247525Sjhb/* Start of reserved space for third-party user-settable options. */ 170247525Sjhb#define TCP_VENDOR SO_VENDOR 171247525Sjhb 172174636Skmacy#define TCP_CA_NAME_MAX 16 /* max congestion control name length */ 173174636Skmacy 174138118Srwatson#define TCPI_OPT_TIMESTAMPS 0x01 175138118Srwatson#define TCPI_OPT_SACK 0x02 176138118Srwatson#define TCPI_OPT_WSCALE 0x04 177138118Srwatson#define TCPI_OPT_ECN 0x08 178178793Skmacy#define TCPI_OPT_TOE 0x10 179138118Srwatson 180138118Srwatson/* 181138118Srwatson * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits 182138118Srwatson * the caller to query certain information about the state of a TCP 183138118Srwatson * connection. We provide an overlapping set of fields with the Linux 184138118Srwatson * implementation, but since this is a fixed size structure, room has been 185138118Srwatson * left for growth. In order to maximize potential future compatibility with 186138118Srwatson * the Linux API, the same variable names and order have been adopted, and 187138118Srwatson * padding left to make room for omitted fields in case they are added later. 188138118Srwatson * 189138118Srwatson * XXX: This is currently an unstable ABI/API, in that it is expected to 190138118Srwatson * change. 191138118Srwatson */ 192138118Srwatsonstruct tcp_info { 193138118Srwatson u_int8_t tcpi_state; /* TCP FSM state. */ 194138118Srwatson u_int8_t __tcpi_ca_state; 195138118Srwatson u_int8_t __tcpi_retransmits; 196138118Srwatson u_int8_t __tcpi_probes; 197138118Srwatson u_int8_t __tcpi_backoff; 198138118Srwatson u_int8_t tcpi_options; /* Options enabled on conn. */ 199138118Srwatson u_int8_t tcpi_snd_wscale:4, /* RFC1323 send shift value. */ 200138118Srwatson tcpi_rcv_wscale:4; /* RFC1323 recv shift value. */ 201138118Srwatson 202200847Sjhb u_int32_t tcpi_rto; /* Retransmission timeout (usec). */ 203138118Srwatson u_int32_t __tcpi_ato; 204200847Sjhb u_int32_t tcpi_snd_mss; /* Max segment size for send. */ 205200847Sjhb u_int32_t tcpi_rcv_mss; /* Max segment size for receive. */ 206138118Srwatson 207138118Srwatson u_int32_t __tcpi_unacked; 208138118Srwatson u_int32_t __tcpi_sacked; 209138118Srwatson u_int32_t __tcpi_lost; 210138118Srwatson u_int32_t __tcpi_retrans; 211138118Srwatson u_int32_t __tcpi_fackets; 212138118Srwatson 213138118Srwatson /* Times; measurements in usecs. */ 214138118Srwatson u_int32_t __tcpi_last_data_sent; 215138118Srwatson u_int32_t __tcpi_last_ack_sent; /* Also unimpl. on Linux? */ 216200847Sjhb u_int32_t tcpi_last_data_recv; /* Time since last recv data. */ 217138118Srwatson u_int32_t __tcpi_last_ack_recv; 218138118Srwatson 219138118Srwatson /* Metrics; variable units. */ 220138118Srwatson u_int32_t __tcpi_pmtu; 221138118Srwatson u_int32_t __tcpi_rcv_ssthresh; 222166433Sbms u_int32_t tcpi_rtt; /* Smoothed RTT in usecs. */ 223166433Sbms u_int32_t tcpi_rttvar; /* RTT variance in usecs. */ 224138118Srwatson u_int32_t tcpi_snd_ssthresh; /* Slow start threshold. */ 225138118Srwatson u_int32_t tcpi_snd_cwnd; /* Send congestion window. */ 226138118Srwatson u_int32_t __tcpi_advmss; 227138118Srwatson u_int32_t __tcpi_reordering; 228138118Srwatson 229138118Srwatson u_int32_t __tcpi_rcv_rtt; 230138136Srwatson u_int32_t tcpi_rcv_space; /* Advertised recv window. */ 231138118Srwatson 232138118Srwatson /* FreeBSD extensions to tcp_info. */ 233138118Srwatson u_int32_t tcpi_snd_wnd; /* Advertised send window. */ 234212765Sandre u_int32_t tcpi_snd_bwnd; /* No longer used. */ 235178793Skmacy u_int32_t tcpi_snd_nxt; /* Next egress seqno */ 236178793Skmacy u_int32_t tcpi_rcv_nxt; /* Next ingress seqno */ 237178793Skmacy u_int32_t tcpi_toe_tid; /* HWTID for TOE endpoints */ 238215434Sgnn u_int32_t tcpi_snd_rexmitpack; /* Retransmitted packets */ 239215434Sgnn u_int32_t tcpi_rcv_ooopack; /* Out-of-order packets */ 240215434Sgnn u_int32_t tcpi_snd_zerowin; /* Zero-sized windows sent */ 241178793Skmacy 242138118Srwatson /* Padding to grow without breaking ABI. */ 243215434Sgnn u_int32_t __tcpi_pad[26]; /* Padding. */ 244138118Srwatson}; 245104342Smike#endif 2462169Spaul 247104342Smike#endif /* !_NETINET_TCP_H_ */ 248