Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/include/ip.h
2 views
1
/* SPDX-License-Identifier: BSD-3-Clause */
2
/*
3
* Copyright (c) 1982, 1986, 1993
4
* The Regents of the University of California. All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of the University nor the names of its contributors
15
* may be used to endorse or promote products derived from this software
16
* without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
* SUCH DAMAGE.
29
*
30
* @(#)ip.h 8.1 (Berkeley) 6/10/93
31
* ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
32
*/
33
34
#ifndef IP_H
35
#define IP_H
36
37
#include <glib.h>
38
39
#if G_BYTE_ORDER == G_BIG_ENDIAN
40
#undef NTOHL
41
#undef NTOHS
42
#undef HTONL
43
#undef HTONS
44
#define NTOHL(d)
45
#define NTOHS(d)
46
#define HTONL(d)
47
#define HTONS(d)
48
#else
49
#ifndef NTOHL
50
#define NTOHL(d) ((d) = ntohl((d)))
51
#endif
52
#ifndef NTOHS
53
#define NTOHS(d) ((d) = ntohs((uint16_t)(d)))
54
#endif
55
#ifndef HTONL
56
#define HTONL(d) ((d) = htonl((d)))
57
#endif
58
#ifndef HTONS
59
#define HTONS(d) ((d) = htons((uint16_t)(d)))
60
#endif
61
#endif
62
63
typedef uint32_t n_long; /* long as received from the net */
64
65
/*
66
* Definitions for internet protocol version 4.
67
* Per RFC 791, September 1981.
68
*/
69
#define IPVERSION 4
70
71
#ifdef RSTSLIRP
72
73
/*
74
* Structure of an internet header, naked of options.
75
*/
76
SLIRP_PACKED_BEGIN
77
struct ip {
78
#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
79
uint8_t ip_v : 4, /* version */
80
ip_hl : 4; /* header length */
81
#else
82
uint8_t ip_hl : 4, /* header length */
83
ip_v : 4; /* version */
84
#endif
85
uint8_t ip_tos; /* type of service */
86
uint16_t ip_len; /* total length */
87
uint16_t ip_id; /* identification */
88
uint16_t ip_off; /* fragment offset field */
89
#define IP_DF 0x4000 /* don't fragment flag */
90
#define IP_MF 0x2000 /* more fragments flag */
91
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
92
uint8_t ip_ttl; /* time to live */
93
uint8_t ip_p; /* protocol */
94
uint16_t ip_sum; /* checksum */
95
struct in_addr ip_src, ip_dst; /* source and dest address */
96
} SLIRP_PACKED_END;
97
98
#endif
99
100
#define IP_MAXPACKET 65535 /* maximum packet size */
101
102
/*
103
* Definitions for IP type of service (ip_tos)
104
*/
105
#define IPTOS_LOWDELAY 0x10
106
#define IPTOS_THROUGHPUT 0x08
107
#define IPTOS_RELIABILITY 0x04
108
109
/*
110
* Definitions for options.
111
*/
112
#define IPOPT_COPIED(o) ((o)&0x80)
113
#define IPOPT_CLASS(o) ((o)&0x60)
114
#define IPOPT_NUMBER(o) ((o)&0x1f)
115
116
#define IPOPT_CONTROL 0x00
117
#define IPOPT_RESERVED1 0x20
118
#define IPOPT_DEBMEAS 0x40
119
#define IPOPT_RESERVED2 0x60
120
121
#define IPOPT_EOL 0 /* end of option list */
122
#define IPOPT_NOP 1 /* no operation */
123
124
#define IPOPT_RR 7 /* record packet route */
125
#define IPOPT_TS 68 /* timestamp */
126
#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
127
#define IPOPT_LSRR 131 /* loose source route */
128
#define IPOPT_SATID 136 /* satnet id */
129
#define IPOPT_SSRR 137 /* strict source route */
130
131
/*
132
* Offsets to fields in options other than EOL and NOP.
133
*/
134
#define IPOPT_OPTVAL 0 /* option ID */
135
#define IPOPT_OLEN 1 /* option length */
136
#define IPOPT_OFFSET 2 /* offset within option */
137
#define IPOPT_MINOFF 4 /* min value of above */
138
139
#ifdef RSTSLIRP
140
141
/*
142
* Time stamp option structure.
143
*/
144
SLIRP_PACKED_BEGIN
145
struct ip_timestamp {
146
uint8_t ipt_code; /* IPOPT_TS */
147
uint8_t ipt_len; /* size of structure (variable) */
148
uint8_t ipt_ptr; /* index of current entry */
149
#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
150
uint8_t ipt_oflw : 4, /* overflow counter */
151
ipt_flg : 4; /* flags, see below */
152
#else
153
uint8_t ipt_flg : 4, /* flags, see below */
154
ipt_oflw : 4; /* overflow counter */
155
#endif
156
union ipt_timestamp {
157
n_long ipt_time[1];
158
struct ipt_ta {
159
struct in_addr ipt_addr;
160
n_long ipt_time;
161
} ipt_ta[1];
162
} ipt_timestamp;
163
} SLIRP_PACKED_END;
164
165
#endif
166
167
/* flag bits for ipt_flg */
168
#define IPOPT_TS_TSONLY 0 /* timestamps only */
169
#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
170
#define IPOPT_TS_PRESPEC 3 /* specified modules only */
171
172
/* bits for security (not byte swapped) */
173
#define IPOPT_SECUR_UNCLASS 0x0000
174
#define IPOPT_SECUR_CONFID 0xf135
175
#define IPOPT_SECUR_EFTO 0x789a
176
#define IPOPT_SECUR_MMMM 0xbc4d
177
#define IPOPT_SECUR_RESTR 0xaf13
178
#define IPOPT_SECUR_SECRET 0xd788
179
#define IPOPT_SECUR_TOPSECRET 0x6bc5
180
181
/*
182
* Internet implementation parameters.
183
*/
184
#define MAXTTL 255 /* maximum time to live (seconds) */
185
#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
186
#define IPFRAGTTL 60 /* time to live for frags, slowhz */
187
#define IPTTLDEC 1 /* subtracted when forwarding */
188
189
#define IP_MSS 576 /* default maximum segment size */
190
191
#if GLIB_SIZEOF_VOID_P == 4
192
SLIRP_PACKED_BEGIN
193
struct mbuf_ptr {
194
struct mbuf *mptr;
195
uint32_t dummy;
196
} SLIRP_PACKED_END;
197
#else
198
SLIRP_PACKED_BEGIN
199
struct mbuf_ptr {
200
struct mbuf *mptr;
201
} SLIRP_PACKED_END;
202
#endif
203
struct qlink {
204
void *next, *prev;
205
};
206
207
/*
208
* Overlay for ip header used by other protocols (tcp, udp).
209
*/
210
SLIRP_PACKED_BEGIN
211
struct ipovly {
212
struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */
213
uint8_t ih_x1; /* (unused) */
214
uint8_t ih_pr; /* protocol */
215
uint16_t ih_len; /* protocol length */
216
struct in_addr ih_src; /* source internet address */
217
struct in_addr ih_dst; /* destination internet address */
218
} SLIRP_PACKED_END;
219
220
/*
221
* Ip reassembly queue structure. Each fragment
222
* being reassembled is attached to one of these structures.
223
* They are timed out after ipq_ttl drops to 0, and may also
224
* be reclaimed if memory becomes tight.
225
*/
226
struct ipq {
227
struct qlink ip_link; /* to other reass headers */
228
uint8_t ipq_ttl; /* time for reass q to live */
229
uint8_t ipq_p; /* protocol of this fragment */
230
uint16_t ipq_id; /* sequence id for reassembly */
231
struct in_addr ipq_src, ipq_dst;
232
};
233
234
struct ipas {
235
struct qlink link;
236
union {
237
struct ipq ipq;
238
struct ip ipf_ip;
239
};
240
};
241
242
#define ipf_off ipf_ip.ip_off
243
#define ipf_tos ipf_ip.ip_tos
244
#define ipf_len ipf_ip.ip_len
245
246
#endif
247
248