tcp.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #ifndef _NETINET_TCP_H
  2. #define _NETINET_TCP_H
  3. #include <features.h>
  4. #define TCP_NODELAY 1
  5. #define TCP_MAXSEG 2
  6. #define TCP_CORK 3
  7. #define TCP_KEEPIDLE 4
  8. #define TCP_KEEPINTVL 5
  9. #define TCP_KEEPCNT 6
  10. #define TCP_SYNCNT 7
  11. #define TCP_LINGER2 8
  12. #define TCP_DEFER_ACCEPT 9
  13. #define TCP_WINDOW_CLAMP 10
  14. #define TCP_INFO 11
  15. #define TCP_QUICKACK 12
  16. #define TCP_CONGESTION 13
  17. #define TCP_MD5SIG 14
  18. #define TCP_THIN_LINEAR_TIMEOUTS 16
  19. #define TCP_THIN_DUPACK 17
  20. #define TCP_USER_TIMEOUT 18
  21. #define TCP_REPAIR 19
  22. #define TCP_REPAIR_QUEUE 20
  23. #define TCP_QUEUE_SEQ 21
  24. #define TCP_REPAIR_OPTIONS 22
  25. #define TCP_FASTOPEN 23
  26. #define TCP_TIMESTAMP 24
  27. #define TCP_NOTSENT_LOWAT 25
  28. #define TCP_CC_INFO 26
  29. #define TCP_SAVE_SYN 27
  30. #define TCP_SAVED_SYN 28
  31. #define TCP_REPAIR_WINDOW 29
  32. #define TCP_FASTOPEN_CONNECT 30
  33. #define TCP_ULP 31
  34. #define TCP_MD5SIG_EXT 32
  35. #define TCP_FASTOPEN_KEY 33
  36. #define TCP_FASTOPEN_NO_COOKIE 34
  37. #define TCP_ZEROCOPY_RECEIVE 35
  38. #define TCP_INQ 36
  39. #define TCP_CM_INQ TCP_INQ
  40. #define TCP_ESTABLISHED 1
  41. #define TCP_SYN_SENT 2
  42. #define TCP_SYN_RECV 3
  43. #define TCP_FIN_WAIT1 4
  44. #define TCP_FIN_WAIT2 5
  45. #define TCP_TIME_WAIT 6
  46. #define TCP_CLOSE 7
  47. #define TCP_CLOSE_WAIT 8
  48. #define TCP_LAST_ACK 9
  49. #define TCP_LISTEN 10
  50. #define TCP_CLOSING 11
  51. enum {
  52. TCP_NLA_PAD,
  53. TCP_NLA_BUSY,
  54. TCP_NLA_RWND_LIMITED,
  55. TCP_NLA_SNDBUF_LIMITED,
  56. TCP_NLA_DATA_SEGS_OUT,
  57. TCP_NLA_TOTAL_RETRANS,
  58. TCP_NLA_PACING_RATE,
  59. TCP_NLA_DELIVERY_RATE,
  60. TCP_NLA_SND_CWND,
  61. TCP_NLA_REORDERING,
  62. TCP_NLA_MIN_RTT,
  63. TCP_NLA_RECUR_RETRANS,
  64. TCP_NLA_DELIVERY_RATE_APP_LMT,
  65. TCP_NLA_SNDQ_SIZE,
  66. TCP_NLA_CA_STATE,
  67. TCP_NLA_SND_SSTHRESH,
  68. TCP_NLA_DELIVERED,
  69. TCP_NLA_DELIVERED_CE,
  70. TCP_NLA_BYTES_SENT,
  71. TCP_NLA_BYTES_RETRANS,
  72. TCP_NLA_DSACK_DUPS,
  73. TCP_NLA_REORD_SEEN,
  74. TCP_NLA_SRTT,
  75. };
  76. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  77. #define TCPOPT_EOL 0
  78. #define TCPOPT_NOP 1
  79. #define TCPOPT_MAXSEG 2
  80. #define TCPOPT_WINDOW 3
  81. #define TCPOPT_SACK_PERMITTED 4
  82. #define TCPOPT_SACK 5
  83. #define TCPOPT_TIMESTAMP 8
  84. #define TCPOLEN_SACK_PERMITTED 2
  85. #define TCPOLEN_WINDOW 3
  86. #define TCPOLEN_MAXSEG 4
  87. #define TCPOLEN_TIMESTAMP 10
  88. #define SOL_TCP 6
  89. #include <sys/types.h>
  90. #include <sys/socket.h>
  91. #include <stdint.h>
  92. typedef uint32_t tcp_seq;
  93. #define TH_FIN 0x01
  94. #define TH_SYN 0x02
  95. #define TH_RST 0x04
  96. #define TH_PUSH 0x08
  97. #define TH_ACK 0x10
  98. #define TH_URG 0x20
  99. struct tcphdr {
  100. #ifdef _GNU_SOURCE
  101. #ifdef __GNUC__
  102. __extension__
  103. #endif
  104. union { struct {
  105. uint16_t source;
  106. uint16_t dest;
  107. uint32_t seq;
  108. uint32_t ack_seq;
  109. #if __BYTE_ORDER == __LITTLE_ENDIAN
  110. uint16_t res1:4;
  111. uint16_t doff:4;
  112. uint16_t fin:1;
  113. uint16_t syn:1;
  114. uint16_t rst:1;
  115. uint16_t psh:1;
  116. uint16_t ack:1;
  117. uint16_t urg:1;
  118. uint16_t res2:2;
  119. #else
  120. uint16_t doff:4;
  121. uint16_t res1:4;
  122. uint16_t res2:2;
  123. uint16_t urg:1;
  124. uint16_t ack:1;
  125. uint16_t psh:1;
  126. uint16_t rst:1;
  127. uint16_t syn:1;
  128. uint16_t fin:1;
  129. #endif
  130. uint16_t window;
  131. uint16_t check;
  132. uint16_t urg_ptr;
  133. }; struct {
  134. #endif
  135. uint16_t th_sport;
  136. uint16_t th_dport;
  137. uint32_t th_seq;
  138. uint32_t th_ack;
  139. #if __BYTE_ORDER == __LITTLE_ENDIAN
  140. uint8_t th_x2:4;
  141. uint8_t th_off:4;
  142. #else
  143. uint8_t th_off:4;
  144. uint8_t th_x2:4;
  145. #endif
  146. uint8_t th_flags;
  147. uint16_t th_win;
  148. uint16_t th_sum;
  149. uint16_t th_urp;
  150. #ifdef _GNU_SOURCE
  151. }; };
  152. #endif
  153. };
  154. #endif
  155. #ifdef _GNU_SOURCE
  156. #define TCPI_OPT_TIMESTAMPS 1
  157. #define TCPI_OPT_SACK 2
  158. #define TCPI_OPT_WSCALE 4
  159. #define TCPI_OPT_ECN 8
  160. #define TCP_CA_Open 0
  161. #define TCP_CA_Disorder 1
  162. #define TCP_CA_CWR 2
  163. #define TCP_CA_Recovery 3
  164. #define TCP_CA_Loss 4
  165. struct tcp_info {
  166. uint8_t tcpi_state;
  167. uint8_t tcpi_ca_state;
  168. uint8_t tcpi_retransmits;
  169. uint8_t tcpi_probes;
  170. uint8_t tcpi_backoff;
  171. uint8_t tcpi_options;
  172. uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  173. uint8_t tcpi_delivery_rate_app_limited : 1;
  174. uint32_t tcpi_rto;
  175. uint32_t tcpi_ato;
  176. uint32_t tcpi_snd_mss;
  177. uint32_t tcpi_rcv_mss;
  178. uint32_t tcpi_unacked;
  179. uint32_t tcpi_sacked;
  180. uint32_t tcpi_lost;
  181. uint32_t tcpi_retrans;
  182. uint32_t tcpi_fackets;
  183. uint32_t tcpi_last_data_sent;
  184. uint32_t tcpi_last_ack_sent;
  185. uint32_t tcpi_last_data_recv;
  186. uint32_t tcpi_last_ack_recv;
  187. uint32_t tcpi_pmtu;
  188. uint32_t tcpi_rcv_ssthresh;
  189. uint32_t tcpi_rtt;
  190. uint32_t tcpi_rttvar;
  191. uint32_t tcpi_snd_ssthresh;
  192. uint32_t tcpi_snd_cwnd;
  193. uint32_t tcpi_advmss;
  194. uint32_t tcpi_reordering;
  195. uint32_t tcpi_rcv_rtt;
  196. uint32_t tcpi_rcv_space;
  197. uint32_t tcpi_total_retrans;
  198. uint64_t tcpi_pacing_rate;
  199. uint64_t tcpi_max_pacing_rate;
  200. uint64_t tcpi_bytes_acked;
  201. uint64_t tcpi_bytes_received;
  202. uint32_t tcpi_segs_out;
  203. uint32_t tcpi_segs_in;
  204. uint32_t tcpi_notsent_bytes;
  205. uint32_t tcpi_min_rtt;
  206. uint32_t tcpi_data_segs_in;
  207. uint32_t tcpi_data_segs_out;
  208. uint64_t tcpi_delivery_rate;
  209. uint64_t tcpi_busy_time;
  210. uint64_t tcpi_rwnd_limited;
  211. uint64_t tcpi_sndbuf_limited;
  212. uint32_t tcpi_delivered;
  213. uint32_t tcpi_delivered_ce;
  214. uint64_t tcpi_bytes_sent;
  215. uint64_t tcpi_bytes_retrans;
  216. uint32_t tcpi_dsack_dups;
  217. uint32_t tcpi_reord_seen;
  218. };
  219. #define TCP_MD5SIG_MAXKEYLEN 80
  220. #define TCP_MD5SIG_FLAG_PREFIX 1
  221. struct tcp_md5sig {
  222. struct sockaddr_storage tcpm_addr;
  223. uint8_t tcpm_flags;
  224. uint8_t tcpm_prefixlen;
  225. uint16_t tcpm_keylen;
  226. uint32_t __tcpm_pad;
  227. uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
  228. };
  229. struct tcp_diag_md5sig {
  230. uint8_t tcpm_family;
  231. uint8_t tcpm_prefixlen;
  232. uint16_t tcpm_keylen;
  233. uint32_t tcpm_addr[4];
  234. uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
  235. };
  236. #define TCP_REPAIR_ON 1
  237. #define TCP_REPAIR_OFF 0
  238. #define TCP_REPAIR_OFF_NO_WP -1
  239. struct tcp_repair_window {
  240. uint32_t snd_wl1;
  241. uint32_t snd_wnd;
  242. uint32_t max_window;
  243. uint32_t rcv_wnd;
  244. uint32_t rcv_wup;
  245. };
  246. struct tcp_zerocopy_receive {
  247. uint64_t address;
  248. uint32_t length;
  249. uint32_t recv_skip_hint;
  250. };
  251. #endif
  252. #endif