VirtualBox

source: vbox/trunk/include/VBox/intnet.h@ 97046

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

Devices/DrvIntNet,NetworkServices,Installer/darwin: First rough attempt at making the internal networking option work on macOS after all KEXTs got removed, bugref:10297

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.5 KB
Line 
1/** @file
2 * INTNET - Internal Networking. (DEV,++)
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_intnet_h
37#define VBOX_INCLUDED_intnet_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43#include <VBox/vmm/stam.h>
44#include <VBox/sup.h>
45#include <iprt/assert.h>
46#include <iprt/asm.h>
47
48RT_C_DECLS_BEGIN
49
50
51/** The userspace internal network service identifier. */
52#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_INTNET_SERVICE_IN_R3)
53# define INTNET_R3_SVC_NAME "org.virtualbox.intnet"
54#endif
55
56
57/**
58 * Generic two-sided ring buffer.
59 *
60 * The deal is that there is exactly one writer and one reader.
61 * When offRead equals offWrite the buffer is empty. In the other
62 * extreme the writer will not use the last free byte in the buffer.
63 */
64typedef struct INTNETRINGBUF
65{
66 /** The offset from this structure to the start of the buffer. */
67 uint32_t offStart;
68 /** The offset from this structure to the end of the buffer. (exclusive). */
69 uint32_t offEnd;
70 /** The current read offset. */
71 uint32_t volatile offReadX;
72 /** Alignment. */
73 uint32_t u32Align0;
74
75 /** The committed write offset. */
76 uint32_t volatile offWriteCom;
77 /** Writer internal current write offset.
78 * This is ahead of offWriteCom when buffer space is handed to a third party for
79 * data gathering. offWriteCom will be assigned this value by the writer then
80 * the frame is ready. */
81 uint32_t volatile offWriteInt;
82 /** The number of bytes written (not counting overflows). */
83 STAMCOUNTER cbStatWritten;
84 /** The number of frames written (not counting overflows). */
85 STAMCOUNTER cStatFrames;
86 /** The number of overflows. */
87 STAMCOUNTER cOverflows;
88} INTNETRINGBUF;
89AssertCompileSize(INTNETRINGBUF, 48);
90/** Pointer to a ring buffer. */
91typedef INTNETRINGBUF *PINTNETRINGBUF;
92
93/** The alignment of a ring buffer. */
94#define INTNETRINGBUF_ALIGNMENT sizeof(INTNETHDR)
95
96/**
97 * Asserts the sanity of the specified INTNETRINGBUF structure.
98 */
99#ifdef VBOX_STRICT
100# define INTNETRINGBUF_ASSERT_SANITY(pRingBuf) \
101 do \
102 { \
103 AssertPtr(pRingBuf); \
104 { \
105 uint32_t const offWriteCom = (pRingBuf)->offWriteCom; \
106 uint32_t const offRead = (pRingBuf)->offReadX; \
107 uint32_t const offWriteInt = (pRingBuf)->offWriteInt; \
108 \
109 AssertMsg(offWriteCom == RT_ALIGN_32(offWriteCom, INTNETHDR_ALIGNMENT), ("%#x\n", offWriteCom)); \
110 AssertMsg(offWriteCom >= (pRingBuf)->offStart, ("%#x %#x\n", offWriteCom, (pRingBuf)->offStart)); \
111 AssertMsg(offWriteCom < (pRingBuf)->offEnd, ("%#x %#x\n", offWriteCom, (pRingBuf)->offEnd)); \
112 \
113 AssertMsg(offRead == RT_ALIGN_32(offRead, INTNETHDR_ALIGNMENT), ("%#x\n", offRead)); \
114 AssertMsg(offRead >= (pRingBuf)->offStart, ("%#x %#x\n", offRead, (pRingBuf)->offStart)); \
115 AssertMsg(offRead < (pRingBuf)->offEnd, ("%#x %#x\n", offRead, (pRingBuf)->offEnd)); \
116 \
117 AssertMsg(offWriteInt == RT_ALIGN_32(offWriteInt, INTNETHDR_ALIGNMENT), ("%#x\n", offWriteInt)); \
118 AssertMsg(offWriteInt >= (pRingBuf)->offStart, ("%#x %#x\n", offWriteInt, (pRingBuf)->offStart)); \
119 AssertMsg(offWriteInt < (pRingBuf)->offEnd, ("%#x %#x\n", offWriteInt, (pRingBuf)->offEnd)); \
120 AssertMsg( offRead <= offWriteCom \
121 ? offWriteCom <= offWriteInt || offWriteInt < offRead \
122 : offWriteCom <= offWriteInt, \
123 ("W=%#x W'=%#x R=%#x\n", offWriteCom, offWriteInt, offRead)); \
124 } \
125 } while (0)
126#else
127# define INTNETRINGBUF_ASSERT_SANITY(pRingBuf) do { } while (0)
128#endif
129
130
131
132/**
133 * A interface buffer.
134 */
135typedef struct INTNETBUF
136{
137 /** Magic number (INTNETBUF_MAGIC). */
138 uint32_t u32Magic;
139 /** The size of the entire buffer. */
140 uint32_t cbBuf;
141 /** The size of the send area. */
142 uint32_t cbSend;
143 /** The size of the receive area. */
144 uint32_t cbRecv;
145 /** The receive buffer. */
146 INTNETRINGBUF Recv;
147 /** The send buffer. */
148 INTNETRINGBUF Send;
149 /** Number of times yields help solve an overflow. */
150 STAMCOUNTER cStatYieldsOk;
151 /** Number of times yields didn't help solve an overflow. */
152 STAMCOUNTER cStatYieldsNok;
153 /** Number of lost packets due to overflows. */
154 STAMCOUNTER cStatLost;
155 /** Number of bad frames (both rings). */
156 STAMCOUNTER cStatBadFrames;
157 /** Reserved for future use. */
158 STAMCOUNTER aStatReserved[2];
159 /** Reserved for future send profiling. */
160 STAMPROFILE StatSend1;
161 /** Reserved for future send profiling. */
162 STAMPROFILE StatSend2;
163 /** Reserved for future receive profiling. */
164 STAMPROFILE StatRecv1;
165 /** Reserved for future receive profiling. */
166 STAMPROFILE StatRecv2;
167 /** Reserved for future profiling. */
168 STAMPROFILE StatReserved;
169} INTNETBUF;
170AssertCompileSize(INTNETBUF, 320);
171AssertCompileMemberOffset(INTNETBUF, Recv, 16);
172AssertCompileMemberOffset(INTNETBUF, Send, 64);
173
174/** Pointer to an interface buffer. */
175typedef INTNETBUF *PINTNETBUF;
176/** Pointer to a const interface buffer. */
177typedef INTNETBUF const *PCINTNETBUF;
178
179/** Magic number for INTNETBUF::u32Magic (Sir William Gerald Golding). */
180#define INTNETBUF_MAGIC UINT32_C(0x19110919)
181
182/**
183 * Asserts the sanity of the specified INTNETBUF structure.
184 */
185#define INTNETBUF_ASSERT_SANITY(pBuf) \
186 do \
187 { \
188 AssertPtr(pBuf); \
189 Assert((pBuf)->u32Magic == INTNETBUF_MAGIC); \
190 { \
191 uint32_t const offRecvStart = (pBuf)->Recv.offStart + RT_UOFFSETOF(INTNETBUF, Recv); \
192 uint32_t const offRecvEnd = (pBuf)->Recv.offStart + RT_UOFFSETOF(INTNETBUF, Recv); \
193 uint32_t const offSendStart = (pBuf)->Send.offStart + RT_UOFFSETOF(INTNETBUF, Send); \
194 uint32_t const offSendEnd = (pBuf)->Send.offStart + RT_UOFFSETOF(INTNETBUF, Send); \
195 \
196 Assert(offRecvEnd > offRecvStart); \
197 Assert(offRecvEnd - offRecvStart == (pBuf)->cbRecv); \
198 Assert(offRecvStart == sizeof(INTNETBUF)); \
199 \
200 Assert(offSendEnd > offSendStart); \
201 Assert(offSendEnd - offSendStart == (pBuf)->cbSend); \
202 Assert(pffSendEnd <= (pBuf)->cbBuf); \
203 \
204 Assert(offSendStart == offRecvEnd); \
205 } \
206 } while (0)
207
208
209/** Internal networking interface handle. */
210typedef uint32_t INTNETIFHANDLE;
211/** Pointer to an internal networking interface handle. */
212typedef INTNETIFHANDLE *PINTNETIFHANDLE;
213
214/** Or mask to obscure the handle index. */
215#define INTNET_HANDLE_MAGIC 0x88880000
216/** Mask to extract the handle index. */
217#define INTNET_HANDLE_INDEX_MASK 0xffff
218/** The maximum number of handles (exclusive) */
219#define INTNET_HANDLE_MAX 0xffff
220/** Invalid handle. */
221#define INTNET_HANDLE_INVALID (0)
222
223
224/**
225 * The frame header.
226 *
227 * The header is intentionally 8 bytes long. It will always
228 * start at an 8 byte aligned address. Assuming that the buffer
229 * size is a multiple of 8 bytes, that means that we can guarantee
230 * that the entire header is contiguous in both virtual and physical
231 * memory.
232 */
233typedef struct INTNETHDR
234{
235 /** The size of the frame. */
236 uint32_t cbFrame : 24;
237 /** Header type. This is currently serving as a magic, it
238 * can be extended later to encode special command frames and stuff. */
239 uint32_t u8Type : 8;
240 /** The offset from the start of this header to where the actual frame starts.
241 * This is used to keep the frame it self contiguous in virtual memory and
242 * thereby both simplify access as well as the descriptor. */
243 int32_t offFrame;
244} INTNETHDR;
245AssertCompileSize(INTNETHDR, 8);
246AssertCompileSizeAlignment(INTNETBUF, sizeof(INTNETHDR));
247/** Pointer to a frame header.*/
248typedef INTNETHDR *PINTNETHDR;
249/** Pointer to a const frame header.*/
250typedef INTNETHDR const *PCINTNETHDR;
251
252/** The alignment of a frame header. */
253#define INTNETHDR_ALIGNMENT sizeof(INTNETHDR)
254AssertCompile(sizeof(INTNETHDR) == INTNETHDR_ALIGNMENT);
255AssertCompile(INTNETHDR_ALIGNMENT <= INTNETRINGBUF_ALIGNMENT);
256
257/** @name Frame types (INTNETHDR::u8Type).
258 * @{ */
259/** Normal frames. */
260#define INTNETHDR_TYPE_FRAME 0x42
261/** Padding frames. */
262#define INTNETHDR_TYPE_PADDING 0x53
263/** Generic segment offload frames.
264 * The frame starts with a PDMNETWORKGSO structure which is followed by the
265 * header template and data. */
266#define INTNETHDR_TYPE_GSO 0x64
267AssertCompileSize(PDMNETWORKGSO, 8);
268/** @} */
269
270/**
271 * Asserts the sanity of the specified INTNETHDR.
272 */
273#ifdef VBOX_STRICT
274#define INTNETHDR_ASSERT_SANITY(pHdr, pRingBuf) \
275 do \
276 { \
277 AssertPtr(pHdr); \
278 Assert(RT_ALIGN_PT(pHdr, INTNETHDR_ALIGNMENT, INTNETHDR *) == pHdr); \
279 Assert( (pHdr)->u8Type == INTNETHDR_TYPE_FRAME \
280 || (pHdr)->u8Type == INTNETHDR_TYPE_GSO \
281 || (pHdr)->u8Type == INTNETHDR_TYPE_PADDING); \
282 { \
283 uintptr_t const offHdr = (uintptr_t)pHdr - (uintptr_t)pRingBuf; \
284 uintptr_t const offFrame = offHdr + (pHdr)->offFrame; \
285 \
286 Assert(offHdr >= (pRingBuf)->offStart); \
287 Assert(offHdr < (pRingBuf)->offEnd); \
288 \
289 /* could do more thorough work here... later, perhaps. */ \
290 Assert(offFrame >= (pRingBuf)->offStart); \
291 Assert(offFrame < (pRingBuf)->offEnd); \
292 } \
293 } while (0)
294#else
295# define INTNETHDR_ASSERT_SANITY(pHdr, pRingBuf) do { } while (0)
296#endif
297
298
299/**
300 * Scatter / Gather segment (internal networking).
301 */
302typedef struct INTNETSEG
303{
304 /** The physical address. NIL_RTHCPHYS is not set. */
305 RTHCPHYS Phys;
306 /** Pointer to the segment data. */
307 void *pv;
308 /** The segment size. */
309 uint32_t cb;
310} INTNETSEG;
311/** Pointer to a internal networking frame segment. */
312typedef INTNETSEG *PINTNETSEG;
313/** Pointer to a internal networking frame segment. */
314typedef INTNETSEG const *PCINTNETSEG;
315
316
317/**
318 * Scatter / Gather list (internal networking).
319 *
320 * This is used when communicating with the trunk port.
321 */
322typedef struct INTNETSG
323{
324 /** Owner data, don't touch! */
325 void *pvOwnerData;
326 /** User data. */
327 void *pvUserData;
328 /** User data 2 in case anyone needs it. */
329 void *pvUserData2;
330 /** GSO context information, set the type to invalid if not relevant. */
331 PDMNETWORKGSO GsoCtx;
332 /** The total length of the scatter gather list. */
333 uint32_t cbTotal;
334 /** The number of users (references).
335 * This is used by the SGRelease code to decide when it can be freed. */
336 uint16_t volatile cUsers;
337 /** Flags, see INTNETSG_FLAGS_* */
338 uint16_t volatile fFlags;
339#if ARCH_BITS == 64
340 /** Alignment padding. */
341 uint16_t uPadding;
342#endif
343 /** The number of segments allocated. */
344 uint16_t cSegsAlloc;
345 /** The number of segments actually used. */
346 uint16_t cSegsUsed;
347 /** Variable sized list of segments. */
348 INTNETSEG aSegs[1];
349} INTNETSG;
350AssertCompileSizeAlignment(INTNETSG, 8);
351/** Pointer to a scatter / gather list. */
352typedef INTNETSG *PINTNETSG;
353/** Pointer to a const scatter / gather list. */
354typedef INTNETSG const *PCINTNETSG;
355
356/** @name INTNETSG::fFlags definitions.
357 * @{ */
358/** Set if the SG is free. */
359#define INTNETSG_FLAGS_FREE RT_BIT_32(1)
360/** Set if the SG is a temporary one that will become invalid upon return.
361 * Try to finish using it before returning, and if that's not possible copy
362 * to other buffers.
363 * When not set, the callee should always free the SG.
364 * Attempts to free it made by the callee will be quietly ignored. */
365#define INTNETSG_FLAGS_TEMP RT_BIT_32(2)
366/** ARP packet, IPv4 + MAC.
367 * @internal */
368#define INTNETSG_FLAGS_ARP_IPV4 RT_BIT_32(3)
369/** Copied to the temporary buffer.
370 * @internal */
371#define INTNETSG_FLAGS_PKT_CP_IN_TMP RT_BIT_32(4)
372/** @} */
373
374
375/** @name Direction (frame source or destination)
376 * @{ */
377/** To/From the wire. */
378#define INTNETTRUNKDIR_WIRE RT_BIT_32(0)
379/** To/From the host. */
380#define INTNETTRUNKDIR_HOST RT_BIT_32(1)
381/** Mask of valid bits. */
382#define INTNETTRUNKDIR_VALID_MASK UINT32_C(3)
383/** @} */
384
385/**
386 * Switch decisions returned by INTNETTRUNKSWPORT::pfnPreRecv.
387 */
388typedef enum INTNETSWDECISION
389{
390 /** The usual invalid zero value. */
391 INTNETSWDECISION_INVALID = 0,
392 /** Everywhere. */
393 INTNETSWDECISION_BROADCAST,
394 /** Only to the internal network. */
395 INTNETSWDECISION_INTNET,
396 /** Only for the trunk (host/wire). */
397 INTNETSWDECISION_TRUNK,
398 /** Used internally to indicate that the packet cannot be handled in the
399 * current context. */
400 INTNETSWDECISION_BAD_CONTEXT,
401 /** Used internally to indicate that the packet should be dropped. */
402 INTNETSWDECISION_DROP,
403 /** The usual 32-bit type expansion. */
404 INTNETSWDECISION_32BIT_HACK = 0x7fffffff
405} INTNETSWDECISION;
406
407
408/**
409 * Network layer address type.
410 */
411typedef enum INTNETADDRTYPE
412{
413 /** The invalid 0 entry. */
414 kIntNetAddrType_Invalid = 0,
415 /** IP version 4. */
416 kIntNetAddrType_IPv4,
417 /** IP version 6. */
418 kIntNetAddrType_IPv6,
419 /** IPX. */
420 kIntNetAddrType_IPX,
421 /** The end of the valid values. */
422 kIntNetAddrType_End,
423 /** The usual 32-bit hack. */
424 kIntNetAddrType_32BitHack = 0x7fffffff
425} INTNETADDRTYPE;
426
427
428/** Pointer to the interface side of a trunk port. */
429typedef struct INTNETTRUNKIFPORT *PINTNETTRUNKIFPORT;
430
431
432/**
433 * Special variation of INTNETTRUNKIFPORT::pfnRelease for use with
434 * INTNETTRUNKSWPORT::pfnDisconnect.
435 *
436 * @param pIfPort Pointer to the INTNETTRUNKIFPORT instance.
437 */
438typedef DECLCALLBACKTYPE(void, FNINTNETTRUNKIFPORTRELEASEBUSY,(PINTNETTRUNKIFPORT pIfPort));
439/** Pointer to a FNINTNETTRUNKIFPORTRELEASEBUSY function. */
440typedef FNINTNETTRUNKIFPORTRELEASEBUSY *PFNINTNETTRUNKIFPORTRELEASEBUSY;
441
442
443/** Pointer to the switch side of a trunk port. */
444typedef struct INTNETTRUNKSWPORT *PINTNETTRUNKSWPORT;
445/**
446 * This is the port on the internal network 'switch', i.e.
447 * what the driver is connected to.
448 *
449 * This is only used for the in-kernel trunk connections.
450 */
451typedef struct INTNETTRUNKSWPORT
452{
453 /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */
454 uint32_t u32Version;
455
456 /**
457 * Examine the packet and figure out where it is going.
458 *
459 * This method is for making packet switching decisions in contexts where
460 * pfnRecv cannot be called or is no longer applicable. This method can be
461 * called from any context.
462 *
463 * @returns INTNETSWDECISION_BROADCAST, INTNETSWDECISION_INTNET or
464 * INTNETSWDECISION_TRUNK. The source is excluded from broadcast &
465 * trunk, of course.
466 *
467 * @param pSwitchPort Pointer to this structure.
468 * @param pvHdrs Pointer to the packet headers.
469 * @param cbHdrs Size of the packet headers. This must be at least 6
470 * bytes (the destination MAC address), but should if
471 * possible also include any VLAN tag and network
472 * layer header (wireless mac address sharing).
473 * @param fSrc Where this frame comes from. Only one bit should be
474 * set!
475 *
476 * @remarks Will only grab the switch table spinlock (interrupt safe). May
477 * signal an event semaphore iff we're racing network cleanup. The
478 * caller must be busy when calling.
479 */
480 DECLR0CALLBACKMEMBER(INTNETSWDECISION, pfnPreRecv,(PINTNETTRUNKSWPORT pSwitchPort,
481 void const *pvHdrs, size_t cbHdrs, uint32_t fSrc));
482
483 /**
484 * Incoming frame.
485 *
486 * The frame may be modified when the trunk port on the switch is set to share
487 * the mac address of the host when hitting the wire. Currently frames
488 * containing ARP packets are subject to this, later other protocols like
489 * NDP/ICMPv6 may need editing as well when operating in this mode. The edited
490 * packet should be forwarded to the host/wire when @c false is returned.
491 *
492 * @returns true if we've handled it and it should be dropped.
493 * false if it should hit the wire/host.
494 *
495 * @param pSwitchPort Pointer to this structure.
496 * @param pvIf Pointer to the interface which received this frame
497 * if available. Can be NULL.
498 * @param pSG The (scatter /) gather structure for the frame. This
499 * will only be use during the call, so a temporary one can
500 * be used. The Phys member will not be used.
501 * @param fSrc Where this frame comes from. Exactly one bit shall be
502 * set!
503 *
504 * @remarks Will only grab the switch table spinlock (interrupt safe). Will
505 * signal event semaphores. The caller must be busy when calling.
506 *
507 * @remarks NAT and TAP will use this interface.
508 *
509 * @todo Do any of the host require notification before frame modifications?
510 * If so, we'll add a callback to INTNETTRUNKIFPORT for this
511 * (pfnSGModifying) and a SG flag.
512 */
513 DECLR0CALLBACKMEMBER(bool, pfnRecv,(PINTNETTRUNKSWPORT pSwitchPort, void *pvIf, PINTNETSG pSG, uint32_t fSrc));
514
515 /**
516 * Retain a SG.
517 *
518 * @param pSwitchPort Pointer to this structure.
519 * @param pSG Pointer to the (scatter /) gather structure.
520 *
521 * @remarks Will not grab any locks. The caller must be busy when calling.
522 */
523 DECLR0CALLBACKMEMBER(void, pfnSGRetain,(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG));
524
525 /**
526 * Release a SG.
527 *
528 * This is called by the pfnXmit code when done with a SG. This may safe
529 * be done in an asynchronous manner.
530 *
531 * @param pSwitchPort Pointer to this structure.
532 * @param pSG Pointer to the (scatter /) gather structure.
533 *
534 * @remarks May signal an event semaphore later on, currently code won't though.
535 * The caller is busy when making this call.
536 */
537 DECLR0CALLBACKMEMBER(void, pfnSGRelease,(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG));
538
539 /**
540 * Selects whether outgoing SGs should have their physical address set.
541 *
542 * By enabling physical addresses in the scatter / gather segments it should
543 * be possible to save some unnecessary address translation and memory locking
544 * in the network stack. (Internal networking knows the physical address for
545 * all the INTNETBUF data and that it's locked memory.) There is a negative
546 * side effects though, frames that crosses page boundaries will require
547 * multiple scather / gather segments.
548 *
549 * @returns The old setting.
550 *
551 * @param pSwitchPort Pointer to this structure.
552 * @param fEnable Whether to enable or disable it.
553 *
554 * @remarks Will not grab any locks. The caller must be busy when calling.
555 */
556 DECLR0CALLBACKMEMBER(bool, pfnSetSGPhys,(PINTNETTRUNKSWPORT pSwitchPort, bool fEnable));
557
558 /**
559 * Reports the MAC address of the trunk.
560 *
561 * This is supposed to be called when creating, connection or reconnecting the
562 * trunk and when the MAC address is changed by the system admin.
563 *
564 * @param pSwitchPort Pointer to this structure.
565 * @param pMacAddr The MAC address.
566 *
567 * @remarks May take a spinlock or two. The caller must be busy when calling.
568 */
569 DECLR0CALLBACKMEMBER(void, pfnReportMacAddress,(PINTNETTRUNKSWPORT pSwitchPort, PCRTMAC pMacAddr));
570
571 /**
572 * Reports the promicuousness of the interface.
573 *
574 * This is supposed to be called when creating, connection or reconnecting the
575 * trunk and when the mode is changed by the system admin.
576 *
577 * @param pSwitchPort Pointer to this structure.
578 * @param fPromiscuous True if the host operates the interface in
579 * promiscuous mode, false if not.
580 *
581 * @remarks May take a spinlock or two. The caller must be busy when calling.
582 */
583 DECLR0CALLBACKMEMBER(void, pfnReportPromiscuousMode,(PINTNETTRUNKSWPORT pSwitchPort, bool fPromiscuous));
584
585 /**
586 * Reports the GSO capabilities of the host, wire or both.
587 *
588 * This is supposed to be used only when creating, connecting or reconnecting
589 * the trunk. It is assumed that the GSO capabilities are kind of static the
590 * rest of the time.
591 *
592 * @param pSwitchPort Pointer to this structure.
593 * @param fGsoCapabilities The GSO capability bit mask. The bits
594 * corresponds to the GSO type with the same value.
595 * @param fDst The destination mask (INTNETTRUNKDIR_XXX).
596 *
597 * @remarks Does not take any locks. The caller must be busy when calling.
598 */
599 DECLR0CALLBACKMEMBER(void, pfnReportGsoCapabilities,(PINTNETTRUNKSWPORT pSwitchPort, uint32_t fGsoCapabilities, uint32_t fDst));
600
601 /**
602 * Reports the no-preemption-xmit capabilities of the host and wire.
603 *
604 * This is supposed to be used only when creating, connecting or reconnecting
605 * the trunk. It is assumed that the GSO capabilities are kind of static the
606 * rest of the time.
607 *
608 * @param pSwitchPort Pointer to this structure.
609 * @param fNoPreemptDsts The destinations (INTNETTRUNKDIR_XXX) which it
610 * is safe to transmit to with preemption disabled.
611 * @param fDst The destination mask (INTNETTRUNKDIR_XXX).
612 *
613 * @remarks Does not take any locks. The caller must be busy when calling.
614 */
615 DECLR0CALLBACKMEMBER(void, pfnReportNoPreemptDsts,(PINTNETTRUNKSWPORT pSwitchPort, uint32_t fNoPreemptDsts));
616
617 /**
618 * Notifications about changes to host IP addresses.
619 *
620 * This is used by networks bridged to wifi that share mac with
621 * the host. Host reports changes to its IP addresses so that L3
622 * switching can ingore guests spoofing host's own IP addresses
623 *
624 * This callback may be null to indicate we are not interested.
625 *
626 * @param pSwitchPort Pointer to this structure.
627 * @param fAdded Whether address is added of removed.
628 * @param enmType Address type.
629 * @param pvAddr Pointer to the address.
630 */
631 DECLR0CALLBACKMEMBER(void, pfnNotifyHostAddress,(PINTNETTRUNKSWPORT pSwitchPort, bool fAdded,
632 INTNETADDRTYPE enmType, const void *pvAddr));
633
634 /**
635 * OS triggered trunk disconnect.
636 *
637 * The caller shall must be busy when calling this method to prevent racing the
638 * network destruction code. This method will always consume this busy reference
639 * (released via @a pfnReleaseBusy using @a pIfPort).
640 *
641 * The caller shall guarantee that there are absolutely no chance of concurrent
642 * calls to this method on the same instance.
643 *
644 * @param pSwitchPort Pointer to this structure.
645 * @param pIfPort The interface port structure corresponding to @a
646 * pSwitchPort and which should be used when
647 * calling @a pfnReleaseBusy. This is required as
648 * the method may no longer have access to a valid
649 * @a pIfPort pointer.
650 * @param pfnReleaseBusy Callback for releasing the callers busy
651 * reference to it's side of things.
652 */
653 DECLR0CALLBACKMEMBER(void, pfnDisconnect,(PINTNETTRUNKSWPORT pSwitchPort, PINTNETTRUNKIFPORT pIfPort,
654 PFNINTNETTRUNKIFPORTRELEASEBUSY pfnReleaseBusy));
655
656 /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */
657 uint32_t u32VersionEnd;
658} INTNETTRUNKSWPORT;
659
660/**
661 * Version number for the INTNETTRUNKIFPORT::u32Version and
662 * INTNETTRUNKIFPORT::u32VersionEnd fields.
663 *
664 * NB: Version @c 0xA2CDf005 is consumed by 4.x branches for the
665 * backport of pfnNotifyHostAddress. On the next version bump use
666 * @c 0xA2CDf006 and remove this reminder.
667 */
668# define INTNETTRUNKSWPORT_VERSION UINT32_C(0xA2CDf004)
669
670
671/**
672 * The trunk interface state used set by INTNETTRUNKIFPORT::pfnSetState.
673 */
674typedef enum INTNETTRUNKIFSTATE
675{
676 /** The invalid zero entry. */
677 INTNETTRUNKIFSTATE_INVALID = 0,
678 /** The trunk is inactive. No calls to INTNETTRUNKSWPORT::pfnRecv or
679 * INTNETTRUNKSWPORT::pfnPreRecv. Calling other methods is OK. */
680 INTNETTRUNKIFSTATE_INACTIVE,
681 /** The trunk is active, no restrictions on methods or anything. */
682 INTNETTRUNKIFSTATE_ACTIVE,
683 /** The trunk is about to be disconnected from the internal network. No
684 * calls to any INTNETRUNKSWPORT methods. */
685 INTNETTRUNKIFSTATE_DISCONNECTING,
686 /** The end of the valid states. */
687 INTNETTRUNKIFSTATE_END,
688 /** The usual 32-bit type blow up hack. */
689 INTNETTRUNKIFSTATE_32BIT_HACK = 0x7fffffff
690} INTNETTRUNKIFSTATE;
691
692
693/**
694 * This is the port on the trunk interface, i.e. the driver side which the
695 * internal network is connected to.
696 *
697 * This is only used for the in-kernel trunk connections.
698 */
699typedef struct INTNETTRUNKIFPORT
700{
701 /** Structure version number. (INTNETTRUNKIFPORT_VERSION) */
702 uint32_t u32Version;
703
704 /**
705 * Retain the object.
706 *
707 * It will normally be called while owning the internal network semaphore.
708 *
709 * @param pIfPort Pointer to this structure.
710 *
711 * @remarks May own the big mutex, no spinlocks.
712 */
713 DECLR0CALLBACKMEMBER(void, pfnRetain,(PINTNETTRUNKIFPORT pIfPort));
714
715 /**
716 * Releases the object.
717 *
718 * This must be called for every pfnRetain call.
719 *
720 * @param pIfPort Pointer to this structure.
721 *
722 * @remarks May own the big mutex, no spinlocks.
723 */
724 DECLR0CALLBACKMEMBER(void, pfnRelease,(PINTNETTRUNKIFPORT pIfPort));
725
726 /**
727 * Disconnect from the switch and release the object.
728 *
729 * The is the counter action of the
730 * INTNETTRUNKNETFLTFACTORY::pfnCreateAndConnect method.
731 *
732 * @param pIfPort Pointer to this structure.
733 *
734 * @remarks Owns the big mutex.
735 */
736 DECLR0CALLBACKMEMBER(void, pfnDisconnectAndRelease,(PINTNETTRUNKIFPORT pIfPort));
737
738 /**
739 * Changes the state of the trunk interface.
740 *
741 * The interface is created in the inactive state (INTNETTRUNKIFSTATE_INACTIVE).
742 * When the first connect VM or service is activated, the internal network
743 * activates the trunk (INTNETTRUNKIFSTATE_ACTIVE). The state may then be set
744 * back and forth between INACTIVE and ACTIVE as VMs are paused, added and
745 * removed.
746 *
747 * Eventually though, the network is destroyed as a result of there being no
748 * more VMs left in it and the state is changed to disconnecting
749 * (INTNETTRUNKIFSTATE_DISCONNECTING) and pfnWaitForIdle is called to make sure
750 * there are no active calls in either direction when pfnDisconnectAndRelease is
751 * called.
752 *
753 * A typical operation to performed by this method is to enable/disable promiscuous
754 * mode on the host network interface when entering/leaving the active state.
755 *
756 * @returns The previous state.
757 *
758 * @param pIfPort Pointer to this structure.
759 * @param enmState The new state.
760 *
761 * @remarks Owns the big mutex. No racing pfnSetState, pfnWaitForIdle,
762 * pfnDisconnectAndRelease or INTNETTRUNKFACTORY::pfnCreateAndConnect
763 * calls.
764 */
765 DECLR0CALLBACKMEMBER(INTNETTRUNKIFSTATE, pfnSetState,(PINTNETTRUNKIFPORT pIfPort, INTNETTRUNKIFSTATE enmState));
766
767 /**
768 * Notifies when the MAC address of an interface is set or changes.
769 *
770 * @param pIfPort Pointer to this structure.
771 * @param pvIfData Pointer to the trunk's interface data (see
772 * pfnConnectInterface).
773 * @param pMac Pointer to the MAC address of the connecting VM NIC.
774 *
775 * @remarks Only busy references to the trunk and the interface.
776 */
777 DECLR0CALLBACKMEMBER(void, pfnNotifyMacAddress,(PINTNETTRUNKIFPORT pIfPort, void *pvIfData, PCRTMAC pMac));
778
779 /**
780 * Called when an interface is connected to the network.
781 *
782 * @returns IPRT status code.
783 * @param pIfPort Pointer to this structure.
784 * @param pvIf Opaque pointer to the interface being connected.
785 * For use INTNETTRUNKSWPORT::pfnRecv.
786 * @param ppvIfData Pointer to a pointer variable that the trunk
787 * implementation can use to associate data with the
788 * interface. This pointer will be passed to the
789 * pfnXmit, pfnNotifyMacAddress and
790 * pfnDisconnectInterface methods.
791 *
792 * @remarks Owns the big mutex. No racing pfnDisconnectAndRelease.
793 */
794 DECLR0CALLBACKMEMBER(int, pfnConnectInterface,(PINTNETTRUNKIFPORT pIfPort, void *pvIf, void **ppvIfData));
795
796 /**
797 * Called when an interface is disconnected from the network.
798 *
799 * @param pIfPort Pointer to this structure.
800 * @param pvIfData Pointer to the trunk's interface data (see
801 * pfnConnectInterface).
802 *
803 * @remarks Owns the big mutex. No racing pfnDisconnectAndRelease.
804 */
805 DECLR0CALLBACKMEMBER(void, pfnDisconnectInterface,(PINTNETTRUNKIFPORT pIfPort, void *pvIfData));
806
807 /**
808 * Waits for the interface to become idle.
809 *
810 * This method must be called before disconnecting and releasing the object in
811 * order to prevent racing incoming/outgoing frames and device
812 * enabling/disabling.
813 *
814 * @returns IPRT status code (see RTSemEventWait).
815 * @param pIfPort Pointer to this structure.
816 * @param cMillies The number of milliseconds to wait. 0 means
817 * no waiting at all. Use RT_INDEFINITE_WAIT for
818 * an indefinite wait.
819 *
820 * @remarks Owns the big mutex. No racing pfnDisconnectAndRelease.
821 */
822 DECLR0CALLBACKMEMBER(int, pfnWaitForIdle,(PINTNETTRUNKIFPORT pIfPort, uint32_t cMillies));
823
824 /**
825 * Transmit a frame.
826 *
827 * @return VBox status code. Error generally means we'll drop the frame.
828 * @param pIfPort Pointer to this structure.
829 * @param pvIfData Pointer to the trunk's interface data (see
830 * pfnConnectInterface).
831 * @param pSG Pointer to the (scatter /) gather structure for the frame.
832 * This may or may not be a temporary buffer. If it's temporary
833 * the transmit operation(s) then it's required to make a copy
834 * of the frame unless it can be transmitted synchronously.
835 * @param fDst The destination mask. At least one bit will be set.
836 *
837 * @remarks No locks. May be called concurrently on several threads.
838 */
839 DECLR0CALLBACKMEMBER(int, pfnXmit,(PINTNETTRUNKIFPORT pIfPort, void *pvIfData, PINTNETSG pSG, uint32_t fDst));
840
841 /** Structure version number. (INTNETTRUNKIFPORT_VERSION) */
842 uint32_t u32VersionEnd;
843} INTNETTRUNKIFPORT;
844
845/** Version number for the INTNETTRUNKIFPORT::u32Version and INTNETTRUNKIFPORT::u32VersionEnd fields. */
846#define INTNETTRUNKIFPORT_VERSION UINT32_C(0xA2CDe001)
847
848
849/**
850 * The component factory interface for create a network
851 * interface filter (like VBoxNetFlt).
852 */
853typedef struct INTNETTRUNKFACTORY
854{
855 /**
856 * Release this factory.
857 *
858 * SUPR0ComponentQueryFactory (SUPDRVFACTORY::pfnQueryFactoryInterface to be precise)
859 * will retain a reference to the factory and the caller has to call this method to
860 * release it once the pfnCreateAndConnect call(s) has been done.
861 *
862 * @param pIfFactory Pointer to this structure.
863 */
864 DECLR0CALLBACKMEMBER(void, pfnRelease,(struct INTNETTRUNKFACTORY *pIfFactory));
865
866 /**
867 * Create an instance for the specfied host interface and connects it
868 * to the internal network trunk port.
869 *
870 * The initial interface active state is false (suspended).
871 *
872 *
873 * @returns VBox status code.
874 * @retval VINF_SUCCESS and *ppIfPort set on success.
875 * @retval VERR_INTNET_FLT_IF_NOT_FOUND if the interface was not found.
876 * @retval VERR_INTNET_FLT_IF_BUSY if the interface is already connected.
877 * @retval VERR_INTNET_FLT_IF_FAILED if it failed for some other reason.
878 *
879 * @param pIfFactory Pointer to this structure.
880 * @param pszName The interface name (OS specific).
881 * @param pSwitchPort Pointer to the port interface on the switch that
882 * this interface is being connected to.
883 * @param fFlags Creation flags, see below.
884 * @param ppIfPort Where to store the pointer to the interface port
885 * on success.
886 *
887 * @remarks Called while owning the network and the out-bound trunk semaphores.
888 */
889 DECLR0CALLBACKMEMBER(int, pfnCreateAndConnect,(struct INTNETTRUNKFACTORY *pIfFactory, const char *pszName,
890 PINTNETTRUNKSWPORT pSwitchPort, uint32_t fFlags,
891 PINTNETTRUNKIFPORT *ppIfPort));
892} INTNETTRUNKFACTORY;
893/** Pointer to the trunk factory. */
894typedef INTNETTRUNKFACTORY *PINTNETTRUNKFACTORY;
895
896/** The UUID for the (current) trunk factory. (case sensitive) */
897#define INTNETTRUNKFACTORY_UUID_STR "de504d93-1d1e-4781-8b73-6ea39a0e36a2"
898
899/** @name INTNETTRUNKFACTORY::pfnCreateAndConnect flags.
900 * @{ */
901/** Don't put the filtered interface in promiscuous mode.
902 * This is used for wireless interface since these can misbehave if
903 * we try to put them in promiscuous mode. (Wireless interfaces are
904 * normally bridged on level 3 instead of level 2.) */
905#define INTNETTRUNKFACTORY_FLAG_NO_PROMISC RT_BIT_32(0)
906/** @} */
907
908
909/**
910 * The trunk connection type.
911 *
912 * Used by IntNetR0Open and associated interfaces.
913 */
914typedef enum INTNETTRUNKTYPE
915{
916 /** Invalid trunk type. */
917 kIntNetTrunkType_Invalid = 0,
918 /** No trunk connection. */
919 kIntNetTrunkType_None,
920 /** We don't care which kind of trunk connection if the network exists,
921 * if it doesn't exist create it without a connection. */
922 kIntNetTrunkType_WhateverNone,
923 /** VirtualBox host network interface filter driver.
924 * The trunk name is the name of the host network interface. */
925 kIntNetTrunkType_NetFlt,
926 /** VirtualBox adapter host driver. */
927 kIntNetTrunkType_NetAdp,
928 /** Nat service (ring-0). */
929 kIntNetTrunkType_SrvNat,
930 /** The end of valid types. */
931 kIntNetTrunkType_End,
932 /** The usual 32-bit hack. */
933 kIntNetTrunkType_32bitHack = 0x7fffffff
934} INTNETTRUNKTYPE;
935
936/** @name IntNetR0Open flags.
937 *
938 * The desired policy options must be specified explicitly, if omitted it is
939 * understood that whatever is current or default is fine with the caller.
940 *
941 * @todo Move the policies out of the flags, use three new parameters.
942 *
943 * @{ */
944/** Share the MAC address with the host when sending something to the wire via the trunk.
945 * This is typically used when the trunk is a NetFlt for a wireless interface. */
946#define INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE RT_BIT_32(0)
947/** Require that the current security and promiscuous policies of the network
948 * is exactly as the ones specified in this open network request.
949 *
950 * Use this with INTNET_OPEN_FLAGS_REQUIRE_AS_RESTRICTIVE_POLICIES to prevent
951 * restrictions from being lifted. If no further policy changes are desired,
952 * apply the relevant _FIXED flags. */
953#define INTNET_OPEN_FLAGS_REQUIRE_EXACT RT_BIT_32(1)
954/** Require that the security and promiscuous policies of the network is at
955 * least as restrictive as specified this request specifies and prevent them
956 * being lifted later on. */
957#define INTNET_OPEN_FLAGS_REQUIRE_AS_RESTRICTIVE_POLICIES RT_BIT_32(2)
958
959/** Network access policy: Fixed if set, changable if clear. */
960#define INTNET_OPEN_FLAGS_ACCESS_FIXED RT_BIT_32(3)
961/** Network access policy: Public network. */
962#define INTNET_OPEN_FLAGS_ACCESS_PUBLIC RT_BIT_32(4)
963/** Network access policy: Restricted network. */
964#define INTNET_OPEN_FLAGS_ACCESS_RESTRICTED RT_BIT_32(5)
965
966/** Promiscuous mode policy: Is it fixed or changable by new participants? */
967#define INTNET_OPEN_FLAGS_PROMISC_FIXED RT_BIT_32(6)
968/** Promiscuous mode policy: Allow the clients to request it. */
969#define INTNET_OPEN_FLAGS_PROMISC_ALLOW_CLIENTS RT_BIT_32(7)
970/** Promiscuous mode policy: Deny the clients from requesting it. */
971#define INTNET_OPEN_FLAGS_PROMISC_DENY_CLIENTS RT_BIT_32(8)
972/** Promiscuous mode policy: Allow the trunk-host to request it. */
973#define INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_HOST RT_BIT_32(9)
974/** Promiscuous mode policy: Deny the trunk-host from requesting it. */
975#define INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_HOST RT_BIT_32(10)
976/** Promiscuous mode policy: Allow the trunk-wire to request it. */
977#define INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_WIRE RT_BIT_32(11)
978/** Promiscuous mode policy: Deny the trunk-wire from requesting it. */
979#define INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_WIRE RT_BIT_32(12)
980
981/** Interface policies: Is it fixed or changable (by admin).
982 * @note Per interface, not network wide. */
983#define INTNET_OPEN_FLAGS_IF_FIXED RT_BIT_32(13)
984/** Interface promiscuous mode policy: Allow the interface to request it. */
985#define INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW RT_BIT_32(14)
986/** Interface promiscuous mode policy: Deny the interface from requesting it. */
987#define INTNET_OPEN_FLAGS_IF_PROMISC_DENY RT_BIT_32(15)
988/** Interface promiscuous mode policy: See unrelated trunk traffic. */
989#define INTNET_OPEN_FLAGS_IF_PROMISC_SEE_TRUNK RT_BIT_32(16)
990/** Interface promiscuous mode policy: No unrelated trunk traffic visible. */
991#define INTNET_OPEN_FLAGS_IF_PROMISC_NO_TRUNK RT_BIT_32(17)
992
993/** Trunk policy: Fixed if set, changable if clear.
994 * @remarks The DISABLED options are considered more restrictive by
995 * INTNET_OPEN_FLAGS_REQUIRE_AS_RESTRICTIVE_POLICIES. */
996#define INTNET_OPEN_FLAGS_TRUNK_FIXED RT_BIT_32(18)
997/** Trunk policy: The host end should be enabled. */
998#define INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED RT_BIT_32(19)
999/** Trunk policy: The host end should be disabled. */
1000#define INTNET_OPEN_FLAGS_TRUNK_HOST_DISABLED RT_BIT_32(20)
1001/** Trunk policy: The host should only see packets destined for it. */
1002#define INTNET_OPEN_FLAGS_TRUNK_HOST_CHASTE_MODE RT_BIT_32(21)
1003/** Trunk policy: The host should see all packets. */
1004#define INTNET_OPEN_FLAGS_TRUNK_HOST_PROMISC_MODE RT_BIT_32(22)
1005/** Trunk policy: The wire end should be enabled. */
1006#define INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED RT_BIT_32(23)
1007/** Trunk policy: The wire end should be disabled. */
1008#define INTNET_OPEN_FLAGS_TRUNK_WIRE_DISABLED RT_BIT_32(24)
1009/** Trunk policy: The wire should only see packets destined for it. */
1010#define INTNET_OPEN_FLAGS_TRUNK_WIRE_CHASTE_MODE RT_BIT_32(25)
1011/** Trunk policy: The wire should see all packets. */
1012#define INTNET_OPEN_FLAGS_TRUNK_WIRE_PROMISC_MODE RT_BIT_32(26)
1013
1014/** Used to enable host specific workarounds.
1015 *
1016 * On darwin this will clear ip_tos in DHCP packets when
1017 * INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE is also set. */
1018#define INTNET_OPEN_FLAGS_WORKAROUND_1 RT_BIT_32(31)
1019
1020
1021/** The mask of valid flags. */
1022#define INTNET_OPEN_FLAGS_MASK UINT32_C(0x83ffffff)
1023/** The mask of all flags use to fix (lock) settings. */
1024#define INTNET_OPEN_FLAGS_FIXED_MASK \
1025 ( INTNET_OPEN_FLAGS_ACCESS_FIXED \
1026 | INTNET_OPEN_FLAGS_PROMISC_FIXED \
1027 | INTNET_OPEN_FLAGS_IF_FIXED \
1028 | INTNET_OPEN_FLAGS_TRUNK_FIXED )
1029
1030/** The mask of all policy pairs. */
1031#define INTNET_OPEN_FLAGS_PAIR_MASK \
1032 ( INTNET_OPEN_FLAGS_ACCESS_PUBLIC | INTNET_OPEN_FLAGS_ACCESS_RESTRICTED \
1033 | INTNET_OPEN_FLAGS_PROMISC_ALLOW_CLIENTS | INTNET_OPEN_FLAGS_PROMISC_DENY_CLIENTS \
1034 | INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_HOST | INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_HOST \
1035 | INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_WIRE | INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_WIRE \
1036 | INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW | INTNET_OPEN_FLAGS_IF_PROMISC_DENY \
1037 | INTNET_OPEN_FLAGS_IF_PROMISC_SEE_TRUNK | INTNET_OPEN_FLAGS_IF_PROMISC_NO_TRUNK \
1038 | INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED | INTNET_OPEN_FLAGS_TRUNK_HOST_DISABLED \
1039 | INTNET_OPEN_FLAGS_TRUNK_HOST_PROMISC_MODE | INTNET_OPEN_FLAGS_TRUNK_HOST_CHASTE_MODE \
1040 | INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED | INTNET_OPEN_FLAGS_TRUNK_WIRE_DISABLED \
1041 | INTNET_OPEN_FLAGS_TRUNK_WIRE_PROMISC_MODE | INTNET_OPEN_FLAGS_TRUNK_WIRE_CHASTE_MODE \
1042 )
1043/** The mask of all relaxed policy bits. */
1044#define INTNET_OPEN_FLAGS_RELAXED_MASK \
1045 ( INTNET_OPEN_FLAGS_ACCESS_PUBLIC \
1046 | INTNET_OPEN_FLAGS_PROMISC_ALLOW_CLIENTS \
1047 | INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_HOST \
1048 | INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_WIRE \
1049 | INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW \
1050 | INTNET_OPEN_FLAGS_IF_PROMISC_SEE_TRUNK \
1051 | INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED \
1052 | INTNET_OPEN_FLAGS_TRUNK_WIRE_PROMISC_MODE \
1053 | INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED \
1054 | INTNET_OPEN_FLAGS_TRUNK_WIRE_PROMISC_MODE \
1055 )
1056/** The mask of all strict policy bits. */
1057#define INTNET_OPEN_FLAGS_STRICT_MASK \
1058 ( INTNET_OPEN_FLAGS_ACCESS_RESTRICTED \
1059 | INTNET_OPEN_FLAGS_PROMISC_DENY_CLIENTS \
1060 | INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_HOST \
1061 | INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_WIRE \
1062 | INTNET_OPEN_FLAGS_IF_PROMISC_DENY \
1063 | INTNET_OPEN_FLAGS_IF_PROMISC_NO_TRUNK \
1064 | INTNET_OPEN_FLAGS_TRUNK_HOST_DISABLED \
1065 | INTNET_OPEN_FLAGS_TRUNK_HOST_CHASTE_MODE \
1066 | INTNET_OPEN_FLAGS_TRUNK_WIRE_DISABLED \
1067 | INTNET_OPEN_FLAGS_TRUNK_WIRE_CHASTE_MODE \
1068 )
1069/** @} */
1070
1071/** The maximum length of a network name. */
1072#define INTNET_MAX_NETWORK_NAME 128
1073
1074/** The maximum length of a trunk name. */
1075#define INTNET_MAX_TRUNK_NAME 64
1076
1077
1078/**
1079 * Request buffer for IntNetR0OpenReq / VMMR0_DO_INTNET_OPEN.
1080 * @see IntNetR0Open.
1081 */
1082typedef struct INTNETOPENREQ
1083{
1084 /** The request header. */
1085 SUPVMMR0REQHDR Hdr;
1086 /** Alternative to passing the taking the session from the VM handle.
1087 * Either use this member or use the VM handle, don't do both. */
1088 PSUPDRVSESSION pSession;
1089 /** The network name. (input) */
1090 char szNetwork[INTNET_MAX_NETWORK_NAME];
1091 /** What to connect to the trunk port. (input)
1092 * This is specific to the trunk type below. */
1093 char szTrunk[INTNET_MAX_TRUNK_NAME];
1094 /** The type of trunk link (NAT, Filter, TAP, etc). (input) */
1095 INTNETTRUNKTYPE enmTrunkType;
1096 /** Flags, see INTNET_OPEN_FLAGS_*. (input) */
1097 uint32_t fFlags;
1098 /** The size of the send buffer. (input) */
1099 uint32_t cbSend;
1100 /** The size of the receive buffer. (input) */
1101 uint32_t cbRecv;
1102 /** The handle to the network interface. (output) */
1103 INTNETIFHANDLE hIf;
1104} INTNETOPENREQ;
1105/** Pointer to an IntNetR0OpenReq / VMMR0_DO_INTNET_OPEN request buffer. */
1106typedef INTNETOPENREQ *PINTNETOPENREQ;
1107
1108INTNETR0DECL(int) IntNetR0OpenReq(PSUPDRVSESSION pSession, PINTNETOPENREQ pReq);
1109
1110
1111/**
1112 * Request buffer for IntNetR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE.
1113 * @see IntNetR0IfClose.
1114 */
1115typedef struct INTNETIFCLOSEREQ
1116{
1117 /** The request header. */
1118 SUPVMMR0REQHDR Hdr;
1119 /** Alternative to passing the taking the session from the VM handle.
1120 * Either use this member or use the VM handle, don't do both. */
1121 PSUPDRVSESSION pSession;
1122 /** The handle to the network interface. */
1123 INTNETIFHANDLE hIf;
1124} INTNETIFCLOSEREQ;
1125/** Pointer to an IntNetR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE request
1126 * buffer. */
1127typedef INTNETIFCLOSEREQ *PINTNETIFCLOSEREQ;
1128
1129INTNETR0DECL(int) IntNetR0IfCloseReq(PSUPDRVSESSION pSession, PINTNETIFCLOSEREQ pReq);
1130
1131
1132/**
1133 * Request buffer for IntNetR0IfGetRing3BufferReq /
1134 * VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS.
1135 * @see IntNetR0IfGetRing3Buffer.
1136 */
1137typedef struct INTNETIFGETBUFFERPTRSREQ
1138{
1139 /** The request header. */
1140 SUPVMMR0REQHDR Hdr;
1141 /** Alternative to passing the taking the session from the VM handle.
1142 * Either use this member or use the VM handle, don't do both. */
1143 PSUPDRVSESSION pSession;
1144 /** Handle to the interface. */
1145 INTNETIFHANDLE hIf;
1146 /** The pointer to the ring-3 buffer. (output) */
1147 R3PTRTYPE(PINTNETBUF) pRing3Buf;
1148 /** The pointer to the ring-0 buffer. (output) */
1149 R0PTRTYPE(PINTNETBUF) pRing0Buf;
1150} INTNETIFGETBUFFERPTRSREQ;
1151/** Pointer to an IntNetR0IfGetRing3BufferReq /
1152 * VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS request buffer. */
1153typedef INTNETIFGETBUFFERPTRSREQ *PINTNETIFGETBUFFERPTRSREQ;
1154
1155INTNETR0DECL(int) IntNetR0IfGetBufferPtrsReq(PSUPDRVSESSION pSession, PINTNETIFGETBUFFERPTRSREQ pReq);
1156
1157
1158/**
1159 * Request buffer for IntNetR0IfSetPromiscuousModeReq /
1160 * VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE.
1161 * @see IntNetR0IfSetPromiscuousMode.
1162 */
1163typedef struct INTNETIFSETPROMISCUOUSMODEREQ
1164{
1165 /** The request header. */
1166 SUPVMMR0REQHDR Hdr;
1167 /** Alternative to passing the taking the session from the VM handle.
1168 * Either use this member or use the VM handle, don't do both. */
1169 PSUPDRVSESSION pSession;
1170 /** Handle to the interface. */
1171 INTNETIFHANDLE hIf;
1172 /** The new promiscuous mode. */
1173 bool fPromiscuous;
1174} INTNETIFSETPROMISCUOUSMODEREQ;
1175/** Pointer to an IntNetR0IfSetPromiscuousModeReq /
1176 * VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE request buffer. */
1177typedef INTNETIFSETPROMISCUOUSMODEREQ *PINTNETIFSETPROMISCUOUSMODEREQ;
1178
1179INTNETR0DECL(int) IntNetR0IfSetPromiscuousModeReq(PSUPDRVSESSION pSession, PINTNETIFSETPROMISCUOUSMODEREQ pReq);
1180
1181
1182/**
1183 * Request buffer for IntNetR0IfSetMacAddressReq /
1184 * VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS.
1185 * @see IntNetR0IfSetMacAddress.
1186 */
1187typedef struct INTNETIFSETMACADDRESSREQ
1188{
1189 /** The request header. */
1190 SUPVMMR0REQHDR Hdr;
1191 /** Alternative to passing the taking the session from the VM handle.
1192 * Either use this member or use the VM handle, don't do both. */
1193 PSUPDRVSESSION pSession;
1194 /** Handle to the interface. */
1195 INTNETIFHANDLE hIf;
1196 /** The new MAC address. */
1197 RTMAC Mac;
1198} INTNETIFSETMACADDRESSREQ;
1199/** Pointer to an IntNetR0IfSetMacAddressReq /
1200 * VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS request buffer. */
1201typedef INTNETIFSETMACADDRESSREQ *PINTNETIFSETMACADDRESSREQ;
1202
1203INTNETR0DECL(int) IntNetR0IfSetMacAddressReq(PSUPDRVSESSION pSession, PINTNETIFSETMACADDRESSREQ pReq);
1204
1205
1206/**
1207 * Request buffer for IntNetR0IfSetActiveReq / VMMR0_DO_INTNET_IF_SET_ACTIVE.
1208 * @see IntNetR0IfSetActive.
1209 */
1210typedef struct INTNETIFSETACTIVEREQ
1211{
1212 /** The request header. */
1213 SUPVMMR0REQHDR Hdr;
1214 /** Alternative to passing the taking the session from the VM handle.
1215 * Either use this member or use the VM handle, don't do both. */
1216 PSUPDRVSESSION pSession;
1217 /** Handle to the interface. */
1218 INTNETIFHANDLE hIf;
1219 /** The new state. */
1220 bool fActive;
1221} INTNETIFSETACTIVEREQ;
1222/** Pointer to an IntNetR0IfSetActiveReq / VMMR0_DO_INTNET_IF_SET_ACTIVE
1223 * request buffer. */
1224typedef INTNETIFSETACTIVEREQ *PINTNETIFSETACTIVEREQ;
1225
1226INTNETR0DECL(int) IntNetR0IfSetActiveReq(PSUPDRVSESSION pSession, PINTNETIFSETACTIVEREQ pReq);
1227
1228
1229/**
1230 * Request buffer for IntNetR0IfSendReq / VMMR0_DO_INTNET_IF_SEND.
1231 * @see IntNetR0IfSend.
1232 */
1233typedef struct INTNETIFSENDREQ
1234{
1235 /** The request header. */
1236 SUPVMMR0REQHDR Hdr;
1237 /** Alternative to passing the taking the session from the VM handle.
1238 * Either use this member or use the VM handle, don't do both. */
1239 PSUPDRVSESSION pSession;
1240 /** Handle to the interface. */
1241 INTNETIFHANDLE hIf;
1242} INTNETIFSENDREQ;
1243/** Pointer to an IntNetR0IfSend() argument package. */
1244typedef INTNETIFSENDREQ *PINTNETIFSENDREQ;
1245
1246INTNETR0DECL(int) IntNetR0IfSendReq(PSUPDRVSESSION pSession, PINTNETIFSENDREQ pReq);
1247
1248
1249/**
1250 * Request buffer for IntNetR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT.
1251 * @see IntNetR0IfWait.
1252 */
1253typedef struct INTNETIFWAITREQ
1254{
1255 /** The request header. */
1256 SUPVMMR0REQHDR Hdr;
1257 /** Alternative to passing the taking the session from the VM handle.
1258 * Either use this member or use the VM handle, don't do both. */
1259 PSUPDRVSESSION pSession;
1260 /** Handle to the interface. */
1261 INTNETIFHANDLE hIf;
1262 /** The number of milliseconds to wait. */
1263 uint32_t cMillies;
1264} INTNETIFWAITREQ;
1265/** Pointer to an IntNetR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT request buffer. */
1266typedef INTNETIFWAITREQ *PINTNETIFWAITREQ;
1267
1268INTNETR0DECL(int) IntNetR0IfWaitReq(PSUPDRVSESSION pSession, PINTNETIFWAITREQ pReq);
1269
1270
1271/**
1272 * Request buffer for IntNetR0IfAbortWaitReq / VMMR0_DO_INTNET_IF_ABORT_WAIT.
1273 * @see IntNetR0IfAbortWait.
1274 */
1275typedef struct INTNETIFABORTWAITREQ
1276{
1277 /** The request header. */
1278 SUPVMMR0REQHDR Hdr;
1279 /** Alternative to passing the taking the session from the VM handle.
1280 * Either use this member or use the VM handle, don't do both. */
1281 PSUPDRVSESSION pSession;
1282 /** Handle to the interface. */
1283 INTNETIFHANDLE hIf;
1284 /** Set this to fend off all future IntNetR0Wait calls. */
1285 bool fNoMoreWaits;
1286} INTNETIFABORTWAITREQ;
1287/** Pointer to an IntNetR0IfAbortWaitReq / VMMR0_DO_INTNET_IF_ABORT_WAIT
1288 * request buffer. */
1289typedef INTNETIFABORTWAITREQ *PINTNETIFABORTWAITREQ;
1290
1291INTNETR0DECL(int) IntNetR0IfAbortWaitReq(PSUPDRVSESSION pSession, PINTNETIFABORTWAITREQ pReq);
1292
1293
1294#if defined(IN_RING0) || defined(IN_INTNET_TESTCASE)
1295/** @name
1296 * @{
1297 */
1298
1299INTNETR0DECL(int) IntNetR0Init(void);
1300INTNETR0DECL(void) IntNetR0Term(void);
1301INTNETR0DECL(int) IntNetR0Open(PSUPDRVSESSION pSession, const char *pszNetwork,
1302 INTNETTRUNKTYPE enmTrunkType, const char *pszTrunk, uint32_t fFlags,
1303 uint32_t cbSend, uint32_t cbRecv, PINTNETIFHANDLE phIf);
1304INTNETR0DECL(uint32_t) IntNetR0GetNetworkCount(void);
1305
1306INTNETR0DECL(int) IntNetR0IfClose(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession);
1307INTNETR0DECL(int) IntNetR0IfGetBufferPtrs(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession,
1308 R3PTRTYPE(PINTNETBUF) *ppRing3Buf, R0PTRTYPE(PINTNETBUF) *ppRing0Buf);
1309INTNETR0DECL(int) IntNetR0IfSetPromiscuousMode(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fPromiscuous);
1310INTNETR0DECL(int) IntNetR0IfSetMacAddress(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PCRTMAC pMac);
1311INTNETR0DECL(int) IntNetR0IfSetActive(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fActive);
1312INTNETR0DECL(int) IntNetR0IfSend(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession);
1313INTNETR0DECL(int) IntNetR0IfWait(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, uint32_t cMillies);
1314INTNETR0DECL(int) IntNetR0IfAbortWait(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession);
1315
1316/** @} */
1317#endif /* IN_RING0 */
1318
1319RT_C_DECLS_END
1320
1321#endif /* !VBOX_INCLUDED_intnet_h */
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