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