VirtualBox

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

最後變更 在這個檔案從25205是 25205,由 vboxsync 提交於 15 年 前

NAT: port-forwarding attempts to active itself till count of (registered and acivated aren't equal)
vbox/#5666 and vbox/#5664.

  • 屬性 svn:eol-style 設為 native
檔案大小: 32.6 KB
 
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.alldomusa.eu.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 dns_list_head;
178 struct dns_domain_list_head dns_domain_list_head;
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 port_forwarding_activated;
321 int port_forwarding_count;
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 special_addr pData->special_addr
407#define dns_addr pData->dns_addr
408#define loopback_addr pData->loopback_addr
409#define client_ethaddr pData->client_ethaddr
410#define exec_list pData->exec_list
411#define slirp_hostname pData->slirp_hostname
412
413#define tcb pData->tcb
414#define tcp_last_so pData->tcp_last_so
415#define tcp_iss pData->tcp_iss
416
417#define tcpstat pData->tcpstat
418#define tcp_now pData->tcp_now
419
420#define tftp_sessions pData->tftp_sessions
421#define tftp_prefix pData->tftp_prefix
422
423#define udpstat pData->udpstat
424#define udb pData->udb
425#define udp_last_so pData->udp_last_so
426
427#define maxfragsperpacket pData->maxfragsperpacket
428#define maxnipq pData->maxnipq
429#define nipq pData->nipq
430
431#define tcp_reass_qsize pData->tcp_reass_qsize
432#define tcp_reass_maxqlen pData->tcp_reass_maxqlen
433#define tcp_reass_maxseg pData->tcp_reass_maxseg
434#define tcp_reass_overflows pData->tcp_reass_overflows
435
436#define queue_tcp_label tcb
437#define queue_udp_label udb
438#define VBOX_X2(x) x
439#define VBOX_X(x) VBOX_X2(x)
440
441#ifdef VBOX_WITH_SLIRP_MT
442
443# define QSOCKET_LOCK(queue) \
444 do { \
445 int rc; \
446 /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \
447 rc = RTCritSectEnter(&VBOX_X(queue) ## _mutex); \
448 AssertReleaseRC(rc); \
449 } while (0)
450# define QSOCKET_UNLOCK(queue) \
451 do { \
452 int rc; \
453 rc = RTCritSectLeave(&VBOX_X(queue) ## _mutex); \
454 AssertReleaseRC(rc); \
455 } while (0)
456# define QSOCKET_LOCK_CREATE(queue) \
457 do { \
458 int rc; \
459 rc = RTCritSectInit(&pData->queue ## _mutex); \
460 AssertReleaseRC(rc); \
461 } while (0)
462# define QSOCKET_LOCK_DESTROY(queue) \
463 do { \
464 int rc = RTCritSectDelete(&pData->queue ## _mutex); \
465 AssertReleaseRC(rc); \
466 } while (0)
467
468# define QSOCKET_FOREACH(so, sonext, label) \
469 QSOCKET_LOCK(VBOX_X2(queue_## label ## _label)); \
470 (so) = (VBOX_X(queue_ ## label ## _label)).so_next; \
471 QSOCKET_UNLOCK(VBOX_X2(queue_## label ##_label)); \
472 if ((so) != &(VBOX_X(queue_## label ## _label))) SOCKET_LOCK((so));\
473 for (;;) \
474 { \
475 if ((so) == &(VBOX_X(queue_## label ## _label))) \
476 { \
477 break; \
478 } \
479 Log2(("%s:%d Processing so:%R[natsock]\n", __FUNCTION__, __LINE__, (so)));
480
481# define CONTINUE_NO_UNLOCK(label) goto loop_end_ ## label ## _mt_nounlock
482# define CONTINUE(label) goto loop_end_ ## label ## _mt
483/* @todo replace queue parameter with macrodinition */
484/* _mt_nounlock - user should lock so_next before calling CONTINUE_NO_UNLOCK */
485# define LOOP_LABEL(label, so, sonext) loop_end_ ## label ## _mt: \
486 (sonext) = (so)->so_next; \
487 SOCKET_UNLOCK(so); \
488 QSOCKET_LOCK(VBOX_X(queue_ ## label ## _label)); \
489 if ((sonext) != &(VBOX_X(queue_## label ## _label))) \
490 { \
491 SOCKET_LOCK((sonext)); \
492 QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \
493 } \
494 else \
495 { \
496 so = &VBOX_X(queue_ ## label ## _label); \
497 QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \
498 break; \
499 } \
500 (so) = (sonext); \
501 continue; \
502 loop_end_ ## label ## _mt_nounlock: \
503 (so) = (sonext)
504
505# define DO_TCP_OUTPUT(data, sotcb) \
506 do { \
507 PRTREQ pReq = NULL; \
508 int rc; \
509 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
510 AssertReleaseRC(rc); \
511 pReq->u.Internal.pfn = (PFNRT)tcp_output; \
512 pReq->u.Internal.cArgs = 2; \
513 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
514 pReq->u.Internal.aArgs[1] = (uintptr_t)(sotcb); \
515 pReq->fFlags = RTREQFLAGS_VOID; \
516 rc = RTReqQueue(pReq, 0); \
517 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
518 { \
519 SOCKET_UNLOCK(so); \
520 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
521 AssertReleaseRC(rc); \
522 SOCKET_LOCK(so); \
523 RTReqFree(pReq); \
524 } \
525 else \
526 AssertReleaseRC(rc); \
527} while(0)
528
529# define DO_TCP_INPUT(data, mbuf, size, so) \
530 do { \
531 PRTREQ pReq = NULL; \
532 int rc; \
533 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
534 AssertReleaseRC(rc); \
535 pReq->u.Internal.pfn = (PFNRT)tcp_input; \
536 pReq->u.Internal.cArgs = 4; \
537 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
538 pReq->u.Internal.aArgs[1] = (uintptr_t)(mbuf); \
539 pReq->u.Internal.aArgs[2] = (uintptr_t)(size); \
540 pReq->u.Internal.aArgs[3] = (uintptr_t)(so); \
541 pReq->fFlags = RTREQFLAGS_VOID|RTREQFLAGS_NO_WAIT; \
542 rc = RTReqQueue(pReq, 0); \
543 AssertReleaseRC(rc); \
544 } while(0)
545
546# define DO_TCP_CONNECT(data, so) \
547 do { \
548 PRTREQ pReq = NULL; \
549 int rc; \
550 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
551 AssertReleaseRC(rc); \
552 pReq->u.Internal.pfn = (PFNRT)tcp_connect; \
553 pReq->u.Internal.cArgs = 2; \
554 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
555 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
556 pReq->fFlags = RTREQFLAGS_VOID; \
557 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
558 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
559 { \
560 SOCKET_UNLOCK(so); \
561 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
562 AssertReleaseRC(rc); \
563 SOCKET_LOCK(so); \
564 RTReqFree(pReq); \
565 } \
566 else \
567 AssertReleaseRC(rc); \
568 } while(0)
569
570# define DO_SOREAD(ret, data, so, ifclose) \
571 do { \
572 PRTREQ pReq = NULL; \
573 int rc; \
574 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
575 AssertReleaseRC(rc); \
576 pReq->u.Internal.pfn = (PFNRT)soread_queue; \
577 pReq->u.Internal.cArgs = 4; \
578 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
579 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
580 pReq->u.Internal.aArgs[2] = (uintptr_t)(ifclose); \
581 pReq->u.Internal.aArgs[3] = (uintptr_t)&(ret); \
582 pReq->fFlags = RTREQFLAGS_VOID; \
583 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
584 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
585 { \
586 SOCKET_UNLOCK(so); \
587 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
588 AssertReleaseRC(rc); \
589 SOCKET_LOCK(so); \
590 RTReqFree(pReq); \
591 } \
592 else \
593 AssertReleaseRC(rc); \
594 } while(0)
595
596# define DO_SOWRITE(ret, data, so) \
597 do { \
598 PRTREQ pReq = NULL; \
599 int rc; \
600 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
601 AssertReleaseRC(rc); \
602 pReq->u.Internal.pfn = (PFNRT)sowrite; \
603 pReq->u.Internal.cArgs = 2; \
604 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
605 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
606 pReq->fFlags = RTREQFLAGS_RETURN_MASK; \
607 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
608 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
609 { \
610 SOCKET_UNLOCK(so); \
611 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
612 SOCKET_LOCK(so); \
613 ret = pReq->iStatus; \
614 RTReqFree(pReq); \
615 } \
616 else \
617 AssertReleaseRC(rc); \
618 } while(0)
619
620# define DO_SORECFROM(data, so) \
621 do { \
622 PRTREQ pReq = NULL; \
623 int rc; \
624 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
625 AssertReleaseRC(rc); \
626 pReq->u.Internal.pfn = (PFNRT)sorecvfrom; \
627 pReq->u.Internal.cArgs = 2; \
628 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
629 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
630 pReq->fFlags = RTREQFLAGS_VOID; \
631 rc = RTReqQueue(pReq, 0); \
632 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
633 { \
634 SOCKET_UNLOCK(so); \
635 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
636 AssertReleaseRC(rc); \
637 SOCKET_LOCK(so); \
638 RTReqFree(pReq); \
639 } \
640 else \
641 AssertReleaseRC(rc); \
642 } while(0)
643
644# define DO_UDP_DETACH(data, so, so_next) \
645 do { \
646 PRTREQ pReq = NULL; \
647 int rc; \
648 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
649 AssertReleaseRC(rc); \
650 pReq->u.Internal.pfn = (PFNRT)udp_detach; \
651 pReq->u.Internal.cArgs = 2; \
652 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
653 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
654 pReq->fFlags = RTREQFLAGS_VOID; \
655 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
656 if (RT_LIKELY(rc) == VERR_TIMEOUT) \
657 { \
658 SOCKET_UNLOCK(so); \
659 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
660 AssertReleaseRC(rc); \
661 if ((so_next) != &udb) SOCKET_LOCK((so_next)); \
662 RTReqFree(pReq); \
663 } \
664 else \
665 AssertReleaseRC(rc); \
666 } while(0)
667
668# define SOLOOKUP(so, label, src, sport, dst, dport) \
669 do { \
670 struct socket *sonxt; \
671 (so) = NULL; \
672 QSOCKET_FOREACH(so, sonxt, label) \
673 /* { */ \
674 if ( so->so_lport == (sport) \
675 && so->so_laddr.s_addr == (src).s_addr \
676 && so->so_faddr.s_addr == (dst).s_addr \
677 && so->so_fport == (dport)) \
678 { \
679 if (sonxt != &VBOX_X2(queue_ ## label ## _label)) \
680 SOCKET_UNLOCK(sonxt); \
681 break; /*so is locked*/ \
682 } \
683 LOOP_LABEL(so, sonxt, label); \
684 } \
685 } \
686 } while (0)
687
688#else /* !VBOX_WITH_SLIRP_MT */
689
690# define QSOCKET_LOCK(queue) do {} while (0)
691# define QSOCKET_UNLOCK(queue) do {} while (0)
692# define QSOCKET_LOCK_CREATE(queue) do {} while (0)
693# define QSOCKET_LOCK_DESTROY(queue) do {} while (0)
694# define QSOCKET_FOREACH(so, sonext, label) \
695 for ((so) = VBOX_X2(queue_ ## label ## _label).so_next; \
696 (so) != &(VBOX_X2(queue_ ## label ## _label)); \
697 (so) = (sonext)) \
698 { \
699 (sonext) = (so)->so_next;
700# define CONTINUE(label) continue
701# define CONTINUE_NO_UNLOCK(label) continue
702# define LOOP_LABEL(label, so, sonext) /* empty*/
703# define DO_TCP_OUTPUT(data, sotcb) tcp_output((data), (sotcb))
704# define DO_TCP_INPUT(data, mbuf, size, so) tcp_input((data), (mbuf), (size), (so))
705# define DO_TCP_CONNECT(data, so) tcp_connect((data), (so))
706# define DO_SOREAD(ret, data, so, ifclose) \
707 do { \
708 (ret) = soread((data), (so), (ifclose)); \
709 } while(0)
710# define DO_SOWRITE(ret, data, so) \
711 do { \
712 (ret) = sowrite((data), (so)); \
713 } while(0)
714# define DO_SORECFROM(data, so) sorecvfrom((data), (so))
715# define SOLOOKUP(so, label, src, sport, dst, dport) \
716 do { \
717 (so) = solookup(&VBOX_X2(queue_ ## label ## _label), (src), (sport), (dst), (dport)); \
718 } while (0)
719# define DO_UDP_DETACH(data, so, ignored) udp_detach((data), (so))
720
721#endif /* !VBOX_WITH_SLIRP_MT */
722
723#define TCP_OUTPUT(data, sotcb) DO_TCP_OUTPUT((data), (sotcb))
724#define TCP_INPUT(data, mbuf, size, so) DO_TCP_INPUT((data), (mbuf), (size), (so))
725#define TCP_CONNECT(data, so) DO_TCP_CONNECT((data), (so))
726#define SOREAD(ret, data, so, ifclose) DO_SOREAD((ret), (data), (so), (ifclose))
727#define SOWRITE(ret, data, so) DO_SOWRITE((ret), (data), (so))
728#define SORECVFROM(data, so) DO_SORECFROM((data), (so))
729#define UDP_DETACH(data, so, so_next) DO_UDP_DETACH((data), (so), (so_next))
730
731/* dnsproxy/dnsproxy.c */
732#define authoritative_port pData->authoritative_port
733#define authoritative_timeout pData->authoritative_timeout
734#define recursive_port pData->recursive_port
735#define recursive_timeout pData->recursive_timeout
736#define stats_timeout pData->stats_timeout
737/* dnsproxy/hash.c */
738#define dns_port pData->port
739#define request_hash pData->request_hash
740#define hash_collisions pData->hash_collisions
741#define active_queries pData->active_queries
742#define all_queries pData->all_queries
743#define authoritative_queries pData->authoritative_queries
744#define recursive_queries pData->recursive_queries
745#define removed_queries pData->removed_queries
746#define dropped_queries pData->dropped_queries
747#define answered_queries pData->answered_queries
748#define dropped_answers pData->dropped_answers
749#define late_answers pData->late_answers
750
751/* dnsproxy/dnsproxy.c */
752#define queryid pData->queryid
753#define authoritative_addr pData->authoritative_addr
754#define recursive_addr pData->recursive_addr
755#define sock_query pData->sock_query
756#define sock_answer pData->sock_answer
757
758#define instancehead pData->instancehead
759
760#ifdef VBOX_WITH_SLIRP_BSD_MBUF
761# define nmbclusters pData->nmbclusters
762# define nmbjumbop pData->nmbjumbop
763# define nmbjumbo9 pData->nmbjumbo9
764# define nmbjumbo16 pData->nmbjumbo16
765# define mbstat pData->mbstat
766# include "ext.h"
767# undef zone_mbuf
768# undef zone_clust
769# undef zone_pack
770# undef zone_jumbop
771# undef zone_jumbo9
772# undef zone_jumbo16
773# undef zone_ext_refcnt
774static inline uma_zone_t slirp_zone_pack(PNATState pData)
775{
776 return pData->zone_pack;
777}
778static inline uma_zone_t slirp_zone_jumbop(PNATState pData)
779{
780 return pData->zone_jumbop;
781}
782static inline uma_zone_t slirp_zone_jumbo9(PNATState pData)
783{
784 return pData->zone_jumbo9;
785}
786static inline uma_zone_t slirp_zone_jumbo16(PNATState pData)
787{
788 return pData->zone_jumbo16;
789}
790static inline uma_zone_t slirp_zone_ext_refcnt(PNATState pData)
791{
792 return pData->zone_ext_refcnt;
793}
794static inline uma_zone_t slirp_zone_mbuf(PNATState pData)
795{
796 return pData->zone_mbuf;
797}
798static inline uma_zone_t slirp_zone_clust(PNATState pData)
799{
800 return pData->zone_clust;
801}
802#ifndef VBOX_SLIRP_BSD
803# define m_adj(m, len) m_adj(pData, (m), (len))
804#endif
805#endif
806
807#endif /* !___slirp_state_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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