VirtualBox

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

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

#2957: VBoxNetAdp: Fixes in generic and darwin parts. No traffic yet.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: VBoxNetAdpInternal.h 17095 2009-02-24 20:08:20Z 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
67enum VBoxNetAdpState
68{
69 kVBoxNetAdpState_Invalid,
70 kVBoxNetAdpState_Transitional,
71 kVBoxNetAdpState_Available,
72 kVBoxNetAdpState_Connected,
73 kVBoxNetAdpState_Active
74};
75typedef enum VBoxNetAdpState VBOXNETADPSTATE;
76
77struct VBoxNetAdapter
78{
79 /** The spinlock protecting the state variables and host interface handle. */
80 RTSPINLOCK hSpinlock;
81
82 /* --- Protected with spinlock. --- */
83
84 /** Denotes availability of this slot in adapter array. */
85 VBOXNETADPSTATE enmState;
86
87 /* --- Unprotected. Atomic access. --- */
88
89 /** Reference count. */
90 uint32_t volatile cRefs;
91 /** The busy count.
92 * This counts the number of current callers and pending packet. */
93 uint32_t volatile cBusy;
94
95 /* --- Unprotected. Do not modify when cBusy > 0. --- */
96
97 /** Our RJ-45 port.
98 * This is what the internal network plugs into. */
99 INTNETTRUNKIFPORT MyPort;
100 /** The RJ-45 port on the INTNET "switch".
101 * This is what we're connected to. */
102 PINTNETTRUNKSWPORT pSwitchPort;
103 /** Pointer to the globals. */
104 PVBOXNETADPGLOBALS pGlobals;
105 /** Corresponds to the digit at the end of device name. */
106 uint8_t uUnit;
107 /** The event that is signaled when we go idle and that pfnWaitForIdle blocks on. */
108 RTSEMEVENT hEventIdle;
109
110 union
111 {
112#ifdef VBOXNETADP_OS_SPECFIC
113 struct
114 {
115# if defined(RT_OS_DARWIN)
116 /** @name Darwin instance data.
117 * @{ */
118 /** Event to signal detachment of interface. */
119 RTSEMEVENT hEvtDetached;
120 /** Pointer to Darwin interface structure. */
121 ifnet_t pIface;
122 /** MAC address. */
123 RTMAC Mac;
124 /** Protocol families attached to this adapter. */
125 protocol_family_t aAttachedFamilies[VBOXNETADP_MAX_FAMILIES];
126# else
127# error PORTME
128# endif
129 } s;
130#endif
131 /** Padding. */
132#if defined(RT_OS_WINDOWS)
133# if defined(VBOX_NETFLT_ONDEMAND_BIND)
134 uint8_t abPadding[192];
135# else
136 uint8_t abPadding[1024];
137# endif
138#elif defined(RT_OS_LINUX)
139 uint8_t abPadding[320];
140#else
141 uint8_t abPadding[64];
142#endif
143 } u;
144 /** The interface name. */
145 char szName[VBOXNETADP_MAX_NAME_LEN];
146};
147typedef struct VBoxNetAdapter VBOXNETADP;
148typedef VBOXNETADP *PVBOXNETADP;
149
150/**
151 * The global data of the VBox filter driver.
152 *
153 * This contains the bit required for communicating with support driver, VBoxDrv
154 * (start out as SupDrv).
155 */
156typedef struct VBOXNETADPGLOBALS
157{
158 /** Mutex protecting the list of instances and state changes. */
159 RTSEMFASTMUTEX hFastMtx;
160 /** Array of adapter instances. */
161 VBOXNETADP aAdapters[VBOXNETADP_MAX_INSTANCES];
162
163 /** The INTNET trunk network interface factory. */
164 INTNETTRUNKFACTORY TrunkFactory;
165 /** The SUPDRV component factory registration. */
166 SUPDRVFACTORY SupDrvFactory;
167 /** The number of current factory references. */
168 int32_t volatile cFactoryRefs;
169 /** The SUPDRV IDC handle (opaque struct). */
170 SUPDRVIDCHANDLE SupDrvIDC;
171} VBOXNETADPGLOBALS;
172
173
174DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
175DECLHIDDEN(void) vboxNetAdpReceive(PVBOXNETADP pThis, PINTNETSG pSG);
176DECLHIDDEN(bool) vboxNetAdpPrepareToReceive(PVBOXNETADP pThis);
177DECLHIDDEN(void) vboxNetAdpCancelReceive(PVBOXNETADP pThis);
178
179DECLHIDDEN(int) vboxNetAdpInitGlobals(PVBOXNETADPGLOBALS pGlobals);
180DECLHIDDEN(int) vboxNetAdpTryDeleteGlobals(PVBOXNETADPGLOBALS pGlobals);
181DECLHIDDEN(bool) vboxNetAdpCanUnload(PVBOXNETADPGLOBALS pGlobals);
182
183DECLHIDDEN(void) vboxNetAdpRetain(PVBOXNETADP pThis);
184DECLHIDDEN(void) vboxNetAdpRelease(PVBOXNETADP pThis);
185DECLHIDDEN(void) vboxNetAdpBusy(PVBOXNETADP pThis);
186DECLHIDDEN(void) vboxNetAdpIdle(PVBOXNETADP pThis);
187
188DECLHIDDEN(int) vboxNetAdpInitGlobalsBase(PVBOXNETADPGLOBALS pGlobals);
189DECLHIDDEN(int) vboxNetAdpInitIdc(PVBOXNETADPGLOBALS pGlobals);
190DECLHIDDEN(void) vboxNetAdpDeleteGlobalsBase(PVBOXNETADPGLOBALS pGlobals);
191DECLHIDDEN(int) vboxNetAdpTryDeleteIdc(PVBOXNETADPGLOBALS pGlobals);
192
193
194
195/** @name The OS specific interface.
196 * @{ */
197/**
198 * Transmits a frame.
199 *
200 * @return IPRT status code.
201 * @param pThis The new instance.
202 * @param pSG The (scatter/)gather list.
203 * @param fDst The destination mask. At least one bit will be set.
204 *
205 * @remarks Owns the out-bound trunk port semaphore.
206 */
207DECLHIDDEN(int) vboxNetAdpPortOsXmit(PVBOXNETADP pThis, PINTNETSG pSG, uint32_t fDst);
208
209/**
210 * Checks if the interface is in promiscuous mode from the host perspective.
211 *
212 * If it is, then the internal networking switch will send frames
213 * heading for the wire to the host as well.
214 *
215 * @see INTNETTRUNKIFPORT::pfnIsPromiscuous for more details.
216 *
217 * @returns true / false accordingly.
218 * @param pThis The instance.
219 *
220 * @remarks Owns the network lock and the out-bound trunk port semaphores.
221 */
222DECLHIDDEN(bool) vboxNetAdpPortOsIsPromiscuous(PVBOXNETADP pThis);
223
224/**
225 * Get the MAC address of the interface we're attached to.
226 *
227 * Used by the internal networking switch for implementing the
228 * shared-MAC-on-the-wire mode.
229 *
230 * @param pThis The instance.
231 * @param pMac Where to store the MAC address.
232 * If you don't know, set all the bits except the first (the multicast one).
233 *
234 * @remarks Owns the network lock and the out-bound trunk port semaphores.
235 */
236DECLHIDDEN(void) vboxNetAdpPortOsGetMacAddress(PVBOXNETADP pThis, PRTMAC pMac);
237
238/**
239 * Checks if the specified MAC address is for any of the host interfaces.
240 *
241 * Used by the internal networking switch to decide the destination(s)
242 * of a frame.
243 *
244 * @returns true / false accordingly.
245 * @param pThis The instance.
246 * @param pMac The MAC address.
247 *
248 * @remarks Owns the network lock and the out-bound trunk port semaphores.
249 */
250DECLHIDDEN(bool) vboxNetAdpPortOsIsHostMac(PVBOXNETADP pThis, PCRTMAC pMac);
251
252/**
253 * This is called to when disconnecting from a network.
254 *
255 * @return IPRT status code.
256 * @param pThis The new instance.
257 *
258 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
259 */
260DECLHIDDEN(int) vboxNetAdpOsDisconnectIt(PVBOXNETADP pThis);
261
262/**
263 * This is called to when connecting to a network.
264 *
265 * @return IPRT status code.
266 * @param pThis The new instance.
267 *
268 * @remarks Owns the semaphores for the global list, the network lock and the out-bound trunk port.
269 */
270DECLHIDDEN(int) vboxNetAdpOsConnectIt(PVBOXNETADP pThis);
271
272/**
273 * This is called to perform OS-specific structure initializations.
274 *
275 * @return IPRT status code.
276 * @param pThis The new instance.
277 *
278 * @remarks Owns no locks.
279 */
280DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
281
282/**
283 * Counter part to vboxNetAdpOsCreate().
284 *
285 * @return IPRT status code.
286 * @param pThis The new instance.
287 *
288 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
289 */
290DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
291
292/**
293 * This is called to attach to the actual host interface
294 * after linking the instance into the list.
295 *
296 * @return IPRT status code.
297 * @param pThis The new instance.
298 * @param pMac The MAC address to use for this instance.
299 *
300 * @remarks Owns no locks.
301 */
302DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
303
304/** @} */
305
306
307__END_DECLS
308
309#endif
310
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