[45138] | 1 | /* $Id: NATNetworkImpl.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[48107] | 3 | * INATNetwork implementation header, lives in VBoxSVC.
|
---|
[45138] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[45138] | 8 | *
|
---|
[96407] | 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
|
---|
[45138] | 26 | */
|
---|
| 27 |
|
---|
[76562] | 28 | #ifndef MAIN_INCLUDED_NATNetworkImpl_h
|
---|
| 29 | #define MAIN_INCLUDED_NATNetworkImpl_h
|
---|
[76487] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
[49742] | 34 | #include "VBoxEvents.h"
|
---|
| 35 | #include "NATNetworkWrap.h"
|
---|
[45138] | 36 |
|
---|
| 37 | #ifdef VBOX_WITH_HOSTNETIF_API
|
---|
| 38 | struct NETIFINFO;
|
---|
| 39 | #endif
|
---|
| 40 |
|
---|
| 41 | namespace settings
|
---|
| 42 | {
|
---|
| 43 | struct NATNetwork;
|
---|
| 44 | struct NATRule;
|
---|
[61009] | 45 | typedef std::map<com::Utf8Str, NATRule> NATRulesMap;
|
---|
[45138] | 46 | }
|
---|
| 47 |
|
---|
[47018] | 48 | #ifdef RT_OS_WINDOWS
|
---|
[47894] | 49 | # define NATSR_EXECUTABLE_NAME "VBoxNetNAT.exe"
|
---|
[47018] | 50 | #else
|
---|
[47894] | 51 | # define NATSR_EXECUTABLE_NAME "VBoxNetNAT"
|
---|
[47018] | 52 | #endif
|
---|
[45138] | 53 |
|
---|
[63934] | 54 | #undef ADDR_ANY ///@todo ADDR_ANY collides with some windows header!
|
---|
| 55 |
|
---|
[48417] | 56 | enum ADDRESSLOOKUPTYPE
|
---|
| 57 | {
|
---|
| 58 | ADDR_GATEWAY,
|
---|
| 59 | ADDR_DHCP,
|
---|
| 60 | ADDR_DHCPLOWERIP,
|
---|
| 61 | ADDR_ANY
|
---|
| 62 | };
|
---|
| 63 |
|
---|
[47018] | 64 | class NATNetworkServiceRunner: public NetworkServiceRunner
|
---|
| 65 | {
|
---|
| 66 | public:
|
---|
| 67 | NATNetworkServiceRunner(): NetworkServiceRunner(NATSR_EXECUTABLE_NAME){}
|
---|
[49494] | 68 | ~NATNetworkServiceRunner(){}
|
---|
[47018] | 69 | };
|
---|
| 70 |
|
---|
[45138] | 71 | class ATL_NO_VTABLE NATNetwork :
|
---|
[49742] | 72 | public NATNetworkWrap
|
---|
[45138] | 73 | {
|
---|
| 74 | public:
|
---|
| 75 |
|
---|
[90828] | 76 | DECLARE_COMMON_CLASS_METHODS(NATNetwork)
|
---|
[45138] | 77 |
|
---|
| 78 | HRESULT FinalConstruct();
|
---|
| 79 | void FinalRelease();
|
---|
| 80 |
|
---|
[60786] | 81 | HRESULT init(VirtualBox *aVirtualBox, com::Utf8Str aName);
|
---|
| 82 | HRESULT i_loadSettings(const settings::NATNetwork &data);
|
---|
[45138] | 83 | void uninit();
|
---|
[49742] | 84 | HRESULT i_saveSettings(settings::NATNetwork &data);
|
---|
[45138] | 85 |
|
---|
[49742] | 86 | private:
|
---|
[45138] | 87 |
|
---|
[49742] | 88 | // Wrapped INATNetwork properties
|
---|
| 89 | HRESULT getNetworkName(com::Utf8Str &aNetworkName);
|
---|
| 90 | HRESULT setNetworkName(const com::Utf8Str &aNetworkName);
|
---|
| 91 | HRESULT getEnabled(BOOL *aEnabled);
|
---|
| 92 | HRESULT setEnabled(BOOL aEnabled);
|
---|
| 93 | HRESULT getNetwork(com::Utf8Str &aNetwork);
|
---|
| 94 | HRESULT setNetwork(const com::Utf8Str &aNetwork);
|
---|
| 95 | HRESULT getGateway(com::Utf8Str &aGateway);
|
---|
| 96 | HRESULT getIPv6Enabled(BOOL *aIPv6Enabled);
|
---|
| 97 | HRESULT setIPv6Enabled(BOOL aIPv6Enabled);
|
---|
| 98 | HRESULT getIPv6Prefix(com::Utf8Str &aIPv6Prefix);
|
---|
| 99 | HRESULT setIPv6Prefix(const com::Utf8Str &aIPv6Prefix);
|
---|
| 100 | HRESULT getAdvertiseDefaultIPv6RouteEnabled(BOOL *aAdvertiseDefaultIPv6RouteEnabled);
|
---|
| 101 | HRESULT setAdvertiseDefaultIPv6RouteEnabled(BOOL aAdvertiseDefaultIPv6RouteEnabled);
|
---|
| 102 | HRESULT getNeedDhcpServer(BOOL *aNeedDhcpServer);
|
---|
| 103 | HRESULT setNeedDhcpServer(BOOL aNeedDhcpServer);
|
---|
| 104 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
| 105 | HRESULT getPortForwardRules4(std::vector<com::Utf8Str> &aPortForwardRules4);
|
---|
| 106 | HRESULT getLocalMappings(std::vector<com::Utf8Str> &aLocalMappings);
|
---|
| 107 | HRESULT getLoopbackIp6(LONG *aLoopbackIp6);
|
---|
| 108 | HRESULT setLoopbackIp6(LONG aLoopbackIp6);
|
---|
| 109 | HRESULT getPortForwardRules6(std::vector<com::Utf8Str> &aPortForwardRules6);
|
---|
[45138] | 110 |
|
---|
[49742] | 111 | // wrapped INATNetwork methods
|
---|
| 112 | HRESULT addLocalMapping(const com::Utf8Str &aHostid,
|
---|
[60786] | 113 | LONG aOffset);
|
---|
[49742] | 114 | HRESULT addPortForwardRule(BOOL aIsIpv6,
|
---|
| 115 | const com::Utf8Str &aRuleName,
|
---|
| 116 | NATProtocol_T aProto,
|
---|
| 117 | const com::Utf8Str &aHostIP,
|
---|
| 118 | USHORT aHostPort,
|
---|
| 119 | const com::Utf8Str &aGuestIP,
|
---|
| 120 | USHORT aGuestPort);
|
---|
| 121 | HRESULT removePortForwardRule(BOOL aISipv6,
|
---|
| 122 | const com::Utf8Str &aRuleName);
|
---|
[81883] | 123 | HRESULT start();
|
---|
[49742] | 124 | HRESULT stop();
|
---|
[47018] | 125 |
|
---|
[49742] | 126 | // Internal methods
|
---|
[87949] | 127 | HRESULT setErrorBusy();
|
---|
| 128 |
|
---|
[49742] | 129 | int i_recalculateIpv4AddressAssignments();
|
---|
| 130 | int i_findFirstAvailableOffset(ADDRESSLOOKUPTYPE, uint32_t *);
|
---|
[58827] | 131 | int i_recalculateIPv6Prefix();
|
---|
[47018] | 132 |
|
---|
[60786] | 133 | void i_getPortForwardRulesFromMap(std::vector<Utf8Str> &aPortForwardRules, settings::NATRulesMap &aRules);
|
---|
[45559] | 134 |
|
---|
[76132] | 135 | void i_updateDnsOptions();
|
---|
[76153] | 136 | void i_updateDomainNameOption(ComPtr<IHost> &host);
|
---|
| 137 | void i_updateDomainNameServerOption(ComPtr<IHost> &host);
|
---|
[76132] | 138 |
|
---|
[45138] | 139 | struct Data;
|
---|
[60786] | 140 | Data *m;
|
---|
[45138] | 141 | };
|
---|
| 142 |
|
---|
[76562] | 143 | #endif /* !MAIN_INCLUDED_NATNetworkImpl_h */
|
---|