VirtualBox

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

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

#2957: Dynamic add/remove via /dev/vboxnetctl ioctls.

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