VirtualBox

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

Last change on this file since 59202 was 57784, checked in by vboxsync, 10 years ago

NAT: rewrite handling of port-forwarding.

The most interesting part is handling of wildcard guest address
(0.0.0.0) for which we are supposed to guess the real guest IP. For
TCP we delay the decision until new connection come and the we can use
the current guess for each new connection. For UDP things are
trickier. For now we set the current guess as the destination on
first incoming packet, but that doesn't handle changes of the guest
address or outgoing packets. This needs more thought.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: libslirp.h 57784 2015-09-16 15:36:31Z vboxsync $ */
2/** @file
3 * NAT - slirp interface.
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 _LIBSLIRP_H
19#define _LIBSLIRP_H
20
21#ifdef RT_OS_WINDOWS
22# include <winsock2.h>
23# ifdef __cplusplus
24extern "C" {
25# endif
26int inet_aton(const char *cp, struct in_addr *ia);
27# ifdef __cplusplus
28}
29# endif
30#else
31# ifdef RT_OS_OS2 /* temporary workaround, see ticket #127 */
32# include <sys/time.h>
33# endif
34# include <sys/select.h>
35# include <poll.h>
36# include <arpa/inet.h>
37#endif
38
39#include <VBox/types.h>
40
41typedef struct NATState *PNATState;
42struct mbuf;
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48int slirp_init(PNATState *, uint32_t, uint32_t, bool, bool, int, int, void *);
49void slirp_register_statistics(PNATState pData, PPDMDRVINS pDrvIns);
50void slirp_deregister_statistics(PNATState pData, PPDMDRVINS pDrvIns);
51void slirp_term(PNATState);
52void slirp_link_up(PNATState);
53void slirp_link_down(PNATState);
54
55#if defined(RT_OS_WINDOWS)
56void slirp_select_fill(PNATState pData, int *pndfs);
57
58void slirp_select_poll(PNATState pData, int fTimeout);
59#else /* RT_OS_WINDOWS */
60void slirp_select_fill(PNATState pData, int *pnfds, struct pollfd *polls);
61void slirp_select_poll(PNATState pData, struct pollfd *polls, int ndfs);
62#endif /* !RT_OS_WINDOWS */
63
64void slirp_input(PNATState pData, struct mbuf *m, size_t cbBuf);
65
66/* you must provide the following functions: */
67void slirp_arm_fast_timer(void *pvUser);
68int slirp_can_output(void * pvUser);
69void slirp_output(void * pvUser, struct mbuf *m, const uint8_t *pkt, int pkt_len);
70void slirp_output_pending(void * pvUser);
71void slirp_urg_output(void *pvUser, struct mbuf *, const uint8_t *pu8Buf, int cb);
72void slirp_post_sent(PNATState pData, void *pvArg);
73
74void slirp_update_guest_addr_guess(PNATState pData, uint32_t guess, const char *msg);
75
76int slirp_add_redirect(PNATState pData, int is_udp, struct in_addr host_addr,
77 int host_port, struct in_addr guest_addr,
78 int guest_port);
79int slirp_remove_redirect(PNATState pData, int is_udp, struct in_addr host_addr,
80 int host_port, struct in_addr guest_addr,
81 int guest_port);
82int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
83 int guest_port);
84
85void slirp_set_dhcp_TFTP_prefix(PNATState pData, const char *tftpPrefix);
86void slirp_set_dhcp_TFTP_bootfile(PNATState pData, const char *bootFile);
87void slirp_set_dhcp_next_server(PNATState pData, const char *nextServer);
88void slirp_set_dhcp_dns_proxy(PNATState pData, bool fDNSProxy);
89void slirp_set_rcvbuf(PNATState pData, int kilobytes);
90void slirp_set_sndbuf(PNATState pData, int kilobytes);
91void slirp_set_tcp_rcvspace(PNATState pData, int kilobytes);
92void slirp_set_tcp_sndspace(PNATState pData, int kilobytes);
93
94int slirp_set_binding_address(PNATState, char *addr);
95void slirp_set_mtu(PNATState, int);
96void slirp_info(PNATState pData, const void *pvArg, const char *pszArgs);
97void slirp_set_somaxconn(PNATState pData, int iSoMaxConn);
98
99/**
100 * This macrodefinition is shortcut for check of hosts where Slirp,
101 * receives notifications from host. For now it's Darwin only. But
102 * Main API has primitives for listening DNS change event since 4.3.
103 */
104#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
105# define HAVE_NOTIFICATION_FOR_DNS_UPDATE 1
106#else
107# define HAVE_NOTIFICATION_FOR_DNS_UPDATE 0
108#endif
109
110
111/**
112 * This method help DrvNAT to select strategy: about VMRESUMEREASON_HOST_RESUME:
113 * - proceed with link termination (we let guest track host DNS settings)
114 * VBOX_NAT_DNS_EXTERNAL
115 * - enforce internal DNS update (we are using dnsproxy and track but don't export DNS host settings)
116 * VBOX_NAT_DNS_DNSPROXY
117 * - ignore (NAT configured to use hostresolver - we aren't track any host DNS changes)
118 * VBOX_NAT_DNS_HOSTRESOLVER
119 * @note: It's safe to call this method from any thread, because settings we're checking
120 * are immutable at runtime.
121 */
122#define VBOX_NAT_DNS_EXTERNAL 0
123#define VBOX_NAT_DNS_DNSPROXY 1
124#define VBOX_NAT_DNS_HOSTRESOLVER 2
125int slirp_host_network_configuration_change_strategy_selector(const PNATState);
126#if defined(RT_OS_WINDOWS)
127
128
129/*
130 * ICMP handle state change
131 */
132# define VBOX_ICMP_EVENT_INDEX 0
133
134/**
135 * This event is for
136 * - slirp_input
137 * - slirp_link_up
138 * - slirp_link_down
139 * - wakeup
140 */
141# define VBOX_WAKEUP_EVENT_INDEX 1
142
143/*
144 * UDP/TCP socket state change (socket ready to receive, to send, ...)
145 */
146# define VBOX_SOCKET_EVENT_INDEX 2
147
148/*
149 * The number of events for WSAWaitForMultipleEvents().
150 */
151# define VBOX_EVENT_COUNT 3
152
153HANDLE *slirp_get_events(PNATState pData);
154void slirp_register_external_event(PNATState pData, HANDLE hEvent, int index);
155#endif /* RT_OS_WINDOWS */
156
157struct mbuf *slirp_ext_m_get(PNATState pData, size_t cbMin, void **ppvBuf, size_t *pcbBuf);
158void slirp_ext_m_free(PNATState pData, struct mbuf *, uint8_t *pu8Buf);
159
160/*
161 * Returns the timeout.
162 */
163unsigned int slirp_get_timeout_ms(PNATState pData);
164
165# ifndef RT_OS_WINDOWS
166/*
167 * Returns the number of sockets.
168 */
169int slirp_get_nsock(PNATState pData);
170# endif
171
172#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
173void slirp_add_host_resolver_mapping(PNATState pData, const char *pszHostName, const char *pszHostNamePattern, uint32_t u32HostIP);
174#endif
175
176#ifdef __cplusplus
177}
178#endif
179
180#endif
Note: See TracBrowser for help on using the repository browser.

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