VirtualBox

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

Last change on this file since 53310 was 53310, checked in by vboxsync, 11 years ago

NAT: We don't support Windows 2000, so use Windows ICMP API directly.
We have been using runtime lookup for some functions and direct calls
for some others which is inconsistent and proves "by construction"
that the indirection is not necessary.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 KB
Line 
1/** @file
2 * NAT - slirp state/configuration.
3 */
4
5/*
6 * Copyright (C) 2006-2012 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.215389.xyz. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___slirp_state_h
18#define ___slirp_state_h
19
20#include <iprt/req.h>
21#include <iprt/critsect.h>
22
23#define COUNTERS_INIT
24#include "counters.h"
25
26#include "ip_icmp.h"
27#include "dnsproxy/dnsproxy.h"
28
29
30/** Where to start DHCP IP number allocation. */
31#define START_ADDR 15
32
33/** DHCP Lease time. */
34#define LEASE_TIME (24 * 3600)
35
36/*
37 * ARP cache this is naive implementaion of ARP
38 * cache of mapping 4 byte IPv4 address to 6 byte
39 * ethernet one.
40 */
41struct arp_cache_entry
42{
43 uint32_t ip;
44 uint8_t ether[6];
45 LIST_ENTRY(arp_cache_entry) list;
46};
47LIST_HEAD(arp_cache_head, arp_cache_entry);
48
49/** TFTP session entry. */
50struct dns_domain_entry
51{
52 char *dd_pszDomain;
53 LIST_ENTRY(dns_domain_entry) dd_list;
54};
55LIST_HEAD(dns_domain_list_head, dns_domain_entry);
56
57#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
58typedef struct DNSMAPPINGENTRY
59{
60 /** host name to map.
61 * @note If pszCName isn't null pszPattern won't be used (see alias_dns.c for
62 * details).
63 */
64 char *pszCName;
65 /** Pattern (simple) of hostnames to map to the specified IP. */
66 char *pszPattern;
67 /** The IP Address. */
68 uint32_t u32IpAddress;
69 /** List entry. */
70 LIST_ENTRY(DNSMAPPINGENTRY) MapList;
71} DNSMAPPINGENTRY, *PDNSMAPPINGENTRY;
72typedef LIST_HEAD(DNSMAPPINGLISTHEAD, DNSMAPPINGENTRY) DNSMAPPINGLISTHEAD;
73#endif
74
75struct dns_entry
76{
77 struct in_addr de_addr;
78 TAILQ_ENTRY(dns_entry) de_list;
79};
80TAILQ_HEAD(dns_list_head, dns_entry);
81TAILQ_HEAD(if_queue, mbuf);
82
83struct port_forward_rule
84{
85 uint16_t proto;
86 uint16_t host_port;
87 uint16_t guest_port;
88 struct in_addr guest_addr;
89 struct in_addr bind_ip;
90 uint8_t mac_address[6]; /*need ETH_ALEN here */
91 int activated;
92 struct socket *so;
93 LIST_ENTRY(port_forward_rule) list;
94};
95LIST_HEAD(port_forward_rule_list, port_forward_rule);
96
97
98
99/* forward declaration */
100struct proto_handler;
101
102/** Main state/configuration structure for slirp NAT. */
103typedef struct NATState
104{
105#define PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name
106#define COUNTING_COUNTER(name, dsc) STAMCOUNTER Stat ## name
107#include "counters.h"
108 /* Stuff from boot.c */
109 void *pbootp_clients;
110 const char *bootp_filename;
111 /* Stuff from if.c */
112 int if_mtu, if_mru;
113 int if_comp;
114 int if_maxlinkhdr;
115 int if_queued;
116 int if_thresh;
117 /* Stuff from icmp.c */
118 struct icmpstat_t icmpstat;
119 /* Stuff from ip_input.c */
120 struct ipstat_t ipstat;
121 struct ipqhead ipq[IPREASS_NHASH];
122 int maxnipq; /* Administrative limit on # of reass queues*/
123 int maxfragsperpacket; /* Maximum number of IPv4 fragments allowed per packet */
124 int nipq; /* total number of reass queues */
125 uint16_t ip_currid;
126 /* Stuff from mbuf.c */
127 /* Stuff from slirp.c */
128 void *pvUser;
129 uint32_t curtime;
130 uint32_t time_fasttimo;
131 uint32_t last_slowtimo;
132 bool do_slowtimo;
133 bool link_up;
134 struct timeval tt;
135 struct in_addr our_addr;
136 struct in_addr alias_addr;
137 struct in_addr special_addr;
138
139 int tcp_rcvspace;
140 int tcp_sndspace;
141 int socket_rcv;
142 int socket_snd;
143 int soMaxConn;
144#ifdef RT_OS_WINDOWS
145 ULONG (WINAPI * pfGetAdaptersAddresses)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG);
146#endif
147 struct dns_list_head pDnsList;
148 struct dns_domain_list_head pDomainList;
149 struct in_addr tftp_server;
150 struct in_addr loopback_addr;
151 uint32_t dnsLastUpdate;
152 uint32_t netmask;
153#ifndef VBOX_WITH_NAT_SERVICE
154 uint8_t client_ethaddr[6];
155#endif
156 const uint8_t *slirp_ethaddr;
157 char slirp_hostname[33];
158 bool fPassDomain;
159 struct in_addr bindIP;
160 /* Stuff from tcp_input.c */
161 struct socket tcb;
162
163 struct socket *tcp_last_so;
164 tcp_seq tcp_iss;
165 /* Stuff from tcp_timer.c */
166 struct tcpstat_t tcpstat;
167 uint32_t tcp_now;
168 int tcp_reass_qsize;
169 int tcp_reass_maxqlen;
170 int tcp_reass_maxseg;
171 int tcp_reass_overflows;
172 /* Stuff from tftp.c */
173 void *pvTftpSessions;
174 int cTftpSession;
175 const char *tftp_prefix;
176 /* Stuff from udp.c */
177 struct udpstat_t udpstat;
178 struct socket udb;
179 struct socket *udp_last_so;
180 struct socket icmp_socket;
181 struct icmp_storage icmp_msg_head;
182# ifndef RT_OS_WINDOWS
183 /* counter of sockets needed for allocation enough room to
184 * process sockets with poll/epoll
185 *
186 * NSOCK_INC/DEC should be injected before every
187 * operation on socket queue (tcb, udb)
188 */
189 int nsock;
190# define NSOCK_INC() do {pData->nsock++;} while (0)
191# define NSOCK_DEC() do {pData->nsock--;} while (0)
192# define NSOCK_INC_EX(ex) do {ex->pData->nsock++;} while (0)
193# define NSOCK_DEC_EX(ex) do {ex->pData->nsock--;} while (0)
194# else
195# define NSOCK_INC() do {} while (0)
196# define NSOCK_DEC() do {} while (0)
197# define NSOCK_INC_EX(ex) do {} while (0)
198# define NSOCK_DEC_EX(ex) do {} while (0)
199# endif
200 int cIcmpCacheSize;
201 int iIcmpCacheLimit;
202# ifdef RT_OS_WINDOWS
203 void *pvIcmpBuffer;
204 uint32_t cbIcmpBuffer;
205# endif
206#if defined(RT_OS_WINDOWS)
207# define VBOX_SOCKET_EVENT (pData->phEvents[VBOX_SOCKET_EVENT_INDEX])
208 HANDLE phEvents[VBOX_EVENT_COUNT];
209#endif
210#ifdef zone_mbuf
211# undef zone_mbuf
212#endif
213 uma_zone_t zone_mbuf;
214#ifdef zone_clust
215# undef zone_clust
216#endif
217 uma_zone_t zone_clust;
218#ifdef zone_pack
219# undef zone_pack
220#endif
221 uma_zone_t zone_pack;
222#ifdef zone_jumbop
223# undef zone_jumbop
224#endif
225 uma_zone_t zone_jumbop;
226#ifdef zone_jumbo9
227# undef zone_jumbo9
228#endif
229 uma_zone_t zone_jumbo9;
230#ifdef zone_jumbo16
231# undef zone_jumbo16
232#endif
233 uma_zone_t zone_jumbo16;
234#ifdef zone_ext_refcnt
235# undef zone_ext_refcnt
236 int nmbclusters; /* limits number of mbuf clusters */
237 int nmbjumbop; /* limits number of page size jumbo clusters */
238 int nmbjumbo9; /* limits number of 9k jumbo clusters */
239 int nmbjumbo16; /* limits number of 16k jumbo clusters */
240 struct mbstat mbstat;
241#endif
242 uma_zone_t zone_ext_refcnt;
243 /**
244 * in (r89055) using of this behaviour has been changed and mean that Slirp
245 * can't parse hosts strucutures/files to provide to guest host name-resolving
246 * configuration, instead Slirp provides .{interface-number + 1}.3 as a nameserver
247 * and proxies DNS queiries to Host's Name Resolver API.
248 */
249 bool fUseHostResolver;
250 /**
251 * Flag whether using the host resolver mode is permanent
252 * because the user configured it that way.
253 */
254 bool fUseHostResolverPermanent;
255 /* from dnsproxy/dnsproxy.h*/
256 unsigned int authoritative_port;
257 unsigned int authoritative_timeout;
258 unsigned int recursive_port;
259 unsigned int recursive_timeout;
260 unsigned int stats_timeout;
261 unsigned int port;
262
263 unsigned long active_queries;
264 unsigned long all_queries;
265 unsigned long authoritative_queries;
266 unsigned long recursive_queries;
267 unsigned long removed_queries;
268 unsigned long dropped_queries;
269 unsigned long answered_queries;
270 unsigned long dropped_answers;
271 unsigned long late_answers;
272 unsigned long hash_collisions;
273 /*dnsproxy/dnsproxy.c*/
274 unsigned short queryid;
275 struct sockaddr_in authoritative_addr;
276 struct sockaddr_in recursive_addr;
277 int sock_query;
278 int sock_answer;
279 /* dnsproxy/hash.c */
280#define HASHSIZE 10
281#define HASH(id) (id & ((1 << HASHSIZE) - 1))
282 struct request *request_hash[1 << HASHSIZE];
283 /* this field control behaviour of DHCP server */
284 bool fUseDnsProxy;
285
286 LIST_HEAD(RT_NOTHING, libalias) instancehead;
287 int i32AliasMode;
288 struct libalias *proxy_alias;
289 LIST_HEAD(handler_chain, proto_handler) handler_chain;
290 /** Critical R/W section to protect the handler chain list. */
291 RTCRITSECTRW CsRwHandlerChain;
292 struct port_forward_rule_list port_forward_rule_head;
293 int cRedirectionsActive;
294 int cRedirectionsStored;
295 struct arp_cache_head arp_cache;
296 /* libalis modules' handlers*/
297 struct proto_handler *ftp_module;
298 struct proto_handler *nbt_module;
299 struct proto_handler *dns_module;
300#ifdef VBOX_WITH_NAT_SEND2HOME
301 /* array of home addresses */
302 struct sockaddr_in *pInSockAddrHomeAddress;
303 /* size of pInSockAddrHomeAddress in elements */
304 int cInHomeAddressSize;
305#endif
306#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
307 DNSMAPPINGLISTHEAD DNSMapHead;
308#endif
309} NATState;
310
311
312/** Default IP time to live. */
313#define ip_defttl IPDEFTTL
314
315/** Number of permanent buffers in mbuf. */
316#define mbuf_thresh 30
317
318/** Use a fixed time before sending keepalive. */
319#define tcp_keepidle TCPTV_KEEP_IDLE
320
321/** Use a fixed interval between keepalive. */
322#define tcp_keepintvl TCPTV_KEEPINTVL
323
324/** Maximum idle time before timing out a connection. */
325#define tcp_maxidle (TCPTV_KEEPCNT * tcp_keepintvl)
326
327/** Default TCP socket options. */
328#define so_options DO_KEEPALIVE
329
330/** Default TCP MSS value. */
331#define tcp_mssdflt TCP_MSS
332
333/** Default TCP round trip time. */
334#define tcp_rttdflt (TCPTV_SRTTDFLT / PR_SLOWHZ)
335
336/** Enable RFC1323 performance enhancements.
337 * @todo check if it really works, it was turned off before. */
338#define tcp_do_rfc1323 1
339
340/** TCP receive buffer size. */
341#define tcp_rcvspace pData->tcp_rcvspace
342
343/** TCP receive buffer size. */
344#define tcp_sndspace pData->tcp_sndspace
345
346/* TCP duplicate ACK retransmit threshold. */
347#define tcprexmtthresh 3
348
349
350#define bootp_filename pData->bootp_filename
351
352#define if_mtu pData->if_mtu
353#define if_mru pData->if_mru
354#define if_comp pData->if_comp
355#define if_maxlinkhdr pData->if_maxlinkhdr
356#define if_queued pData->if_queued
357#define if_thresh pData->if_thresh
358
359#define icmpstat pData->icmpstat
360
361#define ipstat pData->ipstat
362#define ipq pData->ipq
363#define ip_currid pData->ip_currid
364
365#define mbuf_alloced pData->mbuf_alloced
366#define mbuf_max pData->mbuf_max
367#define msize pData->msize
368#define m_freelist pData->m_freelist
369#define m_usedlist pData->m_usedlist
370
371#define curtime pData->curtime
372#define time_fasttimo pData->time_fasttimo
373#define last_slowtimo pData->last_slowtimo
374#define do_slowtimo pData->do_slowtimo
375#define link_up pData->link_up
376#define cUsers pData->cUsers
377#define tt pData->tt
378#define our_addr pData->our_addr
379#ifndef VBOX_SLIRP_ALIAS
380# define alias_addr pData->alias_addr
381#else
382# define handler_chain pData->handler_chain
383#endif
384#define dns_addr pData->dns_addr
385#define loopback_addr pData->loopback_addr
386#define client_ethaddr pData->client_ethaddr
387#define slirp_hostname pData->slirp_hostname
388
389#define tcb pData->tcb
390#define tcp_last_so pData->tcp_last_so
391#define tcp_iss pData->tcp_iss
392
393#define tcpstat pData->tcpstat
394#define tcp_now pData->tcp_now
395
396#define tftp_prefix pData->tftp_prefix
397
398#define udpstat pData->udpstat
399#define udb pData->udb
400#define udp_last_so pData->udp_last_so
401
402#define maxfragsperpacket pData->maxfragsperpacket
403#define maxnipq pData->maxnipq
404#define nipq pData->nipq
405
406#define tcp_reass_qsize pData->tcp_reass_qsize
407#define tcp_reass_maxqlen pData->tcp_reass_maxqlen
408#define tcp_reass_maxseg pData->tcp_reass_maxseg
409#define tcp_reass_overflows pData->tcp_reass_overflows
410
411#define queue_tcp_label tcb
412#define queue_udp_label udb
413#define VBOX_X2(x) x
414#define VBOX_X(x) VBOX_X2(x)
415
416#if 1
417
418# define QSOCKET_LOCK(queue) do {} while (0)
419# define QSOCKET_UNLOCK(queue) do {} while (0)
420# define QSOCKET_LOCK_CREATE(queue) do {} while (0)
421# define QSOCKET_LOCK_DESTROY(queue) do {} while (0)
422# define QSOCKET_FOREACH(so, sonext, label) \
423 for ((so) = VBOX_X2(queue_ ## label ## _label).so_next; \
424 (so) != &(VBOX_X2(queue_ ## label ## _label)); \
425 (so) = (sonext)) \
426 { \
427 (sonext) = (so)->so_next; \
428 Log5(("%s:%d Processing so:%R[natsock]\n", __FUNCTION__, __LINE__, (so)));
429# define CONTINUE(label) continue
430# define CONTINUE_NO_UNLOCK(label) continue
431# define LOOP_LABEL(label, so, sonext) /* empty*/
432# define DO_TCP_OUTPUT(data, sotcb) tcp_output((data), (sotcb))
433# define DO_TCP_INPUT(data, mbuf, size, so) tcp_input((data), (mbuf), (size), (so))
434# define DO_TCP_CONNECT(data, so) tcp_connect((data), (so))
435# define DO_SOREAD(ret, data, so, ifclose) \
436 do { \
437 (ret) = soread((data), (so), (ifclose)); \
438 } while(0)
439# define DO_SOWRITE(ret, data, so) \
440 do { \
441 (ret) = sowrite((data), (so)); \
442 } while(0)
443# define DO_SORECFROM(data, so) sorecvfrom((data), (so))
444# define SOLOOKUP(so, label, src, sport, dst, dport) \
445 do { \
446 (so) = solookup(&VBOX_X2(queue_ ## label ## _label), (src), (sport), (dst), (dport)); \
447 } while (0)
448# define DO_UDP_DETACH(data, so, ignored) udp_detach((data), (so))
449
450#endif
451
452#define TCP_OUTPUT(data, sotcb) DO_TCP_OUTPUT((data), (sotcb))
453#define TCP_INPUT(data, mbuf, size, so) DO_TCP_INPUT((data), (mbuf), (size), (so))
454#define TCP_CONNECT(data, so) DO_TCP_CONNECT((data), (so))
455#define SOREAD(ret, data, so, ifclose) DO_SOREAD((ret), (data), (so), (ifclose))
456#define SOWRITE(ret, data, so) DO_SOWRITE((ret), (data), (so))
457#define SORECVFROM(data, so) DO_SORECFROM((data), (so))
458#define UDP_DETACH(data, so, so_next) DO_UDP_DETACH((data), (so), (so_next))
459
460/* dnsproxy/dnsproxy.c */
461#define authoritative_port pData->authoritative_port
462#define authoritative_timeout pData->authoritative_timeout
463#define recursive_port pData->recursive_port
464#define recursive_timeout pData->recursive_timeout
465#define stats_timeout pData->stats_timeout
466/* dnsproxy/hash.c */
467#define dns_port pData->port
468#define request_hash pData->request_hash
469#define hash_collisions pData->hash_collisions
470#define active_queries pData->active_queries
471#define all_queries pData->all_queries
472#define authoritative_queries pData->authoritative_queries
473#define recursive_queries pData->recursive_queries
474#define removed_queries pData->removed_queries
475#define dropped_queries pData->dropped_queries
476#define answered_queries pData->answered_queries
477#define dropped_answers pData->dropped_answers
478#define late_answers pData->late_answers
479
480/* dnsproxy/dnsproxy.c */
481#define queryid pData->queryid
482#define authoritative_addr pData->authoritative_addr
483#define recursive_addr pData->recursive_addr
484#define sock_query pData->sock_query
485#define sock_answer pData->sock_answer
486
487#define instancehead pData->instancehead
488
489#define nmbclusters pData->nmbclusters
490#define nmbjumbop pData->nmbjumbop
491#define nmbjumbo9 pData->nmbjumbo9
492#define nmbjumbo16 pData->nmbjumbo16
493#define mbstat pData->mbstat
494#include "ext.h"
495#undef zone_mbuf
496#undef zone_clust
497#undef zone_pack
498#undef zone_jumbop
499#undef zone_jumbo9
500#undef zone_jumbo16
501#undef zone_ext_refcnt
502static inline uma_zone_t slirp_zone_pack(PNATState pData)
503{
504 return pData->zone_pack;
505}
506static inline uma_zone_t slirp_zone_jumbop(PNATState pData)
507{
508 return pData->zone_jumbop;
509}
510static inline uma_zone_t slirp_zone_jumbo9(PNATState pData)
511{
512 return pData->zone_jumbo9;
513}
514static inline uma_zone_t slirp_zone_jumbo16(PNATState pData)
515{
516 return pData->zone_jumbo16;
517}
518static inline uma_zone_t slirp_zone_ext_refcnt(PNATState pData)
519{
520 return pData->zone_ext_refcnt;
521}
522static inline uma_zone_t slirp_zone_mbuf(PNATState pData)
523{
524 return pData->zone_mbuf;
525}
526static inline uma_zone_t slirp_zone_clust(PNATState pData)
527{
528 return pData->zone_clust;
529}
530#ifndef VBOX_SLIRP_BSD
531# define m_adj(m, len) m_adj(pData, (m), (len))
532#endif
533
534#endif /* !___slirp_state_h */
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