VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmnetifs.h@ 97693

Last change on this file since 97693 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 17.9 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Network Interfaces.
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vmm_pdmnetifs_h
37#define VBOX_INCLUDED_vmm_pdmnetifs_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_pdm_ifs_net PDM Network Interfaces
48 * @ingroup grp_pdm_interfaces
49 * @{
50 */
51
52
53/**
54 * PDM scatter/gather buffer.
55 *
56 * @todo Promote this to VBox/types.h, VBox/vmm/pdmcommon.h or some such place.
57 */
58typedef struct PDMSCATTERGATHER
59{
60 /** Flags. */
61 size_t fFlags;
62 /** The number of bytes used.
63 * This is cleared on alloc and set by the user. */
64 size_t cbUsed;
65 /** The number of bytes available.
66 * This is set on alloc and not changed by the user. */
67 size_t cbAvailable;
68 /** Private data member for the allocator side. */
69 void *pvAllocator;
70 /** Private data member for the user side. */
71 void *pvUser;
72 /** The number of segments
73 * This is set on alloc and not changed by the user. */
74 size_t cSegs;
75 /** Variable sized array of segments. */
76 PDMDATASEG aSegs[1];
77} PDMSCATTERGATHER;
78/** Pointer to a PDM scatter/gather buffer. */
79typedef PDMSCATTERGATHER *PPDMSCATTERGATHER;
80/** Pointer to a PDM scatter/gather buffer pointer. */
81typedef PPDMSCATTERGATHER *PPPDMSCATTERGATHER;
82
83
84/** @name PDMSCATTERGATHER::fFlags
85 * @{ */
86/** Magic value. */
87#define PDMSCATTERGATHER_FLAGS_MAGIC UINT32_C(0xb1b10000)
88/** Magic mask. */
89#define PDMSCATTERGATHER_FLAGS_MAGIC_MASK UINT32_C(0xffff0000)
90/** Owned by owner number 1. */
91#define PDMSCATTERGATHER_FLAGS_OWNER_1 UINT32_C(0x00000001)
92/** Owned by owner number 2. */
93#define PDMSCATTERGATHER_FLAGS_OWNER_2 UINT32_C(0x00000002)
94/** Owned by owner number 3. */
95#define PDMSCATTERGATHER_FLAGS_OWNER_3 UINT32_C(0x00000002)
96/** Owner mask. */
97#define PDMSCATTERGATHER_FLAGS_OWNER_MASK UINT32_C(0x00000003)
98/** Mask of flags available to general use.
99 * The parties using the SG must all agree upon how to use these of course. */
100#define PDMSCATTERGATHER_FLAGS_AVL_MASK UINT32_C(0x0000f000)
101/** Flags reserved for future use, MBZ. */
102#define PDMSCATTERGATHER_FLAGS_RVD_MASK UINT32_C(0x00000ff8)
103/** @} */
104
105
106/**
107 * Sets the owner of a scatter/gather buffer.
108 *
109 * @param pSgBuf .
110 * @param uNewOwner The new owner.
111 */
112DECLINLINE(void) PDMScatterGatherSetOwner(PPDMSCATTERGATHER pSgBuf, uint32_t uNewOwner)
113{
114 pSgBuf->fFlags = (pSgBuf->fFlags & ~PDMSCATTERGATHER_FLAGS_OWNER_MASK) | uNewOwner;
115}
116
117
118
119/** Pointer to a network port interface */
120typedef struct PDMINETWORKDOWN *PPDMINETWORKDOWN;
121/**
122 * Network port interface (down).
123 * Pair with PDMINETWORKUP.
124 */
125typedef struct PDMINETWORKDOWN
126{
127 /**
128 * Wait until there is space for receiving data. We do not care how much space is available
129 * because pfnReceive() will re-check and notify the guest if necessary.
130 *
131 * This function must be called before the pfnRecieve() method is called.
132 *
133 * @returns VBox status code. VINF_SUCCESS means there is at least one receive descriptor available.
134 * @param pInterface Pointer to the interface structure containing the called function pointer.
135 * @param cMillies Number of milliseconds to wait. 0 means return immediately.
136 *
137 * @thread Non-EMT.
138 */
139 DECLR3CALLBACKMEMBER(int, pfnWaitReceiveAvail,(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies));
140
141 /**
142 * Receive data from the network.
143 *
144 * @returns VBox status code.
145 * @param pInterface Pointer to the interface structure containing the called function pointer.
146 * @param pvBuf The available data.
147 * @param cb Number of bytes available in the buffer.
148 *
149 * @thread Non-EMT.
150 */
151 DECLR3CALLBACKMEMBER(int, pfnReceive,(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb));
152
153 /**
154 * Receive data with segmentation context from the network.
155 *
156 * @returns VBox status code.
157 * @param pInterface Pointer to the interface structure containing the called function pointer.
158 * @param pvBuf The available data.
159 * @param cb Number of bytes available in the buffer.
160 * @param pGso Segmentation context.
161 *
162 * @thread Non-EMT.
163 */
164 DECLR3CALLBACKMEMBER(int, pfnReceiveGso,(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb, PCPDMNETWORKGSO pGso));
165
166 /**
167 * Do pending transmit work on the leaf driver's XMIT thread.
168 *
169 * When a PDMINETWORKUP::pfnBeginTransmit or PDMINETWORKUP::pfnAllocBuf call
170 * fails with VERR_TRY_AGAIN, the leaf drivers XMIT thread will offer to process
171 * the upstream device/driver when the the VERR_TRY_AGAIN condition has been
172 * removed. In some cases the VERR_TRY_AGAIN condition is simply being in an
173 * inconvenient context and the XMIT thread will start working ASAP.
174 *
175 * @param pInterface Pointer to this interface.
176 * @thread Non-EMT.
177 */
178 DECLR3CALLBACKMEMBER(void, pfnXmitPending,(PPDMINETWORKDOWN pInterface));
179
180} PDMINETWORKDOWN;
181/** PDMINETWORKDOWN interface ID. */
182#define PDMINETWORKDOWN_IID "52b8cdbb-a087-493b-baa7-81ec3b803e06"
183
184
185/**
186 * Network link state.
187 */
188typedef enum PDMNETWORKLINKSTATE
189{
190 /** Invalid state. */
191 PDMNETWORKLINKSTATE_INVALID = 0,
192 /** The link is up. */
193 PDMNETWORKLINKSTATE_UP,
194 /** The link is down. */
195 PDMNETWORKLINKSTATE_DOWN,
196 /** The link is temporarily down while resuming. */
197 PDMNETWORKLINKSTATE_DOWN_RESUME
198} PDMNETWORKLINKSTATE;
199
200
201/** Pointer to a network connector interface */
202typedef R3PTRTYPE(struct PDMINETWORKUP *) PPDMINETWORKUPR3;
203/** Pointer to a network connector interface, ring-0 context. */
204typedef R0PTRTYPE(struct PDMINETWORKUPR0 *) PPDMINETWORKUPR0;
205/** Pointer to a network connector interface, raw-mode context. */
206typedef RCPTRTYPE(struct PDMINETWORKUPRC *) PPDMINETWORKUPRC;
207/** Pointer to a current context network connector interface. */
208typedef CTX_SUFF(PPDMINETWORKUP) PPDMINETWORKUP;
209
210/**
211 * Network connector interface (up).
212 * Pair with PDMINETWORKDOWN.
213 */
214typedef struct PDMINETWORKUP
215{
216 /**
217 * Begins a transmit session.
218 *
219 * The leaf driver guarantees that there are no concurrent sessions.
220 *
221 * @retval VINF_SUCCESS on success. Must always call
222 * PDMINETWORKUP::pfnEndXmit.
223 * @retval VERR_TRY_AGAIN if there is already an open transmit session or some
224 * important resource was unavailable (like buffer space). If it's a
225 * resources issue, the driver will signal its XMIT thread and have it
226 * work the device thru the PDMINETWORKDOWN::pfnNotifyBufAvailable
227 * callback method.
228 *
229 * @param pInterface Pointer to the interface structure containing the
230 * called function pointer.
231 * @param fOnWorkerThread Set if we're being called on a work thread. Clear
232 * if an EMT.
233 *
234 * @thread Any, but normally EMT or the XMIT thread.
235 */
236 DECLR3CALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUP pInterface, bool fOnWorkerThread));
237
238 /**
239 * Get a send buffer for passing to pfnSendBuf.
240 *
241 * @retval VINF_SUCCESS on success.
242 * @retval VERR_TRY_AGAIN if temporarily out of buffer space. After this
243 * happens, the driver will call PDMINETWORKDOWN::pfnNotifyBufAvailable
244 * when this is a buffer of the required size available.
245 * @retval VERR_NO_MEMORY if really out of buffer space.
246 * @retval VERR_NET_DOWN if we cannot send anything to the network at this
247 * point in time. Drop the frame with a xmit error. This is typically
248 * only seen when pausing the VM since the device keeps the link state,
249 * but there could of course be races.
250 *
251 * @param pInterface Pointer to the interface structure containing the
252 * called function pointer.
253 * @param cbMin The minimum buffer size.
254 * @param pGso Pointer to a GSO context (only reference while in
255 * this call). NULL indicates no segmentation
256 * offloading. PDMSCATTERGATHER::pvUser is used to
257 * indicate that a network SG uses GSO, usually by
258 * pointing to a copy of @a pGso.
259 * @param ppSgBuf Where to return the buffer. The buffer will be
260 * owned by the caller, designation owner number 1.
261 *
262 * @thread Any, but normally EMT or the XMIT thread.
263 */
264 DECLR3CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUP pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
265 PPPDMSCATTERGATHER ppSgBuf));
266
267 /**
268 * Frees an unused buffer.
269 *
270 * @retval VINF_SUCCESS on success.
271 *
272 * @param pInterface Pointer to the interface structure containing the called function pointer.
273 * @param pSgBuf A buffer from PDMINETWORKUP::pfnAllocBuf or
274 * PDMINETWORKDOWN::pfnNotifyBufAvailable. The buffer
275 * ownership shall be 1.
276 *
277 * @thread Any, but normally EMT or the XMIT thread.
278 */
279 DECLR3CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf));
280
281 /**
282 * Send data to the network.
283 *
284 * @retval VINF_SUCCESS on success.
285 * @retval VERR_NET_DOWN if the NIC is not connected to a network. pSgBuf will
286 * be freed.
287 * @retval VERR_NET_NO_BUFFER_SPACE if we're out of resources. pSgBuf will be
288 * freed.
289 *
290 * @param pInterface Pointer to the interface structure containing the
291 * called function pointer.
292 * @param pSgBuf The buffer containing the data to send. The buffer
293 * ownership shall be 1. The buffer will always be
294 * consumed, regardless of the status code.
295 *
296 * @param fOnWorkerThread Set if we're being called on a work thread. Clear
297 * if an EMT.
298 *
299 * @thread Any, but normally EMT or the XMIT thread.
300 */
301 DECLR3CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
302
303 /**
304 * Ends a transmit session.
305 *
306 * Pairs with successful PDMINETWORKUP::pfnBeginXmit calls.
307 *
308 * @param pInterface Pointer to the interface structure containing the
309 * called function pointer.
310 *
311 * @thread Any, but normally EMT or the XMIT thread.
312 */
313 DECLR3CALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUP pInterface));
314
315 /**
316 * Set promiscuous mode.
317 *
318 * This is called when the promiscuous mode is set. This means that there doesn't have
319 * to be a mode change when it's called.
320 *
321 * @param pInterface Pointer to the interface structure containing the called function pointer.
322 * @param fPromiscuous Set if the adaptor is now in promiscuous mode. Clear if it is not.
323 * @thread EMT ??
324 */
325 DECLR3CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUP pInterface, bool fPromiscuous));
326
327 /**
328 * Notification on link status changes.
329 *
330 * @param pInterface Pointer to the interface structure containing the called function pointer.
331 * @param enmLinkState The new link state.
332 * @thread EMT ??
333 */
334 DECLR3CALLBACKMEMBER(void, pfnNotifyLinkChanged,(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState));
335
336 /** @todo Add a callback that informs the driver chain about MAC address changes if we ever implement that. */
337
338} PDMINETWORKUP;
339
340/** Ring-0 edition of PDMINETWORKUP. */
341typedef struct PDMINETWORKUPR0
342{
343 /** @copydoc PDMINETWORKUP::pfnBeginXmit */
344 DECLR0CALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUPR0 pInterface, bool fOnWorkerThread));
345 /** @copydoc PDMINETWORKUP::pfnAllocBuf */
346 DECLR0CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUPR0 pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
347 PPPDMSCATTERGATHER ppSgBuf));
348 /** @copydoc PDMINETWORKUP::pfnFreeBuf */
349 DECLR0CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUPR0 pInterface, PPDMSCATTERGATHER pSgBuf));
350 /** @copydoc PDMINETWORKUP::pfnSendBuf */
351 DECLR0CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUPR0 pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
352 /** @copydoc PDMINETWORKUP::pfnEndXmit */
353 DECLR0CALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUPR0 pInterface));
354 /** @copydoc PDMINETWORKUP::pfnSetPromiscuousMode */
355 DECLR0CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUPR0 pInterface, bool fPromiscuous));
356} PDMINETWORKUPR0;
357
358/** Raw-mode context edition of PDMINETWORKUP. */
359typedef struct PDMINETWORKUPRC
360{
361 /** @copydoc PDMINETWORKUP::pfnBeginXmit */
362 DECLRCCALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUPRC pInterface, bool fOnWorkerThread));
363 /** @copydoc PDMINETWORKUP::pfnAllocBuf */
364 DECLRCCALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUPRC pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
365 PPPDMSCATTERGATHER ppSgBuf));
366 /** @copydoc PDMINETWORKUP::pfnFreeBuf */
367 DECLRCCALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUPRC pInterface, PPDMSCATTERGATHER pSgBuf));
368 /** @copydoc PDMINETWORKUP::pfnSendBuf */
369 DECLRCCALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUPRC pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
370 /** @copydoc PDMINETWORKUP::pfnEndXmit */
371 DECLRCCALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUPRC pInterface));
372 /** @copydoc PDMINETWORKUP::pfnSetPromiscuousMode */
373 DECLRCCALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUPRC pInterface, bool fPromiscuous));
374} PDMINETWORKUPRC;
375
376/** PDMINETWORKUP interface ID. */
377#define PDMINETWORKUP_IID "67e7e7a8-2594-4649-a1e3-7cee680c6083"
378/** PDMINETWORKUP interface method names. */
379#define PDMINETWORKUP_SYM_LIST "BeginXmit;AllocBuf;FreeBuf;SendBuf;EndXmit;SetPromiscuousMode"
380
381
382/** Pointer to a network config port interface */
383typedef struct PDMINETWORKCONFIG *PPDMINETWORKCONFIG;
384/**
385 * Network config port interface (main).
386 * No interface pair.
387 */
388typedef struct PDMINETWORKCONFIG
389{
390 /**
391 * Gets the current Media Access Control (MAC) address.
392 *
393 * @returns VBox status code.
394 * @param pInterface Pointer to the interface structure containing the called function pointer.
395 * @param pMac Where to store the MAC address.
396 * @thread EMT
397 */
398 DECLR3CALLBACKMEMBER(int, pfnGetMac,(PPDMINETWORKCONFIG pInterface, PRTMAC pMac));
399
400 /**
401 * Gets the new link state.
402 *
403 * @returns The current link state.
404 * @param pInterface Pointer to the interface structure containing the called function pointer.
405 * @thread EMT
406 */
407 DECLR3CALLBACKMEMBER(PDMNETWORKLINKSTATE, pfnGetLinkState,(PPDMINETWORKCONFIG pInterface));
408
409 /**
410 * Sets the new link state.
411 *
412 * @returns VBox status code.
413 * @param pInterface Pointer to the interface structure containing the called function pointer.
414 * @param enmState The new link state
415 * @thread EMT
416 */
417 DECLR3CALLBACKMEMBER(int, pfnSetLinkState,(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState));
418
419} PDMINETWORKCONFIG;
420/** PDMINETWORKCONFIG interface ID. */
421#define PDMINETWORKCONFIG_IID "d6d909e8-716d-415d-b109-534e4478ff4e"
422
423
424/** Pointer to a NAT configuration port. */
425typedef struct PDMINETWORKNATCONFIG *PPDMINETWORKNATCONFIG;
426/**
427 * Network config port interface (main).
428 * No interface pair.
429 */
430typedef struct PDMINETWORKNATCONFIG
431{
432 /**
433 * Inform NAT about the adding/removing redirection rule
434 *
435 * @todo D O C U M E N T M E !
436 * @todo s/u16/u/g
437 */
438 DECLR3CALLBACKMEMBER(int, pfnRedirectRuleCommand ,(PPDMINETWORKNATCONFIG pInterface, bool fRemove,
439 bool fUdp, const char *pHostIp, uint16_t u16HostPort,
440 const char *pGuestIp, uint16_t u16GuestPort));
441 /**
442 * Inform NAT about host DNS settings change.
443 *
444 * IHostNameResolutionConfigurationChangeEvent.
445 */
446 DECLR3CALLBACKMEMBER(void, pfnNotifyDnsChanged, (PPDMINETWORKNATCONFIG pInterface));
447
448} PDMINETWORKNATCONFIG;
449/** PDMINETWORKNATCONFIG interface ID. */
450#define PDMINETWORKNATCONFIG_IID "dc961028-3523-4b52-a93b-e38168a4a9fa"
451/** @} */
452
453RT_C_DECLS_END
454
455#endif /* !VBOX_INCLUDED_vmm_pdmnetifs_h */
456
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