VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NetLib/IntNetIf.h@ 87824

Last change on this file since 87824 was 87824, checked in by vboxsync, 4 years ago

NAT/Net: IntNetIf - a convenience class to talk to an internal network.

This code was lifted out of VBoxNetBaseService to use in the new DHCPD
wihtout dragging in all the baggage that comes with that old confused
base class. Now its time for this code to move out and live its own
life b/c it will (soon) be used for the NAT network (in a forthcoming
commit). This new class is intended to be used as a "has-a" not an
"is-a", so its users can talk to multiple intnets (thought that's not
been tested yet). bugref:9929.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: IntNetIf.h 87824 2021-02-21 22:18:43Z 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 */
37class IntNetIf
38{
39public:
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
78private:
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
89public:
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 ifPump();
102 int ifAbort();
103
104 int getOutputFrame(Frame &rFrame, size_t cbFrame);
105 int ifOutput(Frame &rFrame);
106
107 int ifClose();
108
109private:
110 int r3Init();
111 void r3Fini();
112
113 int vmmInit();
114
115 int ifOpen(const RTCString &strNetwork,
116 INTNETTRUNKTYPE enmTrunkType,
117 const RTCString &strTrunk);
118 int ifGetBuf();
119 int ifActivate();
120
121 int ifWait(uint32_t cMillies = RT_INDEFINITE_WAIT);
122 int ifProcessInput();
123
124 int ifFlush();
125};
126
127#endif /* !VBOX_INCLUDED_SRC_NetLib_IntNetIf_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