VirtualBox

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

Last change on this file since 38436 was 38408, checked in by vboxsync, 13 years ago

vboxnetflt: partial BPF support for bridged interfaces (#5817)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: VBoxNetAdpInternal.h 38408 2011-08-10 20:07:04Z vboxsync $ */
2/** @file
3 * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2008-2011 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 /** 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#if defined(RT_OS_WINDOWS)
129# if defined(VBOX_NETFLT_ONDEMAND_BIND)
130 uint8_t abPadding[192];
131# else
132 uint8_t abPadding[1024];
133# endif
134#elif defined(RT_OS_LINUX)
135 uint8_t abPadding[64];
136#else
137 uint8_t abPadding[64];
138#endif
139 } u;
140 /** The interface name. */
141 char szName[VBOXNETADP_MAX_NAME_LEN];
142};
143typedef struct VBoxNetAdapter VBOXNETADP;
144typedef VBOXNETADP *PVBOXNETADP;
145/* Paranoia checks for alignment and padding. */
146AssertCompileMemberAlignment(VBOXNETADP, u, ARCH_BITS/8);
147AssertCompileMemberAlignment(VBOXNETADP, szName, ARCH_BITS/8);
148AssertCompileMembersSameSize(VBOXNETADP, u, VBOXNETADP, u.abPadding);
149
150DECLHIDDEN(int) vboxNetAdpInit(void);
151DECLHIDDEN(void) vboxNetAdpShutdown(void);
152DECLHIDDEN(int) vboxNetAdpCreate(PVBOXNETADP *ppNew, const char *pcszName);
153DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
154DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
155DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
156
157
158/**
159 * This is called to perform OS-specific structure initializations.
160 *
161 * @return IPRT status code.
162 * @param pThis The new instance.
163 *
164 * @remarks Owns no locks.
165 */
166DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
167
168/**
169 * Counter part to vboxNetAdpOsCreate().
170 *
171 * @return IPRT status code.
172 * @param pThis The new instance.
173 *
174 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
175 */
176DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
177
178/**
179 * This is called to attach to the actual host interface
180 * after linking the instance into the list.
181 *
182 * @return IPRT status code.
183 * @param pThis The new instance.
184 * @param pMac The MAC address to use for this instance.
185 *
186 * @remarks Owns no locks.
187 */
188DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
189
190
191
192RT_C_DECLS_END
193
194#endif
195
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