VirtualBox

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

Last change on this file since 93912 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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