1 | /* $Id: VBoxNetAdpInternal.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef VBOX_INCLUDED_SRC_VBoxNetAdp_VBoxNetAdpInternal_h
|
---|
38 | #define VBOX_INCLUDED_SRC_VBoxNetAdp_VBoxNetAdpInternal_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <VBox/sup.h>
|
---|
44 | #include <VBox/intnet.h>
|
---|
45 | #include <iprt/semaphore.h>
|
---|
46 | #include <iprt/assert.h>
|
---|
47 |
|
---|
48 |
|
---|
49 | RT_C_DECLS_BEGIN
|
---|
50 |
|
---|
51 | /** Pointer to the globals. */
|
---|
52 | typedef struct VBOXNETADPGLOBALS *PVBOXNETADPGLOBALS;
|
---|
53 |
|
---|
54 | #define VBOXNETADP_MAX_INSTANCES 128
|
---|
55 | #define VBOXNETADP_MAX_UNITS 128
|
---|
56 | #define VBOXNETADP_NAME "vboxnet"
|
---|
57 | #define VBOXNETADP_MAX_NAME_LEN 32
|
---|
58 | #define VBOXNETADP_MTU 1500
|
---|
59 | #if defined(RT_OS_DARWIN)
|
---|
60 | # define VBOXNETADP_MAX_FAMILIES 4
|
---|
61 | # define VBOXNETADP_DETACH_TIMEOUT 500
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | #define VBOXNETADP_CTL_DEV_NAME "vboxnetctl"
|
---|
65 | #define VBOXNETADP_CTL_ADD _IOWR('v', 1, VBOXNETADPREQ)
|
---|
66 | #define VBOXNETADP_CTL_REMOVE _IOW('v', 2, VBOXNETADPREQ)
|
---|
67 |
|
---|
68 | typedef struct VBoxNetAdpReq
|
---|
69 | {
|
---|
70 | char szName[VBOXNETADP_MAX_NAME_LEN];
|
---|
71 | } VBOXNETADPREQ;
|
---|
72 | typedef VBOXNETADPREQ *PVBOXNETADPREQ;
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Void entries mark vacant slots in adapter array. Valid entries are busy slots.
|
---|
76 | * As soon as slot is being modified its state changes to transitional.
|
---|
77 | * An entry in transitional state must only be accessed by the thread that
|
---|
78 | * put it to this state.
|
---|
79 | */
|
---|
80 | /**
|
---|
81 | * To avoid races on adapter fields we stick to the following rules:
|
---|
82 | * - rewrite: Int net port calls are serialized
|
---|
83 | * - No modifications are allowed on busy adapters (deactivate first)
|
---|
84 | * Refuse to destroy adapter until it gets to available state
|
---|
85 | * - No transfers (thus getting busy) on inactive adapters
|
---|
86 | * - Init sequence: void->available->connected->active
|
---|
87 | 1) Create
|
---|
88 | 2) Connect
|
---|
89 | 3) Activate
|
---|
90 | * - Destruction sequence: active->connected->available->void
|
---|
91 | 1) Deactivate
|
---|
92 | 2) Disconnect
|
---|
93 | 3) Destroy
|
---|
94 | */
|
---|
95 |
|
---|
96 | enum VBoxNetAdpState
|
---|
97 | {
|
---|
98 | kVBoxNetAdpState_Invalid,
|
---|
99 | kVBoxNetAdpState_Transitional,
|
---|
100 | kVBoxNetAdpState_Active,
|
---|
101 | kVBoxNetAdpState_32BitHack = 0x7FFFFFFF
|
---|
102 | };
|
---|
103 | typedef enum VBoxNetAdpState VBOXNETADPSTATE;
|
---|
104 |
|
---|
105 | struct VBoxNetAdapter
|
---|
106 | {
|
---|
107 | /** Denotes availability of this slot in adapter array. */
|
---|
108 | VBOXNETADPSTATE enmState;
|
---|
109 | /** Corresponds to the digit at the end of device name. */
|
---|
110 | int iUnit;
|
---|
111 |
|
---|
112 | union
|
---|
113 | {
|
---|
114 | #ifdef VBOXNETADP_OS_SPECFIC
|
---|
115 | struct
|
---|
116 | {
|
---|
117 | # if defined(RT_OS_DARWIN)
|
---|
118 | /** @name Darwin instance data.
|
---|
119 | * @{ */
|
---|
120 | /** Event to signal detachment of interface. */
|
---|
121 | RTSEMEVENT hEvtDetached;
|
---|
122 | /** Pointer to Darwin interface structure. */
|
---|
123 | ifnet_t pIface;
|
---|
124 | /** MAC address. */
|
---|
125 | RTMAC Mac;
|
---|
126 | /** @} */
|
---|
127 | # elif defined(RT_OS_LINUX)
|
---|
128 | /** @name Darwin instance data.
|
---|
129 | * @{ */
|
---|
130 | /** Pointer to Linux network device structure. */
|
---|
131 | struct net_device *pNetDev;
|
---|
132 | /** @} */
|
---|
133 | # elif defined(RT_OS_FREEBSD)
|
---|
134 | /** @name FreeBSD instance data.
|
---|
135 | * @{ */
|
---|
136 | struct ifnet *ifp;
|
---|
137 | /** @} */
|
---|
138 | # else
|
---|
139 | # error PORTME
|
---|
140 | # endif
|
---|
141 | } s;
|
---|
142 | #endif
|
---|
143 | /** Union alignment to a pointer. */
|
---|
144 | void *pvAlign;
|
---|
145 | /** Padding. */
|
---|
146 | uint8_t abPadding[64];
|
---|
147 | } u;
|
---|
148 | /** The interface name. */
|
---|
149 | char szName[VBOXNETADP_MAX_NAME_LEN];
|
---|
150 | };
|
---|
151 | typedef struct VBoxNetAdapter VBOXNETADP;
|
---|
152 | typedef VBOXNETADP *PVBOXNETADP;
|
---|
153 | /* Paranoia checks for alignment and padding. */
|
---|
154 | AssertCompileMemberAlignment(VBOXNETADP, u, ARCH_BITS/8);
|
---|
155 | AssertCompileMemberAlignment(VBOXNETADP, szName, ARCH_BITS/8);
|
---|
156 | AssertCompileMembersSameSize(VBOXNETADP, u, VBOXNETADP, u.abPadding);
|
---|
157 |
|
---|
158 | DECLHIDDEN(int) vboxNetAdpInit(void);
|
---|
159 | DECLHIDDEN(void) vboxNetAdpShutdown(void);
|
---|
160 | DECLHIDDEN(int) vboxNetAdpCreate(PVBOXNETADP *ppNew, const char *pcszName);
|
---|
161 | DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
|
---|
162 | DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
|
---|
163 | DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
|
---|
164 |
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * This is called to perform OS-specific structure initializations.
|
---|
168 | *
|
---|
169 | * @return IPRT status code.
|
---|
170 | * @param pThis The new instance.
|
---|
171 | *
|
---|
172 | * @remarks Owns no locks.
|
---|
173 | */
|
---|
174 | DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Counter part to vboxNetAdpOsCreate().
|
---|
178 | *
|
---|
179 | * @return IPRT status code.
|
---|
180 | * @param pThis The new instance.
|
---|
181 | *
|
---|
182 | * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
|
---|
183 | */
|
---|
184 | DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * This is called to attach to the actual host interface
|
---|
188 | * after linking the instance into the list.
|
---|
189 | *
|
---|
190 | * @return IPRT status code.
|
---|
191 | * @param pThis The new instance.
|
---|
192 | * @param pMac The MAC address to use for this instance.
|
---|
193 | *
|
---|
194 | * @remarks Owns no locks.
|
---|
195 | */
|
---|
196 | DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
|
---|
197 |
|
---|
198 |
|
---|
199 |
|
---|
200 | RT_C_DECLS_END
|
---|
201 |
|
---|
202 | #endif /* !VBOX_INCLUDED_SRC_VBoxNetAdp_VBoxNetAdpInternal_h */
|
---|
203 |
|
---|