VirtualBox

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

Last change on this file since 28587 was 28480, checked in by vboxsync, 15 years ago

NAT: nuke dead code.

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