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 | /** Number of DHCP clients supported by NAT. */
|
---|
25 | #define NB_ADDR 16
|
---|
26 |
|
---|
27 | /** Where to start DHCP IP number allocation. */
|
---|
28 | #define START_ADDR 15
|
---|
29 |
|
---|
30 | /** DHCP Lease time. */
|
---|
31 | #define LEASE_TIME (24 * 3600)
|
---|
32 |
|
---|
33 | /** Entry in the table of known DHCP clients. */
|
---|
34 | typedef struct {
|
---|
35 | bool allocated;
|
---|
36 | uint8_t macaddr[6];
|
---|
37 | } BOOTPClient;
|
---|
38 |
|
---|
39 |
|
---|
40 | /** TFTP session entry. */
|
---|
41 | struct tftp_session {
|
---|
42 | int in_use;
|
---|
43 | unsigned char filename[TFTP_FILENAME_MAX];
|
---|
44 |
|
---|
45 | struct in_addr client_ip;
|
---|
46 | u_int16_t client_port;
|
---|
47 |
|
---|
48 | int timestamp;
|
---|
49 | };
|
---|
50 |
|
---|
51 |
|
---|
52 | /** Main state/configuration structure for slirp NAT. */
|
---|
53 | typedef struct NATState
|
---|
54 | {
|
---|
55 | /* Stuff from boot.c */
|
---|
56 | BOOTPClient bootp_clients[NB_ADDR];
|
---|
57 | const char *bootp_filename;
|
---|
58 | /* Stuff from if.c */
|
---|
59 | int if_mtu, if_mru;
|
---|
60 | int if_comp;
|
---|
61 | int if_maxlinkhdr;
|
---|
62 | int if_queued;
|
---|
63 | int if_thresh;
|
---|
64 | struct mbuf if_fastq;
|
---|
65 | struct mbuf if_batchq;
|
---|
66 | struct mbuf *next_m;
|
---|
67 | /* Stuff from icmp.c */
|
---|
68 | struct icmpstat_t icmpstat;
|
---|
69 | /* Stuff from ip_input.c */
|
---|
70 | struct ipstat_t ipstat;
|
---|
71 | #ifndef VBOX_WITH_BSD_REASS
|
---|
72 | struct ipq_t ipq;
|
---|
73 | #else /* !VBOX_WITH_BSD_REASS */
|
---|
74 | struct ipqhead ipq[IPREASS_NHASH];
|
---|
75 | int maxnipq; /* Administrative limit on # of reass queues*/
|
---|
76 | int maxfragsperpacket; /* Maximum number of IPv4 fragments allowed per packet */
|
---|
77 | int nipq; /* total number of reass queues */
|
---|
78 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
79 | uint16_t ip_currid;
|
---|
80 | /* Stuff from mbuf.c */
|
---|
81 | int mbuf_alloced, mbuf_max;
|
---|
82 | int msize;
|
---|
83 | struct mbuf m_freelist, m_usedlist;
|
---|
84 | /* Stuff from slirp.c */
|
---|
85 | void *pvUser;
|
---|
86 | uint32_t curtime;
|
---|
87 | uint32_t time_fasttimo;
|
---|
88 | uint32_t last_slowtimo;
|
---|
89 | bool do_slowtimo;
|
---|
90 | bool link_up;
|
---|
91 | struct timeval tt;
|
---|
92 | struct in_addr our_addr;
|
---|
93 | struct in_addr alias_addr;
|
---|
94 | struct in_addr special_addr;
|
---|
95 | struct in_addr dns_addr;
|
---|
96 | struct in_addr loopback_addr;
|
---|
97 | uint32_t netmask;
|
---|
98 | uint8_t client_ethaddr[6];
|
---|
99 | struct ex_list *exec_list;
|
---|
100 | char slirp_hostname[33];
|
---|
101 | bool fPassDomain;
|
---|
102 | const char *pszDomain;
|
---|
103 | /* Stuff from tcp_input.c */
|
---|
104 | struct socket tcb;
|
---|
105 | struct socket *tcp_last_so;
|
---|
106 | tcp_seq tcp_iss;
|
---|
107 | #if ARCH_BITS == 64
|
---|
108 | /* Stuff from tcp_subr.c */
|
---|
109 | void *apvHash[16384];
|
---|
110 | uint32_t cpvHashUsed;
|
---|
111 | uint32_t cpvHashCollisions;
|
---|
112 | uint64_t cpvHashInserts;
|
---|
113 | uint64_t cpvHashDone;
|
---|
114 | #endif
|
---|
115 | /* Stuff from tcp_timer.c */
|
---|
116 | struct tcpstat_t tcpstat;
|
---|
117 | uint32_t tcp_now;
|
---|
118 | #ifdef VBOX_WITH_BSD_TCP_REASS
|
---|
119 | int tcp_reass_qsize;
|
---|
120 | int tcp_reass_maxqlen;
|
---|
121 | int tcp_reass_maxseg;
|
---|
122 | int tcp_reass_overflows;
|
---|
123 | struct tcpcbhead tcpcbhead;
|
---|
124 | #endif /* VBOX_WITH_BSD_TCP_REASS */
|
---|
125 | /* Stuff from tftp.c */
|
---|
126 | struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
|
---|
127 | const char *tftp_prefix;
|
---|
128 | /* Stuff from udp.c */
|
---|
129 | struct udpstat_t udpstat;
|
---|
130 | struct socket udb;
|
---|
131 | struct socket *udp_last_so;
|
---|
132 | #if defined(VBOX_WITH_SIMPLEFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
|
---|
133 | # define VBOX_SOCKET_EVENT (pData->phEvents[VBOX_SOCKET_EVENT_INDEX])
|
---|
134 | HANDLE phEvents[VBOX_EVENT_COUNT];
|
---|
135 | #endif
|
---|
136 | STAMPROFILE StatFill;
|
---|
137 | STAMPROFILE StatPoll;
|
---|
138 | STAMPROFILE StatFastTimer;
|
---|
139 | STAMPROFILE StatSlowTimer;
|
---|
140 | STAMCOUNTER StatTCP;
|
---|
141 | STAMCOUNTER StatUDP;
|
---|
142 | STAMCOUNTER StatTCPHot;
|
---|
143 | STAMCOUNTER StatUDPHot;
|
---|
144 | } NATState;
|
---|
145 |
|
---|
146 |
|
---|
147 | /** Default IP time to live. */
|
---|
148 | #define ip_defttl IPDEFTTL
|
---|
149 |
|
---|
150 | /** Number of permanent buffers in mbuf. */
|
---|
151 | #define mbuf_thresh 30
|
---|
152 |
|
---|
153 | /** Use a fixed time before sending keepalive. */
|
---|
154 | #define tcp_keepidle TCPTV_KEEP_IDLE
|
---|
155 |
|
---|
156 | /** Use a fixed interval between keepalive. */
|
---|
157 | #define tcp_keepintvl TCPTV_KEEPINTVL
|
---|
158 |
|
---|
159 | /** Maximum idle time before timing out a connection. */
|
---|
160 | #define tcp_maxidle (TCPTV_KEEPCNT * tcp_keepintvl)
|
---|
161 |
|
---|
162 | /** Default TCP socket options. */
|
---|
163 | #define so_options DO_KEEPALIVE
|
---|
164 |
|
---|
165 | /** Default TCP MSS value. */
|
---|
166 | #define tcp_mssdflt TCP_MSS
|
---|
167 |
|
---|
168 | /** Default TCP round trip time. */
|
---|
169 | #define tcp_rttdflt (TCPTV_SRTTDFLT / PR_SLOWHZ)
|
---|
170 |
|
---|
171 | /** Enable RFC1323 performance enhancements.
|
---|
172 | * @todo check if it really works, it was turned off before. */
|
---|
173 | #define tcp_do_rfc1323 1
|
---|
174 |
|
---|
175 | /** TCP receive buffer size. */
|
---|
176 | #define tcp_rcvspace TCP_RCVSPACE
|
---|
177 |
|
---|
178 | /** TCP receive buffer size. */
|
---|
179 | #define tcp_sndspace TCP_SNDSPACE
|
---|
180 |
|
---|
181 | /* TCP duplicate ACK retransmit threshold. */
|
---|
182 | #define tcprexmtthresh 3
|
---|
183 |
|
---|
184 |
|
---|
185 | #define bootp_filename pData->bootp_filename
|
---|
186 | #define bootp_clients pData->bootp_clients
|
---|
187 |
|
---|
188 | #define if_mtu pData->if_mtu
|
---|
189 | #define if_mru pData->if_mru
|
---|
190 | #define if_comp pData->if_comp
|
---|
191 | #define if_maxlinkhdr pData->if_maxlinkhdr
|
---|
192 | #define if_queued pData->if_queued
|
---|
193 | #define if_thresh pData->if_thresh
|
---|
194 | #define if_fastq pData->if_fastq
|
---|
195 | #define if_batchq pData->if_batchq
|
---|
196 | #define next_m pData->next_m
|
---|
197 |
|
---|
198 | #define icmpstat pData->icmpstat
|
---|
199 |
|
---|
200 | #define ipstat pData->ipstat
|
---|
201 | #define ipq pData->ipq
|
---|
202 | #define ip_currid pData->ip_currid
|
---|
203 |
|
---|
204 | #define mbuf_alloced pData->mbuf_alloced
|
---|
205 | #define mbuf_max pData->mbuf_max
|
---|
206 | #define msize pData->msize
|
---|
207 | #define m_freelist pData->m_freelist
|
---|
208 | #define m_usedlist pData->m_usedlist
|
---|
209 |
|
---|
210 | #define curtime pData->curtime
|
---|
211 | #define time_fasttimo pData->time_fasttimo
|
---|
212 | #define last_slowtimo pData->last_slowtimo
|
---|
213 | #define do_slowtimo pData->do_slowtimo
|
---|
214 | #define link_up pData->link_up
|
---|
215 | #define cUsers pData->cUsers
|
---|
216 | #define tt pData->tt
|
---|
217 | #define our_addr pData->our_addr
|
---|
218 | #define alias_addr pData->alias_addr
|
---|
219 | #define special_addr pData->special_addr
|
---|
220 | #define dns_addr pData->dns_addr
|
---|
221 | #define loopback_addr pData->loopback_addr
|
---|
222 | #define client_ethaddr pData->client_ethaddr
|
---|
223 | #define exec_list pData->exec_list
|
---|
224 | #define slirp_hostname pData->slirp_hostname
|
---|
225 |
|
---|
226 | #define tcb pData->tcb
|
---|
227 | #define tcp_last_so pData->tcp_last_so
|
---|
228 | #define tcp_iss pData->tcp_iss
|
---|
229 |
|
---|
230 | #define tcpstat pData->tcpstat
|
---|
231 | #define tcp_now pData->tcp_now
|
---|
232 |
|
---|
233 | #define tftp_sessions pData->tftp_sessions
|
---|
234 | #define tftp_prefix pData->tftp_prefix
|
---|
235 |
|
---|
236 | #define udpstat pData->udpstat
|
---|
237 | #define udb pData->udb
|
---|
238 | #define udp_last_so pData->udp_last_so
|
---|
239 |
|
---|
240 | #ifdef VBOX_WITH_BSD_REASS
|
---|
241 | #define maxfragsperpacket pData->maxfragsperpacket
|
---|
242 | #define maxnipq pData->maxnipq
|
---|
243 | #define nipq pData->nipq
|
---|
244 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
245 |
|
---|
246 | #ifdef VBOX_WITH_BSD_TCP_REASS
|
---|
247 | #define tcp_reass_qsize pData->tcp_reass_qsize
|
---|
248 | #define tcp_reass_maxqlen pData->tcp_reass_maxqlen
|
---|
249 | #define tcp_reass_maxseg pData->tcp_reass_maxseg
|
---|
250 | #define tcp_reass_overflows pData->tcp_reass_overflows
|
---|
251 | #endif /* VBOX_WITH_BSD_TCP_REASS */
|
---|
252 |
|
---|
253 | #if SIZEOF_CHAR_P != 4
|
---|
254 | extern void VBoxU32PtrDone(PNATState pData, void *pv, uint32_t iHint);
|
---|
255 | extern uint32_t VBoxU32PtrHashSlow(PNATState pData, void *pv);
|
---|
256 |
|
---|
257 | /** Hash the pointer, inserting it if need be. */
|
---|
258 | DECLINLINE(uint32_t) VBoxU32PtrHash(PNATState pData, void *pv)
|
---|
259 | {
|
---|
260 | uint32_t i = ((uintptr_t)pv >> 3) % RT_ELEMENTS(pData->apvHash);
|
---|
261 | if (RT_LIKELY(pData->apvHash[i] == pv && pv))
|
---|
262 | return i;
|
---|
263 | return VBoxU32PtrHashSlow(pData, pv);
|
---|
264 | }
|
---|
265 | /** Lookup the hash value. */
|
---|
266 | DECLINLINE(void *) VBoxU32PtrLookup(PNATState pData, uint32_t i)
|
---|
267 | {
|
---|
268 | void *pv;
|
---|
269 | Assert(i < RT_ELEMENTS(pData->apvHash));
|
---|
270 | pv = pData->apvHash[i];
|
---|
271 | Assert(pv || !i);
|
---|
272 | return pv;
|
---|
273 | }
|
---|
274 | #endif
|
---|
275 |
|
---|
276 |
|
---|
277 | #endif /* !_slirp_state_h_ */
|
---|