VirtualBox

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

Last change on this file since 50837 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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