VirtualBox

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

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

slirp: code readability

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette