1 | /* $Id: IntNetIf.h 87900 2021-03-01 16:56:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IntNetIf - Convenience class implementing an IntNet connection.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_NetLib_IntNetIf_h
|
---|
19 | #define VBOX_INCLUDED_SRC_NetLib_IntNetIf_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <iprt/cdefs.h>
|
---|
25 |
|
---|
26 | #include <iprt/initterm.h>
|
---|
27 | #include <iprt/cpp/ministring.h>
|
---|
28 |
|
---|
29 | #include <VBox/sup.h>
|
---|
30 | #include <VBox/vmm/vmm.h>
|
---|
31 | #include <VBox/intnet.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Convenience class implementing an IntNet connection.
|
---|
36 | */
|
---|
37 | class IntNetIf
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | /**
|
---|
41 | * User input callback function.
|
---|
42 | *
|
---|
43 | * @param pvUser The user specified argument.
|
---|
44 | * @param pvFrame The pointer to the frame data.
|
---|
45 | * @param cbFrame The length of the frame data.
|
---|
46 | */
|
---|
47 | typedef DECLCALLBACKTYPE(void, FNINPUT,(void *pvUser, void *pvFrame, uint32_t cbFrame));
|
---|
48 |
|
---|
49 | /** Pointer to the user input callback function. */
|
---|
50 | typedef FNINPUT *PFNINPUT;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * User GSO input callback function.
|
---|
54 | *
|
---|
55 | * @param pvUser The user specified argument.
|
---|
56 | * @param pcGso The pointer to the GSO context.
|
---|
57 | * @param cbFrame The length of the GSO data.
|
---|
58 | */
|
---|
59 | typedef DECLCALLBACKTYPE(void, FNINPUTGSO,(void *pvUser, PCPDMNETWORKGSO pcGso, uint32_t cbFrame));
|
---|
60 |
|
---|
61 | /** Pointer to the user GSO input callback function. */
|
---|
62 | typedef FNINPUTGSO *PFNINPUTGSO;
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * An output frame in the send ring buffer.
|
---|
67 | *
|
---|
68 | * Obtained with getOutputFrame(). Caller should copy frame
|
---|
69 | * contents to pvFrame and pass the frame structure to ifOutput()
|
---|
70 | * to be sent to the network.
|
---|
71 | */
|
---|
72 | struct Frame {
|
---|
73 | PINTNETHDR pHdr;
|
---|
74 | void *pvFrame;
|
---|
75 | };
|
---|
76 |
|
---|
77 |
|
---|
78 | private:
|
---|
79 | PSUPDRVSESSION m_pSession;
|
---|
80 | INTNETIFHANDLE m_hIf;
|
---|
81 | PINTNETBUF m_pIfBuf;
|
---|
82 |
|
---|
83 | PFNINPUT m_pfnInput;
|
---|
84 | void *m_pvUser;
|
---|
85 |
|
---|
86 | PFNINPUTGSO m_pfnInputGSO;
|
---|
87 | void *m_pvUserGSO;
|
---|
88 |
|
---|
89 | public:
|
---|
90 | IntNetIf();
|
---|
91 | ~IntNetIf();
|
---|
92 |
|
---|
93 | int init(const RTCString &strNetwork,
|
---|
94 | INTNETTRUNKTYPE enmTrunkType = kIntNetTrunkType_WhateverNone,
|
---|
95 | const RTCString &strTrunk = RTCString());
|
---|
96 | void uninit();
|
---|
97 |
|
---|
98 | int setInputCallback(PFNINPUT pfnInput, void *pvUser);
|
---|
99 | int setInputGSOCallback(PFNINPUTGSO pfnInputGSO, void *pvUser);
|
---|
100 |
|
---|
101 | int ifSetPromiscuous(bool fPromiscuous = true);
|
---|
102 |
|
---|
103 | int ifPump();
|
---|
104 | int ifAbort();
|
---|
105 |
|
---|
106 | int getOutputFrame(Frame &rFrame, size_t cbFrame);
|
---|
107 | int ifOutput(Frame &rFrame);
|
---|
108 |
|
---|
109 | int ifClose();
|
---|
110 |
|
---|
111 | private:
|
---|
112 | int r3Init();
|
---|
113 | void r3Fini();
|
---|
114 |
|
---|
115 | int vmmInit();
|
---|
116 |
|
---|
117 | int ifOpen(const RTCString &strNetwork,
|
---|
118 | INTNETTRUNKTYPE enmTrunkType,
|
---|
119 | const RTCString &strTrunk);
|
---|
120 | int ifGetBuf();
|
---|
121 | int ifActivate();
|
---|
122 |
|
---|
123 | int ifWait(uint32_t cMillies = RT_INDEFINITE_WAIT);
|
---|
124 | int ifProcessInput();
|
---|
125 |
|
---|
126 | int ifFlush();
|
---|
127 | };
|
---|
128 |
|
---|
129 | #endif /* !VBOX_INCLUDED_SRC_NetLib_IntNetIf_h */
|
---|