1 | /** @file
|
---|
2 | * NAT state/configuration.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * If you received this file as part of a commercial VirtualBox
|
---|
17 | * distribution, then only the terms of your commercial VirtualBox
|
---|
18 | * license agreement apply instead of the previous paragraph.
|
---|
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 | struct ipq_t ipq;
|
---|
72 | uint16_t ip_currid;
|
---|
73 | /* Stuff from mbuf.c */
|
---|
74 | int mbuf_alloced, mbuf_max;
|
---|
75 | int msize;
|
---|
76 | struct mbuf m_freelist, m_usedlist;
|
---|
77 | /* Stuff from slirp.c */
|
---|
78 | void *pvUser;
|
---|
79 | uint32_t curtime;
|
---|
80 | uint32_t time_fasttimo;
|
---|
81 | uint32_t last_slowtimo;
|
---|
82 | bool do_slowtimo;
|
---|
83 | bool link_up;
|
---|
84 | struct timeval tt;
|
---|
85 | struct in_addr our_addr;
|
---|
86 | struct in_addr alias_addr;
|
---|
87 | struct in_addr special_addr;
|
---|
88 | struct in_addr dns_addr;
|
---|
89 | struct in_addr loopback_addr;
|
---|
90 | uint8_t client_ethaddr[6];
|
---|
91 | struct ex_list *exec_list;
|
---|
92 | char slirp_hostname[33];
|
---|
93 | /* Stuff from tcp_input.c */
|
---|
94 | struct socket tcb;
|
---|
95 | struct socket *tcp_last_so;
|
---|
96 | tcp_seq tcp_iss;
|
---|
97 | #if ARCH_BITS == 64
|
---|
98 | /* Stuff from tcp_subr.c */
|
---|
99 | void *apvHash[16384];
|
---|
100 | uint32_t cpvHashUsed;
|
---|
101 | uint32_t cpvHashCollisions;
|
---|
102 | uint64_t cpvHashInserts;
|
---|
103 | uint64_t cpvHashDone;
|
---|
104 | #endif
|
---|
105 | /* Stuff from tcp_timer.c */
|
---|
106 | struct tcpstat_t tcpstat;
|
---|
107 | uint32_t tcp_now;
|
---|
108 | /* Stuff from tftp.c */
|
---|
109 | struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
|
---|
110 | const char *tftp_prefix;
|
---|
111 | /* Stuff from udp.c */
|
---|
112 | struct udpstat_t udpstat;
|
---|
113 | struct socket udb;
|
---|
114 | struct socket *udp_last_so;
|
---|
115 | } NATState;
|
---|
116 |
|
---|
117 |
|
---|
118 | /** Default IP time to live. */
|
---|
119 | #define ip_defttl IPDEFTTL
|
---|
120 |
|
---|
121 | /** Number of permanent buffers in mbuf. */
|
---|
122 | #define mbuf_thresh 30
|
---|
123 |
|
---|
124 | /** Use a fixed time before sending keepalive. */
|
---|
125 | #define tcp_keepidle TCPTV_KEEP_IDLE
|
---|
126 |
|
---|
127 | /** Use a fixed interval between keepalive. */
|
---|
128 | #define tcp_keepintvl TCPTV_KEEPINTVL
|
---|
129 |
|
---|
130 | /** Maximum idle time before timing out a connection. */
|
---|
131 | #define tcp_maxidle (TCPTV_KEEPCNT * tcp_keepintvl)
|
---|
132 |
|
---|
133 | /** Default TCP socket options. */
|
---|
134 | #define so_options DO_KEEPALIVE
|
---|
135 |
|
---|
136 | /** Default TCP MSS value. */
|
---|
137 | #define tcp_mssdflt TCP_MSS
|
---|
138 |
|
---|
139 | /** Default TCP round trip time. */
|
---|
140 | #define tcp_rttdflt (TCPTV_SRTTDFLT / PR_SLOWHZ)
|
---|
141 |
|
---|
142 | /** Enable RFC1323 performance enhancements.
|
---|
143 | * @todo check if it really works, it was turned off before. */
|
---|
144 | #define tcp_do_rfc1323 1
|
---|
145 |
|
---|
146 | /** TCP receive buffer size. */
|
---|
147 | #define tcp_rcvspace TCP_RCVSPACE
|
---|
148 |
|
---|
149 | /** TCP receive buffer size. */
|
---|
150 | #define tcp_sndspace TCP_SNDSPACE
|
---|
151 |
|
---|
152 | /* TCP duplicate ACK retransmit threshold. */
|
---|
153 | #define tcprexmtthresh 3
|
---|
154 |
|
---|
155 |
|
---|
156 | #define bootp_filename pData->bootp_filename
|
---|
157 | #define bootp_clients pData->bootp_clients
|
---|
158 |
|
---|
159 | #define if_mtu pData->if_mtu
|
---|
160 | #define if_mru pData->if_mru
|
---|
161 | #define if_comp pData->if_comp
|
---|
162 | #define if_maxlinkhdr pData->if_maxlinkhdr
|
---|
163 | #define if_queued pData->if_queued
|
---|
164 | #define if_thresh pData->if_thresh
|
---|
165 | #define if_fastq pData->if_fastq
|
---|
166 | #define if_batchq pData->if_batchq
|
---|
167 | #define next_m pData->next_m
|
---|
168 |
|
---|
169 | #define icmpstat pData->icmpstat
|
---|
170 |
|
---|
171 | #define ipstat pData->ipstat
|
---|
172 | #define ipq pData->ipq
|
---|
173 | #define ip_currid pData->ip_currid
|
---|
174 |
|
---|
175 | #define mbuf_alloced pData->mbuf_alloced
|
---|
176 | #define mbuf_max pData->mbuf_max
|
---|
177 | #define msize pData->msize
|
---|
178 | #define m_freelist pData->m_freelist
|
---|
179 | #define m_usedlist pData->m_usedlist
|
---|
180 |
|
---|
181 | #define curtime pData->curtime
|
---|
182 | #define time_fasttimo pData->time_fasttimo
|
---|
183 | #define last_slowtimo pData->last_slowtimo
|
---|
184 | #define do_slowtimo pData->do_slowtimo
|
---|
185 | #define link_up pData->link_up
|
---|
186 | #define cUsers pData->cUsers
|
---|
187 | #define tt pData->tt
|
---|
188 | #define our_addr pData->our_addr
|
---|
189 | #define alias_addr pData->alias_addr
|
---|
190 | #define special_addr pData->special_addr
|
---|
191 | #define dns_addr pData->dns_addr
|
---|
192 | #define loopback_addr pData->loopback_addr
|
---|
193 | #define client_ethaddr pData->client_ethaddr
|
---|
194 | #define exec_list pData->exec_list
|
---|
195 | #define slirp_hostname pData->slirp_hostname
|
---|
196 |
|
---|
197 | #define tcb pData->tcb
|
---|
198 | #define tcp_last_so pData->tcp_last_so
|
---|
199 | #define tcp_iss pData->tcp_iss
|
---|
200 |
|
---|
201 | #define tcpstat pData->tcpstat
|
---|
202 | #define tcp_now pData->tcp_now
|
---|
203 |
|
---|
204 | #define tftp_sessions pData->tftp_sessions
|
---|
205 | #define tftp_prefix pData->tftp_prefix
|
---|
206 |
|
---|
207 | #define udpstat pData->udpstat
|
---|
208 | #define udb pData->udb
|
---|
209 | #define udp_last_so pData->udp_last_so
|
---|
210 |
|
---|
211 |
|
---|
212 | #if SIZEOF_CHAR_P != 4
|
---|
213 | extern void VBoxU32PtrDone(PNATState pData, void *pv, uint32_t iHint);
|
---|
214 | extern uint32_t VBoxU32PtrHashSlow(PNATState pData, void *pv);
|
---|
215 |
|
---|
216 | /** Hash the pointer, inserting it if need be. */
|
---|
217 | DECLINLINE(uint32_t) VBoxU32PtrHash(PNATState pData, void *pv)
|
---|
218 | {
|
---|
219 | uint32_t i = ((uintptr_t)pv >> 3) % RT_ELEMENTS(pData->apvHash);
|
---|
220 | if (RT_LIKELY(pData->apvHash[i] == pv && pv))
|
---|
221 | return i;
|
---|
222 | return VBoxU32PtrHashSlow(pData, pv);
|
---|
223 | }
|
---|
224 | /** Lookup the hash value. */
|
---|
225 | DECLINLINE(void *) VBoxU32PtrLookup(PNATState pData, uint32_t i)
|
---|
226 | {
|
---|
227 | void *pv;
|
---|
228 | Assert(i < RT_ELEMENTS(pData->apvHash));
|
---|
229 | pv = pData->apvHash[i];
|
---|
230 | Assert(pv || !i);
|
---|
231 | return pv;
|
---|
232 | }
|
---|
233 | #endif
|
---|
234 |
|
---|
235 |
|
---|
236 | #endif /* !_slirp_state_h_ */
|
---|