VirtualBox

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

最後變更 在這個檔案從27843是 26404,由 vboxsync 提交於 15 年 前

NAT: applied patch from xtracker 3993 (use BSD mbufs)

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

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