VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/slirp.h@ 35346

Last change on this file since 35346 was 35346, checked in by vboxsync, 14 years ago

VMM reorg: Moving the public include files from include/VBox to include/VBox/vmm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1/* $Id: slirp.h 35346 2010-12-27 16:13:13Z vboxsync $ */
2/** @file
3 * NAT - slirp (declarations/defines).
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef __COMMON_H__
19#define __COMMON_H__
20
21#include <VBox/vmm/stam.h>
22
23#ifdef RT_OS_WINDOWS
24# include <winsock2.h>
25# include <ws2tcpip.h>
26typedef int socklen_t;
27#endif
28#ifdef RT_OS_OS2 /* temporary workaround, see ticket #127 */
29# define mbstat mbstat_os2
30# include <sys/socket.h>
31# undef mbstat
32typedef int socklen_t;
33#endif
34
35#define CONFIG_QEMU
36
37#ifdef DEBUG
38# undef DEBUG
39# define DEBUG 1
40#endif
41
42#ifndef CONFIG_QEMU
43# include "version.h"
44#endif
45#define LOG_GROUP LOG_GROUP_DRV_NAT
46#include <VBox/log.h>
47#include <iprt/mem.h>
48#ifdef RT_OS_WINDOWS
49# include <windows.h>
50# include <io.h>
51#endif
52#include <iprt/asm.h>
53#include <iprt/assert.h>
54#include <iprt/string.h>
55#include <iprt/dir.h>
56#include <iprt/rand.h>
57#include <VBox/types.h>
58
59#undef malloc
60#define malloc dont_use_malloc
61#undef free
62#define free dont_use_free
63#undef realloc
64#define realloc dont_use_realloc
65#undef strdup
66#define strdup dont_use_strdup
67
68#include "slirp_config.h"
69
70#ifdef RT_OS_WINDOWS
71
72# ifndef _MSC_VER
73# include <inttypes.h>
74# endif
75
76
77# include <sys/timeb.h>
78# include <iphlpapi.h>
79
80/* We don't want the errno.h versions of these error defines. */
81# if defined(_MSC_VER) && _MSC_VER >= 1600
82# include <errno.h>
83# undef EWOULDBLOCK
84# undef EINPROGRESS
85# undef ENOTCONN
86# undef EHOSTUNREACH
87# undef ENETUNREACH
88# undef ECONNREFUSED
89# endif
90# define EWOULDBLOCK WSAEWOULDBLOCK
91# define EINPROGRESS WSAEINPROGRESS
92# define ENOTCONN WSAENOTCONN
93# define EHOSTUNREACH WSAEHOSTUNREACH
94# define ENETUNREACH WSAENETUNREACH
95# define ECONNREFUSED WSAECONNREFUSED
96
97typedef uint8_t u_int8_t;
98typedef uint16_t u_int16_t;
99typedef uint32_t u_int32_t;
100
101#else /* !RT_OS_WINDOWS */
102
103# define ioctlsocket ioctl
104# define closesocket(s) close(s)
105# define O_BINARY 0
106
107#endif /* !RT_OS_WINDOWS */
108
109#if defined(RT_OS_WINDOWS) || defined (RT_OS_SOLARIS)
110typedef uint64_t u_int64_t;
111typedef char *caddr_t;
112#endif
113
114#include <sys/types.h>
115#ifdef HAVE_SYS_BITYPES_H
116# include <sys/bitypes.h>
117#endif
118
119#ifdef _MSC_VER
120# include <time.h>
121#else /* !_MSC_VER */
122# include <sys/time.h>
123#endif /* !_MSC_VER */
124
125#ifdef NEED_TYPEDEFS
126typedef char int8_t;
127typedef unsigned char u_int8_t;
128
129# if SIZEOF_SHORT == 2
130 typedef short int16_t;
131 typedef unsigned short u_int16_t;
132# else
133# if SIZEOF_INT == 2
134 typedef int int16_t;
135 typedef unsigned int u_int16_t;
136# else
137 #error Cannot find a type with sizeof() == 2
138# endif
139# endif
140
141# if SIZEOF_SHORT == 4
142 typedef short int32_t;
143 typedef unsigned short u_int32_t;
144# else
145# if SIZEOF_INT == 4
146 typedef int int32_t;
147 typedef unsigned int u_int32_t;
148# else
149 #error Cannot find a type with sizeof() == 4
150# endif
151# endif
152#endif /* NEED_TYPEDEFS */
153
154#ifdef HAVE_UNISTD_H
155# include <unistd.h>
156#endif
157
158#ifdef HAVE_STDLIB_H
159# include <stdlib.h>
160#endif
161
162#include <errno.h>
163
164
165#ifndef HAVE_MEMMOVE
166# define memmove(x, y, z) bcopy(y, x, z)
167#endif
168
169#if TIME_WITH_SYS_TIME
170# include <sys/time.h>
171# include <time.h>
172#else
173# if HAVE_SYS_TIME_H
174# include <sys/time.h>
175# else
176# include <time.h>
177# endif
178#endif
179
180#ifdef HAVE_STRING_H
181# include <string.h>
182#else
183# include <strings.h>
184#endif
185
186#ifndef RT_OS_WINDOWS
187# include <sys/uio.h>
188#endif
189
190#ifndef RT_OS_WINDOWS
191# include <netinet/in.h>
192# include <arpa/inet.h>
193#endif
194
195#ifdef GETTIMEOFDAY_ONE_ARG
196# define gettimeofday(x, y) gettimeofday(x)
197#endif
198
199#ifndef HAVE_INET_ATON
200int inet_aton (const char *cp, struct in_addr *ia);
201#endif
202
203#include <fcntl.h>
204#ifndef NO_UNIX_SOCKETS
205# include <sys/un.h>
206#endif
207#include <signal.h>
208#ifdef HAVE_SYS_SIGNAL_H
209# include <sys/signal.h>
210#endif
211#ifndef RT_OS_WINDOWS
212# include <sys/socket.h>
213#endif
214
215#if defined(HAVE_SYS_IOCTL_H)
216# include <sys/ioctl.h>
217#endif
218
219#ifdef HAVE_SYS_SELECT_H
220# include <sys/select.h>
221#endif
222
223#ifdef HAVE_SYS_WAIT_H
224# include <sys/wait.h>
225#endif
226
227#ifdef HAVE_SYS_FILIO_H
228# include <sys/filio.h>
229#endif
230
231#if defined(__STDC__) || defined(_MSC_VER)
232# include <stdarg.h>
233#else
234# include <varargs.h>
235#endif
236
237#include <sys/stat.h>
238
239/* Avoid conflicting with the libc insque() and remque(), which
240 * have different prototypes. */
241#define insque slirp_insque
242#define remque slirp_remque
243
244#ifdef HAVE_SYS_STROPTS_H
245# include <sys/stropts.h>
246#endif
247
248#include "libslirp.h"
249
250#include "debug.h"
251
252#include "ip.h"
253#include "tcp.h"
254#include "tcp_timer.h"
255#include "tcp_var.h"
256#include "tcpip.h"
257#include "udp.h"
258#include "icmp_var.h"
259#include "mbuf.h"
260#include "if.h"
261#include "sbuf.h"
262#include "socket.h"
263#include "main.h"
264#include "misc.h"
265#include "ctl.h"
266#include "bootp.h"
267#include "tftp.h"
268
269#include "slirp_state.h"
270
271#undef PVM /* XXX Mac OS X hack */
272
273#ifndef NULL
274# define NULL (void *)0
275#endif
276
277void if_start (PNATState);
278
279#ifndef HAVE_INDEX
280 char *index (const char *, int);
281#endif
282
283#ifndef HAVE_GETHOSTID
284 long gethostid (void);
285#endif
286
287#ifndef RT_OS_WINDOWS
288#include <netdb.h>
289#endif
290
291#include "dnsproxy/dnsproxy.h"
292
293#define DEFAULT_BAUD 115200
294
295int get_dns_addr(PNATState pData, struct in_addr *pdns_addr);
296
297/* cksum.c */
298typedef uint16_t u_short;
299typedef unsigned int u_int;
300#include "in_cksum.h"
301
302/* if.c */
303void if_init (PNATState);
304void if_output (PNATState, struct socket *, struct mbuf *);
305
306/* ip_input.c */
307void ip_init (PNATState);
308void ip_input (PNATState, struct mbuf *);
309struct mbuf * ip_reass (PNATState, register struct mbuf *);
310void ip_freef (PNATState, struct ipqhead *, struct ipq_t *);
311void ip_slowtimo (PNATState);
312void ip_stripoptions (register struct mbuf *, struct mbuf *);
313
314/* ip_output.c */
315int ip_output (PNATState, struct socket *, struct mbuf *);
316int ip_output0 (PNATState, struct socket *, struct mbuf *, int urg);
317
318/* tcp_input.c */
319int tcp_reass (PNATState, struct tcpcb *, struct tcphdr *, int *, struct mbuf *);
320void tcp_input (PNATState, register struct mbuf *, int, struct socket *);
321void tcp_dooptions (PNATState, struct tcpcb *, u_char *, int, struct tcpiphdr *);
322void tcp_xmit_timer (PNATState, register struct tcpcb *, int);
323int tcp_mss (PNATState, register struct tcpcb *, u_int);
324
325/* tcp_output.c */
326int tcp_output (PNATState, register struct tcpcb *);
327void tcp_setpersist (register struct tcpcb *);
328
329/* tcp_subr.c */
330void tcp_init (PNATState);
331void tcp_template (struct tcpcb *);
332void tcp_respond (PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
333struct tcpcb * tcp_newtcpcb (PNATState, struct socket *);
334struct tcpcb * tcp_close (PNATState, register struct tcpcb *);
335void tcp_drain (void);
336void tcp_sockclosed (PNATState, struct tcpcb *);
337int tcp_fconnect (PNATState, struct socket *);
338void tcp_connect (PNATState, struct socket *);
339int tcp_attach (PNATState, struct socket *);
340u_int8_t tcp_tos (struct socket *);
341int tcp_ctl (PNATState, struct socket *);
342struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err);
343
344/*slirp.c*/
345void slirp_arp_who_has(PNATState pData, uint32_t dst);
346int slirp_arp_cache_update(PNATState pData, uint32_t dst, const uint8_t *mac);
347void slirp_arp_cache_add(PNATState pData, uint32_t ip, const uint8_t *ether);
348int slirp_arp_cache_update_or_add(PNATState pData, uint32_t dst, const uint8_t *mac);
349int slirp_init_dns_list(PNATState pData);
350void slirp_release_dns_list(PNATState pData);
351#define MIN_MRU 128
352#define MAX_MRU 16384
353
354#ifndef RT_OS_WINDOWS
355# define min(x, y) ((x) < (y) ? (x) : (y))
356# define max(x, y) ((x) > (y) ? (x) : (y))
357#endif
358
359#ifdef RT_OS_WINDOWS
360# undef errno
361# if 0 /* debugging */
362int errno_func(const char *file, int line);
363# define errno (errno_func(__FILE__, __LINE__))
364# else
365# define errno (WSAGetLastError())
366# endif
367#endif
368
369# define ETH_ALEN 6
370# define ETH_HLEN 14
371
372# define ARPOP_REQUEST 1 /* ARP request */
373# define ARPOP_REPLY 2 /* ARP reply */
374
375struct ethhdr
376{
377 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
378 unsigned char h_source[ETH_ALEN]; /* source ether addr */
379 unsigned short h_proto; /* packet type ID field */
380};
381AssertCompileSize(struct ethhdr, 14);
382
383/*
384 * (vvl) externing of sscanf.
385 */
386int sscanf(const char *s, const char *format, ...);
387
388#if defined(VBOX_SLIRP_ALIAS) || defined(VBOX_SLIRP_BSD)
389
390# define ip_next(ip) (void *)((uint8_t *)(ip) + ((ip)->ip_hl << 2))
391# define udp_next(udp) (void *)((uint8_t *)&((struct udphdr *)(udp))[1])
392# define bcopy(src, dst, len) memcpy((dst), (src), (len))
393# define bcmp(a1, a2, len) memcmp((a1), (a2), (len))
394# define NO_FW_PUNCH
395
396# ifdef alias_addr
397# ifndef VBOX_SLIRP_BSD
398# error alias_addr has already defined!!!
399# else
400# undef alias_addr
401# endif
402# endif
403
404# define arc4random() RTRandU32()
405# undef malloc
406# undef calloc
407# undef free
408# define malloc(x) RTMemAlloc((x))
409# define calloc(x, n) RTMemAllocZ((x)*(n))
410# define free(x) RTMemFree((x))
411# ifndef __unused
412# define __unused
413# endif
414
415# define strncasecmp RTStrNICmp
416# define stderr NULL
417# define stdout NULL
418
419# ifdef VBOX_WITH_DEBUG_LIBALIAS
420# define LIBALIAS_DEBUG
421# endif
422
423# define fflush(x) do{} while(0)
424# include "ext.h"
425#endif /*VBOX_SLIRP_ALIAS*/
426
427/**
428 * @todo might be useful to make it configurable, especially in terms of Intnet behind NAT
429 */
430# define maxusers 32
431# define max_protohdr 0
432/**
433 * @todo (vvl) for now ignore these values, later perhaps initialize tuning parameters
434 */
435# define TUNABLE_INT_FETCH(name, pval) do { } while (0)
436# define SYSCTL_PROC(a0, a1, a2, a3, a4, a5, a6, a7, a8) const int dummy_ ## a6 = 0
437# define SYSCTL_STRUCT(a0, a1, a2, a3, a4, a5, a6) const int dummy_ ## a5 = 0
438# define SYSINIT(a0, a1, a2, a3, a4) const int dummy_ ## a3 = 0
439# define sysctl_handle_int(a0, a1, a2, a3) 0
440# define EVENTHANDLER_INVOKE(a) do{}while(0)
441# define EVENTHANDLER_REGISTER(a0, a1, a2, a3) do{}while(0)
442# define KASSERT AssertMsg
443
444struct dummy_req
445{
446 void *newptr;
447};
448
449#define SYSCTL_HANDLER_ARGS PNATState pData, void *oidp, struct dummy_req *req
450
451void mbuf_init(void *);
452# define cksum(m, len) in_cksum_skip((m), (len), 0)
453
454int ftp_alias_load(PNATState);
455int ftp_alias_unload(PNATState);
456int nbt_alias_load(PNATState);
457int nbt_alias_unload(PNATState);
458int dns_alias_load(PNATState);
459int dns_alias_unload(PNATState);
460int slirp_arp_lookup_ip_by_ether(PNATState, const uint8_t *, uint32_t *);
461int slirp_arp_lookup_ether_by_ip(PNATState, uint32_t, uint8_t *);
462
463static inline size_t slirp_size(PNATState pData)
464{
465 if (if_mtu < MSIZE)
466 return MCLBYTES;
467 else if (if_mtu < MCLBYTES)
468 return MCLBYTES;
469 else if (if_mtu < MJUM9BYTES)
470 return MJUM9BYTES;
471 else if (if_mtu < MJUM16BYTES)
472 return MJUM16BYTES;
473 else
474 AssertMsgFailed(("Unsupported size"));
475 return 0;
476}
477#endif
478
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette