VirtualBox

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

Last change on this file since 35824 was 35824, checked in by vboxsync, 14 years ago

netadp: coding style

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: VBoxNetAdpInternal.h 35824 2011-02-02 13:32:03Z vboxsync $ */
2/** @file
3 * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2008 Oracle Corporation
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
18#ifndef ___VBoxNetAdpInternal_h___
19#define ___VBoxNetAdpInternal_h___
20
21#include <VBox/sup.h>
22#include <VBox/intnet.h>
23#include <iprt/semaphore.h>
24#include <iprt/assert.h>
25
26
27RT_C_DECLS_BEGIN
28
29/** Pointer to the globals. */
30typedef struct VBOXNETADPGLOBALS *PVBOXNETADPGLOBALS;
31
32#define VBOXNETADP_MAX_INSTANCES 8
33#define VBOXNETADP_MAX_UNITS 128
34#define VBOXNETADP_NAME "vboxnet"
35#define VBOXNETADP_MAX_NAME_LEN 32
36#define VBOXNETADP_MTU 1500
37#if defined(RT_OS_DARWIN)
38# define VBOXNETADP_MAX_FAMILIES 4
39# define VBOXNETADP_DETACH_TIMEOUT 500
40#endif
41
42#define VBOXNETADP_CTL_DEV_NAME "vboxnetctl"
43#define VBOXNETADP_CTL_ADD _IOWR('v', 1, VBOXNETADPREQ)
44#define VBOXNETADP_CTL_REMOVE _IOW('v', 2, VBOXNETADPREQ)
45
46typedef struct VBoxNetAdpReq
47{
48 char szName[VBOXNETADP_MAX_NAME_LEN];
49} VBOXNETADPREQ;
50typedef VBOXNETADPREQ *PVBOXNETADPREQ;
51
52/**
53 * Void entries mark vacant slots in adapter array. Valid entries are busy slots.
54 * As soon as slot is being modified its state changes to transitional.
55 * An entry in transitional state must only be accessed by the thread that
56 * put it to this state.
57 */
58/**
59 * To avoid races on adapter fields we stick to the following rules:
60 * - rewrite: Int net port calls are serialized
61 * - No modifications are allowed on busy adapters (deactivate first)
62 * Refuse to destroy adapter until it gets to available state
63 * - No transfers (thus getting busy) on inactive adapters
64 * - Init sequence: void->available->connected->active
65 1) Create
66 2) Connect
67 3) Activate
68 * - Destruction sequence: active->connected->available->void
69 1) Deactivate
70 2) Disconnect
71 3) Destroy
72*/
73
74enum VBoxNetAdpState
75{
76 kVBoxNetAdpState_Invalid,
77 kVBoxNetAdpState_Transitional,
78 kVBoxNetAdpState_Active,
79 kVBoxNetAdpState_U32Hack = 0xFFFFFFFF
80};
81typedef enum VBoxNetAdpState VBOXNETADPSTATE;
82
83struct VBoxNetAdapter
84{
85 /** Denotes availability of this slot in adapter array. */
86 VBOXNETADPSTATE enmState;
87 /** Corresponds to the digit at the end of device name. */
88 int iUnit;
89
90 union
91 {
92#ifdef VBOXNETADP_OS_SPECFIC
93 struct
94 {
95# if defined(RT_OS_DARWIN)
96 /** @name Darwin instance data.
97 * @{ */
98 /** Event to signal detachment of interface. */
99 RTSEMEVENT hEvtDetached;
100 /** Pointer to Darwin interface structure. */
101 ifnet_t pIface;
102 /** MAC address. */
103 RTMAC Mac;
104 /** Protocol families attached to this adapter. */
105 protocol_family_t aAttachedFamilies[VBOXNETADP_MAX_FAMILIES];
106 /** @} */
107# elif defined(RT_OS_LINUX)
108 /** @name Darwin instance data.
109 * @{ */
110 /** Pointer to Linux network device structure. */
111 struct net_device *pNetDev;
112 /** @} */
113# elif defined(RT_OS_FREEBSD)
114 /** @name FreeBSD instance data.
115 * @{ */
116 struct ifnet *ifp;
117 /** @} */
118# else
119# error PORTME
120# endif
121 } s;
122#endif
123 /** Padding. */
124#if defined(RT_OS_WINDOWS)
125# if defined(VBOX_NETFLT_ONDEMAND_BIND)
126 uint8_t abPadding[192];
127# else
128 uint8_t abPadding[1024];
129# endif
130#elif defined(RT_OS_LINUX)
131 uint8_t abPadding[64];
132#else
133 uint8_t abPadding[64];
134#endif
135 } u;
136 /** The interface name. */
137 char szName[VBOXNETADP_MAX_NAME_LEN];
138};
139typedef struct VBoxNetAdapter VBOXNETADP;
140typedef VBOXNETADP *PVBOXNETADP;
141
142DECLHIDDEN(int) vboxNetAdpInit(void);
143DECLHIDDEN(void) vboxNetAdpShutdown(void);
144DECLHIDDEN(int) vboxNetAdpCreate(PVBOXNETADP *ppNew, const char *pcszName);
145DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
146DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
147DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
148
149
150/**
151 * This is called to perform OS-specific structure initializations.
152 *
153 * @return IPRT status code.
154 * @param pThis The new instance.
155 *
156 * @remarks Owns no locks.
157 */
158DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
159
160/**
161 * Counter part to vboxNetAdpOsCreate().
162 *
163 * @return IPRT status code.
164 * @param pThis The new instance.
165 *
166 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
167 */
168DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
169
170/**
171 * This is called to attach to the actual host interface
172 * after linking the instance into the list.
173 *
174 * @return IPRT status code.
175 * @param pThis The new instance.
176 * @param pMac The MAC address to use for this instance.
177 *
178 * @remarks Owns no locks.
179 */
180DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
181
182
183
184RT_C_DECLS_END
185
186#endif
187
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