1 | /* $Id: IntNetIf.h 97075 2022-10-10 16:37:13Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IntNetIf - Convenience class implementing an IntNet connection.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_NetLib_IntNetIf_h
|
---|
29 | #define VBOX_INCLUDED_SRC_NetLib_IntNetIf_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 |
|
---|
36 | #include <iprt/initterm.h>
|
---|
37 | #include <iprt/cpp/ministring.h>
|
---|
38 |
|
---|
39 | #include <VBox/sup.h>
|
---|
40 | #include <VBox/vmm/vmm.h>
|
---|
41 | #include <VBox/intnet.h>
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Low-level internal network access helpers to hide away the different variants (R0 SUP or R3 XPC on macOS).
|
---|
47 | */
|
---|
48 | /** Internal networking interface context handle. */
|
---|
49 | typedef struct INTNETIFCTXINT *INTNETIFCTX;
|
---|
50 | /** Pointer to an internal networking interface context handle. */
|
---|
51 | typedef INTNETIFCTX *PINTNETIFCTX;
|
---|
52 |
|
---|
53 |
|
---|
54 | DECLHIDDEN(int) IntNetR3IfCtxCreate(PINTNETIFCTX phIfCtx, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
|
---|
55 | const char *pszTrunk, uint32_t cbSend, uint32_t cbRecv, uint32_t fFlags);
|
---|
56 | DECLHIDDEN(int) IntNetR3IfCtxDestroy(INTNETIFCTX hIfCtx);
|
---|
57 | DECLHIDDEN(int) IntNetR3IfCtxQueryBufferPtr(INTNETIFCTX hIfCtx, PINTNETBUF *ppIfBuf);
|
---|
58 | DECLHIDDEN(int) IntNetR3IfCtxSetActive(INTNETIFCTX hIfCtx, bool fActive);
|
---|
59 | DECLHIDDEN(int) IntNetR3IfCtxSetPromiscuous(INTNETIFCTX hIfCtx, bool fPromiscuous);
|
---|
60 | DECLHIDDEN(int) IntNetR3IfSend(INTNETIFCTX hIfCtx);
|
---|
61 | DECLHIDDEN(int) IntNetR3IfWait(INTNETIFCTX hIfCtx, uint32_t cMillies);
|
---|
62 | DECLHIDDEN(int) IntNetR3IfWaitAbort(INTNETIFCTX hIfCtx);
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Convenience class implementing an IntNet connection.
|
---|
67 | */
|
---|
68 | class IntNetIf
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | /**
|
---|
72 | * User input callback function.
|
---|
73 | *
|
---|
74 | * @param pvUser The user specified argument.
|
---|
75 | * @param pvFrame The pointer to the frame data.
|
---|
76 | * @param cbFrame The length of the frame data.
|
---|
77 | */
|
---|
78 | typedef DECLCALLBACKTYPE(void, FNINPUT,(void *pvUser, void *pvFrame, uint32_t cbFrame));
|
---|
79 |
|
---|
80 | /** Pointer to the user input callback function. */
|
---|
81 | typedef FNINPUT *PFNINPUT;
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * User GSO input callback function.
|
---|
85 | *
|
---|
86 | * @param pvUser The user specified argument.
|
---|
87 | * @param pcGso The pointer to the GSO context.
|
---|
88 | * @param cbFrame The length of the GSO data.
|
---|
89 | */
|
---|
90 | typedef DECLCALLBACKTYPE(void, FNINPUTGSO,(void *pvUser, PCPDMNETWORKGSO pcGso, uint32_t cbFrame));
|
---|
91 |
|
---|
92 | /** Pointer to the user GSO input callback function. */
|
---|
93 | typedef FNINPUTGSO *PFNINPUTGSO;
|
---|
94 |
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * An output frame in the send ring buffer.
|
---|
98 | *
|
---|
99 | * Obtained with getOutputFrame(). Caller should copy frame
|
---|
100 | * contents to pvFrame and pass the frame structure to ifOutput()
|
---|
101 | * to be sent to the network.
|
---|
102 | */
|
---|
103 | struct Frame {
|
---|
104 | PINTNETHDR pHdr;
|
---|
105 | void *pvFrame;
|
---|
106 | };
|
---|
107 |
|
---|
108 |
|
---|
109 | private:
|
---|
110 | INTNETIFCTX m_hIf;
|
---|
111 | PINTNETBUF m_pIfBuf;
|
---|
112 |
|
---|
113 | PFNINPUT m_pfnInput;
|
---|
114 | void *m_pvUser;
|
---|
115 |
|
---|
116 | PFNINPUTGSO m_pfnInputGSO;
|
---|
117 | void *m_pvUserGSO;
|
---|
118 |
|
---|
119 | public:
|
---|
120 | IntNetIf();
|
---|
121 | ~IntNetIf();
|
---|
122 |
|
---|
123 | int init(const RTCString &strNetwork,
|
---|
124 | INTNETTRUNKTYPE enmTrunkType = kIntNetTrunkType_WhateverNone,
|
---|
125 | const RTCString &strTrunk = RTCString());
|
---|
126 | void uninit();
|
---|
127 |
|
---|
128 | int setInputCallback(PFNINPUT pfnInput, void *pvUser);
|
---|
129 | int setInputGSOCallback(PFNINPUTGSO pfnInputGSO, void *pvUser);
|
---|
130 |
|
---|
131 | int ifSetPromiscuous(bool fPromiscuous = true);
|
---|
132 |
|
---|
133 | int ifPump();
|
---|
134 | int ifAbort();
|
---|
135 |
|
---|
136 | int getOutputFrame(Frame &rFrame, size_t cbFrame);
|
---|
137 | int ifOutput(Frame &rFrame);
|
---|
138 |
|
---|
139 | int ifClose();
|
---|
140 |
|
---|
141 | private:
|
---|
142 | int ifOpen(const RTCString &strNetwork,
|
---|
143 | INTNETTRUNKTYPE enmTrunkType,
|
---|
144 | const RTCString &strTrunk);
|
---|
145 | int ifGetBuf();
|
---|
146 | int ifActivate();
|
---|
147 |
|
---|
148 | int ifWait(uint32_t cMillies = RT_INDEFINITE_WAIT);
|
---|
149 | int ifProcessInput();
|
---|
150 |
|
---|
151 | int ifFlush();
|
---|
152 | };
|
---|
153 |
|
---|
154 | #endif /* !VBOX_INCLUDED_SRC_NetLib_IntNetIf_h */
|
---|