VirtualBox

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

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

NAT: clean up.

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