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> 37226610Sed#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 100292706Spkelsey#define TCPOPT_FAST_OPEN 34 101292706Spkelsey#define TCPOLEN_FAST_OPEN_EMPTY 2 102292706Spkelsey#define TCPOLEN_FAST_OPEN_MIN 6 103292706Spkelsey#define TCPOLEN_FAST_OPEN_MAX 18 1046247Swollman 105130989Sps/* Miscellaneous constants */ 106149403Sps#define MAX_SACK_BLKS 6 /* Max # SACK blocks stored at receiver side */ 107146552Sps#define TCP_MAX_SACK 4 /* MAX # SACKs sent in any segment */ 108130989Sps 109130989Sps 1101541Srgrimes/* 111212653Sandre * The default maximum segment size (MSS) to be used for new TCP connections 112212653Sandre * when path MTU discovery is not enabled. 113212653Sandre * 114212653Sandre * RFC879 derives the default MSS from the largest datagram size hosts are 115212653Sandre * minimally required to handle directly or through IP reassembly minus the 116212653Sandre * size of the IP and TCP header. With IPv6 the minimum MTU is specified 117212653Sandre * in RFC2460. 118212653Sandre * 119212653Sandre * For IPv4 the MSS is 576 - sizeof(struct tcpiphdr) 120212653Sandre * For IPv6 the MSS is IPV6_MMTU - sizeof(struct ip6_hdr) - sizeof(struct tcphdr) 121212653Sandre * 122212653Sandre * We use explicit numerical definition here to avoid header pollution. 1231541Srgrimes */ 124212653Sandre#define TCP_MSS 536 125212653Sandre#define TCP6_MSS 1220 126212653Sandre 127124258Sandre/* 128212731Sandre * Limit the lowest MSS we accept for path MTU discovery and the TCP SYN MSS 129212731Sandre * option. Allowing low values of MSS can consume significant resources and 130212731Sandre * be used to mount a resource exhaustion attack. 131212653Sandre * Connections requesting lower MSS values will be rounded up to this value 132212731Sandre * and the IP_DF flag will be cleared to allow fragmentation along the path. 133212653Sandre * 134212653Sandre * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments. Setting 135212653Sandre * it to "0" disables the minmss check. 136212653Sandre * 137212731Sandre * The default value is fine for TCP across the Internet's smallest official 138212731Sandre * link MTU (256 bytes for AX.25 packet radio). However, a connection is very 139212731Sandre * unlikely to come across such low MTU interfaces these days (anno domini 2003). 140124258Sandre */ 141124290Sandre#define TCP_MINMSS 216 1421541Srgrimes 1431541Srgrimes#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ 1446247Swollman#define TTCP_CLIENT_SND_WND 4096 /* dflt send window for T/TCP client */ 1451541Srgrimes 1461541Srgrimes#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ 1471541Srgrimes 148133874Srwatson#define TCP_MAXBURST 4 /* maximum segments in a burst */ 14960067Sjlemon 1506247Swollman#define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */ 1516247Swollman#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr)) 1526247Swollman /* max space left for options */ 153104342Smike#endif /* __BSD_VISIBLE */ 1546247Swollman 1551541Srgrimes/* 156245823Sjhb * User-settable options (used with setsockopt). These are discrete 157245823Sjhb * values and are not masked together. Some values appear to be 158245823Sjhb * bitmasks for historical reasons. 1591541Srgrimes */ 160245823Sjhb#define TCP_NODELAY 1 /* don't delay send to coalesce packets */ 161104342Smike#if __BSD_VISIBLE 162245823Sjhb#define TCP_MAXSEG 2 /* set maximum segment size */ 163245823Sjhb#define TCP_NOPUSH 4 /* don't push last block of write */ 164245823Sjhb#define TCP_NOOPT 8 /* don't use TCP options */ 165245823Sjhb#define TCP_MD5SIG 16 /* use MD5 digests (RFC2385) */ 166245823Sjhb#define TCP_INFO 32 /* retrieve tcp_info structure */ 167245823Sjhb#define TCP_CONGESTION 64 /* get/set congestion control algorithm */ 168294540Sglebius#define TCP_CCALGOOPT 65 /* get/set cc algorithm specific options */ 169245823Sjhb#define TCP_KEEPINIT 128 /* N, time to establish connection */ 170245823Sjhb#define TCP_KEEPIDLE 256 /* L,N,X start keeplives after this period */ 171245823Sjhb#define TCP_KEEPINTVL 512 /* L,N interval between keepalives */ 172245823Sjhb#define TCP_KEEPCNT 1024 /* L,N number of keepalives before close */ 173292706Spkelsey#define TCP_FASTOPEN 1025 /* enable TFO / was created via TFO */ 174289276Shiren#define TCP_PCAP_OUT 2048 /* number of output packets to keep */ 175289276Shiren#define TCP_PCAP_IN 4096 /* number of input packets to keep */ 176292309Srrs#define TCP_FUNCTION_BLK 8192 /* Set the tcp function pointers to the specified stack */ 177246210Sjhb/* Start of reserved space for third-party user-settable options. */ 178246210Sjhb#define TCP_VENDOR SO_VENDOR 179246210Sjhb 180174636Skmacy#define TCP_CA_NAME_MAX 16 /* max congestion control name length */ 181174636Skmacy 182138118Srwatson#define TCPI_OPT_TIMESTAMPS 0x01 183138118Srwatson#define TCPI_OPT_SACK 0x02 184138118Srwatson#define TCPI_OPT_WSCALE 0x04 185138118Srwatson#define TCPI_OPT_ECN 0x08 186178793Skmacy#define TCPI_OPT_TOE 0x10 187138118Srwatson 188138118Srwatson/* 189138118Srwatson * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits 190138118Srwatson * the caller to query certain information about the state of a TCP 191138118Srwatson * connection. We provide an overlapping set of fields with the Linux 192138118Srwatson * implementation, but since this is a fixed size structure, room has been 193138118Srwatson * left for growth. In order to maximize potential future compatibility with 194138118Srwatson * the Linux API, the same variable names and order have been adopted, and 195138118Srwatson * padding left to make room for omitted fields in case they are added later. 196138118Srwatson * 197138118Srwatson * XXX: This is currently an unstable ABI/API, in that it is expected to 198138118Srwatson * change. 199138118Srwatson */ 200138118Srwatsonstruct tcp_info { 201138118Srwatson u_int8_t tcpi_state; /* TCP FSM state. */ 202138118Srwatson u_int8_t __tcpi_ca_state; 203138118Srwatson u_int8_t __tcpi_retransmits; 204138118Srwatson u_int8_t __tcpi_probes; 205138118Srwatson u_int8_t __tcpi_backoff; 206138118Srwatson u_int8_t tcpi_options; /* Options enabled on conn. */ 207138118Srwatson u_int8_t tcpi_snd_wscale:4, /* RFC1323 send shift value. */ 208138118Srwatson tcpi_rcv_wscale:4; /* RFC1323 recv shift value. */ 209138118Srwatson 210200847Sjhb u_int32_t tcpi_rto; /* Retransmission timeout (usec). */ 211138118Srwatson u_int32_t __tcpi_ato; 212200847Sjhb u_int32_t tcpi_snd_mss; /* Max segment size for send. */ 213200847Sjhb u_int32_t tcpi_rcv_mss; /* Max segment size for receive. */ 214138118Srwatson 215138118Srwatson u_int32_t __tcpi_unacked; 216138118Srwatson u_int32_t __tcpi_sacked; 217138118Srwatson u_int32_t __tcpi_lost; 218138118Srwatson u_int32_t __tcpi_retrans; 219138118Srwatson u_int32_t __tcpi_fackets; 220138118Srwatson 221138118Srwatson /* Times; measurements in usecs. */ 222138118Srwatson u_int32_t __tcpi_last_data_sent; 223138118Srwatson u_int32_t __tcpi_last_ack_sent; /* Also unimpl. on Linux? */ 224200847Sjhb u_int32_t tcpi_last_data_recv; /* Time since last recv data. */ 225138118Srwatson u_int32_t __tcpi_last_ack_recv; 226138118Srwatson 227138118Srwatson /* Metrics; variable units. */ 228138118Srwatson u_int32_t __tcpi_pmtu; 229138118Srwatson u_int32_t __tcpi_rcv_ssthresh; 230166433Sbms u_int32_t tcpi_rtt; /* Smoothed RTT in usecs. */ 231166433Sbms u_int32_t tcpi_rttvar; /* RTT variance in usecs. */ 232138118Srwatson u_int32_t tcpi_snd_ssthresh; /* Slow start threshold. */ 233138118Srwatson u_int32_t tcpi_snd_cwnd; /* Send congestion window. */ 234138118Srwatson u_int32_t __tcpi_advmss; 235138118Srwatson u_int32_t __tcpi_reordering; 236138118Srwatson 237138118Srwatson u_int32_t __tcpi_rcv_rtt; 238138136Srwatson u_int32_t tcpi_rcv_space; /* Advertised recv window. */ 239138118Srwatson 240138118Srwatson /* FreeBSD extensions to tcp_info. */ 241138118Srwatson u_int32_t tcpi_snd_wnd; /* Advertised send window. */ 242212765Sandre u_int32_t tcpi_snd_bwnd; /* No longer used. */ 243178793Skmacy u_int32_t tcpi_snd_nxt; /* Next egress seqno */ 244178793Skmacy u_int32_t tcpi_rcv_nxt; /* Next ingress seqno */ 245178793Skmacy u_int32_t tcpi_toe_tid; /* HWTID for TOE endpoints */ 246215434Sgnn u_int32_t tcpi_snd_rexmitpack; /* Retransmitted packets */ 247215434Sgnn u_int32_t tcpi_rcv_ooopack; /* Out-of-order packets */ 248215434Sgnn u_int32_t tcpi_snd_zerowin; /* Zero-sized windows sent */ 249178793Skmacy 250138118Srwatson /* Padding to grow without breaking ABI. */ 251215434Sgnn u_int32_t __tcpi_pad[26]; /* Padding. */ 252138118Srwatson}; 253104342Smike#endif 254292309Srrs#define TCP_FUNCTION_NAME_LEN_MAX 32 2552169Spaul 256292309Srrsstruct tcp_function_set { 257292309Srrs char function_set_name[TCP_FUNCTION_NAME_LEN_MAX]; 258292309Srrs uint32_t pcbcnt; 259292309Srrs}; 260292309Srrs 261104342Smike#endif /* !_NETINET_TCP_H_ */ 262