VirtualBox

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

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

Devices: whitespace cleanup

  • Property svn:eol-style set to native
File size: 32.5 KB
Line 
1/** @file
2 * NAT state/configuration.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
19 */
20
21#ifndef ___slirp_state_h
22#define ___slirp_state_h
23
24#include <iprt/req.h>
25#include <iprt/critsect.h>
26
27#define COUNTERS_INIT
28#include "counters.h"
29
30#include "ip_icmp.h"
31#include "dnsproxy/dnsproxy.h"
32
33
34/** Where to start DHCP IP number allocation. */
35#define START_ADDR 15
36
37/** DHCP Lease time. */
38#define LEASE_TIME (24 * 3600)
39
40/*
41 * ARP cache this is naive implementaion of ARP
42 * cache of mapping 4 byte IPv4 address to 6 byte
43 * ethernet one.
44 */
45struct arp_cache_entry
46{
47 uint32_t ip;
48 uint8_t ether[6];
49 LIST_ENTRY(arp_cache_entry) list;
50};
51LIST_HEAD(arp_cache_head, arp_cache_entry);
52
53/** TFTP session entry. */
54struct tftp_session
55{
56 int in_use;
57 unsigned char filename[TFTP_FILENAME_MAX];
58
59 struct in_addr client_ip;
60 u_int16_t client_port;
61
62 int timestamp;
63};
64
65struct dns_domain_entry
66{
67 char *dd_pszDomain;
68 LIST_ENTRY(dns_domain_entry) dd_list;
69};
70LIST_HEAD(dns_domain_list_head, dns_domain_entry);
71
72struct dns_entry
73{
74 struct in_addr de_addr;
75 TAILQ_ENTRY(dns_entry) de_list;
76};
77TAILQ_HEAD(dns_list_head, dns_entry);
78#ifdef VBOX_WITH_SLIRP_BSD_MBUF
79TAILQ_HEAD(if_queue, mbuf);
80#endif
81
82struct port_forward_rule
83{
84 uint16_t proto;
85 uint16_t host_port;
86 uint16_t guest_port;
87#ifndef VBOX_WITH_NAT_SERVICE
88 struct in_addr guest_addr;
89#endif
90 struct in_addr bind_ip;
91 uint8_t mac_address[6]; /*need ETH_ALEN here */
92 int activated;
93 LIST_ENTRY(port_forward_rule) list;
94};
95LIST_HEAD(port_forward_rule_list, port_forward_rule);
96
97#ifndef VBOX_WITH_SLIRP_BSD_MBUF
98struct mbuf_zone
99{
100 LIST_ENTRY(mbuf_zone) list;
101 uint8_t *mbuf_zone_base_addr;
102};
103LIST_HEAD(mbuf_zone_list, mbuf_zone);
104#endif
105
106
107/* forward declaration */
108struct proto_handler;
109
110/** Main state/configuration structure for slirp NAT. */
111typedef struct NATState
112{
113#define PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name
114#define COUNTING_COUNTER(name, dsc) STAMCOUNTER Stat ## name
115#include "counters.h"
116 /* Stuff from boot.c */
117 void *pbootp_clients;
118 const char *bootp_filename;
119 /* Stuff from if.c */
120 int if_mtu, if_mru;
121 int if_comp;
122 int if_maxlinkhdr;
123 int if_queued;
124 int if_thresh;
125#ifndef VBOX_WITH_SLIRP_BSD_MBUF
126 struct mbuf if_fastq;
127 struct mbuf if_batchq;
128#else
129 struct if_queue if_fastq;
130 struct if_queue if_batchq;
131#endif
132 struct mbuf *next_m;
133 /* Stuff from icmp.c */
134 struct icmpstat_t icmpstat;
135 /* Stuff from ip_input.c */
136 struct ipstat_t ipstat;
137 struct ipqhead ipq[IPREASS_NHASH];
138 int maxnipq; /* Administrative limit on # of reass queues*/
139 int maxfragsperpacket; /* Maximum number of IPv4 fragments allowed per packet */
140 int nipq; /* total number of reass queues */
141 uint16_t ip_currid;
142 /* Stuff from mbuf.c */
143 int mbuf_alloced, mbuf_max;
144 int msize;
145 struct mbuf m_freelist, m_usedlist;
146#ifndef VBOX_WITH_SLIRP_BSD_MBUF
147 struct mbuf_zone_list mbuf_zone_head;
148 RTCRITSECT cs_mbuf_zone;
149 int fmbuf_water_line;
150 int mbuf_water_line_limit;
151 int mbuf_zone_count;
152 int fmbuf_water_warn_sent;
153 uint32_t tsmbuf_water_warn_sent;
154#endif
155 /* Stuff from slirp.c */
156 void *pvUser;
157 uint32_t curtime;
158 uint32_t time_fasttimo;
159 uint32_t last_slowtimo;
160 bool do_slowtimo;
161 bool link_up;
162 struct timeval tt;
163 struct in_addr our_addr;
164 struct in_addr alias_addr;
165 struct in_addr special_addr;
166
167 int tcp_rcvspace;
168 int tcp_sndspace;
169 int socket_rcv;
170 int socket_snd;
171#ifdef VBOX_WITH_SLIRP_MT
172 PRTREQQUEUE pReqQueue;
173#endif
174#ifdef RT_OS_WINDOWS
175 ULONG (WINAPI * pfGetAdaptersAddresses)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG);
176#endif
177 struct dns_list_head pDnsList;
178 struct dns_domain_list_head pDomainList;
179 struct in_addr tftp_server;
180 struct in_addr loopback_addr;
181 uint32_t netmask;
182#ifndef VBOX_WITH_NAT_SERVICE
183 uint8_t client_ethaddr[6];
184#endif
185 const uint8_t *slirp_ethaddr;
186 struct ex_list *exec_list;
187 char slirp_hostname[33];
188 bool fPassDomain;
189 struct in_addr bindIP;
190 /* Stuff from tcp_input.c */
191 struct socket tcb;
192#ifdef VBOX_WITH_SLIRP_MT
193 RTCRITSECT tcb_mutex;
194#endif
195 struct socket *tcp_last_so;
196 tcp_seq tcp_iss;
197 /* Stuff from tcp_timer.c */
198 struct tcpstat_t tcpstat;
199 uint32_t tcp_now;
200 int tcp_reass_qsize;
201 int tcp_reass_maxqlen;
202 int tcp_reass_maxseg;
203 int tcp_reass_overflows;
204 /* Stuff from tftp.c */
205 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
206 const char *tftp_prefix;
207 /* Stuff from udp.c */
208 struct udpstat_t udpstat;
209 struct socket udb;
210#ifdef VBOX_WITH_SLIRP_MT
211 RTCRITSECT udb_mutex;
212#endif
213 struct socket *udp_last_so;
214 struct socket icmp_socket;
215 struct icmp_storage icmp_msg_head;
216# ifndef RT_OS_WINDOWS
217 /* counter of sockets needed for allocation enough room to
218 * process sockets with poll/epoll
219 *
220 * NSOCK_INC/DEC should be injected before every
221 * operation on socket queue (tcb, udb)
222 */
223 int nsock;
224# define NSOCK_INC() do {pData->nsock++;} while (0)
225# define NSOCK_DEC() do {pData->nsock--;} while (0)
226# define NSOCK_INC_EX(ex) do {ex->pData->nsock++;} while (0)
227# define NSOCK_DEC_EX(ex) do {ex->pData->nsock--;} while (0)
228# else
229# define NSOCK_INC() do {} while (0)
230# define NSOCK_DEC() do {} while (0)
231# define NSOCK_INC_EX(ex) do {} while (0)
232# define NSOCK_DEC_EX(ex) do {} while (0)
233# endif
234# ifdef RT_OS_WINDOWS
235 void *pvIcmpBuffer;
236 size_t szIcmpBuffer;
237 /* Accordin MSDN specification IcmpParseReplies
238 * function should be detected in runtime
239 */
240 long (WINAPI * pfIcmpParseReplies)(void *, long);
241 BOOL (WINAPI * pfIcmpCloseHandle)(HANDLE);
242 HMODULE hmIcmpLibrary;
243# endif
244#if defined(RT_OS_WINDOWS)
245# define VBOX_SOCKET_EVENT (pData->phEvents[VBOX_SOCKET_EVENT_INDEX])
246 HANDLE phEvents[VBOX_EVENT_COUNT];
247#endif
248#ifdef VBOX_WITH_SLIRP_BSD_MBUF
249# ifdef zone_mbuf
250# undef zone_mbuf
251# endif
252 uma_zone_t zone_mbuf;
253# ifdef zone_clust
254# undef zone_clust
255# endif
256 uma_zone_t zone_clust;
257# ifdef zone_pack
258# undef zone_pack
259# endif
260 uma_zone_t zone_pack;
261# ifdef zone_jumbop
262# undef zone_jumbop
263# endif
264 uma_zone_t zone_jumbop;
265# ifdef zone_jumbo9
266# undef zone_jumbo9
267# endif
268 uma_zone_t zone_jumbo9;
269# ifdef zone_jumbo16
270# undef zone_jumbo16
271# endif
272 uma_zone_t zone_jumbo16;
273# ifdef zone_ext_refcnt
274# undef zone_ext_refcnt
275 int nmbclusters; /* limits number of mbuf clusters */
276 int nmbjumbop; /* limits number of page size jumbo clusters */
277 int nmbjumbo9; /* limits number of 9k jumbo clusters */
278 int nmbjumbo16; /* limits number of 16k jumbo clusters */
279 struct mbstat mbstat;
280# endif
281 uma_zone_t zone_ext_refcnt;
282#endif
283 int use_host_resolver;
284 /* from dnsproxy/dnsproxy.h*/
285 unsigned int authoritative_port;
286 unsigned int authoritative_timeout;
287 unsigned int recursive_port;
288 unsigned int recursive_timeout;
289 unsigned int stats_timeout;
290 unsigned int port;
291
292 unsigned long active_queries;
293 unsigned long all_queries;
294 unsigned long authoritative_queries;
295 unsigned long recursive_queries;
296 unsigned long removed_queries;
297 unsigned long dropped_queries;
298 unsigned long answered_queries;
299 unsigned long dropped_answers;
300 unsigned long late_answers;
301 unsigned long hash_collisions;
302 /*dnsproxy/dnsproxy.c*/
303 unsigned short queryid;
304 struct sockaddr_in authoritative_addr;
305 struct sockaddr_in recursive_addr;
306 int sock_query;
307 int sock_answer;
308 /* dnsproxy/hash.c */
309#define HASHSIZE 10
310#define HASH(id) (id & ((1 << HASHSIZE) - 1))
311 struct request *request_hash[1 << HASHSIZE];
312 /* this field control behaviour of DHCP server */
313 bool use_dns_proxy;
314
315 LIST_HEAD(RT_NOTHING, libalias) instancehead;
316 struct libalias *proxy_alias;
317 struct libalias *dns_alias;
318 LIST_HEAD(handler_chain, proto_handler) handler_chain;
319 struct port_forward_rule_list port_forward_rule_head;
320 int cRedirectionsActive;
321 int cRedirectionsStored;
322 struct arp_cache_head arp_cache;
323 /*libalis modules' handlers*/
324 struct proto_handler *ftp_module;
325 struct proto_handler *nbt_module;
326 struct proto_handler *dns_module;
327
328} NATState;
329
330
331/** Default IP time to live. */
332#define ip_defttl IPDEFTTL
333
334/** Number of permanent buffers in mbuf. */
335#define mbuf_thresh 30
336
337/** Use a fixed time before sending keepalive. */
338#define tcp_keepidle TCPTV_KEEP_IDLE
339
340/** Use a fixed interval between keepalive. */
341#define tcp_keepintvl TCPTV_KEEPINTVL
342
343/** Maximum idle time before timing out a connection. */
344#define tcp_maxidle (TCPTV_KEEPCNT * tcp_keepintvl)
345
346/** Default TCP socket options. */
347#define so_options DO_KEEPALIVE
348
349/** Default TCP MSS value. */
350#define tcp_mssdflt TCP_MSS
351
352/** Default TCP round trip time. */
353#define tcp_rttdflt (TCPTV_SRTTDFLT / PR_SLOWHZ)
354
355/** Enable RFC1323 performance enhancements.
356 * @todo check if it really works, it was turned off before. */
357#define tcp_do_rfc1323 1
358
359/** TCP receive buffer size. */
360#define tcp_rcvspace pData->tcp_rcvspace
361
362/** TCP receive buffer size. */
363#define tcp_sndspace pData->tcp_sndspace
364
365/* TCP duplicate ACK retransmit threshold. */
366#define tcprexmtthresh 3
367
368
369#define bootp_filename pData->bootp_filename
370
371#define if_mtu pData->if_mtu
372#define if_mru pData->if_mru
373#define if_comp pData->if_comp
374#define if_maxlinkhdr pData->if_maxlinkhdr
375#define if_queued pData->if_queued
376#define if_thresh pData->if_thresh
377#define if_fastq pData->if_fastq
378#define if_batchq pData->if_batchq
379#define next_m pData->next_m
380
381#define icmpstat pData->icmpstat
382
383#define ipstat pData->ipstat
384#define ipq pData->ipq
385#define ip_currid pData->ip_currid
386
387#define mbuf_alloced pData->mbuf_alloced
388#define mbuf_max pData->mbuf_max
389#define msize pData->msize
390#define m_freelist pData->m_freelist
391#define m_usedlist pData->m_usedlist
392
393#define curtime pData->curtime
394#define time_fasttimo pData->time_fasttimo
395#define last_slowtimo pData->last_slowtimo
396#define do_slowtimo pData->do_slowtimo
397#define link_up pData->link_up
398#define cUsers pData->cUsers
399#define tt pData->tt
400#define our_addr pData->our_addr
401#ifndef VBOX_SLIRP_ALIAS
402# define alias_addr pData->alias_addr
403#else
404# define handler_chain pData->handler_chain
405#endif
406#define dns_addr pData->dns_addr
407#define loopback_addr pData->loopback_addr
408#define client_ethaddr pData->client_ethaddr
409#define exec_list pData->exec_list
410#define slirp_hostname pData->slirp_hostname
411
412#define tcb pData->tcb
413#define tcp_last_so pData->tcp_last_so
414#define tcp_iss pData->tcp_iss
415
416#define tcpstat pData->tcpstat
417#define tcp_now pData->tcp_now
418
419#define tftp_sessions pData->tftp_sessions
420#define tftp_prefix pData->tftp_prefix
421
422#define udpstat pData->udpstat
423#define udb pData->udb
424#define udp_last_so pData->udp_last_so
425
426#define maxfragsperpacket pData->maxfragsperpacket
427#define maxnipq pData->maxnipq
428#define nipq pData->nipq
429
430#define tcp_reass_qsize pData->tcp_reass_qsize
431#define tcp_reass_maxqlen pData->tcp_reass_maxqlen
432#define tcp_reass_maxseg pData->tcp_reass_maxseg
433#define tcp_reass_overflows pData->tcp_reass_overflows
434
435#define queue_tcp_label tcb
436#define queue_udp_label udb
437#define VBOX_X2(x) x
438#define VBOX_X(x) VBOX_X2(x)
439
440#ifdef VBOX_WITH_SLIRP_MT
441
442# define QSOCKET_LOCK(queue) \
443 do { \
444 int rc; \
445 /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \
446 rc = RTCritSectEnter(&VBOX_X(queue) ## _mutex); \
447 AssertRC(rc); \
448 } while (0)
449# define QSOCKET_UNLOCK(queue) \
450 do { \
451 int rc; \
452 rc = RTCritSectLeave(&VBOX_X(queue) ## _mutex); \
453 AssertRC(rc); \
454 } while (0)
455# define QSOCKET_LOCK_CREATE(queue) \
456 do { \
457 int rc; \
458 rc = RTCritSectInit(&pData->queue ## _mutex); \
459 AssertRC(rc); \
460 } while (0)
461# define QSOCKET_LOCK_DESTROY(queue) \
462 do { \
463 int rc = RTCritSectDelete(&pData->queue ## _mutex); \
464 AssertRC(rc); \
465 } while (0)
466
467# define QSOCKET_FOREACH(so, sonext, label) \
468 QSOCKET_LOCK(VBOX_X2(queue_## label ## _label)); \
469 (so) = (VBOX_X(queue_ ## label ## _label)).so_next; \
470 QSOCKET_UNLOCK(VBOX_X2(queue_## label ##_label)); \
471 if ((so) != &(VBOX_X(queue_## label ## _label))) SOCKET_LOCK((so));\
472 for (;;) \
473 { \
474 if ((so) == &(VBOX_X(queue_## label ## _label))) \
475 { \
476 break; \
477 } \
478 Log2(("%s:%d Processing so:%R[natsock]\n", __FUNCTION__, __LINE__, (so)));
479
480# define CONTINUE_NO_UNLOCK(label) goto loop_end_ ## label ## _mt_nounlock
481# define CONTINUE(label) goto loop_end_ ## label ## _mt
482/* @todo replace queue parameter with macrodinition */
483/* _mt_nounlock - user should lock so_next before calling CONTINUE_NO_UNLOCK */
484# define LOOP_LABEL(label, so, sonext) loop_end_ ## label ## _mt: \
485 (sonext) = (so)->so_next; \
486 SOCKET_UNLOCK(so); \
487 QSOCKET_LOCK(VBOX_X(queue_ ## label ## _label)); \
488 if ((sonext) != &(VBOX_X(queue_## label ## _label))) \
489 { \
490 SOCKET_LOCK((sonext)); \
491 QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \
492 } \
493 else \
494 { \
495 so = &VBOX_X(queue_ ## label ## _label); \
496 QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \
497 break; \
498 } \
499 (so) = (sonext); \
500 continue; \
501 loop_end_ ## label ## _mt_nounlock: \
502 (so) = (sonext)
503
504# define DO_TCP_OUTPUT(data, sotcb) \
505 do { \
506 PRTREQ pReq = NULL; \
507 int rc; \
508 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
509 AssertRC(rc); \
510 pReq->u.Internal.pfn = (PFNRT)tcp_output; \
511 pReq->u.Internal.cArgs = 2; \
512 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
513 pReq->u.Internal.aArgs[1] = (uintptr_t)(sotcb); \
514 pReq->fFlags = RTREQFLAGS_VOID; \
515 rc = RTReqQueue(pReq, 0); \
516 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
517 { \
518 SOCKET_UNLOCK(so); \
519 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
520 AssertReleaseRC(rc); \
521 SOCKET_LOCK(so); \
522 RTReqFree(pReq); \
523 } \
524 else \
525 AssertReleaseRC(rc); \
526} while(0)
527
528# define DO_TCP_INPUT(data, mbuf, size, so) \
529 do { \
530 PRTREQ pReq = NULL; \
531 int rc; \
532 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
533 AssertReleaseRC(rc); \
534 pReq->u.Internal.pfn = (PFNRT)tcp_input; \
535 pReq->u.Internal.cArgs = 4; \
536 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
537 pReq->u.Internal.aArgs[1] = (uintptr_t)(mbuf); \
538 pReq->u.Internal.aArgs[2] = (uintptr_t)(size); \
539 pReq->u.Internal.aArgs[3] = (uintptr_t)(so); \
540 pReq->fFlags = RTREQFLAGS_VOID|RTREQFLAGS_NO_WAIT; \
541 rc = RTReqQueue(pReq, 0); \
542 AssertReleaseRC(rc); \
543 } while(0)
544
545# define DO_TCP_CONNECT(data, so) \
546 do { \
547 PRTREQ pReq = NULL; \
548 int rc; \
549 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
550 AssertReleaseRC(rc); \
551 pReq->u.Internal.pfn = (PFNRT)tcp_connect; \
552 pReq->u.Internal.cArgs = 2; \
553 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
554 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
555 pReq->fFlags = RTREQFLAGS_VOID; \
556 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
557 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
558 { \
559 SOCKET_UNLOCK(so); \
560 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
561 AssertReleaseRC(rc); \
562 SOCKET_LOCK(so); \
563 RTReqFree(pReq); \
564 } \
565 else \
566 AssertReleaseRC(rc); \
567 } while(0)
568
569# define DO_SOREAD(ret, data, so, ifclose) \
570 do { \
571 PRTREQ pReq = NULL; \
572 int rc; \
573 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
574 AssertReleaseRC(rc); \
575 pReq->u.Internal.pfn = (PFNRT)soread_queue; \
576 pReq->u.Internal.cArgs = 4; \
577 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
578 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
579 pReq->u.Internal.aArgs[2] = (uintptr_t)(ifclose); \
580 pReq->u.Internal.aArgs[3] = (uintptr_t)&(ret); \
581 pReq->fFlags = RTREQFLAGS_VOID; \
582 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
583 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
584 { \
585 SOCKET_UNLOCK(so); \
586 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
587 AssertReleaseRC(rc); \
588 SOCKET_LOCK(so); \
589 RTReqFree(pReq); \
590 } \
591 else \
592 AssertReleaseRC(rc); \
593 } while(0)
594
595# define DO_SOWRITE(ret, data, so) \
596 do { \
597 PRTREQ pReq = NULL; \
598 int rc; \
599 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
600 AssertReleaseRC(rc); \
601 pReq->u.Internal.pfn = (PFNRT)sowrite; \
602 pReq->u.Internal.cArgs = 2; \
603 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
604 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
605 pReq->fFlags = RTREQFLAGS_RETURN_MASK; \
606 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
607 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
608 { \
609 SOCKET_UNLOCK(so); \
610 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
611 SOCKET_LOCK(so); \
612 ret = pReq->iStatus; \
613 RTReqFree(pReq); \
614 } \
615 else \
616 AssertReleaseRC(rc); \
617 } while(0)
618
619# define DO_SORECFROM(data, so) \
620 do { \
621 PRTREQ pReq = NULL; \
622 int rc; \
623 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
624 AssertReleaseRC(rc); \
625 pReq->u.Internal.pfn = (PFNRT)sorecvfrom; \
626 pReq->u.Internal.cArgs = 2; \
627 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
628 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
629 pReq->fFlags = RTREQFLAGS_VOID; \
630 rc = RTReqQueue(pReq, 0); \
631 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
632 { \
633 SOCKET_UNLOCK(so); \
634 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
635 AssertReleaseRC(rc); \
636 SOCKET_LOCK(so); \
637 RTReqFree(pReq); \
638 } \
639 else \
640 AssertReleaseRC(rc); \
641 } while(0)
642
643# define DO_UDP_DETACH(data, so, so_next) \
644 do { \
645 PRTREQ pReq = NULL; \
646 int rc; \
647 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
648 AssertReleaseRC(rc); \
649 pReq->u.Internal.pfn = (PFNRT)udp_detach; \
650 pReq->u.Internal.cArgs = 2; \
651 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
652 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
653 pReq->fFlags = RTREQFLAGS_VOID; \
654 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
655 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
656 { \
657 SOCKET_UNLOCK(so); \
658 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
659 AssertReleaseRC(rc); \
660 if ((so_next) != &udb) SOCKET_LOCK((so_next)); \
661 RTReqFree(pReq); \
662 } \
663 else \
664 AssertReleaseRC(rc); \
665 } while(0)
666
667# define SOLOOKUP(so, label, src, sport, dst, dport) \
668 do { \
669 struct socket *sonxt; \
670 (so) = NULL; \
671 QSOCKET_FOREACH(so, sonxt, label) \
672 /* { */ \
673 if ( so->so_lport == (sport) \
674 && so->so_laddr.s_addr == (src).s_addr \
675 && so->so_faddr.s_addr == (dst).s_addr \
676 && so->so_fport == (dport)) \
677 { \
678 if (sonxt != &VBOX_X2(queue_ ## label ## _label)) \
679 SOCKET_UNLOCK(sonxt); \
680 break; /*so is locked*/ \
681 } \
682 LOOP_LABEL(so, sonxt, label); \
683 } \
684 } \
685 } while (0)
686
687#else /* !VBOX_WITH_SLIRP_MT */
688
689# define QSOCKET_LOCK(queue) do {} while (0)
690# define QSOCKET_UNLOCK(queue) do {} while (0)
691# define QSOCKET_LOCK_CREATE(queue) do {} while (0)
692# define QSOCKET_LOCK_DESTROY(queue) do {} while (0)
693# define QSOCKET_FOREACH(so, sonext, label) \
694 for ((so) = VBOX_X2(queue_ ## label ## _label).so_next; \
695 (so) != &(VBOX_X2(queue_ ## label ## _label)); \
696 (so) = (sonext)) \
697 { \
698 (sonext) = (so)->so_next;
699# define CONTINUE(label) continue
700# define CONTINUE_NO_UNLOCK(label) continue
701# define LOOP_LABEL(label, so, sonext) /* empty*/
702# define DO_TCP_OUTPUT(data, sotcb) tcp_output((data), (sotcb))
703# define DO_TCP_INPUT(data, mbuf, size, so) tcp_input((data), (mbuf), (size), (so))
704# define DO_TCP_CONNECT(data, so) tcp_connect((data), (so))
705# define DO_SOREAD(ret, data, so, ifclose) \
706 do { \
707 (ret) = soread((data), (so), (ifclose)); \
708 } while(0)
709# define DO_SOWRITE(ret, data, so) \
710 do { \
711 (ret) = sowrite((data), (so)); \
712 } while(0)
713# define DO_SORECFROM(data, so) sorecvfrom((data), (so))
714# define SOLOOKUP(so, label, src, sport, dst, dport) \
715 do { \
716 (so) = solookup(&VBOX_X2(queue_ ## label ## _label), (src), (sport), (dst), (dport)); \
717 } while (0)
718# define DO_UDP_DETACH(data, so, ignored) udp_detach((data), (so))
719
720#endif /* !VBOX_WITH_SLIRP_MT */
721
722#define TCP_OUTPUT(data, sotcb) DO_TCP_OUTPUT((data), (sotcb))
723#define TCP_INPUT(data, mbuf, size, so) DO_TCP_INPUT((data), (mbuf), (size), (so))
724#define TCP_CONNECT(data, so) DO_TCP_CONNECT((data), (so))
725#define SOREAD(ret, data, so, ifclose) DO_SOREAD((ret), (data), (so), (ifclose))
726#define SOWRITE(ret, data, so) DO_SOWRITE((ret), (data), (so))
727#define SORECVFROM(data, so) DO_SORECFROM((data), (so))
728#define UDP_DETACH(data, so, so_next) DO_UDP_DETACH((data), (so), (so_next))
729
730/* dnsproxy/dnsproxy.c */
731#define authoritative_port pData->authoritative_port
732#define authoritative_timeout pData->authoritative_timeout
733#define recursive_port pData->recursive_port
734#define recursive_timeout pData->recursive_timeout
735#define stats_timeout pData->stats_timeout
736/* dnsproxy/hash.c */
737#define dns_port pData->port
738#define request_hash pData->request_hash
739#define hash_collisions pData->hash_collisions
740#define active_queries pData->active_queries
741#define all_queries pData->all_queries
742#define authoritative_queries pData->authoritative_queries
743#define recursive_queries pData->recursive_queries
744#define removed_queries pData->removed_queries
745#define dropped_queries pData->dropped_queries
746#define answered_queries pData->answered_queries
747#define dropped_answers pData->dropped_answers
748#define late_answers pData->late_answers
749
750/* dnsproxy/dnsproxy.c */
751#define queryid pData->queryid
752#define authoritative_addr pData->authoritative_addr
753#define recursive_addr pData->recursive_addr
754#define sock_query pData->sock_query
755#define sock_answer pData->sock_answer
756
757#define instancehead pData->instancehead
758
759#ifdef VBOX_WITH_SLIRP_BSD_MBUF
760# define nmbclusters pData->nmbclusters
761# define nmbjumbop pData->nmbjumbop
762# define nmbjumbo9 pData->nmbjumbo9
763# define nmbjumbo16 pData->nmbjumbo16
764# define mbstat pData->mbstat
765# include "ext.h"
766# undef zone_mbuf
767# undef zone_clust
768# undef zone_pack
769# undef zone_jumbop
770# undef zone_jumbo9
771# undef zone_jumbo16
772# undef zone_ext_refcnt
773static inline uma_zone_t slirp_zone_pack(PNATState pData)
774{
775 return pData->zone_pack;
776}
777static inline uma_zone_t slirp_zone_jumbop(PNATState pData)
778{
779 return pData->zone_jumbop;
780}
781static inline uma_zone_t slirp_zone_jumbo9(PNATState pData)
782{
783 return pData->zone_jumbo9;
784}
785static inline uma_zone_t slirp_zone_jumbo16(PNATState pData)
786{
787 return pData->zone_jumbo16;
788}
789static inline uma_zone_t slirp_zone_ext_refcnt(PNATState pData)
790{
791 return pData->zone_ext_refcnt;
792}
793static inline uma_zone_t slirp_zone_mbuf(PNATState pData)
794{
795 return pData->zone_mbuf;
796}
797static inline uma_zone_t slirp_zone_clust(PNATState pData)
798{
799 return pData->zone_clust;
800}
801#ifndef VBOX_SLIRP_BSD
802# define m_adj(m, len) m_adj(pData, (m), (len))
803#endif
804#endif
805
806#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