]>
Commit | Line | Data |
---|---|---|
f0cbd3ec FB |
1 | #ifndef __COMMON_H__ |
2 | #define __COMMON_H__ | |
3 | ||
5fa0ab8f | 4 | #include "config-host.h" |
f0cbd3ec FB |
5 | #include "slirp_config.h" |
6 | ||
379ff53d FB |
7 | #ifdef _WIN32 |
8 | # include <inttypes.h> | |
9 | ||
379ff53d FB |
10 | typedef char *caddr_t; |
11 | ||
34444131 | 12 | # include <windows.h> |
379ff53d | 13 | # include <winsock2.h> |
116842ee | 14 | # include <ws2tcpip.h> |
379ff53d FB |
15 | # include <sys/timeb.h> |
16 | # include <iphlpapi.h> | |
17 | ||
379ff53d FB |
18 | #else |
19 | # define ioctlsocket ioctl | |
20 | # define closesocket(s) close(s) | |
4a2b39d3 AF |
21 | # if !defined(__HAIKU__) |
22 | # define O_BINARY 0 | |
23 | # endif | |
379ff53d FB |
24 | #endif |
25 | ||
f0cbd3ec FB |
26 | #include <sys/types.h> |
27 | #ifdef HAVE_SYS_BITYPES_H | |
28 | # include <sys/bitypes.h> | |
29 | #endif | |
30 | ||
170c6f87 FB |
31 | #include <sys/time.h> |
32 | ||
f0cbd3ec FB |
33 | #ifdef HAVE_UNISTD_H |
34 | # include <unistd.h> | |
35 | #endif | |
36 | ||
37 | #ifdef HAVE_STDLIB_H | |
38 | # include <stdlib.h> | |
39 | #endif | |
40 | ||
41 | #include <stdio.h> | |
42 | #include <errno.h> | |
43 | ||
44 | #ifndef HAVE_MEMMOVE | |
45 | #define memmove(x, y, z) bcopy(y, x, z) | |
46 | #endif | |
47 | ||
48 | #if TIME_WITH_SYS_TIME | |
49 | # include <sys/time.h> | |
50 | # include <time.h> | |
51 | #else | |
eb38c52c | 52 | # ifdef HAVE_SYS_TIME_H |
f0cbd3ec FB |
53 | # include <sys/time.h> |
54 | # else | |
55 | # include <time.h> | |
56 | # endif | |
57 | #endif | |
58 | ||
59 | #ifdef HAVE_STRING_H | |
60 | # include <string.h> | |
61 | #else | |
62 | # include <strings.h> | |
63 | #endif | |
64 | ||
379ff53d | 65 | #ifndef _WIN32 |
f0cbd3ec | 66 | #include <sys/uio.h> |
379ff53d | 67 | #endif |
f0cbd3ec | 68 | |
379ff53d | 69 | #ifndef _WIN32 |
f0cbd3ec FB |
70 | #include <netinet/in.h> |
71 | #include <arpa/inet.h> | |
379ff53d | 72 | #endif |
f0cbd3ec | 73 | |
f0cbd3ec FB |
74 | /* Systems lacking strdup() definition in <string.h>. */ |
75 | #if defined(ultrix) | |
6cb9c6d3 | 76 | char *strdup(const char *); |
f0cbd3ec FB |
77 | #endif |
78 | ||
79 | /* Systems lacking malloc() definition in <stdlib.h>. */ | |
80 | #if defined(ultrix) || defined(hcx) | |
6cb9c6d3 BS |
81 | void *malloc(size_t arg); |
82 | void free(void *ptr); | |
f0cbd3ec FB |
83 | #endif |
84 | ||
f0cbd3ec FB |
85 | #include <fcntl.h> |
86 | #ifndef NO_UNIX_SOCKETS | |
87 | #include <sys/un.h> | |
88 | #endif | |
89 | #include <signal.h> | |
90 | #ifdef HAVE_SYS_SIGNAL_H | |
91 | # include <sys/signal.h> | |
92 | #endif | |
379ff53d | 93 | #ifndef _WIN32 |
f0cbd3ec | 94 | #include <sys/socket.h> |
379ff53d | 95 | #endif |
f0cbd3ec | 96 | |
ee2654ac | 97 | #if defined(HAVE_SYS_IOCTL_H) |
f0cbd3ec | 98 | # include <sys/ioctl.h> |
f0cbd3ec FB |
99 | #endif |
100 | ||
f0cbd3ec FB |
101 | #ifdef HAVE_SYS_SELECT_H |
102 | # include <sys/select.h> | |
103 | #endif | |
104 | ||
105 | #ifdef HAVE_SYS_WAIT_H | |
106 | # include <sys/wait.h> | |
107 | #endif | |
108 | ||
109 | #ifdef HAVE_SYS_FILIO_H | |
110 | # include <sys/filio.h> | |
111 | #endif | |
112 | ||
113 | #ifdef USE_PPP | |
114 | #include <ppp/slirppp.h> | |
115 | #endif | |
116 | ||
117 | #ifdef __STDC__ | |
118 | #include <stdarg.h> | |
119 | #else | |
120 | #include <varargs.h> | |
121 | #endif | |
122 | ||
123 | #include <sys/stat.h> | |
124 | ||
125 | /* Avoid conflicting with the libc insque() and remque(), which | |
126 | have different prototypes. */ | |
127 | #define insque slirp_insque | |
128 | #define remque slirp_remque | |
129 | ||
130 | #ifdef HAVE_SYS_STROPTS_H | |
131 | #include <sys/stropts.h> | |
132 | #endif | |
133 | ||
134 | #include "debug.h" | |
135 | ||
1de7afc9 PB |
136 | #include "qemu/queue.h" |
137 | #include "qemu/sockets.h" | |
9c7ffe26 | 138 | #include "net/eth.h" |
b1c99fcd | 139 | |
460fec67 | 140 | #include "libslirp.h" |
f0cbd3ec FB |
141 | #include "ip.h" |
142 | #include "tcp.h" | |
143 | #include "tcp_timer.h" | |
144 | #include "tcp_var.h" | |
145 | #include "tcpip.h" | |
146 | #include "udp.h" | |
e6d43cfb | 147 | #include "ip_icmp.h" |
f0cbd3ec FB |
148 | #include "mbuf.h" |
149 | #include "sbuf.h" | |
150 | #include "socket.h" | |
151 | #include "if.h" | |
152 | #include "main.h" | |
153 | #include "misc.h" | |
f0cbd3ec FB |
154 | #ifdef USE_PPP |
155 | #include "ppp/pppd.h" | |
156 | #include "ppp/ppp.h" | |
157 | #endif | |
158 | ||
159 | #include "bootp.h" | |
c7f74643 | 160 | #include "tftp.h" |
460fec67 | 161 | |
1a0ca1e1 FC |
162 | #define ARPOP_REQUEST 1 /* ARP request */ |
163 | #define ARPOP_REPLY 2 /* ARP reply */ | |
164 | ||
165 | struct ethhdr { | |
166 | unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ | |
167 | unsigned char h_source[ETH_ALEN]; /* source ether addr */ | |
168 | unsigned short h_proto; /* packet type ID field */ | |
169 | }; | |
170 | ||
171 | struct arphdr { | |
172 | unsigned short ar_hrd; /* format of hardware address */ | |
173 | unsigned short ar_pro; /* format of protocol address */ | |
174 | unsigned char ar_hln; /* length of hardware address */ | |
175 | unsigned char ar_pln; /* length of protocol address */ | |
176 | unsigned short ar_op; /* ARP opcode (command) */ | |
177 | ||
178 | /* | |
179 | * Ethernet looks like this : This bit is variable sized however... | |
180 | */ | |
181 | unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ | |
182 | uint32_t ar_sip; /* sender IP address */ | |
183 | unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ | |
184 | uint32_t ar_tip; /* target IP address */ | |
541dc0d4 | 185 | } QEMU_PACKED; |
1a0ca1e1 FC |
186 | |
187 | #define ARP_TABLE_SIZE 16 | |
188 | ||
189 | typedef struct ArpTable { | |
190 | struct arphdr table[ARP_TABLE_SIZE]; | |
191 | int next_victim; | |
192 | } ArpTable; | |
193 | ||
5a371a2e | 194 | void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]); |
1a0ca1e1 | 195 | |
5a371a2e | 196 | bool arp_table_search(Slirp *slirp, uint32_t ip_addr, |
1a0ca1e1 | 197 | uint8_t out_ethaddr[ETH_ALEN]); |
40ff6d7e | 198 | |
460fec67 | 199 | struct Slirp { |
72cf2d4f | 200 | QTAILQ_ENTRY(Slirp) entry; |
fe0ff43c LPF |
201 | u_int time_fasttimo; |
202 | u_int last_slowtimo; | |
203 | bool do_slowtimo; | |
b1c99fcd | 204 | |
460fec67 JK |
205 | /* virtual network configuration */ |
206 | struct in_addr vnetwork_addr; | |
207 | struct in_addr vnetwork_mask; | |
208 | struct in_addr vhost_addr; | |
209 | struct in_addr vdhcp_startaddr; | |
210 | struct in_addr vnameserver_addr; | |
211 | ||
460fec67 JK |
212 | struct in_addr client_ipaddr; |
213 | char client_hostname[33]; | |
214 | ||
215 | int restricted; | |
460fec67 JK |
216 | struct ex_list *exec_list; |
217 | ||
218 | /* mbuf states */ | |
219 | struct mbuf m_freelist, m_usedlist; | |
220 | int mbuf_alloced; | |
221 | ||
222 | /* if states */ | |
460fec67 JK |
223 | struct mbuf if_fastq; /* fast queue (for interactive data) */ |
224 | struct mbuf if_batchq; /* queue for non-interactive data */ | |
225 | struct mbuf *next_m; /* pointer to next mbuf to output */ | |
953e7f54 | 226 | bool if_start_busy; /* avoid if_start recursion */ |
460fec67 JK |
227 | |
228 | /* ip states */ | |
229 | struct ipq ipq; /* ip reass. queue */ | |
b6dce92e | 230 | uint16_t ip_id; /* ip packet ctr, for ids */ |
460fec67 JK |
231 | |
232 | /* bootp/dhcp states */ | |
233 | BOOTPClient bootp_clients[NB_BOOTP_CLIENTS]; | |
234 | char *bootp_filename; | |
63d2960b KS |
235 | size_t vdnssearch_len; |
236 | uint8_t *vdnssearch; | |
460fec67 JK |
237 | |
238 | /* tcp states */ | |
239 | struct socket tcb; | |
240 | struct socket *tcp_last_so; | |
241 | tcp_seq tcp_iss; /* tcp initial send seq # */ | |
b6dce92e | 242 | uint32_t tcp_now; /* for RFC 1323 timestamps */ |
460fec67 JK |
243 | |
244 | /* udp states */ | |
245 | struct socket udb; | |
246 | struct socket *udp_last_so; | |
247 | ||
e6d43cfb JK |
248 | /* icmp states */ |
249 | struct socket icmp; | |
250 | struct socket *icmp_last_so; | |
251 | ||
460fec67 JK |
252 | /* tftp states */ |
253 | char *tftp_prefix; | |
254 | struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX]; | |
255 | ||
1a0ca1e1 FC |
256 | ArpTable arp_table; |
257 | ||
9f8bd042 | 258 | void *opaque; |
460fec67 JK |
259 | }; |
260 | ||
ad0d8c4c | 261 | extern Slirp *slirp_instance; |
f0cbd3ec | 262 | |
f0cbd3ec FB |
263 | #ifndef NULL |
264 | #define NULL (void *)0 | |
265 | #endif | |
266 | ||
267 | #ifndef FULL_BOLT | |
6cb9c6d3 | 268 | void if_start(Slirp *); |
f0cbd3ec | 269 | #else |
6cb9c6d3 | 270 | void if_start(struct ttys *); |
f0cbd3ec FB |
271 | #endif |
272 | ||
f0cbd3ec | 273 | #ifndef HAVE_STRERROR |
64b85a8f | 274 | char *strerror(int error); |
f0cbd3ec FB |
275 | #endif |
276 | ||
277 | #ifndef HAVE_INDEX | |
6cb9c6d3 | 278 | char *index(const char *, int); |
f0cbd3ec FB |
279 | #endif |
280 | ||
281 | #ifndef HAVE_GETHOSTID | |
6cb9c6d3 | 282 | long gethostid(void); |
f0cbd3ec FB |
283 | #endif |
284 | ||
379ff53d | 285 | #ifndef _WIN32 |
f0cbd3ec | 286 | #include <netdb.h> |
379ff53d | 287 | #endif |
f0cbd3ec FB |
288 | |
289 | #define DEFAULT_BAUD 115200 | |
290 | ||
9634d903 BS |
291 | #define SO_OPTIONS DO_KEEPALIVE |
292 | #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL) | |
293 | ||
63d2960b KS |
294 | /* dnssearch.c */ |
295 | int translate_dnssearch(Slirp *s, const char ** names); | |
296 | ||
f0cbd3ec FB |
297 | /* cksum.c */ |
298 | int cksum(struct mbuf *m, int len); | |
299 | ||
300 | /* if.c */ | |
6cb9c6d3 BS |
301 | void if_init(Slirp *); |
302 | void if_output(struct socket *, struct mbuf *); | |
f0cbd3ec FB |
303 | |
304 | /* ip_input.c */ | |
6cb9c6d3 | 305 | void ip_init(Slirp *); |
a68adc22 | 306 | void ip_cleanup(Slirp *); |
6cb9c6d3 BS |
307 | void ip_input(struct mbuf *); |
308 | void ip_slowtimo(Slirp *); | |
309 | void ip_stripoptions(register struct mbuf *, struct mbuf *); | |
f0cbd3ec FB |
310 | |
311 | /* ip_output.c */ | |
6cb9c6d3 | 312 | int ip_output(struct socket *, struct mbuf *); |
f0cbd3ec FB |
313 | |
314 | /* tcp_input.c */ | |
6cb9c6d3 BS |
315 | void tcp_input(register struct mbuf *, int, struct socket *); |
316 | int tcp_mss(register struct tcpcb *, u_int); | |
f0cbd3ec FB |
317 | |
318 | /* tcp_output.c */ | |
6cb9c6d3 BS |
319 | int tcp_output(register struct tcpcb *); |
320 | void tcp_setpersist(register struct tcpcb *); | |
f0cbd3ec FB |
321 | |
322 | /* tcp_subr.c */ | |
6cb9c6d3 | 323 | void tcp_init(Slirp *); |
a68adc22 | 324 | void tcp_cleanup(Slirp *); |
6cb9c6d3 BS |
325 | void tcp_template(struct tcpcb *); |
326 | void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int); | |
327 | struct tcpcb * tcp_newtcpcb(struct socket *); | |
328 | struct tcpcb * tcp_close(register struct tcpcb *); | |
329 | void tcp_sockclosed(struct tcpcb *); | |
330 | int tcp_fconnect(struct socket *); | |
331 | void tcp_connect(struct socket *); | |
332 | int tcp_attach(struct socket *); | |
b6dce92e | 333 | uint8_t tcp_tos(struct socket *); |
6cb9c6d3 BS |
334 | int tcp_emu(struct socket *, struct mbuf *); |
335 | int tcp_ctl(struct socket *); | |
9fafc9ea | 336 | struct tcpcb *tcp_drop(struct tcpcb *tp, int err); |
f0cbd3ec FB |
337 | |
338 | #ifdef USE_PPP | |
339 | #define MIN_MRU MINMRU | |
340 | #define MAX_MRU MAXMRU | |
341 | #else | |
342 | #define MIN_MRU 128 | |
343 | #define MAX_MRU 16384 | |
344 | #endif | |
345 | ||
379ff53d FB |
346 | #ifndef _WIN32 |
347 | #define min(x,y) ((x) < (y) ? (x) : (y)) | |
348 | #define max(x,y) ((x) > (y) ? (x) : (y)) | |
349 | #endif | |
350 | ||
02d2c54c | 351 | #ifdef _WIN32 |
ef6ff6b7 | 352 | #undef errno |
02d2c54c FB |
353 | #define errno (WSAGetLastError()) |
354 | #endif | |
355 | ||
f0cbd3ec | 356 | #endif |