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