tcp.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. */
  31. #ifndef _NETINET_TCP_H
  32. #define _NETINET_TCP_H 1
  33. #include <features.h>
  34. /*
  35. * User-settable options (used with setsockopt).
  36. */
  37. #define TCP_NODELAY 1 /* Don't delay send to coalesce packets */
  38. #define TCP_MAXSEG 2 /* Set maximum segment size */
  39. #define TCP_CORK 3 /* Control sending of partial frames */
  40. #define TCP_KEEPIDLE 4 /* Start keeplives after this period */
  41. #define TCP_KEEPINTVL 5 /* Interval between keepalives */
  42. #define TCP_KEEPCNT 6 /* Number of keepalives before death */
  43. #define TCP_SYNCNT 7 /* Number of SYN retransmits */
  44. #define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */
  45. #define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */
  46. #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
  47. #define TCP_INFO 11 /* Information about this connection. */
  48. #define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */
  49. #define TCP_CONGESTION 13 /* Congestion control algorithm. */
  50. #define TCP_MD5SIG 14 /* TCP MD5 Signature (RFC2385) */
  51. #define TCP_COOKIE_TRANSACTIONS 15 /* TCP Cookie Transactions */
  52. #define TCP_THIN_LINEAR_TIMEOUTS 16 /* Use linear timeouts for thin streams*/
  53. #define TCP_THIN_DUPACK 17 /* Fast retrans. after 1 dupack */
  54. #define TCP_USER_TIMEOUT 18 /* How long for loss retry before timeout */
  55. #define TCP_REPAIR 19 /* TCP sock is under repair right now */
  56. #define TCP_REPAIR_QUEUE 20 /* Set TCP queue to repair */
  57. #define TCP_QUEUE_SEQ 21 /* Set sequence number of repaired queue. */
  58. #define TCP_REPAIR_OPTIONS 22 /* Repair TCP connection options */
  59. #define TCP_FASTOPEN 23 /* Enable FastOpen on listeners */
  60. #define TCP_TIMESTAMP 24 /* TCP time stamp */
  61. #ifdef __USE_MISC
  62. # include <sys/types.h>
  63. # include <sys/socket.h>
  64. # include <stdint.h>
  65. typedef uint32_t tcp_seq;
  66. /*
  67. * TCP header.
  68. * Per RFC 793, September, 1981.
  69. */
  70. struct tcphdr
  71. {
  72. __extension__ union
  73. {
  74. struct
  75. {
  76. uint16_t th_sport; /* source port */
  77. uint16_t th_dport; /* destination port */
  78. tcp_seq th_seq; /* sequence number */
  79. tcp_seq th_ack; /* acknowledgement number */
  80. # if __BYTE_ORDER == __LITTLE_ENDIAN
  81. uint8_t th_x2:4; /* (unused) */
  82. uint8_t th_off:4; /* data offset */
  83. # endif
  84. # if __BYTE_ORDER == __BIG_ENDIAN
  85. uint8_t th_off:4; /* data offset */
  86. uint8_t th_x2:4; /* (unused) */
  87. # endif
  88. uint8_t th_flags;
  89. # define TH_FIN 0x01
  90. # define TH_SYN 0x02
  91. # define TH_RST 0x04
  92. # define TH_PUSH 0x08
  93. # define TH_ACK 0x10
  94. # define TH_URG 0x20
  95. uint16_t th_win; /* window */
  96. uint16_t th_sum; /* checksum */
  97. uint16_t th_urp; /* urgent pointer */
  98. };
  99. struct
  100. {
  101. uint16_t source;
  102. uint16_t dest;
  103. uint32_t seq;
  104. uint32_t ack_seq;
  105. # if __BYTE_ORDER == __LITTLE_ENDIAN
  106. uint16_t res1:4;
  107. uint16_t doff:4;
  108. uint16_t fin:1;
  109. uint16_t syn:1;
  110. uint16_t rst:1;
  111. uint16_t psh:1;
  112. uint16_t ack:1;
  113. uint16_t urg:1;
  114. uint16_t res2:2;
  115. # elif __BYTE_ORDER == __BIG_ENDIAN
  116. uint16_t doff:4;
  117. uint16_t res1:4;
  118. uint16_t res2:2;
  119. uint16_t urg:1;
  120. uint16_t ack:1;
  121. uint16_t psh:1;
  122. uint16_t rst:1;
  123. uint16_t syn:1;
  124. uint16_t fin:1;
  125. # else
  126. # error "Adjust your <bits/endian.h> defines"
  127. # endif
  128. uint16_t window;
  129. uint16_t check;
  130. uint16_t urg_ptr;
  131. };
  132. };
  133. };
  134. enum
  135. {
  136. TCP_ESTABLISHED = 1,
  137. TCP_SYN_SENT,
  138. TCP_SYN_RECV,
  139. TCP_FIN_WAIT1,
  140. TCP_FIN_WAIT2,
  141. TCP_TIME_WAIT,
  142. TCP_CLOSE,
  143. TCP_CLOSE_WAIT,
  144. TCP_LAST_ACK,
  145. TCP_LISTEN,
  146. TCP_CLOSING /* now a valid state */
  147. };
  148. # define TCPOPT_EOL 0
  149. # define TCPOPT_NOP 1
  150. # define TCPOPT_MAXSEG 2
  151. # define TCPOLEN_MAXSEG 4
  152. # define TCPOPT_WINDOW 3
  153. # define TCPOLEN_WINDOW 3
  154. # define TCPOPT_SACK_PERMITTED 4 /* Experimental */
  155. # define TCPOLEN_SACK_PERMITTED 2
  156. # define TCPOPT_SACK 5 /* Experimental */
  157. # define TCPOPT_TIMESTAMP 8
  158. # define TCPOLEN_TIMESTAMP 10
  159. # define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
  160. # define TCPOPT_TSTAMP_HDR \
  161. (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
  162. /*
  163. * Default maximum segment size for TCP.
  164. * With an IP MSS of 576, this is 536,
  165. * but 512 is probably more convenient.
  166. * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
  167. */
  168. # define TCP_MSS 512
  169. # define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
  170. # define TCP_MAX_WINSHIFT 14 /* maximum window shift */
  171. # define SOL_TCP 6 /* TCP level */
  172. # define TCPI_OPT_TIMESTAMPS 1
  173. # define TCPI_OPT_SACK 2
  174. # define TCPI_OPT_WSCALE 4
  175. # define TCPI_OPT_ECN 8
  176. /* Values for tcpi_state. */
  177. enum tcp_ca_state
  178. {
  179. TCP_CA_Open = 0,
  180. TCP_CA_Disorder = 1,
  181. TCP_CA_CWR = 2,
  182. TCP_CA_Recovery = 3,
  183. TCP_CA_Loss = 4
  184. };
  185. struct tcp_info
  186. {
  187. u_int8_t tcpi_state;
  188. u_int8_t tcpi_ca_state;
  189. u_int8_t tcpi_retransmits;
  190. u_int8_t tcpi_probes;
  191. u_int8_t tcpi_backoff;
  192. u_int8_t tcpi_options;
  193. u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  194. u_int32_t tcpi_rto;
  195. u_int32_t tcpi_ato;
  196. u_int32_t tcpi_snd_mss;
  197. u_int32_t tcpi_rcv_mss;
  198. u_int32_t tcpi_unacked;
  199. u_int32_t tcpi_sacked;
  200. u_int32_t tcpi_lost;
  201. u_int32_t tcpi_retrans;
  202. u_int32_t tcpi_fackets;
  203. /* Times. */
  204. u_int32_t tcpi_last_data_sent;
  205. u_int32_t tcpi_last_ack_sent; /* Not remembered, sorry. */
  206. u_int32_t tcpi_last_data_recv;
  207. u_int32_t tcpi_last_ack_recv;
  208. /* Metrics. */
  209. u_int32_t tcpi_pmtu;
  210. u_int32_t tcpi_rcv_ssthresh;
  211. u_int32_t tcpi_rtt;
  212. u_int32_t tcpi_rttvar;
  213. u_int32_t tcpi_snd_ssthresh;
  214. u_int32_t tcpi_snd_cwnd;
  215. u_int32_t tcpi_advmss;
  216. u_int32_t tcpi_reordering;
  217. u_int32_t tcpi_rcv_rtt;
  218. u_int32_t tcpi_rcv_space;
  219. u_int32_t tcpi_total_retrans;
  220. };
  221. /* For TCP_MD5SIG socket option. */
  222. #define TCP_MD5SIG_MAXKEYLEN 80
  223. struct tcp_md5sig
  224. {
  225. struct sockaddr_storage tcpm_addr; /* Address associated. */
  226. u_int16_t __tcpm_pad1; /* Zero. */
  227. u_int16_t tcpm_keylen; /* Key length. */
  228. u_int32_t __tcpm_pad2; /* Zero. */
  229. u_int8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* Key (binary). */
  230. };
  231. #endif /* Misc. */
  232. #endif /* netinet/tcp.h */