VirtualBox

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

Last change on this file since 68246 was 63513, checked in by vboxsync, 8 years ago

VBoxNetAdptInternal.h: VBoxNetAdpState: As correctly pointed out by clang: ISO C restricts enumerator values to range of 'int' (4294967295 is too large). The 32-bit enum size ensurance hacks are all using 0x7fffffff.

  • 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 63513 2016-08-15 23:16:23Z vboxsync $ */
2/** @file
3 * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2008-2016 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 128
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_32BitHack = 0x7FFFFFFF
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 /** @} */
105# elif defined(RT_OS_LINUX)
106 /** @name Darwin instance data.
107 * @{ */
108 /** Pointer to Linux network device structure. */
109 struct net_device *pNetDev;
110 /** @} */
111# elif defined(RT_OS_FREEBSD)
112 /** @name FreeBSD instance data.
113 * @{ */
114 struct ifnet *ifp;
115 /** @} */
116# else
117# error PORTME
118# endif
119 } s;
120#endif
121 /** Union alignment to a pointer. */
122 void *pvAlign;
123 /** Padding. */
124 uint8_t abPadding[64];
125 } u;
126 /** The interface name. */
127 char szName[VBOXNETADP_MAX_NAME_LEN];
128};
129typedef struct VBoxNetAdapter VBOXNETADP;
130typedef VBOXNETADP *PVBOXNETADP;
131/* Paranoia checks for alignment and padding. */
132AssertCompileMemberAlignment(VBOXNETADP, u, ARCH_BITS/8);
133AssertCompileMemberAlignment(VBOXNETADP, szName, ARCH_BITS/8);
134AssertCompileMembersSameSize(VBOXNETADP, u, VBOXNETADP, u.abPadding);
135
136DECLHIDDEN(int) vboxNetAdpInit(void);
137DECLHIDDEN(void) vboxNetAdpShutdown(void);
138DECLHIDDEN(int) vboxNetAdpCreate(PVBOXNETADP *ppNew, const char *pcszName);
139DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
140DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
141DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
142
143
144/**
145 * This is called to perform OS-specific structure initializations.
146 *
147 * @return IPRT status code.
148 * @param pThis The new instance.
149 *
150 * @remarks Owns no locks.
151 */
152DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
153
154/**
155 * Counter part to vboxNetAdpOsCreate().
156 *
157 * @return IPRT status code.
158 * @param pThis The new instance.
159 *
160 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
161 */
162DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
163
164/**
165 * This is called to attach to the actual host interface
166 * after linking the instance into the list.
167 *
168 * @return IPRT status code.
169 * @param pThis The new instance.
170 * @param pMac The MAC address to use for this instance.
171 *
172 * @remarks Owns no locks.
173 */
174DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
175
176
177
178RT_C_DECLS_END
179
180#endif
181
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