VirtualBox

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

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

NAT: trac ticket 13630 - use generation numbers as poor man's weak
references to prevent dnsproxy from using stale request::dns_server.

This commit has some extra LogRel() for the user to confirm the fix,
which are to be changed to Log2.

XXX: TOO: Clean up in dnsproxy_query() needs more investigation.
Existing code just punts with an "XXX" comment on sendto() failure,
which doesn't doesn't look right.

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