VirtualBox

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

Last change on this file since 23004 was 22895, checked in by vboxsync, 16 years ago

NAT: BSD mbuf's related changeset.

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