1 /*- 2 * Copyright (c) 1982, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)tcp.h 8.1 (Berkeley) 6/10/93 30 * $FreeBSD$ 31 */ 32 33 /* 34 * samkumar: In one instance (in struct tcphdr), where there are Big Endian 35 * and Little Endian alternatives for ordering two fields, I hardcoded the 36 * Little Endian alternative. If ever we port this to a Big Endian platform, 37 * we should look at that very closely, and consider rewriting it. 38 */ 39 40 #ifndef TCPLP_NETINET_TCP_H_ 41 #define TCPLP_NETINET_TCP_H_ 42 43 #include <stdint.h> 44 #include <stdio.h> 45 46 #define KASSERT(COND, MSG) if (!(COND)) tcplp_sys_panic MSG 47 48 typedef uint32_t tcp_seq; 49 50 #define tcp6_seq tcp_seq /* for KAME src sync over BSD*'s */ 51 #define tcp6hdr tcphdr /* for KAME src sync over BSD*'s */ 52 53 /* 54 * TCP header. 55 * Per RFC 793, September, 1981. 56 */ 57 struct tcphdr { 58 uint16_t th_sport; /* source port */ 59 uint16_t th_dport; /* destination port */ 60 tcp_seq th_seq; /* sequence number */ 61 tcp_seq th_ack; /* acknowledgement number */ 62 63 /* 64 * samkumar: The original FreeBSD code used bit fields for the offset and 65 * unused bits, within this byte. I've rewritten it to avoid the use of 66 * bit fields, so that the code is more portable. The original code, which 67 * defined the order of bit fields based on the platform's endianness, is 68 * included below, commented out using "#if 0". 69 */ 70 uint8_t th_off_x2; /* data offset and unused bits */ 71 #define TH_OFF_SHIFT 4 72 73 #if 0 74 #if BYTE_ORDER == LITTLE_ENDIAN 75 uint8_t th_x2:4, /* (unused) */ 76 th_off:4; /* data offset */ 77 #endif 78 #if BYTE_ORDER == BIG_ENDIAN 79 uint8_t th_off:4, /* data offset */ 80 th_x2:4; /* (unused) */ 81 #endif 82 #endif 83 84 uint8_t th_flags; 85 #define TH_FIN 0x01 86 #define TH_SYN 0x02 87 #define TH_RST 0x04 88 #define TH_PUSH 0x08 89 #define TH_ACK 0x10 90 #define TH_URG 0x20 91 #define TH_ECE 0x40 92 #define TH_CWR 0x80 93 #define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECE|TH_CWR) 94 #define PRINT_TH_FLAGS "\20\1FIN\2SYN\3RST\4PUSH\5ACK\6URG\7ECE\10CWR" 95 96 uint16_t th_win; /* window */ 97 uint16_t th_sum; /* checksum */ 98 uint16_t th_urp; /* urgent pointer */ 99 }; 100 101 #define TCPOPT_EOL 0 102 #define TCPOLEN_EOL 1 103 #define TCPOPT_PAD 0 /* padding after EOL */ 104 #define TCPOLEN_PAD 1 105 #define TCPOPT_NOP 1 106 #define TCPOLEN_NOP 1 107 #define TCPOPT_MAXSEG 2 108 #define TCPOLEN_MAXSEG 4 109 #define TCPOPT_WINDOW 3 110 #define TCPOLEN_WINDOW 3 111 #define TCPOPT_SACK_PERMITTED 4 112 #define TCPOLEN_SACK_PERMITTED 2 113 #define TCPOPT_SACK 5 114 #define TCPOLEN_SACKHDR 2 115 #define TCPOLEN_SACK 8 /* 2*sizeof(tcp_seq) */ 116 #define TCPOPT_TIMESTAMP 8 117 #define TCPOLEN_TIMESTAMP 10 118 #define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ 119 #define TCPOPT_SIGNATURE 19 /* Keyed MD5: RFC 2385 */ 120 #define TCPOLEN_SIGNATURE 18 121 #define TCPOPT_FAST_OPEN 34 122 #define TCPOLEN_FAST_OPEN_EMPTY 2 123 124 /* Miscellaneous constants */ 125 #define MAX_SACK_BLKS 6 /* Max # SACK blocks stored at receiver side */ 126 #define TCP_MAX_SACK 4 /* MAX # SACKs sent in any segment */ 127 128 129 /* 130 * The default maximum segment size (MSS) to be used for new TCP connections 131 * when path MTU discovery is not enabled. 132 * 133 * RFC879 derives the default MSS from the largest datagram size hosts are 134 * minimally required to handle directly or through IP reassembly minus the 135 * size of the IP and TCP header. With IPv6 the minimum MTU is specified 136 * in RFC2460. 137 * 138 * For IPv4 the MSS is 576 - sizeof(struct tcpiphdr) 139 * For IPv6 the MSS is IPV6_MMTU - sizeof(struct ip6_hdr) - sizeof(struct tcphdr) 140 * 141 * We use explicit numerical definition here to avoid header pollution. 142 */ 143 #define TCP_MSS 536 144 #define TCP6_MSS 1220 145 146 /* 147 * Limit the lowest MSS we accept for path MTU discovery and the TCP SYN MSS 148 * option. Allowing low values of MSS can consume significant resources and 149 * be used to mount a resource exhaustion attack. 150 * Connections requesting lower MSS values will be rounded up to this value 151 * and the IP_DF flag will be cleared to allow fragmentation along the path. 152 * 153 * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments. Setting 154 * it to "0" disables the minmss check. 155 * 156 * The default value is fine for TCP across the Internet's smallest official 157 * link MTU (256 bytes for AX.25 packet radio). However, a connection is very 158 * unlikely to come across such low MTU interfaces these days (anno domini 2003). 159 */ 160 #define TCP_MINMSS 216 161 162 #define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ 163 #define TTCP_CLIENT_SND_WND 4096 /* dflt send window for T/TCP client */ 164 165 #define TCP_MAX_WINSHIFT 14 /* maximum window shift */ 166 167 #define TCP_MAXBURST 4 /* maximum segments in a burst */ 168 169 #define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */ 170 #define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr)) 171 /* max space left for options */ 172 #define TCP_FASTOPEN_MIN_COOKIE_LEN 4 /* Per RFC7413 */ 173 #define TCP_FASTOPEN_MAX_COOKIE_LEN 16 /* Per RFC7413 */ 174 #define TCP_FASTOPEN_PSK_LEN 16 /* Same as TCP_FASTOPEN_KEY_LEN */ 175 176 /* 177 * User-settable options (used with setsockopt). These are discrete 178 * values and are not masked together. Some values appear to be 179 * bitmasks for historical reasons. 180 */ 181 #define TCP_NODELAY 1 /* don't delay send to coalesce packets */ 182 #define TCP_MAXSEG 2 /* set maximum segment size */ 183 #define TCP_NOPUSH 4 /* don't push last block of write */ 184 #define TCP_NOOPT 8 /* don't use TCP options */ 185 #define TCP_MD5SIG 16 /* use MD5 digests (RFC2385) */ 186 #define TCP_INFO 32 /* retrieve tcp_info structure */ 187 #define TCP_CONGESTION 64 /* get/set congestion control algorithm */ 188 #define TCP_KEEPINIT 128 /* N, time to establish connection */ 189 #define TCP_KEEPIDLE 256 /* L,N,X start keeplives after this period */ 190 #define TCP_KEEPINTVL 512 /* L,N interval between keepalives */ 191 #define TCP_KEEPCNT 1024 /* L,N number of keepalives before close */ 192 #define TCP_PCAP_OUT 2048 /* number of output packets to keep */ 193 #define TCP_PCAP_IN 4096 /* number of input packets to keep */ 194 195 /* Start of reserved space for third-party user-settable options. */ 196 #define TCP_VENDOR SO_VENDOR 197 198 #define TCP_CA_NAME_MAX 16 /* max congestion control name length */ 199 200 #define TCPI_OPT_TIMESTAMPS 0x01 201 #define TCPI_OPT_SACK 0x02 202 #define TCPI_OPT_WSCALE 0x04 203 #define TCPI_OPT_ECN 0x08 204 #define TCPI_OPT_TOE 0x10 205 206 #endif /* !_NETINET_TCP_H_ */ 207