VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h@ 17256

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

#2957: vboxnetadp is now a dummy device attached to intnet via vboxnetflt.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/* $Id: VBoxNetAdpInternal.h 17256 2009-03-02 16:23:00Z vboxsync $ */
2/** @file
3 * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___VBoxNetAdpInternal_h___
23#define ___VBoxNetAdpInternal_h___
24
25#include <VBox/sup.h>
26#include <VBox/intnet.h>
27#include <iprt/semaphore.h>
28#include <iprt/assert.h>
29
30
31__BEGIN_DECLS
32
33/** Pointer to the globals. */
34typedef struct VBOXNETADPGLOBALS *PVBOXNETADPGLOBALS;
35
36#define VBOXNETADP_MAX_INSTANCES 8
37#define VBOXNETADP_NAME "vboxnet"
38#define VBOXNETADP_MAX_NAME_LEN 32
39#define VBOXNETADP_MTU 1500
40#if defined(RT_OS_DARWIN)
41# define VBOXNETADP_MAX_FAMILIES 4
42# define VBOXNETADP_DETACH_TIMEOUT 500
43#endif
44
45/**
46 * Void entries mark vacant slots in adapter array. Valid entries are busy slots.
47 * As soon as slot is being modified its state changes to transitional.
48 * An entry in transitional state must only be accessed by the thread that
49 * put it to this state.
50 */
51/**
52 * To avoid races on adapter fields we stick to the following rules:
53 * - rewrite: Int net port calls are serialized
54 * - No modifications are allowed on busy adapters (deactivate first)
55 * Refuse to destroy adapter until it gets to available state
56 * - No transfers (thus getting busy) on inactive adapters
57 * - Init sequence: void->available->connected->active
58 1) Create
59 2) Connect
60 3) Activate
61 * - Destruction sequence: active->connected->available->void
62 1) Deactivate
63 2) Disconnect
64 3) Destroy
65*/
66
67#ifdef VBOXANETADP_DO_NOT_USE_NETFLT
68enum VBoxNetAdpState
69{
70 kVBoxNetAdpState_Invalid,
71 kVBoxNetAdpState_Transitional,
72 kVBoxNetAdpState_Available,
73 kVBoxNetAdpState_Connected,
74 kVBoxNetAdpState_Active
75};
76typedef enum VBoxNetAdpState VBOXNETADPSTATE;
77#endif /* VBOXANETADP_DO_NOT_USE_NETFLT */
78
79struct VBoxNetAdapter
80{
81#ifdef VBOXANETADP_DO_NOT_USE_NETFLT
82 /** The spinlock protecting the state variables and host interface handle. */
83 RTSPINLOCK hSpinlock;
84
85 /* --- Protected with spinlock. --- */
86
87 /** Denotes availability of this slot in adapter array. */
88 VBOXNETADPSTATE enmState;
89
90 /* --- Unprotected. Atomic access. --- */
91
92 /** Reference count. */
93 uint32_t volatile cRefs;
94 /** The busy count.
95 * This counts the number of current callers and pending packet. */
96 uint32_t volatile cBusy;
97
98 /* --- Unprotected. Do not modify when cBusy > 0. --- */
99
100 /** Our RJ-45 port.
101 * This is what the internal network plugs into. */
102 INTNETTRUNKIFPORT MyPort;
103 /** The RJ-45 port on the INTNET "switch".
104 * This is what we're connected to. */
105 PINTNETTRUNKSWPORT pSwitchPort;
106 /** Pointer to the globals. */
107 PVBOXNETADPGLOBALS pGlobals;
108 /** The event that is signaled when we go idle and that pfnWaitForIdle blocks on. */
109 RTSEMEVENT hEventIdle;
110#endif /* !VBOXANETADP_DO_NOT_USE_NETFLT */
111 /** Corresponds to the digit at the end of device name. */
112 uint8_t uUnit;
113
114 union
115 {
116#ifdef VBOXNETADP_OS_SPECFIC
117 struct
118 {
119# if defined(RT_OS_DARWIN)
120 /** @name Darwin instance data.
121 * @{ */
122 /** Event to signal detachment of interface. */
123 RTSEMEVENT hEvtDetached;
124 /** Pointer to Darwin interface structure. */
125 ifnet_t pIface;
126 /** MAC address. */
127 RTMAC Mac;
128 /** Protocol families attached to this adapter. */
129 protocol_family_t aAttachedFamilies[VBOXNETADP_MAX_FAMILIES];
130# else
131# error PORTME
132# endif
133 } s;
134#endif
135 /** Padding. */
136#if defined(RT_OS_WINDOWS)
137# if defined(VBOX_NETFLT_ONDEMAND_BIND)
138 uint8_t abPadding[192];
139# else
140 uint8_t abPadding[1024];
141# endif
142#elif defined(RT_OS_LINUX)
143 uint8_t abPadding[320];
144#else
145 uint8_t abPadding[64];
146#endif
147 } u;
148 /** The interface name. */
149 char szName[VBOXNETADP_MAX_NAME_LEN];
150};
151typedef struct VBoxNetAdapter VBOXNETADP;
152typedef VBOXNETADP *PVBOXNETADP;
153
154#ifdef VBOXANETADP_DO_NOT_USE_NETFLT
155/**
156 * The global data of the VBox filter driver.
157 *
158 * This contains the bit required for communicating with support driver, VBoxDrv
159 * (start out as SupDrv).
160 */
161typedef struct VBOXNETADPGLOBALS
162{
163 /** Mutex protecting the list of instances and state changes. */
164 RTSEMFASTMUTEX hFastMtx;
165 /** Array of adapter instances. */
166 VBOXNETADP aAdapters[VBOXNETADP_MAX_INSTANCES];
167
168 /** The INTNET trunk network interface factory. */
169 INTNETTRUNKFACTORY TrunkFactory;
170 /** The SUPDRV component factory registration. */
171 SUPDRVFACTORY SupDrvFactory;
172 /** The number of current factory references. */
173 int32_t volatile cFactoryRefs;
174 /** The SUPDRV IDC handle (opaque struct). */
175 SUPDRVIDCHANDLE SupDrvIDC;
176} VBOXNETADPGLOBALS;
177
178
179DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
180DECLHIDDEN(void) vboxNetAdpReceive(PVBOXNETADP pThis, PINTNETSG pSG);
181DECLHIDDEN(bool) vboxNetAdpPrepareToReceive(PVBOXNETADP pThis);
182DECLHIDDEN(void) vboxNetAdpCancelReceive(PVBOXNETADP pThis);
183
184DECLHIDDEN(int) vboxNetAdpInitGlobals(PVBOXNETADPGLOBALS pGlobals);
185DECLHIDDEN(int) vboxNetAdpTryDeleteGlobals(PVBOXNETADPGLOBALS pGlobals);
186DECLHIDDEN(bool) vboxNetAdpCanUnload(PVBOXNETADPGLOBALS pGlobals);
187
188DECLHIDDEN(void) vboxNetAdpRetain(PVBOXNETADP pThis);
189DECLHIDDEN(void) vboxNetAdpRelease(PVBOXNETADP pThis);
190DECLHIDDEN(void) vboxNetAdpBusy(PVBOXNETADP pThis);
191DECLHIDDEN(void) vboxNetAdpIdle(PVBOXNETADP pThis);
192
193DECLHIDDEN(int) vboxNetAdpInitGlobalsBase(PVBOXNETADPGLOBALS pGlobals);
194DECLHIDDEN(int) vboxNetAdpInitIdc(PVBOXNETADPGLOBALS pGlobals);
195DECLHIDDEN(void) vboxNetAdpDeleteGlobalsBase(PVBOXNETADPGLOBALS pGlobals);
196DECLHIDDEN(int) vboxNetAdpTryDeleteIdc(PVBOXNETADPGLOBALS pGlobals);
197
198
199
200/** @name The OS specific interface.
201 * @{ */
202/**
203 * Transmits a frame.
204 *
205 * @return IPRT status code.
206 * @param pThis The new instance.
207 * @param pSG The (scatter/)gather list.
208 * @param fDst The destination mask. At least one bit will be set.
209 *
210 * @remarks Owns the out-bound trunk port semaphore.
211 */
212DECLHIDDEN(int) vboxNetAdpPortOsXmit(PVBOXNETADP pThis, PINTNETSG pSG, uint32_t fDst);
213
214/**
215 * Checks if the interface is in promiscuous mode from the host perspective.
216 *
217 * If it is, then the internal networking switch will send frames
218 * heading for the wire to the host as well.
219 *
220 * @see INTNETTRUNKIFPORT::pfnIsPromiscuous for more details.
221 *
222 * @returns true / false accordingly.
223 * @param pThis The instance.
224 *
225 * @remarks Owns the network lock and the out-bound trunk port semaphores.
226 */
227DECLHIDDEN(bool) vboxNetAdpPortOsIsPromiscuous(PVBOXNETADP pThis);
228
229/**
230 * Get the MAC address of the interface we're attached to.
231 *
232 * Used by the internal networking switch for implementing the
233 * shared-MAC-on-the-wire mode.
234 *
235 * @param pThis The instance.
236 * @param pMac Where to store the MAC address.
237 * If you don't know, set all the bits except the first (the multicast one).
238 *
239 * @remarks Owns the network lock and the out-bound trunk port semaphores.
240 */
241DECLHIDDEN(void) vboxNetAdpPortOsGetMacAddress(PVBOXNETADP pThis, PRTMAC pMac);
242
243/**
244 * Checks if the specified MAC address is for any of the host interfaces.
245 *
246 * Used by the internal networking switch to decide the destination(s)
247 * of a frame.
248 *
249 * @returns true / false accordingly.
250 * @param pThis The instance.
251 * @param pMac The MAC address.
252 *
253 * @remarks Owns the network lock and the out-bound trunk port semaphores.
254 */
255DECLHIDDEN(bool) vboxNetAdpPortOsIsHostMac(PVBOXNETADP pThis, PCRTMAC pMac);
256
257/**
258 * This is called to when disconnecting from a network.
259 *
260 * @return IPRT status code.
261 * @param pThis The new instance.
262 *
263 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
264 */
265DECLHIDDEN(int) vboxNetAdpOsDisconnectIt(PVBOXNETADP pThis);
266
267/**
268 * This is called to when connecting to a network.
269 *
270 * @return IPRT status code.
271 * @param pThis The new instance.
272 *
273 * @remarks Owns the semaphores for the global list, the network lock and the out-bound trunk port.
274 */
275DECLHIDDEN(int) vboxNetAdpOsConnectIt(PVBOXNETADP pThis);
276
277/**
278 * This is called to perform OS-specific structure initializations.
279 *
280 * @return IPRT status code.
281 * @param pThis The new instance.
282 *
283 * @remarks Owns no locks.
284 */
285DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
286
287/**
288 * Counter part to vboxNetAdpOsCreate().
289 *
290 * @return IPRT status code.
291 * @param pThis The new instance.
292 *
293 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
294 */
295DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
296
297/**
298 * This is called to attach to the actual host interface
299 * after linking the instance into the list.
300 *
301 * @return IPRT status code.
302 * @param pThis The new instance.
303 * @param pMac The MAC address to use for this instance.
304 *
305 * @remarks Owns no locks.
306 */
307DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
308
309/** @} */
310#endif /* !VBOXANETADP_DO_NOT_USE_NETFLT */
311
312
313__END_DECLS
314
315#endif
316
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