VirtualBox

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

Last change on this file was 99739, checked in by vboxsync, 12 months ago

*: doxygen corrections (mostly about removing @returns from functions returning void).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
RevLine 
[16960]1/* $Id: VBoxNetAdpInternal.h 99739 2023-05-11 01:01:08Z vboxsync $ */
2/** @file
3 * VBoxNetAdp - Network Filter Driver (Host), Internal Header.
4 */
5
6/*
[98103]7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
[16960]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
[69250]11 *
[96407]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 *
[69250]25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
[96407]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
[69250]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.
[96407]33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
[16960]35 */
36
[76568]37#ifndef VBOX_INCLUDED_SRC_VBoxNetAdp_VBoxNetAdpInternal_h
38#define VBOX_INCLUDED_SRC_VBoxNetAdp_VBoxNetAdpInternal_h
[76527]39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
[16960]42
43#include <VBox/sup.h>
44#include <VBox/intnet.h>
45#include <iprt/semaphore.h>
46#include <iprt/assert.h>
47
48
[20374]49RT_C_DECLS_BEGIN
[16960]50
51/** Pointer to the globals. */
52typedef struct VBOXNETADPGLOBALS *PVBOXNETADPGLOBALS;
53
[41272]54#define VBOXNETADP_MAX_INSTANCES 128
[35809]55#define VBOXNETADP_MAX_UNITS 128
[16960]56#define VBOXNETADP_NAME "vboxnet"
[17095]57#define VBOXNETADP_MAX_NAME_LEN 32
[16960]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
[18859]64#define VBOXNETADP_CTL_DEV_NAME "vboxnetctl"
[35809]65#define VBOXNETADP_CTL_ADD _IOWR('v', 1, VBOXNETADPREQ)
[18859]66#define VBOXNETADP_CTL_REMOVE _IOW('v', 2, VBOXNETADPREQ)
67
68typedef struct VBoxNetAdpReq
69{
70 char szName[VBOXNETADP_MAX_NAME_LEN];
71} VBOXNETADPREQ;
72typedef VBOXNETADPREQ *PVBOXNETADPREQ;
73
[16960]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
96enum VBoxNetAdpState
97{
98 kVBoxNetAdpState_Invalid,
99 kVBoxNetAdpState_Transitional,
[18859]100 kVBoxNetAdpState_Active,
[63513]101 kVBoxNetAdpState_32BitHack = 0x7FFFFFFF
[16960]102};
103typedef enum VBoxNetAdpState VBOXNETADPSTATE;
104
105struct 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. */
[35824]110 int iUnit;
[16960]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;
[18973]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 /** @} */
[22875]133# elif defined(RT_OS_FREEBSD)
134 /** @name FreeBSD instance data.
135 * @{ */
136 struct ifnet *ifp;
137 /** @} */
[16960]138# else
139# error PORTME
140# endif
141 } s;
142#endif
[38389]143 /** Union alignment to a pointer. */
[38388]144 void *pvAlign;
[38389]145 /** Padding. */
[18973]146 uint8_t abPadding[64];
[16960]147 } u;
148 /** The interface name. */
[17095]149 char szName[VBOXNETADP_MAX_NAME_LEN];
[16960]150};
151typedef struct VBoxNetAdapter VBOXNETADP;
152typedef VBOXNETADP *PVBOXNETADP;
[38388]153/* Paranoia checks for alignment and padding. */
154AssertCompileMemberAlignment(VBOXNETADP, u, ARCH_BITS/8);
155AssertCompileMemberAlignment(VBOXNETADP, szName, ARCH_BITS/8);
156AssertCompileMembersSameSize(VBOXNETADP, u, VBOXNETADP, u.abPadding);
[16960]157
[18973]158DECLHIDDEN(int) vboxNetAdpInit(void);
159DECLHIDDEN(void) vboxNetAdpShutdown(void);
[35824]160DECLHIDDEN(int) vboxNetAdpCreate(PVBOXNETADP *ppNew, const char *pcszName);
[18973]161DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
162DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
[16960]163DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac);
164
165
166/**
[17095]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 */
174DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
175
176/**
[16960]177 * Counter part to vboxNetAdpOsCreate().
178 *
179 * @param pThis The new instance.
180 *
181 * @remarks May own the semaphores for the global list, the network lock and the out-bound trunk port.
182 */
183DECLHIDDEN(void) vboxNetAdpOsDestroy(PVBOXNETADP pThis);
184
185/**
186 * This is called to attach to the actual host interface
187 * after linking the instance into the list.
188 *
189 * @return IPRT status code.
190 * @param pThis The new instance.
191 * @param pMac The MAC address to use for this instance.
192 *
193 * @remarks Owns no locks.
194 */
[35809]195DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
[16960]196
197
198
[20374]199RT_C_DECLS_END
[16960]200
[76568]201#endif /* !VBOX_INCLUDED_SRC_VBoxNetAdp_VBoxNetAdpInternal_h */
[16960]202
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use