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