VirtualBox

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

Last change on this file since 55461 was 54106, checked in by vboxsync, 10 years ago

NAT: Introduce PDMINETWORKNATCONFIG::pfnNotifyDnsChanged and call it
on IHostNameResolutionConfigurationChangeEvent. This is just the
plumbing so far, there's no actual callback yet.

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