VirtualBox

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

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

VBox/types.h,pdmnetifs.h: Replaced PDMDATASEG with RTSGSEG since the two structures are identical. This should make it easy to create a RTSGBUF for a PDMSCATTERGATHER buffer (just limit the operations to cbUsed bytes). [scm fix]

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

© 2023 Oracle
ContactPrivacy policyTerms of Use