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 "ip_icmp.h"
|
---|
26 | #include "dnsproxy/dnsproxy.h"
|
---|
27 |
|
---|
28 | /** Number of DHCP clients supported by NAT. */
|
---|
29 | #define NB_ADDR 16
|
---|
30 |
|
---|
31 | /** Where to start DHCP IP number allocation. */
|
---|
32 | #define START_ADDR 15
|
---|
33 |
|
---|
34 | /** DHCP Lease time. */
|
---|
35 | #define LEASE_TIME (24 * 3600)
|
---|
36 |
|
---|
37 | /** Entry in the table of known DHCP clients. */
|
---|
38 | typedef struct
|
---|
39 | {
|
---|
40 | bool allocated;
|
---|
41 | uint8_t macaddr[6];
|
---|
42 | #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
|
---|
43 | struct in_addr addr;
|
---|
44 | #endif
|
---|
45 | } BOOTPClient;
|
---|
46 |
|
---|
47 |
|
---|
48 | /** TFTP session entry. */
|
---|
49 | struct tftp_session
|
---|
50 | {
|
---|
51 | int in_use;
|
---|
52 | unsigned char filename[TFTP_FILENAME_MAX];
|
---|
53 |
|
---|
54 | struct in_addr client_ip;
|
---|
55 | u_int16_t client_port;
|
---|
56 |
|
---|
57 | int timestamp;
|
---|
58 | };
|
---|
59 |
|
---|
60 | struct dns_domain_entry
|
---|
61 | {
|
---|
62 | char *dd_pszDomain;
|
---|
63 | LIST_ENTRY(dns_domain_entry) dd_list;
|
---|
64 | };
|
---|
65 | LIST_HEAD(dns_domain_list_head, dns_domain_entry);
|
---|
66 |
|
---|
67 | struct dns_entry
|
---|
68 | {
|
---|
69 | struct in_addr de_addr;
|
---|
70 | TAILQ_ENTRY(dns_entry) de_list;
|
---|
71 | };
|
---|
72 | TAILQ_HEAD(dns_list_head, dns_entry);
|
---|
73 |
|
---|
74 | /** Main state/configuration structure for slirp NAT. */
|
---|
75 | typedef struct NATState
|
---|
76 | {
|
---|
77 | /* Stuff from boot.c */
|
---|
78 | BOOTPClient bootp_clients[NB_ADDR];
|
---|
79 | const char *bootp_filename;
|
---|
80 | /* Stuff from if.c */
|
---|
81 | int if_mtu, if_mru;
|
---|
82 | int if_comp;
|
---|
83 | int if_maxlinkhdr;
|
---|
84 | int if_queued;
|
---|
85 | int if_thresh;
|
---|
86 | struct mbuf if_fastq;
|
---|
87 | struct mbuf if_batchq;
|
---|
88 | struct mbuf *next_m;
|
---|
89 | /* Stuff from icmp.c */
|
---|
90 | struct icmpstat_t icmpstat;
|
---|
91 | /* Stuff from ip_input.c */
|
---|
92 | struct ipstat_t ipstat;
|
---|
93 | struct ipqhead ipq[IPREASS_NHASH];
|
---|
94 | int maxnipq; /* Administrative limit on # of reass queues*/
|
---|
95 | int maxfragsperpacket; /* Maximum number of IPv4 fragments allowed per packet */
|
---|
96 | int nipq; /* total number of reass queues */
|
---|
97 | uint16_t ip_currid;
|
---|
98 | /* Stuff from mbuf.c */
|
---|
99 | int mbuf_alloced, mbuf_max;
|
---|
100 | int msize;
|
---|
101 | struct mbuf m_freelist, m_usedlist;
|
---|
102 | /* Stuff from slirp.c */
|
---|
103 | void *pvUser;
|
---|
104 | uint32_t curtime;
|
---|
105 | uint32_t time_fasttimo;
|
---|
106 | uint32_t last_slowtimo;
|
---|
107 | bool do_slowtimo;
|
---|
108 | bool link_up;
|
---|
109 | struct timeval tt;
|
---|
110 | struct in_addr our_addr;
|
---|
111 | struct in_addr alias_addr;
|
---|
112 | struct in_addr special_addr;
|
---|
113 |
|
---|
114 | int tcp_rcvspace;
|
---|
115 | int tcp_sndspace;
|
---|
116 | int socket_rcv;
|
---|
117 | int socket_snd;
|
---|
118 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
119 | PRTREQQUEUE pReqQueue;
|
---|
120 | #endif
|
---|
121 | #ifdef RT_OS_WINDOWS
|
---|
122 | ULONG (WINAPI * pfGetAdaptersAddresses)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG);
|
---|
123 | #endif
|
---|
124 | struct dns_list_head dns_list_head;
|
---|
125 | struct dns_domain_list_head dns_domain_list_head;
|
---|
126 | struct in_addr tftp_server;
|
---|
127 | struct in_addr loopback_addr;
|
---|
128 | uint32_t netmask;
|
---|
129 | #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
|
---|
130 | uint8_t client_ethaddr[6];
|
---|
131 | #else
|
---|
132 | const uint8_t *slirp_ethaddr;
|
---|
133 | #endif
|
---|
134 | struct ex_list *exec_list;
|
---|
135 | char slirp_hostname[33];
|
---|
136 | bool fPassDomain;
|
---|
137 | struct in_addr bindIP;
|
---|
138 | /* Stuff from tcp_input.c */
|
---|
139 | struct socket tcb;
|
---|
140 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
141 | RTCRITSECT tcb_mutex;
|
---|
142 | #endif
|
---|
143 | struct socket *tcp_last_so;
|
---|
144 | tcp_seq tcp_iss;
|
---|
145 | /* Stuff from tcp_timer.c */
|
---|
146 | struct tcpstat_t tcpstat;
|
---|
147 | uint32_t tcp_now;
|
---|
148 | int tcp_reass_qsize;
|
---|
149 | int tcp_reass_maxqlen;
|
---|
150 | int tcp_reass_maxseg;
|
---|
151 | int tcp_reass_overflows;
|
---|
152 | /* Stuff from tftp.c */
|
---|
153 | struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
|
---|
154 | const char *tftp_prefix;
|
---|
155 | /* Stuff from udp.c */
|
---|
156 | struct udpstat_t udpstat;
|
---|
157 | struct socket udb;
|
---|
158 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
159 | RTCRITSECT udb_mutex;
|
---|
160 | #endif
|
---|
161 | struct socket *udp_last_so;
|
---|
162 | struct socket icmp_socket;
|
---|
163 | struct icmp_storage icmp_msg_head;
|
---|
164 | # ifndef RT_OS_WINDOWS
|
---|
165 | /* counter of sockets needed for allocation enough room to
|
---|
166 | * process sockets with poll/epoll
|
---|
167 | *
|
---|
168 | * NSOCK_INC/DEC should be injected before every
|
---|
169 | * operation on socket queue (tcb, udb)
|
---|
170 | */
|
---|
171 | int nsock;
|
---|
172 | # define NSOCK_INC() do {pData->nsock++;} while (0)
|
---|
173 | # define NSOCK_DEC() do {pData->nsock--;} while (0)
|
---|
174 | # define NSOCK_INC_EX(ex) do {ex->pData->nsock++;} while (0)
|
---|
175 | # define NSOCK_DEC_EX(ex) do {ex->pData->nsock--;} while (0)
|
---|
176 | # else
|
---|
177 | # define NSOCK_INC() do {} while (0)
|
---|
178 | # define NSOCK_DEC() do {} while (0)
|
---|
179 | # define NSOCK_INC_EX(ex) do {} while (0)
|
---|
180 | # define NSOCK_DEC_EX(ex) do {} while (0)
|
---|
181 | # endif
|
---|
182 | # ifdef RT_OS_WINDOWS
|
---|
183 | void *pvIcmpBuffer;
|
---|
184 | size_t szIcmpBuffer;
|
---|
185 | /* Accordin MSDN specification IcmpParseReplies
|
---|
186 | * function should be detected in runtime
|
---|
187 | */
|
---|
188 | long (WINAPI * pfIcmpParseReplies)(void *, long);
|
---|
189 | BOOL (WINAPI * pfIcmpCloseHandle)(HANDLE);
|
---|
190 | HMODULE hmIcmpLibrary;
|
---|
191 | # endif
|
---|
192 | #if defined(RT_OS_WINDOWS)
|
---|
193 | # define VBOX_SOCKET_EVENT (pData->phEvents[VBOX_SOCKET_EVENT_INDEX])
|
---|
194 | HANDLE phEvents[VBOX_EVENT_COUNT];
|
---|
195 | #endif
|
---|
196 |
|
---|
197 | /* from dnsproxy/dnsproxy.h*/
|
---|
198 | unsigned int authoritative_port;
|
---|
199 | unsigned int authoritative_timeout;
|
---|
200 | unsigned int recursive_port;
|
---|
201 | unsigned int recursive_timeout;
|
---|
202 | unsigned int stats_timeout;
|
---|
203 | unsigned int port;
|
---|
204 |
|
---|
205 | unsigned long active_queries;
|
---|
206 | unsigned long all_queries;
|
---|
207 | unsigned long authoritative_queries;
|
---|
208 | unsigned long recursive_queries;
|
---|
209 | unsigned long removed_queries;
|
---|
210 | unsigned long dropped_queries;
|
---|
211 | unsigned long answered_queries;
|
---|
212 | unsigned long dropped_answers;
|
---|
213 | unsigned long late_answers;
|
---|
214 | unsigned long hash_collisions;
|
---|
215 | /*dnsproxy/dnsproxy.c*/
|
---|
216 | unsigned short queryid;
|
---|
217 | struct sockaddr_in authoritative_addr;
|
---|
218 | struct sockaddr_in recursive_addr;
|
---|
219 | int sock_query;
|
---|
220 | int sock_answer;
|
---|
221 | /* dnsproxy/hash.c */
|
---|
222 | #define HASHSIZE 10
|
---|
223 | #define HASH(id) (id & ((1 << HASHSIZE) - 1))
|
---|
224 | struct request *request_hash[1 << HASHSIZE];
|
---|
225 | /* this field control behaviour of DHCP server */
|
---|
226 | bool use_dns_proxy;
|
---|
227 |
|
---|
228 | #ifdef VBOX_WITH_SLIRP_ALIAS
|
---|
229 | LIST_HEAD(RT_NOTHING, libalias) instancehead;
|
---|
230 | struct libalias *proxy_alias;
|
---|
231 | #endif
|
---|
232 |
|
---|
233 | #define PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name
|
---|
234 | #define COUNTING_COUNTER(name, dsc) STAMCOUNTER Stat ## name
|
---|
235 |
|
---|
236 | #include "counters.h"
|
---|
237 |
|
---|
238 | #undef PROFILE_COUNTER
|
---|
239 | #undef COUNTING_COUNTER
|
---|
240 |
|
---|
241 | } NATState;
|
---|
242 |
|
---|
243 |
|
---|
244 | /** Default IP time to live. */
|
---|
245 | #define ip_defttl IPDEFTTL
|
---|
246 |
|
---|
247 | /** Number of permanent buffers in mbuf. */
|
---|
248 | #define mbuf_thresh 30
|
---|
249 |
|
---|
250 | /** Use a fixed time before sending keepalive. */
|
---|
251 | #define tcp_keepidle TCPTV_KEEP_IDLE
|
---|
252 |
|
---|
253 | /** Use a fixed interval between keepalive. */
|
---|
254 | #define tcp_keepintvl TCPTV_KEEPINTVL
|
---|
255 |
|
---|
256 | /** Maximum idle time before timing out a connection. */
|
---|
257 | #define tcp_maxidle (TCPTV_KEEPCNT * tcp_keepintvl)
|
---|
258 |
|
---|
259 | /** Default TCP socket options. */
|
---|
260 | #define so_options DO_KEEPALIVE
|
---|
261 |
|
---|
262 | /** Default TCP MSS value. */
|
---|
263 | #define tcp_mssdflt TCP_MSS
|
---|
264 |
|
---|
265 | /** Default TCP round trip time. */
|
---|
266 | #define tcp_rttdflt (TCPTV_SRTTDFLT / PR_SLOWHZ)
|
---|
267 |
|
---|
268 | /** Enable RFC1323 performance enhancements.
|
---|
269 | * @todo check if it really works, it was turned off before. */
|
---|
270 | #define tcp_do_rfc1323 1
|
---|
271 |
|
---|
272 | /** TCP receive buffer size. */
|
---|
273 | #define tcp_rcvspace pData->tcp_rcvspace
|
---|
274 |
|
---|
275 | /** TCP receive buffer size. */
|
---|
276 | #define tcp_sndspace pData->tcp_sndspace
|
---|
277 |
|
---|
278 | /* TCP duplicate ACK retransmit threshold. */
|
---|
279 | #define tcprexmtthresh 3
|
---|
280 |
|
---|
281 |
|
---|
282 | #define bootp_filename pData->bootp_filename
|
---|
283 | #define bootp_clients pData->bootp_clients
|
---|
284 |
|
---|
285 | #define if_mtu pData->if_mtu
|
---|
286 | #define if_mru pData->if_mru
|
---|
287 | #define if_comp pData->if_comp
|
---|
288 | #define if_maxlinkhdr pData->if_maxlinkhdr
|
---|
289 | #define if_queued pData->if_queued
|
---|
290 | #define if_thresh pData->if_thresh
|
---|
291 | #define if_fastq pData->if_fastq
|
---|
292 | #define if_batchq pData->if_batchq
|
---|
293 | #define next_m pData->next_m
|
---|
294 |
|
---|
295 | #define icmpstat pData->icmpstat
|
---|
296 |
|
---|
297 | #define ipstat pData->ipstat
|
---|
298 | #define ipq pData->ipq
|
---|
299 | #define ip_currid pData->ip_currid
|
---|
300 |
|
---|
301 | #define mbuf_alloced pData->mbuf_alloced
|
---|
302 | #define mbuf_max pData->mbuf_max
|
---|
303 | #define msize pData->msize
|
---|
304 | #define m_freelist pData->m_freelist
|
---|
305 | #define m_usedlist pData->m_usedlist
|
---|
306 |
|
---|
307 | #define curtime pData->curtime
|
---|
308 | #define time_fasttimo pData->time_fasttimo
|
---|
309 | #define last_slowtimo pData->last_slowtimo
|
---|
310 | #define do_slowtimo pData->do_slowtimo
|
---|
311 | #define link_up pData->link_up
|
---|
312 | #define cUsers pData->cUsers
|
---|
313 | #define tt pData->tt
|
---|
314 | #define our_addr pData->our_addr
|
---|
315 | #ifndef VBOX_SLIRP_ALIAS
|
---|
316 | # define alias_addr pData->alias_addr
|
---|
317 | #endif
|
---|
318 | #define special_addr pData->special_addr
|
---|
319 | #define dns_addr pData->dns_addr
|
---|
320 | #define loopback_addr pData->loopback_addr
|
---|
321 | #define client_ethaddr pData->client_ethaddr
|
---|
322 | #define exec_list pData->exec_list
|
---|
323 | #define slirp_hostname pData->slirp_hostname
|
---|
324 |
|
---|
325 | #define tcb pData->tcb
|
---|
326 | #define tcp_last_so pData->tcp_last_so
|
---|
327 | #define tcp_iss pData->tcp_iss
|
---|
328 |
|
---|
329 | #define tcpstat pData->tcpstat
|
---|
330 | #define tcp_now pData->tcp_now
|
---|
331 |
|
---|
332 | #define tftp_sessions pData->tftp_sessions
|
---|
333 | #define tftp_prefix pData->tftp_prefix
|
---|
334 |
|
---|
335 | #define udpstat pData->udpstat
|
---|
336 | #define udb pData->udb
|
---|
337 | #define udp_last_so pData->udp_last_so
|
---|
338 |
|
---|
339 | #define maxfragsperpacket pData->maxfragsperpacket
|
---|
340 | #define maxnipq pData->maxnipq
|
---|
341 | #define nipq pData->nipq
|
---|
342 |
|
---|
343 | #define tcp_reass_qsize pData->tcp_reass_qsize
|
---|
344 | #define tcp_reass_maxqlen pData->tcp_reass_maxqlen
|
---|
345 | #define tcp_reass_maxseg pData->tcp_reass_maxseg
|
---|
346 | #define tcp_reass_overflows pData->tcp_reass_overflows
|
---|
347 |
|
---|
348 | #define queue_tcp_label tcb
|
---|
349 | #define queue_udp_label udb
|
---|
350 | #define VBOX_X2(x) x
|
---|
351 | #define VBOX_X(x) VBOX_X2(x)
|
---|
352 |
|
---|
353 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
354 |
|
---|
355 | # define QSOCKET_LOCK(queue) \
|
---|
356 | do { \
|
---|
357 | int rc; \
|
---|
358 | /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \
|
---|
359 | rc = RTCritSectEnter(&VBOX_X(queue) ## _mutex); \
|
---|
360 | AssertReleaseRC(rc); \
|
---|
361 | } while (0)
|
---|
362 | # define QSOCKET_UNLOCK(queue) \
|
---|
363 | do { \
|
---|
364 | int rc; \
|
---|
365 | rc = RTCritSectLeave(&VBOX_X(queue) ## _mutex); \
|
---|
366 | AssertReleaseRC(rc); \
|
---|
367 | } while (0)
|
---|
368 | # define QSOCKET_LOCK_CREATE(queue) \
|
---|
369 | do { \
|
---|
370 | int rc; \
|
---|
371 | rc = RTCritSectInit(&pData->queue ## _mutex); \
|
---|
372 | AssertReleaseRC(rc); \
|
---|
373 | } while (0)
|
---|
374 | # define QSOCKET_LOCK_DESTROY(queue) \
|
---|
375 | do { \
|
---|
376 | int rc = RTCritSectDelete(&pData->queue ## _mutex); \
|
---|
377 | AssertReleaseRC(rc); \
|
---|
378 | } while (0)
|
---|
379 |
|
---|
380 | # define QSOCKET_FOREACH(so, sonext, label) \
|
---|
381 | QSOCKET_LOCK(VBOX_X2(queue_## label ## _label)); \
|
---|
382 | (so) = (VBOX_X(queue_ ## label ## _label)).so_next; \
|
---|
383 | QSOCKET_UNLOCK(VBOX_X2(queue_## label ##_label)); \
|
---|
384 | if ((so) != &(VBOX_X(queue_## label ## _label))) SOCKET_LOCK((so));\
|
---|
385 | for (;;) \
|
---|
386 | { \
|
---|
387 | if ((so) == &(VBOX_X(queue_## label ## _label))) \
|
---|
388 | { \
|
---|
389 | break; \
|
---|
390 | } \
|
---|
391 | Log2(("%s:%d Processing so:%R[natsock]\n", __FUNCTION__, __LINE__, (so)));
|
---|
392 |
|
---|
393 | # define CONTINUE_NO_UNLOCK(label) goto loop_end_ ## label ## _mt_nounlock
|
---|
394 | # define CONTINUE(label) goto loop_end_ ## label ## _mt
|
---|
395 | /* @todo replace queue parameter with macrodinition */
|
---|
396 | /* _mt_nounlock - user should lock so_next before calling CONTINUE_NO_UNLOCK */
|
---|
397 | # define LOOP_LABEL(label, so, sonext) loop_end_ ## label ## _mt: \
|
---|
398 | (sonext) = (so)->so_next; \
|
---|
399 | SOCKET_UNLOCK(so); \
|
---|
400 | QSOCKET_LOCK(VBOX_X(queue_ ## label ## _label)); \
|
---|
401 | if ((sonext) != &(VBOX_X(queue_## label ## _label))) \
|
---|
402 | { \
|
---|
403 | SOCKET_LOCK((sonext)); \
|
---|
404 | QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \
|
---|
405 | } \
|
---|
406 | else \
|
---|
407 | { \
|
---|
408 | so = &VBOX_X(queue_ ## label ## _label); \
|
---|
409 | QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \
|
---|
410 | break; \
|
---|
411 | } \
|
---|
412 | (so) = (sonext); \
|
---|
413 | continue; \
|
---|
414 | loop_end_ ## label ## _mt_nounlock: \
|
---|
415 | (so) = (sonext)
|
---|
416 |
|
---|
417 | # define DO_TCP_OUTPUT(data, sotcb) \
|
---|
418 | do { \
|
---|
419 | PRTREQ pReq = NULL; \
|
---|
420 | int rc; \
|
---|
421 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
422 | AssertReleaseRC(rc); \
|
---|
423 | pReq->u.Internal.pfn = (PFNRT)tcp_output; \
|
---|
424 | pReq->u.Internal.cArgs = 2; \
|
---|
425 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
426 | pReq->u.Internal.aArgs[1] = (uintptr_t)(sotcb); \
|
---|
427 | pReq->fFlags = RTREQFLAGS_VOID; \
|
---|
428 | rc = RTReqQueue(pReq, 0); \
|
---|
429 | if (RT_LIKELY(rc) == VERR_TIMEOUT) \
|
---|
430 | { \
|
---|
431 | SOCKET_UNLOCK(so); \
|
---|
432 | rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
|
---|
433 | AssertReleaseRC(rc); \
|
---|
434 | SOCKET_LOCK(so); \
|
---|
435 | RTReqFree(pReq); \
|
---|
436 | } \
|
---|
437 | else \
|
---|
438 | AssertReleaseRC(rc); \
|
---|
439 | } while(0)
|
---|
440 |
|
---|
441 | # define DO_TCP_INPUT(data, mbuf, size, so) \
|
---|
442 | do { \
|
---|
443 | PRTREQ pReq = NULL; \
|
---|
444 | int rc; \
|
---|
445 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
446 | AssertReleaseRC(rc); \
|
---|
447 | pReq->u.Internal.pfn = (PFNRT)tcp_input; \
|
---|
448 | pReq->u.Internal.cArgs = 4; \
|
---|
449 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
450 | pReq->u.Internal.aArgs[1] = (uintptr_t)(mbuf); \
|
---|
451 | pReq->u.Internal.aArgs[2] = (uintptr_t)(size); \
|
---|
452 | pReq->u.Internal.aArgs[3] = (uintptr_t)(so); \
|
---|
453 | pReq->fFlags = RTREQFLAGS_VOID|RTREQFLAGS_NO_WAIT; \
|
---|
454 | rc = RTReqQueue(pReq, 0); \
|
---|
455 | AssertReleaseRC(rc); \
|
---|
456 | } while(0)
|
---|
457 |
|
---|
458 | # define DO_TCP_CONNECT(data, so) \
|
---|
459 | do { \
|
---|
460 | PRTREQ pReq = NULL; \
|
---|
461 | int rc; \
|
---|
462 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
463 | AssertReleaseRC(rc); \
|
---|
464 | pReq->u.Internal.pfn = (PFNRT)tcp_connect; \
|
---|
465 | pReq->u.Internal.cArgs = 2; \
|
---|
466 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
467 | pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
|
---|
468 | pReq->fFlags = RTREQFLAGS_VOID; \
|
---|
469 | rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
|
---|
470 | if (RT_LIKELY(rc) == VERR_TIMEOUT) \
|
---|
471 | { \
|
---|
472 | SOCKET_UNLOCK(so); \
|
---|
473 | rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
|
---|
474 | AssertReleaseRC(rc); \
|
---|
475 | SOCKET_LOCK(so); \
|
---|
476 | RTReqFree(pReq); \
|
---|
477 | } \
|
---|
478 | else \
|
---|
479 | AssertReleaseRC(rc); \
|
---|
480 | } while(0)
|
---|
481 |
|
---|
482 | # define DO_SOREAD(ret, data, so, ifclose) \
|
---|
483 | do { \
|
---|
484 | PRTREQ pReq = NULL; \
|
---|
485 | int rc; \
|
---|
486 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
487 | AssertReleaseRC(rc); \
|
---|
488 | pReq->u.Internal.pfn = (PFNRT)soread_queue; \
|
---|
489 | pReq->u.Internal.cArgs = 4; \
|
---|
490 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
491 | pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
|
---|
492 | pReq->u.Internal.aArgs[2] = (uintptr_t)(ifclose); \
|
---|
493 | pReq->u.Internal.aArgs[3] = (uintptr_t)&(ret); \
|
---|
494 | pReq->fFlags = RTREQFLAGS_VOID; \
|
---|
495 | rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
|
---|
496 | if (RT_LIKELY(rc) == VERR_TIMEOUT) \
|
---|
497 | { \
|
---|
498 | SOCKET_UNLOCK(so); \
|
---|
499 | rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
|
---|
500 | AssertReleaseRC(rc); \
|
---|
501 | SOCKET_LOCK(so); \
|
---|
502 | RTReqFree(pReq); \
|
---|
503 | } \
|
---|
504 | else \
|
---|
505 | AssertReleaseRC(rc); \
|
---|
506 | } while(0)
|
---|
507 |
|
---|
508 | # define DO_SOWRITE(ret, data, so) \
|
---|
509 | do { \
|
---|
510 | PRTREQ pReq = NULL; \
|
---|
511 | int rc; \
|
---|
512 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
513 | AssertReleaseRC(rc); \
|
---|
514 | pReq->u.Internal.pfn = (PFNRT)sowrite; \
|
---|
515 | pReq->u.Internal.cArgs = 2; \
|
---|
516 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
517 | pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
|
---|
518 | pReq->fFlags = RTREQFLAGS_RETURN_MASK; \
|
---|
519 | rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
|
---|
520 | if (RT_LIKELY(rc) == VERR_TIMEOUT) \
|
---|
521 | { \
|
---|
522 | SOCKET_UNLOCK(so); \
|
---|
523 | rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
|
---|
524 | SOCKET_LOCK(so); \
|
---|
525 | ret = pReq->iStatus; \
|
---|
526 | RTReqFree(pReq); \
|
---|
527 | } \
|
---|
528 | else \
|
---|
529 | AssertReleaseRC(rc); \
|
---|
530 | } while(0)
|
---|
531 |
|
---|
532 | # define DO_SORECFROM(data, so) \
|
---|
533 | do { \
|
---|
534 | PRTREQ pReq = NULL; \
|
---|
535 | int rc; \
|
---|
536 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
537 | AssertReleaseRC(rc); \
|
---|
538 | pReq->u.Internal.pfn = (PFNRT)sorecvfrom; \
|
---|
539 | pReq->u.Internal.cArgs = 2; \
|
---|
540 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
541 | pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
|
---|
542 | pReq->fFlags = RTREQFLAGS_VOID; \
|
---|
543 | rc = RTReqQueue(pReq, 0); \
|
---|
544 | if (RT_LIKELY(rc) == VERR_TIMEOUT) \
|
---|
545 | { \
|
---|
546 | SOCKET_UNLOCK(so); \
|
---|
547 | rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
|
---|
548 | AssertReleaseRC(rc); \
|
---|
549 | SOCKET_LOCK(so); \
|
---|
550 | RTReqFree(pReq); \
|
---|
551 | } \
|
---|
552 | else \
|
---|
553 | AssertReleaseRC(rc); \
|
---|
554 | } while(0)
|
---|
555 |
|
---|
556 | # define DO_UDP_DETACH(data, so, so_next) \
|
---|
557 | do { \
|
---|
558 | PRTREQ pReq = NULL; \
|
---|
559 | int rc; \
|
---|
560 | rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \
|
---|
561 | AssertReleaseRC(rc); \
|
---|
562 | pReq->u.Internal.pfn = (PFNRT)udp_detach; \
|
---|
563 | pReq->u.Internal.cArgs = 2; \
|
---|
564 | pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \
|
---|
565 | pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \
|
---|
566 | pReq->fFlags = RTREQFLAGS_VOID; \
|
---|
567 | rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \
|
---|
568 | if (RT_LIKELY(rc) == VERR_TIMEOUT) \
|
---|
569 | { \
|
---|
570 | SOCKET_UNLOCK(so); \
|
---|
571 | rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \
|
---|
572 | AssertReleaseRC(rc); \
|
---|
573 | if ((so_next) != &udb) SOCKET_LOCK((so_next)); \
|
---|
574 | RTReqFree(pReq); \
|
---|
575 | } \
|
---|
576 | else \
|
---|
577 | AssertReleaseRC(rc); \
|
---|
578 | } while(0)
|
---|
579 |
|
---|
580 | # define SOLOOKUP(so, label, src, sport, dst, dport) \
|
---|
581 | do { \
|
---|
582 | struct socket *sonxt; \
|
---|
583 | (so) = NULL; \
|
---|
584 | QSOCKET_FOREACH(so, sonxt, label) \
|
---|
585 | /* { */ \
|
---|
586 | if ( so->so_lport == (sport) \
|
---|
587 | && so->so_laddr.s_addr == (src).s_addr \
|
---|
588 | && so->so_faddr.s_addr == (dst).s_addr \
|
---|
589 | && so->so_fport == (dport)) \
|
---|
590 | { \
|
---|
591 | if (sonxt != &VBOX_X2(queue_ ## label ## _label)) \
|
---|
592 | SOCKET_UNLOCK(sonxt); \
|
---|
593 | break; /*so is locked*/ \
|
---|
594 | } \
|
---|
595 | LOOP_LABEL(so, sonxt, label); \
|
---|
596 | } \
|
---|
597 | } \
|
---|
598 | } while (0)
|
---|
599 |
|
---|
600 | #else /* !VBOX_WITH_SLIRP_MT */
|
---|
601 |
|
---|
602 | # define QSOCKET_LOCK(queue) do {} while (0)
|
---|
603 | # define QSOCKET_UNLOCK(queue) do {} while (0)
|
---|
604 | # define QSOCKET_LOCK_CREATE(queue) do {} while (0)
|
---|
605 | # define QSOCKET_LOCK_DESTROY(queue) do {} while (0)
|
---|
606 | # define QSOCKET_FOREACH(so, sonext, label) \
|
---|
607 | for ((so) = VBOX_X2(queue_ ## label ## _label).so_next; \
|
---|
608 | (so) != &(VBOX_X2(queue_ ## label ## _label)); \
|
---|
609 | (so) = (sonext)) \
|
---|
610 | { \
|
---|
611 | (sonext) = (so)->so_next;
|
---|
612 | # define CONTINUE(label) continue
|
---|
613 | # define CONTINUE_NO_UNLOCK(label) continue
|
---|
614 | # define LOOP_LABEL(label, so, sonext) /* empty*/
|
---|
615 | # define DO_TCP_OUTPUT(data, sotcb) tcp_output((data), (sotcb))
|
---|
616 | # define DO_TCP_INPUT(data, mbuf, size, so) tcp_input((data), (mbuf), (size), (so))
|
---|
617 | # define DO_TCP_CONNECT(data, so) tcp_connect((data), (so))
|
---|
618 | # define DO_SOREAD(ret, data, so, ifclose) \
|
---|
619 | do { \
|
---|
620 | (ret) = soread((data), (so), (ifclose)); \
|
---|
621 | } while(0)
|
---|
622 | # define DO_SOWRITE(ret, data, so) \
|
---|
623 | do { \
|
---|
624 | (ret) = sowrite((data), (so)); \
|
---|
625 | } while(0)
|
---|
626 | # define DO_SORECFROM(data, so) sorecvfrom((data), (so))
|
---|
627 | # define SOLOOKUP(so, label, src, sport, dst, dport) \
|
---|
628 | do { \
|
---|
629 | (so) = solookup(&VBOX_X2(queue_ ## label ## _label), (src), (sport), (dst), (dport)); \
|
---|
630 | } while (0)
|
---|
631 | # define DO_UDP_DETACH(data, so, ignored) udp_detach((data), (so))
|
---|
632 |
|
---|
633 | #endif /* !VBOX_WITH_SLIRP_MT */
|
---|
634 |
|
---|
635 | #define TCP_OUTPUT(data, sotcb) DO_TCP_OUTPUT((data), (sotcb))
|
---|
636 | #define TCP_INPUT(data, mbuf, size, so) DO_TCP_INPUT((data), (mbuf), (size), (so))
|
---|
637 | #define TCP_CONNECT(data, so) DO_TCP_CONNECT((data), (so))
|
---|
638 | #define SOREAD(ret, data, so, ifclose) DO_SOREAD((ret), (data), (so), (ifclose))
|
---|
639 | #define SOWRITE(ret, data, so) DO_SOWRITE((ret), (data), (so))
|
---|
640 | #define SORECVFROM(data, so) DO_SORECFROM((data), (so))
|
---|
641 | #define UDP_DETACH(data, so, so_next) DO_UDP_DETACH((data), (so), (so_next))
|
---|
642 |
|
---|
643 | /* dnsproxy/dnsproxy.c */
|
---|
644 | #define authoritative_port pData->authoritative_port
|
---|
645 | #define authoritative_timeout pData->authoritative_timeout
|
---|
646 | #define recursive_port pData->recursive_port
|
---|
647 | #define recursive_timeout pData->recursive_timeout
|
---|
648 | #define stats_timeout pData->stats_timeout
|
---|
649 | /* dnsproxy/hash.c */
|
---|
650 | #define dns_port pData->port
|
---|
651 | #define request_hash pData->request_hash
|
---|
652 | #define hash_collisions pData->hash_collisions
|
---|
653 | #define active_queries pData->active_queries
|
---|
654 | #define all_queries pData->all_queries
|
---|
655 | #define authoritative_queries pData->authoritative_queries
|
---|
656 | #define recursive_queries pData->recursive_queries
|
---|
657 | #define removed_queries pData->removed_queries
|
---|
658 | #define dropped_queries pData->dropped_queries
|
---|
659 | #define answered_queries pData->answered_queries
|
---|
660 | #define dropped_answers pData->dropped_answers
|
---|
661 | #define late_answers pData->late_answers
|
---|
662 |
|
---|
663 | /* dnsproxy/dnsproxy.c */
|
---|
664 | #define queryid pData->queryid
|
---|
665 | #define authoritative_addr pData->authoritative_addr
|
---|
666 | #define recursive_addr pData->recursive_addr
|
---|
667 | #define sock_query pData->sock_query
|
---|
668 | #define sock_answer pData->sock_answer
|
---|
669 |
|
---|
670 | #ifdef VBOX_WITH_SLIRP_ALIAS
|
---|
671 | # define instancehead pData->instancehead
|
---|
672 | #endif
|
---|
673 |
|
---|
674 | #endif /* !___slirp_state_h */
|
---|