tcp.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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_TX_DELAY 37
  40. #define TCP_CM_INQ TCP_INQ
  41. #define TCP_ESTABLISHED 1
  42. #define TCP_SYN_SENT 2
  43. #define TCP_SYN_RECV 3
  44. #define TCP_FIN_WAIT1 4
  45. #define TCP_FIN_WAIT2 5
  46. #define TCP_TIME_WAIT 6
  47. #define TCP_CLOSE 7
  48. #define TCP_CLOSE_WAIT 8
  49. #define TCP_LAST_ACK 9
  50. #define TCP_LISTEN 10
  51. #define TCP_CLOSING 11
  52. enum {
  53. TCP_NLA_PAD,
  54. TCP_NLA_BUSY,
  55. TCP_NLA_RWND_LIMITED,
  56. TCP_NLA_SNDBUF_LIMITED,
  57. TCP_NLA_DATA_SEGS_OUT,
  58. TCP_NLA_TOTAL_RETRANS,
  59. TCP_NLA_PACING_RATE,
  60. TCP_NLA_DELIVERY_RATE,
  61. TCP_NLA_SND_CWND,
  62. TCP_NLA_REORDERING,
  63. TCP_NLA_MIN_RTT,
  64. TCP_NLA_RECUR_RETRANS,
  65. TCP_NLA_DELIVERY_RATE_APP_LMT,
  66. TCP_NLA_SNDQ_SIZE,
  67. TCP_NLA_CA_STATE,
  68. TCP_NLA_SND_SSTHRESH,
  69. TCP_NLA_DELIVERED,
  70. TCP_NLA_DELIVERED_CE,
  71. TCP_NLA_BYTES_SENT,
  72. TCP_NLA_BYTES_RETRANS,
  73. TCP_NLA_DSACK_DUPS,
  74. TCP_NLA_REORD_SEEN,
  75. TCP_NLA_SRTT,
  76. TCP_NLA_TIMEOUT_REHASH,
  77. TCP_NLA_BYTES_NOTSENT,
  78. TCP_NLA_EDT,
  79. TCP_NLA_TTL,
  80. };
  81. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  82. #define TCPOPT_EOL 0
  83. #define TCPOPT_NOP 1
  84. #define TCPOPT_MAXSEG 2
  85. #define TCPOPT_WINDOW 3
  86. #define TCPOPT_SACK_PERMITTED 4
  87. #define TCPOPT_SACK 5
  88. #define TCPOPT_TIMESTAMP 8
  89. #define TCPOLEN_SACK_PERMITTED 2
  90. #define TCPOLEN_WINDOW 3
  91. #define TCPOLEN_MAXSEG 4
  92. #define TCPOLEN_TIMESTAMP 10
  93. #define SOL_TCP 6
  94. #include <sys/types.h>
  95. #include <sys/socket.h>
  96. #include <stdint.h>
  97. typedef uint32_t tcp_seq;
  98. #define TH_FIN 0x01
  99. #define TH_SYN 0x02
  100. #define TH_RST 0x04
  101. #define TH_PUSH 0x08
  102. #define TH_ACK 0x10
  103. #define TH_URG 0x20
  104. struct tcphdr {
  105. #ifdef _GNU_SOURCE
  106. #ifdef __GNUC__
  107. __extension__
  108. #endif
  109. union { struct {
  110. uint16_t source;
  111. uint16_t dest;
  112. uint32_t seq;
  113. uint32_t ack_seq;
  114. #if __BYTE_ORDER == __LITTLE_ENDIAN
  115. uint16_t res1:4;
  116. uint16_t doff:4;
  117. uint16_t fin:1;
  118. uint16_t syn:1;
  119. uint16_t rst:1;
  120. uint16_t psh:1;
  121. uint16_t ack:1;
  122. uint16_t urg:1;
  123. uint16_t res2:2;
  124. #else
  125. uint16_t doff:4;
  126. uint16_t res1:4;
  127. uint16_t res2:2;
  128. uint16_t urg:1;
  129. uint16_t ack:1;
  130. uint16_t psh:1;
  131. uint16_t rst:1;
  132. uint16_t syn:1;
  133. uint16_t fin:1;
  134. #endif
  135. uint16_t window;
  136. uint16_t check;
  137. uint16_t urg_ptr;
  138. }; struct {
  139. #endif
  140. uint16_t th_sport;
  141. uint16_t th_dport;
  142. uint32_t th_seq;
  143. uint32_t th_ack;
  144. #if __BYTE_ORDER == __LITTLE_ENDIAN
  145. uint8_t th_x2:4;
  146. uint8_t th_off:4;
  147. #else
  148. uint8_t th_off:4;
  149. uint8_t th_x2:4;
  150. #endif
  151. uint8_t th_flags;
  152. uint16_t th_win;
  153. uint16_t th_sum;
  154. uint16_t th_urp;
  155. #ifdef _GNU_SOURCE
  156. }; };
  157. #endif
  158. };
  159. #endif
  160. #ifdef _GNU_SOURCE
  161. #define TCPI_OPT_TIMESTAMPS 1
  162. #define TCPI_OPT_SACK 2
  163. #define TCPI_OPT_WSCALE 4
  164. #define TCPI_OPT_ECN 8
  165. #define TCP_CA_Open 0
  166. #define TCP_CA_Disorder 1
  167. #define TCP_CA_CWR 2
  168. #define TCP_CA_Recovery 3
  169. #define TCP_CA_Loss 4
  170. enum tcp_fastopen_client_fail {
  171. TFO_STATUS_UNSPEC,
  172. TFO_COOKIE_UNAVAILABLE,
  173. TFO_DATA_NOT_ACKED,
  174. TFO_SYN_RETRANSMITTED,
  175. };
  176. struct tcp_info {
  177. uint8_t tcpi_state;
  178. uint8_t tcpi_ca_state;
  179. uint8_t tcpi_retransmits;
  180. uint8_t tcpi_probes;
  181. uint8_t tcpi_backoff;
  182. uint8_t tcpi_options;
  183. uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  184. uint8_t tcpi_delivery_rate_app_limited : 1, tcpi_fastopen_client_fail : 2;
  185. uint32_t tcpi_rto;
  186. uint32_t tcpi_ato;
  187. uint32_t tcpi_snd_mss;
  188. uint32_t tcpi_rcv_mss;
  189. uint32_t tcpi_unacked;
  190. uint32_t tcpi_sacked;
  191. uint32_t tcpi_lost;
  192. uint32_t tcpi_retrans;
  193. uint32_t tcpi_fackets;
  194. uint32_t tcpi_last_data_sent;
  195. uint32_t tcpi_last_ack_sent;
  196. uint32_t tcpi_last_data_recv;
  197. uint32_t tcpi_last_ack_recv;
  198. uint32_t tcpi_pmtu;
  199. uint32_t tcpi_rcv_ssthresh;
  200. uint32_t tcpi_rtt;
  201. uint32_t tcpi_rttvar;
  202. uint32_t tcpi_snd_ssthresh;
  203. uint32_t tcpi_snd_cwnd;
  204. uint32_t tcpi_advmss;
  205. uint32_t tcpi_reordering;
  206. uint32_t tcpi_rcv_rtt;
  207. uint32_t tcpi_rcv_space;
  208. uint32_t tcpi_total_retrans;
  209. uint64_t tcpi_pacing_rate;
  210. uint64_t tcpi_max_pacing_rate;
  211. uint64_t tcpi_bytes_acked;
  212. uint64_t tcpi_bytes_received;
  213. uint32_t tcpi_segs_out;
  214. uint32_t tcpi_segs_in;
  215. uint32_t tcpi_notsent_bytes;
  216. uint32_t tcpi_min_rtt;
  217. uint32_t tcpi_data_segs_in;
  218. uint32_t tcpi_data_segs_out;
  219. uint64_t tcpi_delivery_rate;
  220. uint64_t tcpi_busy_time;
  221. uint64_t tcpi_rwnd_limited;
  222. uint64_t tcpi_sndbuf_limited;
  223. uint32_t tcpi_delivered;
  224. uint32_t tcpi_delivered_ce;
  225. uint64_t tcpi_bytes_sent;
  226. uint64_t tcpi_bytes_retrans;
  227. uint32_t tcpi_dsack_dups;
  228. uint32_t tcpi_reord_seen;
  229. uint32_t tcpi_rcv_ooopack;
  230. uint32_t tcpi_snd_wnd;
  231. };
  232. #define TCP_MD5SIG_MAXKEYLEN 80
  233. #define TCP_MD5SIG_FLAG_PREFIX 0x1
  234. #define TCP_MD5SIG_FLAG_IFINDEX 0x2
  235. struct tcp_md5sig {
  236. struct sockaddr_storage tcpm_addr;
  237. uint8_t tcpm_flags;
  238. uint8_t tcpm_prefixlen;
  239. uint16_t tcpm_keylen;
  240. int tcpm_ifindex;
  241. uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
  242. };
  243. struct tcp_diag_md5sig {
  244. uint8_t tcpm_family;
  245. uint8_t tcpm_prefixlen;
  246. uint16_t tcpm_keylen;
  247. uint32_t tcpm_addr[4];
  248. uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
  249. };
  250. #define TCP_REPAIR_ON 1
  251. #define TCP_REPAIR_OFF 0
  252. #define TCP_REPAIR_OFF_NO_WP -1
  253. struct tcp_repair_window {
  254. uint32_t snd_wl1;
  255. uint32_t snd_wnd;
  256. uint32_t max_window;
  257. uint32_t rcv_wnd;
  258. uint32_t rcv_wup;
  259. };
  260. #define TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT 0x1
  261. struct tcp_zerocopy_receive {
  262. uint64_t address;
  263. uint32_t length;
  264. uint32_t recv_skip_hint;
  265. uint32_t inq;
  266. int32_t err;
  267. uint64_t copybuf_address;
  268. int32_t copybuf_len;
  269. uint32_t flags;
  270. uint64_t msg_control;
  271. uint64_t msg_controllen;
  272. uint32_t msg_flags;
  273. uint32_t reserved;
  274. };
  275. #endif
  276. #endif