VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h@ 12479

最後變更 在這個檔案從12479是 12008,由 vboxsync 提交於 16 年 前

code formating, comments added to structureas and types definitions

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 11.8 KB
 
1/* $Id: VBoxNetFltInternal.h 12008 2008-09-02 20:16:28Z vboxsync $ */
2/** @file
3 * VBoxNetFlt - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
8 *
9 * Sun Microsystems, Inc. confidential
10 * All rights reserved
11 */
12
13#ifndef ___VBoxNetFltInternal_h___
14#define ___VBoxNetFltInternal_h___
15
16#include <VBox/sup.h>
17#include <VBox/intnet.h>
18#include <iprt/semaphore.h>
19#include <iprt/assert.h>
20
21
22__BEGIN_DECLS
23
24/** Pointer to the globals. */
25typedef struct VBOXNETFLTGLOBALS *PVBOXNETFLTGLOBALS;
26
27
28/**
29 * The state of a filter driver instance.
30 *
31 * The state machine differs a bit between the platforms because of
32 * the way we hook into the stack. On some hosts we can dynamically
33 * attach when required (on CreateInstance) and on others we will
34 * have to connect when the network stack is bound up. These modes
35 * are called static and dynamic config and governed at compile time
36 * by the VBOXNETFLT_STATIC_CONFIG define.
37 *
38 * See sec_netflt_msc for more details on locking and synchronization.
39 */
40typedef enum VBOXNETFTLINSSTATE
41{
42 /** The usual invalid state. */
43 kVBoxNetFltInsState_Invalid = 0,
44 /** Initialization.
45 * We've reserved the interface name but need to attach to the actual
46 * network interface outside the lock to avoid deadlocks.
47 * In the dynamic case this happens during a Create(Instance) call.
48 * In the static case it happens during driver initialization. */
49 kVBoxNetFltInsState_Initializing,
50#ifdef VBOXNETFLT_STATIC_CONFIG
51 /** Unconnected, not hooked up to a switch (static only).
52 * The filter driver instance has been instantiated and hooked up,
53 * waiting to be connected to an internal network. */
54 kVBoxNetFltInsState_Unconnected,
55#endif
56 /** Connected to an internal network. */
57 kVBoxNetFltInsState_Connected,
58 /** Disconnecting from the internal network and possibly the host network interface.
59 * Partly for reasons of deadlock avoidance again. */
60 kVBoxNetFltInsState_Disconnecting,
61 /** The instance has been disconnected from both the host and the internal network. */
62 kVBoxNetFltInsState_Destroyed,
63
64 /** The habitual 32-bit enum hack. */
65 kVBoxNetFltInsState_32BitHack = 0x7fffffff
66} VBOXNETFTLINSSTATE;
67
68
69/**
70 * The per-instance data of the VBox filter driver.
71 *
72 * This is data associated with a network interface / NIC / wossname which
73 * the filter driver has been or may be attached to. When possible it is
74 * attached dynamically, but this may not be possible on all OSes so we have
75 * to be flexible about things.
76 *
77 * A network interface / NIC / wossname can only have one filter driver
78 * instance attached to it. So, attempts at connecting an internal network
79 * to an interface that's already in use (connected to another internal network)
80 * will result in a VERR_SHARING_VIOLATION.
81 *
82 * Only one internal network can connect to a filter driver instance.
83 */
84typedef struct VBOXNETFLTINS
85{
86 /** Pointer to the next interface in the list. (VBOXNETFLTGLOBAL::pInstanceHead) */
87 struct VBOXNETFLTINS *pNext;
88 /** Our RJ-45 port.
89 * This is what the internal network plugs into. */
90 INTNETTRUNKIFPORT MyPort;
91 /** The RJ-45 port on the INTNET "switch".
92 * This is what we're connected to. */
93 PINTNETTRUNKSWPORT pSwitchPort;
94 /** Pointer to the globals. */
95 PVBOXNETFLTGLOBALS pGlobals;
96
97 /** The spinlock protecting the state variables and host interface handle. */
98 RTSPINLOCK hSpinlock;
99 /** The current interface state. */
100 VBOXNETFTLINSSTATE volatile enmState;
101 /** Active / Suspended indicator. */
102 bool volatile fActive;
103 /** Disconnected from the host network interface. */
104 bool volatile fDisconnectedFromHost;
105 /** Rediscovery is pending.
106 * cBusy will never reach zero during rediscovery, so which
107 * takes care of serializing rediscovery and disconnecting. */
108 bool volatile fRediscoveryPending;
109#if (ARCH_BITS == 32) && defined(__GNUC__)
110 uint32_t u32Padding; /**< Alignment padding, will assert in ASMAtomicUoWriteU64 otherwise. */
111#endif
112 /** The timestamp of the last rediscovery. */
113 uint64_t volatile NanoTSLastRediscovery;
114 /** Reference count. */
115 uint32_t volatile cRefs;
116 /** The busy count.
117 * This counts the number of current callers and pending packet. */
118 uint32_t volatile cBusy;
119 /** The event that is signaled when we go idle and that pfnWaitForIdle blocks on. */
120 RTSEMEVENT hEventIdle;
121
122 union
123 {
124#ifdef VBOXNETFLT_OS_SPECFIC
125 struct
126 {
127# if defined(RT_OS_DARWIN)
128 /** @name Darwin instance data.
129 * @{ */
130 /** Pointer to the darwin network interface we're attached to.
131 * This is treated as highly volatile and should only be read and retained
132 * while owning hSpinlock. Releasing references to this should not be done
133 * while owning it though as we might end up destroying it in some paths. */
134 ifnet_t volatile pIfNet;
135 /** The interface filter handle.
136 * Same access rules as with pIfNet. */
137 interface_filter_t volatile pIfFilter;
138 /** Whether we've need to set promiscuous mode when the interface comes up. */
139 bool volatile fNeedSetPromiscuous;
140 /** Whether we've successfully put the interface into to promiscuous mode.
141 * This is for dealing with the ENETDOWN case. */
142 bool volatile fSetPromiscuous;
143 /** The MAC address of the interface. */
144 RTMAC Mac;
145 /** @} */
146# elif defined(RT_OS_LINUX)
147 /** @name Linux instance data
148 * @{ */
149 /** Pointer to the device. */
150 struct net_device volatile *pDev;
151 /** @} */
152# elif defined(RT_OS_SOLARIS)
153 /** @name Solaris instance data.
154 * @{ */
155 /** Pointer to the bound IP stream. */
156 void *pvStream;
157 /** Pointer to the bound ARP stream. */
158 void *pvArpStream;
159 /** The MAC address of the interface. */
160 RTMAC Mac;
161# elif defined(RT_OS_WINDOWS)
162 /** pointer to the filter driver device context */
163 PADAPT volatile pIfAdaptor;
164# else
165# error "PORTME"
166# endif
167 } s;
168#endif
169 /** Padding. */
170 uint8_t abPadding[32];
171 } u;
172
173 /** The interface name. */
174 char szName[1];
175} VBOXNETFLTINS;
176/** Pointer to the instance data of a host network filter driver. */
177typedef struct VBOXNETFLTINS *PVBOXNETFLTINS;
178
179AssertCompileMemberAlignment(VBOXNETFLTINS, NanoTSLastRediscovery, 8);
180#ifdef VBOXNETFLT_OS_SPECFIC
181AssertCompile(RT_SIZEOFMEMB(VBOXNETFLTINS, u.s) <= RT_SIZEOFMEMB(VBOXNETFLTINS, u.abPadding));
182#endif
183
184
185/**
186 * The global data of the VBox filter driver.
187 *
188 * This contains the bit required for communicating with support driver, VBoxDrv
189 * (start out as SupDrv).
190 */
191typedef struct VBOXNETFLTGLOBALS
192{
193 /** Mutex protecting the list of instances and state changes. */
194 RTSEMFASTMUTEX hFastMtx;
195 /** Pointer to a list of instance data. */
196 PVBOXNETFLTINS pInstanceHead;
197
198 /** The INTNET trunk network interface factory. */
199 INTNETTRUNKFACTORY TrunkFactory;
200 /** The SUPDRV component factory registration. */
201 SUPDRVFACTORY SupDrvFactory;
202 /** The number of current factory references. */
203 int32_t volatile cFactoryRefs;
204
205 /** The SUPDRV IDC handle (opaque struct). */
206 SUPDRVIDCHANDLE SupDrvIDC;
207} VBOXNETFLTGLOBALS;
208
209
210DECLHIDDEN(int) vboxNetFltInitGlobals(PVBOXNETFLTGLOBALS pGlobals);
211DECLHIDDEN(int) vboxNetFltTryDeleteGlobals(PVBOXNETFLTGLOBALS pGlobals);
212DECLHIDDEN(bool) vboxNetFltCanUnload(PVBOXNETFLTGLOBALS pGlobals);
213DECLHIDDEN(PVBOXNETFLTINS) vboxNetFltFindInstance(PVBOXNETFLTGLOBALS pGlobals, const char *pszName);
214
215DECLHIDDEN(void) vboxNetFltRetain(PVBOXNETFLTINS pThis, bool fBusy);
216DECLHIDDEN(void) vboxNetFltRelease(PVBOXNETFLTINS pThis, bool fBusy);
217
218
219/** @name The OS specific interface.
220 * @{ */
221/**
222 * Try rediscover the host interface.
223 *
224 * This is called periodically from the transmit path if we're marked as
225 * disconnected from the host. There is no chance of a race here.
226 *
227 * @returns true if the interface was successfully rediscovered and reattach,
228 * otherwise false.
229 * @param pThis The new instance.
230 */
231DECLHIDDEN(bool) vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis);
232
233/**
234 * Transmits a frame.
235 *
236 * @return IPRT status code.
237 * @param pThis The new instance.
238 * @param pSG The (scatter/)gather list.
239 * @param fDst The destination mask. At least one bit will be set.
240 *
241 * @remarks Owns the out-bound trunk port semaphore.
242 */
243DECLHIDDEN(int) vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst);
244
245/**
246 * Checks if the interface is in promiscuous mode from the host perspective.
247 *
248 * If it is, then the internal networking switch will send frames
249 * heading for the wire to the host as well.
250 *
251 * @returns true / false accordingly.
252 * @param pThis The instance.
253 *
254 * @remarks Owns the network lock and the out-bound trunk port semaphores.
255 */
256DECLHIDDEN(bool) vboxNetFltPortOsIsPromiscuous(PVBOXNETFLTINS pThis);
257
258/**
259 * Get the MAC address of the interface we're attached to.
260 *
261 * Used by the internal networking switch for implementing the
262 * shared-MAC-on-the-wire mode.
263 *
264 * @param pThis The instance.
265 * @param pMac Where to store the MAC address.
266 * If you don't know, set all the bits except the first (the multicast one).
267 *
268 * @remarks Owns the network lock and the out-bound trunk port semaphores.
269 */
270DECLHIDDEN(void) vboxNetFltPortOsGetMacAddress(PVBOXNETFLTINS pThis, PRTMAC pMac);
271
272/**
273 * Checks if the specified MAC address is for any of the host interfaces.
274 *
275 * Used by the internal networking switch to decide the destination(s)
276 * of a frame.
277 *
278 * @returns true / false accordingly.
279 * @param pThis The instance.
280 * @param pMac The MAC address.
281 *
282 * @remarks Owns the network lock and the out-bound trunk port semaphores.
283 */
284DECLHIDDEN(bool) vboxNetFltPortOsIsHostMac(PVBOXNETFLTINS pThis, PCRTMAC pMac);
285
286/**
287 * This is called when activating or suspending the instance.
288 *
289 * Use this method to enable and disable promiscuous mode on
290 * the interface to prevent unnecessary interrupt load.
291 *
292 * It is only called when the state changes.
293 *
294 * @param pThis The instance.
295 *
296 * @remarks Owns the lock for the out-bound trunk port.
297 */
298DECLHIDDEN(void) vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive);
299
300/**
301 * This is called to when disconnecting from a network.
302 *
303 * @return IPRT status code.
304 * @param pThis The new instance.
305 *
306 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
307 */
308DECLHIDDEN(int) vboxNetFltOsDisconnectIt(PVBOXNETFLTINS pThis);
309
310/**
311 * This is called to when connecting to a network.
312 *
313 * @return IPRT status code.
314 * @param pThis The new instance.
315 *
316 * @remarks Owns the semaphores for the global list, the network lock and the out-bound trunk port.
317 */
318DECLHIDDEN(int) vboxNetFltOsConnectIt(PVBOXNETFLTINS pThis);
319
320/**
321 * Counter part to vboxNetFltOsInitInstance().
322 *
323 * @return IPRT status code.
324 * @param pThis The new instance.
325 *
326 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
327 */
328DECLHIDDEN(void) vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis);
329
330/**
331 * This is called to attach to the actual host interface
332 * after linking the instance into the list.
333 *
334 * @return IPRT status code.
335 * @param pThis The new instance.
336 *
337 * @remarks Owns no locks.
338 */
339DECLHIDDEN(int) vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis);
340
341/**
342 * This is called to perform structure initializations.
343 *
344 * @return IPRT status code.
345 * @param pThis The new instance.
346 *
347 * @remarks Owns no locks.
348 */
349DECLHIDDEN(int) vboxNetFltOsPreInitInstance(PVBOXNETFLTINS pThis);
350/** @} */
351
352
353__END_DECLS
354
355#endif
356
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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