VirtualBox

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

Last change on this file since 9897 was 9803, checked in by vboxsync, 16 years ago

vacation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.4 KB
Line 
1/** @file
2 * INETNET - Internal Networking.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_intnet_h
31#define ___VBox_intnet_h
32
33#include <VBox/types.h>
34#include <VBox/stam.h>
35#include <VBox/sup.h>
36#include <iprt/assert.h>
37#include <iprt/asm.h>
38
39__BEGIN_DECLS
40
41
42/** Pointer to an internal network ring-0 instance. */
43typedef struct INTNET *PINTNET;
44
45/**
46 * Generic two-sided ring buffer.
47 *
48 * The deal is that there is exactly one writer and one reader.
49 * When offRead equals offWrite the buffer is empty. In the other
50 * extreme the writer will not use the last free byte in the buffer.
51 */
52typedef struct INTNETRINGBUF
53{
54 /** The start of the buffer offset relative to the. (inclusive) */
55 uint32_t offStart;
56 /** The offset to the end of the buffer. (exclusive) */
57 uint32_t offEnd;
58 /** The current read offset. */
59 uint32_t volatile offRead;
60 /** The current write offset. */
61 uint32_t volatile offWrite;
62} INTNETRINGBUF;
63/** Pointer to a ring buffer. */
64typedef INTNETRINGBUF *PINTNETRINGBUF;
65
66/**
67 * Get the amount of space available for writing.
68 *
69 * @returns Number of available bytes.
70 * @param pRingBuf The ring buffer.
71 */
72DECLINLINE(uint32_t) INTNETRingGetWritable(PINTNETRINGBUF pRingBuf)
73{
74 return pRingBuf->offRead <= pRingBuf->offWrite
75 ? pRingBuf->offEnd - pRingBuf->offWrite + pRingBuf->offRead - pRingBuf->offStart - 1
76 : pRingBuf->offRead - pRingBuf->offWrite - 1;
77}
78
79
80/**
81 * Get the amount of data ready for reading.
82 *
83 * @returns Number of ready bytes.
84 * @param pRingBuf The ring buffer.
85 */
86DECLINLINE(uint32_t) INTNETRingGetReadable(PINTNETRINGBUF pRingBuf)
87{
88 return pRingBuf->offRead <= pRingBuf->offWrite
89 ? pRingBuf->offWrite - pRingBuf->offRead
90 : pRingBuf->offEnd - pRingBuf->offRead + pRingBuf->offWrite - pRingBuf->offStart;
91}
92
93
94/**
95 * A interface buffer.
96 */
97typedef struct INTNETBUF
98{
99 /** The size of the entire buffer. */
100 uint32_t cbBuf;
101 /** The size of the send area. */
102 uint32_t cbSend;
103 /** The size of the receive area. */
104 uint32_t cbRecv;
105 /** The receive buffer. */
106 INTNETRINGBUF Recv;
107 /** The send buffer. */
108 INTNETRINGBUF Send;
109 /** Number of times yields help solve an overflow. */
110 STAMCOUNTER cStatYieldsOk;
111 /** Number of times yields didn't help solve an overflow. */
112 STAMCOUNTER cStatYieldsNok;
113 /** Number of lost packets due to overflows. */
114 STAMCOUNTER cStatLost;
115 /** Number of packets received (not counting lost ones). */
116 STAMCOUNTER cStatRecvs;
117 /** Number of frame bytes received (not couting lost frames). */
118 STAMCOUNTER cbStatRecv;
119 /** Number of packets received. */
120 STAMCOUNTER cStatSends;
121 /** Number of frame bytes sent. */
122 STAMCOUNTER cbStatSend;
123} INTNETBUF;
124/** Pointer to an interface buffer. */
125typedef INTNETBUF *PINTNETBUF;
126/** Pointer to a const interface buffer. */
127typedef INTNETBUF const *PCINTNETBUF;
128
129/** Internal networking interface handle. */
130typedef uint32_t INTNETIFHANDLE;
131/** Pointer to an internal networking interface handle. */
132typedef INTNETIFHANDLE *PINTNETIFHANDLE;
133
134/** Or mask to obscure the handle index. */
135#define INTNET_HANDLE_MAGIC 0x88880000
136/** Mask to extract the handle index. */
137#define INTNET_HANDLE_INDEX_MASK 0xffff
138/** The maximum number of handles (exclusive) */
139#define INTNET_HANDLE_MAX 0xffff
140/** Invalid handle. */
141#define INTNET_HANDLE_INVALID (0)
142
143
144/**
145 * The packet header.
146 *
147 * The header is intentionally 8 bytes long. It will always
148 * start at an 8 byte aligned address. Assuming that the buffer
149 * size is a multiple of 8 bytes, that means that we can guarantee
150 * that the entire header is contiguous in both virtual and physical
151 * memory.
152 */
153#pragma pack(1)
154typedef struct INTNETHDR
155{
156 /** Header type. This is currently serving as a magic, it
157 * can be extended later to encode special command packets and stuff. */
158 uint16_t u16Type;
159 /** The size of the frame. */
160 uint16_t cbFrame;
161 /** The offset from the start of this header to where the actual frame starts.
162 * This is used to keep the frame it self continguous in virtual memory and
163 * thereby both simplify reading and */
164 int32_t offFrame;
165} INTNETHDR;
166#pragma pack()
167/** Pointer to a packet header.*/
168typedef INTNETHDR *PINTNETHDR;
169/** Pointer to a const packet header.*/
170typedef INTNETHDR const *PCINTNETHDR;
171
172/** INTNETHDR::u16Type value for normal frames. */
173#define INTNETHDR_TYPE_FRAME 0x2442
174
175
176/**
177 * Calculates the pointer to the frame.
178 *
179 * @returns Pointer to the start of the frame.
180 * @param pHdr Pointer to the packet header
181 * @param pBuf The buffer the header is within. Only used in strict builds.
182 */
183DECLINLINE(void *) INTNETHdrGetFramePtr(PCINTNETHDR pHdr, PCINTNETBUF pBuf)
184{
185 uint8_t *pu8 = (uint8_t *)pHdr + pHdr->offFrame;
186#ifdef VBOX_STRICT
187 const uintptr_t off = (uintptr_t)pu8 - (uintptr_t)pBuf;
188 Assert(pHdr->u16Type == INTNETHDR_TYPE_FRAME);
189 Assert(off < pBuf->cbBuf);
190 Assert(off + pHdr->cbFrame <= pBuf->cbBuf);
191#endif
192 NOREF(pBuf);
193 return pu8;
194}
195
196
197/**
198 * Skips to the next (read) frame in the buffer.
199 *
200 * @param pBuf The buffer.
201 * @param pRingBuf The ring buffer in question.
202 */
203DECLINLINE(void) INTNETRingSkipFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf)
204{
205 uint32_t offRead = pRingBuf->offRead;
206 PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offRead);
207 Assert(pRingBuf->offRead < pBuf->cbBuf);
208 Assert(pRingBuf->offRead >= pRingBuf->offStart);
209 Assert(pRingBuf->offRead < pRingBuf->offEnd);
210
211 /* skip the frame */
212 offRead += pHdr->offFrame + pHdr->cbFrame;
213 offRead = RT_ALIGN_32(offRead, sizeof(INTNETHDR));
214 Assert(offRead <= pRingBuf->offEnd && offRead >= pRingBuf->offStart);
215 if (offRead >= pRingBuf->offEnd)
216 offRead = pRingBuf->offStart;
217 ASMAtomicXchgU32(&pRingBuf->offRead, offRead);
218}
219
220
221/**
222 * Scatter / Gather segment (internal networking).
223 */
224typedef struct INTNETSEG
225{
226 /** The physical address. NIL_RTHCPHYS is not set. */
227 RTHCPHYS Phys;
228 /** Pointer to the segment data. */
229 void *pv;
230 /** The segment size. */
231 uint32_t cb;
232} INTNETSEG;
233/** Pointer to a internal networking packet segment. */
234typedef INTNETSEG *PINTNETSEG;
235/** Pointer to a internal networking packet segment. */
236typedef INTNETSEG const *PCINTNETSEG;
237
238
239/**
240 * Scatter / Gather list (internal networking).
241 *
242 * This is used when communicating with the trunk port.
243 */
244typedef struct INTNETSG
245{
246 /** The total length of the scatter gather list. */
247 uint32_t cbTotal;
248 /** The number of users (references).
249 * This is used by the SGRelease code to decide when it can be freed. */
250 uint16_t volatile cUsers;
251 /** Flags, see INTNETSG_FLAGS_* */
252 uint16_t volatile fFlags;
253 /** The number of segments allocated. */
254 uint16_t cSegsAlloc;
255 /** The number of segments actually used. */
256 uint16_t cSegsUsed;
257 /** Variable sized list of segments. */
258 INTNETSEG aSegs[1];
259} INTNETSG;
260/** Pointer to a scatter / gather list. */
261typedef INTNETSG *PINTNETSG;
262/** Pointer to a const scatter / gather list. */
263typedef INTNETSG const *PCINTNETSG;
264
265/** @name INTNETSG::fFlags definitions.
266 * @{ */
267/** Set if the SG is free. */
268#define INTNETSG_FLAGS_FREE RT_BIT_32(1)
269/** Set if the SG is a temporary one that will become invalid upon return.
270 * Try to finish using it before returning, and if that's not possible copy
271 * to other buffers.
272 * When not set, the callee should always free the SG.
273 * Attempts to free it made by the callee will be quietly ignored. */
274#define INTNETSG_FLAGS_TEMP RT_BIT_32(2)
275/** @} */
276
277
278/**
279 * Initializes a scatter / gather buffer from a internal networking packet.
280 *
281 * @returns Pointer to the start of the frame.
282 * @param pSG Pointer to the scatter / gather structure.
283 * (The fFlags, cUsers, and cSegsAlloc members are left untouched.)
284 * @param pHdr Pointer to the packet header.
285 * @param pBuf The buffer the header is within. Only used in strict builds.
286 * @remarks Perhaps move this...
287 */
288DECLINLINE(void) INTNETSgInitFromPkt(PINTNETSG pSG, PCINTNETHDR pPktHdr, PCINTNETBUF pBuf)
289{
290 pSG->cSegsUsed = 1;
291 pSG->cbTotal = pSG->aSegs[0].cb = pPktHdr->cbFrame;
292 pSG->aSegs[0].pv = INTNETHdrGetFramePtr(pPktHdr, pBuf);
293 pSG->aSegs[0].Phys = NIL_RTHCPHYS;
294}
295
296
297
298/** Pointer to the switch side of a trunk port. */
299typedef struct INTNETTRUNKSWPORT *PINTNETTRUNKSWPORT;
300/**
301 * This is the port on the internal network 'switch', i.e.
302 * what the driver is connected to.
303 *
304 * This is only used for the in-kernel trunk connections.
305 */
306typedef struct INTNETTRUNKSWPORT
307{
308 /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */
309 uint32_t u32Version;
310
311 /**
312 * Selects whether outgoing SGs should have their physical address set.
313 *
314 * By enabling physical addresses in the scatter / gather segments it should
315 * be possible to save some unnecessary address translation and memory locking
316 * in the network stack. (Internal networking knows the physical address for
317 * all the INTNETBUF data and that it's locked memory.) There is a negative
318 * side effects though, frames that crosses page boundraries will require
319 * multiple scather / gather segments.
320 *
321 * @returns The old setting.
322 *
323 * @param pIfPort Pointer to this structure.
324 * @param fEnable Whether to enable or disable it.
325 *
326 * @remarks Will grab the network semaphore.
327 */
328 DECLR0CALLBACKMEMBER(bool, pfnSetSGPhys,(PINTNETTRUNKSWPORT pIfPort, bool fEnable));
329
330 /**
331 * Frame from the host that's about to hit the wire.
332 *
333 * @returns true if we've handled it and it should be dropped.
334 * false if it should hit the wire.
335 *
336 * @param pIfPort Pointer to this structure.
337 * @param pSG The (scatter /) gather structure for the frame.
338 * This will only be use during the call, so a temporary one can
339 * be used. The Phys member will not be used.
340 *
341 * @remarks Will grab the network semaphore.
342 *
343 * @remark NAT and TAP will use this interface.
344 */
345 DECLR0CALLBACKMEMBER(bool, pfnRecvHost,(PINTNETTRUNKSWPORT pIfPort, PINTNETSG pSG));
346
347 /**
348 * Frame from the wire that's about to hit the network stack.
349 *
350 * @returns true if we've handled it and it should be dropped.
351 * false if it should hit the network stack.
352 *
353 * @param pIfPort Pointer to this structure.
354 * @param pSG The (scatter /) gather structure for the frame.
355 * This will only be use during the call, so a temporary one can
356 * be used. The Phys member will not be used.
357 *
358 * @remarks Will grab the network semaphore.
359 *
360 * @remark NAT and TAP will not this interface.
361 */
362 DECLR0CALLBACKMEMBER(bool, pfnRecvWire,(PINTNETTRUNKSWPORT pIfPort, PINTNETSG pSG));
363
364 /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */
365 uint32_t u32VersionEnd;
366} INTNETTRUNKSWPORT;
367
368/** Version number for the INTNETTRUNKIFPORT::u32Version and INTNETTRUNKIFPORT::u32VersionEnd fields. */
369#define INTNETTRUNKSWPORT_VERSION UINT32_C(0xA2CDf001)
370
371
372/** Pointer to the interface side of a trunk port. */
373typedef struct INTNETTRUNKIFPORT *PINTNETTRUNKIFPORT;
374/**
375 * This is the port on the trunk interface, i.e. the driver
376 * side which the internal network is connected to.
377 *
378 * This is only used for the in-kernel trunk connections.
379 */
380typedef struct INTNETTRUNKIFPORT
381{
382 /** Structure version number. (INTNETTRUNKIFPORT_VERSION) */
383 uint32_t u32Version;
384
385 /**
386 * Retain the object.
387 *
388 * It will normally be called while owning the internal network semaphore.
389 *
390 * @param pIfPort Pointer to this structure.
391 */
392 DECLR0CALLBACKMEMBER(void, pfnRetain,(PINTNETTRUNKIFPORT pIfPort));
393
394 /**
395 * Releases the object.
396 *
397 * This must be called for every pfnRetain call. Where possible, it
398 * should be executed without holding any locks unless the caller
399 * is certain it is not going to trigger the destructor.
400 *
401 * @param pIfPort Pointer to this structure.
402 */
403 DECLR0CALLBACKMEMBER(void, pfnRelease,(PINTNETTRUNKIFPORT pIfPort));
404
405 /**
406 * Disconnect from the switch and release the object.
407 *
408 * The is the counter action of the
409 * INTNETTRUNKNETFLTFACTORY::pfnCreateAndConnect method.
410 *
411 * @param pIfPort Pointer to this structure.
412 */
413 DECLR0CALLBACKMEMBER(void, pfnDisconnectAndRelease,(PINTNETTRUNKIFPORT pIfPort));
414
415 /**
416 * Changes the active state of the interface.
417 *
418 * The interface is created in the suspended (non-active) state and then activated
419 * when the VM/network is started. It may be suspended and re-activated later
420 * for various reasons. It will finally be suspended again before disconnecting
421 * the interface from the internal network, however, this might be done immediately
422 * before disconnecting and may leave an incoming frame waiting on the internal network
423 * semaphore.
424 *
425 * @returns The previous state.
426 *
427 * @param pIfPort Pointer to this structure.
428 * @param fActive True if the new state is 'active', false if the new state is 'suspended'.
429 *
430 * @remarks Called while owning the network semaphore.
431 */
432 DECLR0CALLBACKMEMBER(bool, pfnSetActive,(PINTNETTRUNKIFPORT pIfPort, bool fActive));
433
434 /**
435 * Waits for the interface to become idle.
436 *
437 * This method must be called before disconnecting and releasing the
438 * object in order to prevent racing incoming/outgoing packets and
439 * device enabling/disabling.
440 *
441 * @param pIfPort Pointer to this structure.
442 * @param cMillies The number of milliseconds to wait. 0 means
443 * no waiting at all. Use RT_INDEFINITE_WAIT for
444 * an indefinite wait.
445 *
446 * @remarks Will not grab any semaphores.
447 */
448 DECLR0CALLBACKMEMBER(bool, pfnWaitForIdle,(PINTNETTRUNKIFPORT pIfPort, uint32_t cMillies));
449
450 /**
451 * Tests if the mac address belongs to any of the host NICs
452 * and should take the pfnSendToHost route.
453 *
454 * @returns true / false.
455 *
456 * @param pIfPort Pointer to this structure.
457 * @param pMac Pointer to the mac address.
458 *
459 * @remarks Called while owning the network semaphore.
460 *
461 * @remarks TAP and NAT will compare with their own MAC address and let all their
462 * traffic go over the pfnSendToHost method.
463 */
464 DECLR0CALLBACKMEMBER(bool, pfnIsHostMac,(PINTNETTRUNKIFPORT pIfPort, PCPDMMAC pMac));
465
466 /**
467 * Tests whether the host is operating the interface is promiscuous mode.
468 *
469 * The default behavior of internal networking 'switch' is to 'autodetect'
470 * promiscuous mode on the trunk port, which is where this method is used.
471 * For security reasons this default my of course be overridden so that the
472 * host cannot sniff at what's going on.
473 *
474 * Note that this differs from operating the trunk port on the switch in
475 * 'promiscuous' mode, because that relates to the bits going to the wire.
476 *
477 * @returns true / false.
478 *
479 * @param pIfPort Pointer to this structure.
480 *
481 * @remarks Called while owning the network semaphore.
482 */
483 DECLR0CALLBACKMEMBER(bool, pfnIsPromiscuous,(PINTNETTRUNKIFPORT pIfPort));
484
485 /**
486 * Send the frame to the host.
487 *
488 * This path is taken if pfnIsHostMac returns true and the trunk port on the
489 * internal network is configured to let traffic thru to the host. It may also
490 * be taken if the host is in promiscuous mode and the internal network is
491 * configured to respect this for internal targets.
492 *
493 * @return VBox status code. Error generally means we'll drop the packet.
494 * @param pIfPort Pointer to this structure.
495 * @param pSG Pointer to the (scatter /) gather structure for the frame.
496 * This will never be a temporary one, so, it's safe to
497 * do this asynchronously to save unnecessary buffer
498 * allocating and copying.
499 *
500 * @remarks Called while owning the network semaphore?
501 *
502 * @remarks TAP and NAT will use this interface for all their traffic, see pfnIsHostMac.
503 */
504 DECLR0CALLBACKMEMBER(int, pfnSendToHost,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG));
505
506 /**
507 * Put the frame on the wire.
508 *
509 * This path is taken if pfnIsHostMac returns false and the trunk port on the
510 * internal network is configured to let traffic out on the wire. This may also
511 * be taken for both internal and host traffic if the trunk port is configured
512 * to be in promiscuous mode.
513 *
514 * @return VBox status code. Error generally means we'll drop the packet.
515 * @param pIfPort Pointer to this structure.
516 * @param pSG Pointer to the (scatter /) gather structure for the frame.
517 * This will never be a temporary one, so, it's safe to
518 * do this asynchronously to save unnecessary buffer
519 * allocating and copying.
520 *
521 * @remarks Called while owning the network semaphore?
522 *
523 * @remarks TAP and NAT will call pfnSGRelease and return successfully.
524 */
525 DECLR0CALLBACKMEMBER(int, pfnSendToWire,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG));
526
527 /**
528 * This is called by the pfnSendToHost and pfnSendToWire code when they are
529 * done with a SG.
530 *
531 * It may be called after they return if the frame was pushed in an
532 * async manner.
533 *
534 * @param pIfPort Pointer to this structure.
535 * @param pSG Pointer to the (scatter /) gather structure.
536 *
537 * @remarks Will grab the network semaphore.
538 */
539 DECLR0CALLBACKMEMBER(void, pfnSGRelease,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG));
540
541 /** Structure version number. (INTNETTRUNKIFPORT_VERSION) */
542 uint32_t u32VersionEnd;
543} INTNETTRUNKIFPORT;
544
545/** Version number for the INTNETTRUNKIFPORT::u32Version and INTNETTRUNKIFPORT::u32VersionEnd fields. */
546#define INTNETTRUNKIFPORT_VERSION UINT32_C(0xA2CDe001)
547
548
549/**
550 * The component factory interface for create a network
551 * interface filter (like VBoxNetFlt).
552 */
553typedef struct INTNETTRUNKNETFLTFACTORY
554{
555 /**
556 * Create an instance for the specfied host interface.
557 *
558 * The initial interface active state is false (suspended).
559 *
560 *
561 * @returns VBox status code.
562 * @retval VINF_SUCCESS and *ppIfPort set on success.
563 * @retval VERR_INTNET_FLT_IF_NOT_FOUND if the interface was not found.
564 * @retval VERR_INTNET_FLT_IF_BUSY if the interface is already connected.
565 * @retval VERR_INTNET_FLT_IF_FAILED if it failed for some other reason.
566 *
567 * @param pIfFactory Pointer to this structure.
568 * @param pszName The interface name (OS specific).
569 * @param pSwitchPort Pointer to the port interface on the switch that
570 * this interface is being connected to.
571 * @param ppIfPort Where to store the pointer to the interface port
572 * on success.
573 *
574 * @remarks Called while owning the network semaphore.
575 */
576 DECLR0CALLBACKMEMBER(int, pfnCreate,(struct INTNETTRUNKNETFLTFACTORY *pIfFactory, const char *pszName,
577 PINTNETTRUNKSWPORT pSwitchPort, PINTNETTRUNKIFPORT *ppIfPort));
578} INTNETTRUNKNETFLTFACTORY;
579/** Pointer to the trunk factory. */
580typedef INTNETTRUNKNETFLTFACTORY *PINTNETTRUNKNETFLTFACTORY;
581
582/** The UUID for the current network interface filter factory. */
583#define INTNETTRUNKNETFLTFACTORY_UUID_STR "0e32db7d-165d-4fc9-9bce-acb2798ce7fb"
584
585
586
587
588/** The maximum length of a network name. */
589#define INTNET_MAX_NETWORK_NAME 128
590
591
592/**
593 * Request buffer for INTNETR0OpenReq / VMMR0_DO_INTNET_OPEN.
594 * @see INTNETR0Open.
595 */
596typedef struct INTNETOPENREQ
597{
598 /** The request header. */
599 SUPVMMR0REQHDR Hdr;
600 /** The network name. (input) */
601 char szNetwork[INTNET_MAX_NETWORK_NAME];
602 /** The size of the send buffer. (input) */
603 uint32_t cbSend;
604 /** The size of the receive buffer. (input) */
605 uint32_t cbRecv;
606 /** Whether new participants should be subjected to access check or not. */
607 bool fRestrictAccess;
608 /** The handle to the network interface. (output) */
609 INTNETIFHANDLE hIf;
610} INTNETOPENREQ;
611/** Pointer to an INTNETR0OpenReq / VMMR0_DO_INTNET_OPEN request buffer. */
612typedef INTNETOPENREQ *PINTNETOPENREQ;
613
614INTNETR0DECL(int) INTNETR0OpenReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETOPENREQ pReq);
615
616
617/**
618 * Request buffer for INTNETR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE.
619 * @see INTNETR0IfClose.
620 */
621typedef struct INTNETIFCLOSEREQ
622{
623 /** The request header. */
624 SUPVMMR0REQHDR Hdr;
625 /** The handle to the network interface. */
626 INTNETIFHANDLE hIf;
627} INTNETIFCLOSEREQ;
628/** Pointer to an INTNETR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE request buffer. */
629typedef INTNETIFCLOSEREQ *PINTNETIFCLOSEREQ;
630
631INTNETR0DECL(int) INTNETR0IfCloseReq(PINTNET pIntNet, PINTNETIFCLOSEREQ pReq);
632
633
634/**
635 * Request buffer for INTNETR0IfGetRing3BufferReq / VMMR0_DO_INTNET_IF_GET_RING3_BUFFER.
636 * @see INTNETR0IfGetRing3Buffer.
637 */
638typedef struct INTNETIFGETRING3BUFFERREQ
639{
640 /** The request header. */
641 SUPVMMR0REQHDR Hdr;
642 /** Handle to the interface. */
643 INTNETIFHANDLE hIf;
644 /** The pointer to the ring3 buffer. (output) */
645 R3PTRTYPE(PINTNETBUF) pRing3Buf;
646} INTNETIFGETRING3BUFFERREQ;
647/** Pointer to an INTNETR0IfGetRing3BufferReq / VMMR0_DO_INTNET_IF_GET_RING3_BUFFER request buffer. */
648typedef INTNETIFGETRING3BUFFERREQ *PINTNETIFGETRING3BUFFERREQ;
649
650INTNETR0DECL(int) INTNETR0IfGetRing3BufferReq(PINTNET pIntNet, PINTNETIFGETRING3BUFFERREQ pReq);
651
652
653/**
654 * Request buffer for INTNETR0IfSetPromiscuousModeReq / VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE.
655 * @see INTNETR0IfSetPromiscuousMode.
656 */
657typedef struct INTNETIFSETPROMISCUOUSMODEREQ
658{
659 /** The request header. */
660 SUPVMMR0REQHDR Hdr;
661 /** Handle to the interface. */
662 INTNETIFHANDLE hIf;
663 /** The new promiscuous mode. */
664 bool fPromiscuous;
665} INTNETIFSETPROMISCUOUSMODEREQ;
666/** Pointer to an INTNETR0IfSetPromiscuousModeReq / VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE request buffer. */
667typedef INTNETIFSETPROMISCUOUSMODEREQ *PINTNETIFSETPROMISCUOUSMODEREQ;
668
669INTNETR0DECL(int) INTNETR0IfSetPromiscuousModeReq(PINTNET pIntNet, PINTNETIFSETPROMISCUOUSMODEREQ pReq);
670
671
672/**
673 * Request buffer for INTNETR0IfSendReq / VMMR0_DO_INTNET_IF_SEND.
674 * @see INTNETR0IfSend.
675 */
676typedef struct INTNETIFSENDREQ
677{
678 /** The request header. */
679 SUPVMMR0REQHDR Hdr;
680 /** Handle to the interface. */
681 INTNETIFHANDLE hIf;
682} INTNETIFSENDREQ;
683/** Pointer to an INTNETR0IfSend() argument package. */
684typedef INTNETIFSENDREQ *PINTNETIFSENDREQ;
685
686INTNETR0DECL(int) INTNETR0IfSendReq(PINTNET pIntNet, PINTNETIFSENDREQ pReq);
687
688
689/**
690 * Request buffer for INTNETR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT.
691 * @see INTNETR0IfWait.
692 */
693typedef struct INTNETIFWAITREQ
694{
695 /** The request header. */
696 SUPVMMR0REQHDR Hdr;
697 /** Handle to the interface. */
698 INTNETIFHANDLE hIf;
699 /** The number of milliseconds to wait. */
700 uint32_t cMillies;
701} INTNETIFWAITREQ;
702/** Pointer to an INTNETR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT request buffer. */
703typedef INTNETIFWAITREQ *PINTNETIFWAITREQ;
704
705INTNETR0DECL(int) INTNETR0IfWaitReq(PINTNET pIntNet, PINTNETIFWAITREQ pReq);
706
707
708#if defined(IN_RING0) || defined(IN_INTNET_TESTCASE)
709/** @name
710 * @{
711 */
712
713/**
714 * Create an instance of the Ring-0 internal networking service.
715 *
716 * @returns VBox status code.
717 * @param ppIntNet Where to store the instance pointer.
718 */
719INTNETR0DECL(int) INTNETR0Create(PINTNET *ppIntNet);
720
721/**
722 * Destroys an instance of the Ring-0 internal networking service.
723 *
724 * @param pIntNet Pointer to the instance data.
725 */
726INTNETR0DECL(void) INTNETR0Destroy(PINTNET pIntNet);
727
728/**
729 * Opens a network interface and attaches it to the specified network.
730 *
731 * @returns VBox status code.
732 * @param pIntNet The internal network instance.
733 * @param pSession The session handle.
734 * @param pszNetwork The network name.
735 * @param cbSend The send buffer size.
736 * @param cbRecv The receive buffer size.
737 * @param fRestrictAccess Whether new participants should be subjected to access check or not.
738 * @param phIf Where to store the handle to the network interface.
739 */
740INTNETR0DECL(int) INTNETR0Open(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, unsigned cbSend, unsigned cbRecv, bool fRestrictAccess, PINTNETIFHANDLE phIf);
741
742/**
743 * Close an interface.
744 *
745 * @returns VBox status code.
746 * @param pIntNet The instance handle.
747 * @param hIf The interface handle.
748 */
749INTNETR0DECL(int) INTNETR0IfClose(PINTNET pIntNet, INTNETIFHANDLE hIf);
750
751/**
752 * Gets the ring-0 address of the current buffer.
753 *
754 * @returns VBox status code.
755 * @param pIntNet The instance data.
756 * @param hIF The interface handle.
757 * @param ppRing0Buf Where to store the address of the ring-3 mapping.
758 */
759INTNETR0DECL(int) INTNETR0IfGetRing0Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, PINTNETBUF *ppRing0Buf);
760
761/**
762 * Maps the default buffer into ring 3.
763 *
764 * @returns VBox status code.
765 * @param pIntNet The instance data.
766 * @param hIF The interface handle.
767 * @param ppRing3Buf Where to store the address of the ring-3 mapping.
768 */
769INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, R3PTRTYPE(PINTNETBUF) *ppRing3Buf);
770
771/**
772 * Sets the promiscuous mode property of an interface.
773 *
774 * @returns VBox status code.
775 * @param pIntNet The instance handle.
776 * @param hIf The interface handle.
777 * @param fPromiscuous Set if the interface should be in promiscuous mode, clear if not.
778 */
779INTNETR0DECL(int) INTNETR0IfSetPromiscuousMode(PINTNET pIntNet, INTNETIFHANDLE hIf, bool fPromiscuous);
780
781/**
782 * Sends one or more frames.
783 *
784 * The function will first the frame which is passed as the optional
785 * arguments pvFrame and cbFrame. These are optional since it also
786 * possible to chain together one or more frames in the send buffer
787 * which the function will process after considering it's arguments.
788 *
789 * @returns VBox status code.
790 * @param pIntNet The instance data.
791 * @param hIF The interface handle.
792 * @param pvFrame Pointer to the frame.
793 * @param cbFrame Size of the frame.
794 */
795INTNETR0DECL(int) INTNETR0IfSend(PINTNET pIntNet, INTNETIFHANDLE hIf, const void *pvFrame, unsigned cbFrame);
796
797/**
798 * Wait for the interface to get signaled.
799 * The interface will be signaled when is put into the receive buffer.
800 *
801 * @returns VBox status code.
802 * @param pIntNet The instance handle.
803 * @param hIf The interface handle.
804 * @param cMillies Number of milliseconds to wait. RT_INDEFINITE_WAIT should be
805 * used if indefinite wait is desired.
806 */
807INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, uint32_t cMillies);
808
809/** @} */
810#endif /* IN_RING0 */
811
812__END_DECLS
813
814#endif
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