VirtualBox

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

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

slirp:coding style

  • Property svn:eol-style set to native
File size: 8.1 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# ifdef RT_OS_WINDOWS
140 void *pvIcmpBuffer;
141 size_t szIcmpBuffer;
142 /* Accordin MSDN specification IcmpParseReplies
143 * function should be detected in runtime
144 */
145 long (WINAPI * pfIcmpParseReplies)(void *, long);
146 BOOL (WINAPI * pfIcmpCloseHandle)(HANDLE);
147 HMODULE hmIcmpLibrary;
148# endif
149#endif
150#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
151# define VBOX_SOCKET_EVENT (pData->phEvents[VBOX_SOCKET_EVENT_INDEX])
152 HANDLE phEvents[VBOX_EVENT_COUNT];
153#endif
154 STAMPROFILE StatFill;
155 STAMPROFILE StatPoll;
156 STAMPROFILE StatFastTimer;
157 STAMPROFILE StatSlowTimer;
158 STAMCOUNTER StatTCP;
159 STAMCOUNTER StatUDP;
160 STAMCOUNTER StatTCPHot;
161 STAMCOUNTER StatUDPHot;
162} NATState;
163
164
165/** Default IP time to live. */
166#define ip_defttl IPDEFTTL
167
168/** Number of permanent buffers in mbuf. */
169#define mbuf_thresh 30
170
171/** Use a fixed time before sending keepalive. */
172#define tcp_keepidle TCPTV_KEEP_IDLE
173
174/** Use a fixed interval between keepalive. */
175#define tcp_keepintvl TCPTV_KEEPINTVL
176
177/** Maximum idle time before timing out a connection. */
178#define tcp_maxidle (TCPTV_KEEPCNT * tcp_keepintvl)
179
180/** Default TCP socket options. */
181#define so_options DO_KEEPALIVE
182
183/** Default TCP MSS value. */
184#define tcp_mssdflt TCP_MSS
185
186/** Default TCP round trip time. */
187#define tcp_rttdflt (TCPTV_SRTTDFLT / PR_SLOWHZ)
188
189/** Enable RFC1323 performance enhancements.
190 * @todo check if it really works, it was turned off before. */
191#define tcp_do_rfc1323 1
192
193/** TCP receive buffer size. */
194#define tcp_rcvspace TCP_RCVSPACE
195
196/** TCP receive buffer size. */
197#define tcp_sndspace TCP_SNDSPACE
198
199/* TCP duplicate ACK retransmit threshold. */
200#define tcprexmtthresh 3
201
202
203#define bootp_filename pData->bootp_filename
204#define bootp_clients pData->bootp_clients
205
206#define if_mtu pData->if_mtu
207#define if_mru pData->if_mru
208#define if_comp pData->if_comp
209#define if_maxlinkhdr pData->if_maxlinkhdr
210#define if_queued pData->if_queued
211#define if_thresh pData->if_thresh
212#define if_fastq pData->if_fastq
213#define if_batchq pData->if_batchq
214#define next_m pData->next_m
215
216#define icmpstat pData->icmpstat
217
218#define ipstat pData->ipstat
219#define ipq pData->ipq
220#define ip_currid pData->ip_currid
221
222#define mbuf_alloced pData->mbuf_alloced
223#define mbuf_max pData->mbuf_max
224#define msize pData->msize
225#define m_freelist pData->m_freelist
226#define m_usedlist pData->m_usedlist
227
228#define curtime pData->curtime
229#define time_fasttimo pData->time_fasttimo
230#define last_slowtimo pData->last_slowtimo
231#define do_slowtimo pData->do_slowtimo
232#define link_up pData->link_up
233#define cUsers pData->cUsers
234#define tt pData->tt
235#define our_addr pData->our_addr
236#define alias_addr pData->alias_addr
237#define special_addr pData->special_addr
238#define dns_addr pData->dns_addr
239#define loopback_addr pData->loopback_addr
240#define client_ethaddr pData->client_ethaddr
241#define exec_list pData->exec_list
242#define slirp_hostname pData->slirp_hostname
243
244#define tcb pData->tcb
245#define tcp_last_so pData->tcp_last_so
246#define tcp_iss pData->tcp_iss
247
248#define tcpstat pData->tcpstat
249#define tcp_now pData->tcp_now
250
251#define tftp_sessions pData->tftp_sessions
252#define tftp_prefix pData->tftp_prefix
253
254#define udpstat pData->udpstat
255#define udb pData->udb
256#define udp_last_so pData->udp_last_so
257
258#ifdef VBOX_WITH_BSD_REASS
259
260#define maxfragsperpacket pData->maxfragsperpacket
261#define maxnipq pData->maxnipq
262#define nipq pData->nipq
263
264#define tcp_reass_qsize pData->tcp_reass_qsize
265#define tcp_reass_maxqlen pData->tcp_reass_maxqlen
266#define tcp_reass_maxseg pData->tcp_reass_maxseg
267#define tcp_reass_overflows pData->tcp_reass_overflows
268
269#else /* ! VBOX_WITH_BSD_REASS */
270
271#if SIZEOF_CHAR_P != 4
272 extern void VBoxU32PtrDone(PNATState pData, void *pv, uint32_t iHint);
273 extern uint32_t VBoxU32PtrHashSlow(PNATState pData, void *pv);
274
275 /** Hash the pointer, inserting it if need be. */
276 DECLINLINE(uint32_t) VBoxU32PtrHash(PNATState pData, void *pv)
277 {
278 uint32_t i = ((uintptr_t)pv >> 3) % RT_ELEMENTS(pData->apvHash);
279 if (RT_LIKELY(pData->apvHash[i] == pv && pv))
280 return i;
281 return VBoxU32PtrHashSlow(pData, pv);
282 }
283 /** Lookup the hash value. */
284 DECLINLINE(void *) VBoxU32PtrLookup(PNATState pData, uint32_t i)
285 {
286 void *pv;
287 Assert(i < RT_ELEMENTS(pData->apvHash));
288 pv = pData->apvHash[i];
289 Assert(pv || !i);
290 return pv;
291 }
292#endif
293
294#endif
295
296#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