VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: libslirp.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * NAT - slirp interface.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef _LIBSLIRP_H
29#define _LIBSLIRP_H
30
31#ifdef RT_OS_WINDOWS
32# include <iprt/win/winsock2.h>
33# ifdef __cplusplus
34extern "C" {
35# endif
36int inet_aton(const char *cp, struct in_addr *ia);
37# ifdef __cplusplus
38}
39# endif
40#else
41# ifdef RT_OS_OS2 /* temporary workaround, see ticket #127 */
42# include <sys/time.h>
43# endif
44# include <sys/select.h>
45# include <poll.h>
46# include <arpa/inet.h>
47#endif
48
49#include <VBox/types.h>
50#include <iprt/req.h>
51
52typedef struct NATState *PNATState;
53struct mbuf;
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59int slirp_init(PNATState *, uint32_t, uint32_t, bool, bool, int, int, bool, void *);
60void slirp_register_statistics(PNATState pData, PPDMDRVINS pDrvIns);
61void slirp_deregister_statistics(PNATState pData, PPDMDRVINS pDrvIns);
62void slirp_term(PNATState);
63void slirp_link_up(PNATState);
64void slirp_link_down(PNATState);
65
66#if defined(RT_OS_WINDOWS)
67void slirp_select_fill(PNATState pData, int *pndfs);
68
69void slirp_select_poll(PNATState pData, int fTimeout);
70#else /* RT_OS_WINDOWS */
71void slirp_select_fill(PNATState pData, int *pnfds, struct pollfd *polls);
72void slirp_select_poll(PNATState pData, struct pollfd *polls, int ndfs);
73#endif /* !RT_OS_WINDOWS */
74
75void slirp_input(PNATState pData, struct mbuf *m, size_t cbBuf);
76
77/* you must provide the following functions: */
78void slirp_arm_fast_timer(void *pvUser);
79int slirp_can_output(void * pvUser);
80void slirp_output(void * pvUser, struct mbuf *m, const uint8_t *pkt, int pkt_len);
81void slirp_output_pending(void * pvUser);
82void slirp_urg_output(void *pvUser, struct mbuf *, const uint8_t *pu8Buf, int cb);
83void slirp_post_sent(PNATState pData, void *pvArg);
84
85int slirp_call(void *pvUser, PRTREQ *ppReq, RTMSINTERVAL cMillies,
86 unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
87
88int slirp_call_hostres(void *pvUser, PRTREQ *ppReq, RTMSINTERVAL cMillies,
89 unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
90
91
92void slirp_update_guest_addr_guess(PNATState pData, uint32_t guess, const char *msg);
93
94int slirp_add_redirect(PNATState pData, int is_udp, struct in_addr host_addr,
95 int host_port, struct in_addr guest_addr,
96 int guest_port);
97int slirp_remove_redirect(PNATState pData, int is_udp, struct in_addr host_addr,
98 int host_port, struct in_addr guest_addr,
99 int guest_port);
100int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
101 int guest_port);
102
103void slirp_set_dhcp_TFTP_prefix(PNATState pData, const char *tftpPrefix);
104void slirp_set_dhcp_TFTP_bootfile(PNATState pData, const char *bootFile);
105void slirp_set_dhcp_next_server(PNATState pData, const char *nextServer);
106void slirp_set_dhcp_dns_proxy(PNATState pData, bool fDNSProxy);
107void slirp_set_rcvbuf(PNATState pData, int kilobytes);
108void slirp_set_sndbuf(PNATState pData, int kilobytes);
109void slirp_set_tcp_rcvspace(PNATState pData, int kilobytes);
110void slirp_set_tcp_sndspace(PNATState pData, int kilobytes);
111
112int slirp_set_binding_address(PNATState, char *addr);
113void slirp_set_mtu(PNATState, int);
114void slirp_info(PNATState pData, const void *pvArg, const char *pszArgs);
115void slirp_set_somaxconn(PNATState pData, int iSoMaxConn);
116
117/**
118 * This macrodefinition is shortcut for check of hosts where Slirp,
119 * receives notifications from host. For now it's Darwin only. But
120 * Main API has primitives for listening DNS change event since 4.3.
121 */
122#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
123# define HAVE_NOTIFICATION_FOR_DNS_UPDATE 1
124#else
125# define HAVE_NOTIFICATION_FOR_DNS_UPDATE 0
126#endif
127
128
129/**
130 * This method help DrvNAT to select strategy: about VMRESUMEREASON_HOST_RESUME:
131 * - proceed with link termination (we let guest track host DNS settings)
132 * VBOX_NAT_DNS_EXTERNAL
133 * - enforce internal DNS update (we are using dnsproxy and track but don't export DNS host settings)
134 * VBOX_NAT_DNS_DNSPROXY
135 * - ignore (NAT configured to use hostresolver - we aren't track any host DNS changes)
136 * VBOX_NAT_DNS_HOSTRESOLVER
137 * @note: It's safe to call this method from any thread, because settings we're checking
138 * are immutable at runtime.
139 */
140#define VBOX_NAT_DNS_EXTERNAL 0
141#define VBOX_NAT_DNS_DNSPROXY 1
142#define VBOX_NAT_DNS_HOSTRESOLVER 2
143int slirp_host_network_configuration_change_strategy_selector(const PNATState);
144#if defined(RT_OS_WINDOWS)
145
146
147/*
148 * ICMP handle state change
149 */
150# define VBOX_ICMP_EVENT_INDEX 0
151
152/**
153 * This event is for
154 * - slirp_input
155 * - slirp_link_up
156 * - slirp_link_down
157 * - wakeup
158 */
159# define VBOX_WAKEUP_EVENT_INDEX 1
160
161/*
162 * UDP/TCP socket state change (socket ready to receive, to send, ...)
163 */
164# define VBOX_SOCKET_EVENT_INDEX 2
165
166/*
167 * The number of events for WSAWaitForMultipleEvents().
168 */
169# define VBOX_EVENT_COUNT 3
170
171HANDLE *slirp_get_events(PNATState pData);
172void slirp_register_external_event(PNATState pData, HANDLE hEvent, int index);
173#endif /* RT_OS_WINDOWS */
174
175struct mbuf *slirp_ext_m_get(PNATState pData, size_t cbMin, void **ppvBuf, size_t *pcbBuf);
176void slirp_ext_m_free(PNATState pData, struct mbuf *, uint8_t *pu8Buf);
177
178/*
179 * Returns the timeout.
180 */
181unsigned int slirp_get_timeout_ms(PNATState pData);
182
183# ifndef RT_OS_WINDOWS
184/*
185 * Returns the number of sockets.
186 */
187int slirp_get_nsock(PNATState pData);
188# endif
189
190#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
191void slirp_add_host_resolver_mapping(PNATState pData,
192 const char *pszHostName, bool fPattern,
193 uint32_t u32HostIP);
194#endif
195
196#ifdef __cplusplus
197}
198#endif
199
200#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use