Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4973 | right-hear | 1 | #ifndef _NETINET_TCP_H |
2 | #define _NETINET_TCP_H |
||
3 | |||
4 | #include |
||
5 | #include |
||
6 | |||
7 | __BEGIN_DECLS |
||
8 | |||
9 | struct tcphdr { /* size 20/0x14 40/0x28 with IP header */ |
||
10 | uint16_t source; /* offset 0 20/0x14 */ |
||
11 | uint16_t dest; /* offset 2 22/0x16 */ |
||
12 | uint32_t seq; /* offset 4 24/0x18 */ |
||
13 | uint32_t ack_seq; /* offset 8 28/0x1c */ |
||
14 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
||
15 | uint16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1; |
||
16 | #else |
||
17 | uint16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1; |
||
18 | #endif |
||
19 | /* offset 12/0xc 32/0x20 */ |
||
20 | uint16_t window; /* offset 14/0xe 34/0x22 */ |
||
21 | uint16_t check; /* offset 16/0x10 36/0x24 */ |
||
22 | uint16_t urg_ptr; /* offset 18/0x12 38/0x26 */ |
||
23 | }; |
||
24 | |||
25 | |||
26 | enum { |
||
27 | TCP_ESTABLISHED = 1, |
||
28 | TCP_SYN_SENT, |
||
29 | TCP_SYN_RECV, |
||
30 | TCP_FIN_WAIT1, |
||
31 | TCP_FIN_WAIT2, |
||
32 | TCP_TIME_WAIT, |
||
33 | TCP_CLOSE, |
||
34 | TCP_CLOSE_WAIT, |
||
35 | TCP_LAST_ACK, |
||
36 | TCP_LISTEN, |
||
37 | TCP_CLOSING, /* now a valid state */ |
||
38 | |||
39 | TCP_MAX_STATES /* Leave at the end! */ |
||
40 | }; |
||
41 | |||
42 | #define TCP_STATE_MASK 0xF |
||
43 | #define TCP_ACTION_FIN (1 << 7) |
||
44 | |||
45 | enum { |
||
46 | TCPF_ESTABLISHED = (1 << 1), |
||
47 | TCPF_SYN_SENT = (1 << 2), |
||
48 | TCPF_SYN_RECV = (1 << 3), |
||
49 | TCPF_FIN_WAIT1 = (1 << 4), |
||
50 | TCPF_FIN_WAIT2 = (1 << 5), |
||
51 | TCPF_TIME_WAIT = (1 << 6), |
||
52 | TCPF_CLOSE = (1 << 7), |
||
53 | TCPF_CLOSE_WAIT = (1 << 8), |
||
54 | TCPF_LAST_ACK = (1 << 9), |
||
55 | TCPF_LISTEN = (1 << 10), |
||
56 | TCPF_CLOSING = (1 << 11) |
||
57 | }; |
||
58 | |||
59 | /* |
||
60 | * The union cast uses a gcc extension to avoid aliasing problems |
||
61 | * (union is compatible to any of its members) |
||
62 | * This means this part of the code is -fstrict-aliasing safe now. |
||
63 | */ |
||
64 | union tcp_word_hdr { |
||
65 | struct tcphdr hdr; |
||
66 | uint32_t words[5]; |
||
67 | }; |
||
68 | |||
69 | #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3]) |
||
70 | |||
71 | enum { |
||
72 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
||
73 | TCP_FLAG_CWR = 0x00008000, |
||
74 | TCP_FLAG_ECE = 0x00004000, |
||
75 | TCP_FLAG_URG = 0x00002000, |
||
76 | TCP_FLAG_ACK = 0x00001000, |
||
77 | TCP_FLAG_PSH = 0x00000800, |
||
78 | TCP_FLAG_RST = 0x00000400, |
||
79 | TCP_FLAG_SYN = 0x00000200, |
||
80 | TCP_FLAG_FIN = 0x00000100, |
||
81 | TCP_RESERVED_BITS = 0x0000C00F, |
||
82 | TCP_DATA_OFFSET = 0x000000F0 |
||
83 | #else |
||
84 | TCP_FLAG_CWR = 0x00800000, |
||
85 | TCP_FLAG_ECE = 0x00400000, |
||
86 | TCP_FLAG_URG = 0x00200000, |
||
87 | TCP_FLAG_ACK = 0x00100000, |
||
88 | TCP_FLAG_PSH = 0x00080000, |
||
89 | TCP_FLAG_RST = 0x00040000, |
||
90 | TCP_FLAG_SYN = 0x00020000, |
||
91 | TCP_FLAG_FIN = 0x00010000, |
||
92 | TCP_RESERVED_BITS = 0x0FC00000, |
||
93 | TCP_DATA_OFFSET = 0xF0000000 |
||
94 | #endif |
||
95 | }; |
||
96 | |||
97 | /* TCP socket options */ |
||
98 | #define TCP_NODELAY 1 /* Turn off Nagle's algorithm. */ |
||
99 | #define TCP_MAXSEG 2 /* Limit MSS */ |
||
100 | #define TCP_CORK 3 /* Never send partially complete segments */ |
||
101 | #define TCP_KEEPIDLE 4 /* Start keeplives after this period */ |
||
102 | #define TCP_KEEPINTVL 5 /* Interval between keepalives */ |
||
103 | #define TCP_KEEPCNT 6 /* Number of keepalives before death */ |
||
104 | #define TCP_SYNCNT 7 /* Number of SYN retransmits */ |
||
105 | #define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */ |
||
106 | #define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */ |
||
107 | #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */ |
||
108 | #define TCP_INFO 11 /* Information about this connection. */ |
||
109 | #define TCP_QUICKACK 12 /* Block/reenable quick acks */ |
||
110 | |||
111 | #define TCPI_OPT_TIMESTAMPS 1 |
||
112 | #define TCPI_OPT_SACK 2 |
||
113 | #define TCPI_OPT_WSCALE 4 |
||
114 | #define TCPI_OPT_ECN 8 |
||
115 | |||
116 | enum tcp_ca_state { |
||
117 | TCP_CA_Open = 0, |
||
118 | #define TCPF_CA_Open (1< |
||
119 | TCP_CA_Disorder = 1, |
||
120 | #define TCPF_CA_Disorder (1< |
||
121 | TCP_CA_CWR = 2, |
||
122 | #define TCPF_CA_CWR (1< |
||
123 | TCP_CA_Recovery = 3, |
||
124 | #define TCPF_CA_Recovery (1< |
||
125 | TCP_CA_Loss = 4 |
||
126 | #define TCPF_CA_Loss (1< |
||
127 | }; |
||
128 | |||
129 | struct tcp_info { |
||
130 | uint8_t tcpi_state; |
||
131 | uint8_t tcpi_ca_state; |
||
132 | uint8_t tcpi_retransmits; |
||
133 | uint8_t tcpi_probes; |
||
134 | uint8_t tcpi_backoff; |
||
135 | uint8_t tcpi_options; |
||
136 | uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; |
||
137 | |||
138 | uint32_t tcpi_rto; |
||
139 | uint32_t tcpi_ato; |
||
140 | uint32_t tcpi_snd_mss; |
||
141 | uint32_t tcpi_rcv_mss; |
||
142 | |||
143 | uint32_t tcpi_unacked; |
||
144 | uint32_t tcpi_sacked; |
||
145 | uint32_t tcpi_lost; |
||
146 | uint32_t tcpi_retrans; |
||
147 | uint32_t tcpi_fackets; |
||
148 | |||
149 | /* Times. */ |
||
150 | uint32_t tcpi_last_data_sent; |
||
151 | uint32_t tcpi_last_ack_sent; /* Not remembered, sorry. */ |
||
152 | uint32_t tcpi_last_data_recv; |
||
153 | uint32_t tcpi_last_ack_recv; |
||
154 | |||
155 | /* Metrics. */ |
||
156 | uint32_t tcpi_pmtu; |
||
157 | uint32_t tcpi_rcv_ssthresh; |
||
158 | uint32_t tcpi_rtt; |
||
159 | uint32_t tcpi_rttvar; |
||
160 | uint32_t tcpi_snd_ssthresh; |
||
161 | uint32_t tcpi_snd_cwnd; |
||
162 | uint32_t tcpi_advmss; |
||
163 | uint32_t tcpi_reordering; |
||
164 | }; |
||
165 | |||
166 | __END_DECLS |
||
167 | |||
168 | #endif |