VirtualBox

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

Last change on this file since 77921 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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