VirtualBox

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

最後變更 在這個檔案從57907是 57907,由 vboxsync 提交於 9 年 前

VBoxNetAdp/darwin: use bpfattach() without tap and send callbacks.
Default behavior is fine and we get bpf packet injection for free.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.4 KB
 
1/* $Id: VBoxNetAdpInternal.h 57907 2015-09-26 03:35:03Z vboxsync $ */
2/** @file
3 * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2008-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 /** @} */
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 /** Union alignment to a pointer. */
124 void *pvAlign;
125 /** Padding. */
126 uint8_t abPadding[64];
127 } u;
128 /** The interface name. */
129 char szName[VBOXNETADP_MAX_NAME_LEN];
130};
131typedef struct VBoxNetAdapter VBOXNETADP;
132typedef VBOXNETADP *PVBOXNETADP;
133/* Paranoia checks for alignment and padding. */
134AssertCompileMemberAlignment(VBOXNETADP, u, ARCH_BITS/8);
135AssertCompileMemberAlignment(VBOXNETADP, szName, ARCH_BITS/8);
136AssertCompileMembersSameSize(VBOXNETADP, u, VBOXNETADP, u.abPadding);
137
138DECLHIDDEN(int) vboxNetAdpInit(void);
139DECLHIDDEN(void) vboxNetAdpShutdown(void);
140DECLHIDDEN(int) vboxNetAdpCreate(PVBOXNETADP *ppNew, const char *pcszName);
141DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
142DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
143DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
144
145
146/**
147 * This is called to perform OS-specific structure initializations.
148 *
149 * @return IPRT status code.
150 * @param pThis The new instance.
151 *
152 * @remarks Owns no locks.
153 */
154DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
155
156/**
157 * Counter part to vboxNetAdpOsCreate().
158 *
159 * @return IPRT status code.
160 * @param pThis The new instance.
161 *
162 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
163 */
164DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
165
166/**
167 * This is called to attach to the actual host interface
168 * after linking the instance into the list.
169 *
170 * @return IPRT status code.
171 * @param pThis The new instance.
172 * @param pMac The MAC address to use for this instance.
173 *
174 * @remarks Owns no locks.
175 */
176DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
177
178
179
180RT_C_DECLS_END
181
182#endif
183
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette