• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _ADAPT_NETINET_TCP_H
32 #define _ADAPT_NETINET_TCP_H
33 
34 #include <sys/features.h>
35 
36 #define TCP_NODELAY     1
37 #define TCP_MAXSEG      2
38 #define TCP_CORK        3
39 #define TCP_KEEPIDLE    4
40 #define TCP_KEEPINTVL   5
41 #define TCP_KEEPCNT     6
42 #define TCP_SYNCNT      7
43 
44 #define TCP_ESTABLISHED  1
45 #define TCP_SYN_SENT     2
46 #define TCP_SYN_RECV     3
47 #define TCP_FIN_WAIT1    4
48 #define TCP_FIN_WAIT2    5
49 #define TCP_TIME_WAIT    6
50 #define TCP_CLOSE        7
51 #define TCP_CLOSE_WAIT   8
52 #define TCP_LAST_ACK     9
53 #define TCP_LISTEN       10
54 #define TCP_CLOSING      11
55 
56 #ifdef _GNU_SOURCE
57 #define TCPI_OPT_TIMESTAMPS     1
58 #define TCPI_OPT_SACK           2
59 #define TCPI_OPT_WSCALE         4
60 #define TCPI_OPT_ECN            8
61 
62 #define TCP_CA_Open             0
63 #define TCP_CA_Disorder         1
64 #define TCP_CA_CWR              2
65 #define TCP_CA_Recovery         3
66 #define TCP_CA_Loss             4
67 #endif
68 
69 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
70 #define TCPOPT_EOL              0
71 #define TCPOPT_NOP              1
72 #define TCPOPT_MAXSEG           2
73 #define TCPOPT_WINDOW           3
74 #define TCPOPT_SACK_PERMITTED   4
75 #define TCPOPT_SACK             5
76 #define TCPOPT_TIMESTAMP        8
77 #define TCPOLEN_SACK_PERMITTED  2
78 #define TCPOLEN_WINDOW          3
79 #define TCPOLEN_MAXSEG          4
80 #define TCPOLEN_TIMESTAMP       10
81 
82 #define SOL_TCP 6
83 
84 #include <sys/types.h>
85 #include <sys/socket.h>
86 #include <stdint.h>
87 
88 #define TH_FIN  0x01
89 #define TH_SYN  0x02
90 #define TH_RST  0x04
91 #define TH_PUSH 0x08
92 #define TH_ACK  0x10
93 #define TH_URG  0x20
94 
95 typedef uint32_t tcp_seq;
96 
97 struct tcphdr {
98 #ifdef _GNU_SOURCE
99 #ifdef __GNUC__
100     __extension__
101 #endif
102     union { struct {
103 
104     uint16_t source;
105     uint16_t dest;
106     uint32_t seq;
107     uint32_t ack_seq;
108 #if BYTE_ORDER == LITTLE_ENDIAN
109     uint16_t res1:4;
110     uint16_t doff:4;
111     uint16_t fin:1;
112     uint16_t syn:1;
113     uint16_t rst:1;
114     uint16_t psh:1;
115     uint16_t ack:1;
116     uint16_t urg:1;
117     uint16_t res2:2;
118 #else
119     uint16_t doff:4;
120     uint16_t res1:4;
121     uint16_t res2:2;
122     uint16_t urg:1;
123     uint16_t ack:1;
124     uint16_t psh:1;
125     uint16_t rst:1;
126     uint16_t syn:1;
127     uint16_t fin:1;
128 #endif
129     uint16_t window;
130     uint16_t check;
131     uint16_t urg_ptr;
132 
133     }; struct {
134 #endif
135 
136     uint16_t th_sport;
137     uint16_t th_dport;
138     uint32_t th_seq;
139     uint32_t th_ack;
140 #if BYTE_ORDER == LITTLE_ENDIAN
141     uint8_t th_x2:4;
142     uint8_t th_off:4;
143 #else
144     uint8_t th_off:4;
145     uint8_t th_x2:4;
146 #endif
147     uint8_t th_flags;
148     uint16_t th_win;
149     uint16_t th_sum;
150     uint16_t th_urp;
151 
152 #ifdef _GNU_SOURCE
153     }; };
154 #endif
155 };
156 #endif /* _GNU_SOURCE || _BSD_SOURCE */
157 
158 #ifdef _GNU_SOURCE
159 #define TCP_MD5SIG_MAXKEYLEN    80
160 #define TCP_MD5SIG_FLAG_PREFIX  1
161 
162 #define TCP_REPAIR_ON        1
163 #define TCP_REPAIR_OFF        0
164 #define TCP_REPAIR_OFF_NO_WP    -1
165 
166 struct tcp_info {
167     uint8_t tcpi_state;
168     uint8_t tcpi_ca_state;
169     uint8_t tcpi_retransmits;
170     uint8_t tcpi_probes;
171     uint8_t tcpi_backoff;
172     uint8_t tcpi_options;
173     uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
174     uint8_t tcpi_delivery_rate_app_limited : 1;
175     uint32_t tcpi_rto;
176     uint32_t tcpi_ato;
177     uint32_t tcpi_snd_mss;
178     uint32_t tcpi_rcv_mss;
179     uint32_t tcpi_unacked;
180     uint32_t tcpi_sacked;
181     uint32_t tcpi_lost;
182     uint32_t tcpi_retrans;
183     uint32_t tcpi_fackets;
184     uint32_t tcpi_last_data_sent;
185     uint32_t tcpi_last_ack_sent;
186     uint32_t tcpi_last_data_recv;
187     uint32_t tcpi_last_ack_recv;
188     uint32_t tcpi_pmtu;
189     uint32_t tcpi_rcv_ssthresh;
190     uint32_t tcpi_rtt;
191     uint32_t tcpi_rttvar;
192     uint32_t tcpi_snd_ssthresh;
193     uint32_t tcpi_snd_cwnd;
194     uint32_t tcpi_advmss;
195     uint32_t tcpi_reordering;
196     uint32_t tcpi_rcv_rtt;
197     uint32_t tcpi_rcv_space;
198     uint32_t tcpi_total_retrans;
199     uint64_t tcpi_pacing_rate;
200     uint64_t tcpi_max_pacing_rate;
201     uint64_t tcpi_bytes_acked;
202     uint64_t tcpi_bytes_received;
203     uint32_t tcpi_segs_out;
204     uint32_t tcpi_segs_in;
205     uint32_t tcpi_notsent_bytes;
206     uint32_t tcpi_min_rtt;
207     uint32_t tcpi_data_segs_in;
208     uint32_t tcpi_data_segs_out;
209     uint64_t tcpi_delivery_rate;
210     uint64_t tcpi_busy_time;
211     uint64_t tcpi_rwnd_limited;
212     uint64_t tcpi_sndbuf_limited;
213     uint32_t tcpi_delivered;
214     uint32_t tcpi_delivered_ce;
215     uint64_t tcpi_bytes_sent;
216     uint64_t tcpi_bytes_retrans;
217     uint32_t tcpi_dsack_dups;
218     uint32_t tcpi_reord_seen;
219     uint32_t tcpi_rcv_ooopack;
220     uint32_t tcpi_snd_wnd;
221 };
222 
223 struct tcp_md5sig {
224     struct sockaddr_storage tcpm_addr;
225     uint8_t tcpm_flags;
226     uint8_t tcpm_prefixlen;
227     uint16_t tcpm_keylen;
228     uint32_t __tcpm_pad;
229     uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
230 };
231 
232 struct tcp_diag_md5sig {
233     uint8_t tcpm_family;
234     uint8_t tcpm_prefixlen;
235     uint16_t tcpm_keylen;
236     uint32_t tcpm_addr[4];
237     uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
238 };
239 
240 struct tcp_repair_window {
241     uint32_t snd_wl1;
242     uint32_t snd_wnd;
243     uint32_t max_window;
244     uint32_t rcv_wnd;
245     uint32_t rcv_wup;
246 };
247 
248 struct tcp_zerocopy_receive {
249     uint64_t address;
250     uint32_t length;
251     uint32_t recv_skip_hint;
252 };
253 #endif /* _GNU_SOURCE */
254 
255 #endif /* !_ADAPT_NETINET_TCP_H */
256