VirtualBox

source: vbox/trunk/src/VBox/Main/include/NATNetworkImpl.h@ 48328

Last change on this file since 48328 was 48107, checked in by vboxsync, 11 years ago

NATNetwork windows build fix. Fixed memory leak in recalculateIpv4AddressAssignments due to confusing string handling and simplified the code there a little (~20 lines shorter). Fixed indentation and some other nits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: NATNetworkImpl.h 48107 2013-08-27 22:15:13Z vboxsync $ */
2/** @file
3 * INATNetwork implementation header, lives in VBoxSVC.
4 */
5
6/*
7 * Copyright (C) 2006-2011 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
21#include "VirtualBoxBase.h"
22
23#ifdef VBOX_WITH_HOSTNETIF_API
24struct NETIFINFO;
25#endif
26
27#ifdef VBOX_WITH_NAT_SERVICE
28# define NAT_XML_SERIALIZATION 1
29#endif
30
31namespace settings
32{
33 struct NATNetwork;
34 struct NATRule;
35}
36
37#ifdef RT_OS_WINDOWS
38# define NATSR_EXECUTABLE_NAME "VBoxNetNAT.exe"
39#else
40# define NATSR_EXECUTABLE_NAME "VBoxNetNAT"
41#endif
42
43class NATNetworkServiceRunner: public NetworkServiceRunner
44{
45public:
46 NATNetworkServiceRunner(): NetworkServiceRunner(NATSR_EXECUTABLE_NAME){}
47 virtual ~NATNetworkServiceRunner(){}
48};
49
50class ATL_NO_VTABLE NATNetwork :
51 public VirtualBoxBase,
52 VBOX_SCRIPTABLE_IMPL(INATNetwork)
53{
54public:
55
56 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(NATNetwork, INATNetwork)
57
58 DECLARE_NOT_AGGREGATABLE (NATNetwork)
59
60 DECLARE_PROTECT_FINAL_CONSTRUCT()
61
62 BEGIN_COM_MAP (NATNetwork)
63 VBOX_DEFAULT_INTERFACE_ENTRIES(INATNetwork)
64 END_COM_MAP()
65
66 DECLARE_EMPTY_CTOR_DTOR (NATNetwork)
67
68 HRESULT FinalConstruct();
69 void FinalRelease();
70
71 HRESULT init(VirtualBox *aVirtualBox,
72 IN_BSTR aName);
73
74
75 HRESULT init(VirtualBox *aVirtualBox,
76 const settings::NATNetwork &data);
77#ifdef NAT_XML_SERIALIZATION
78 HRESULT saveSettings(settings::NATNetwork &data);
79#endif
80 void uninit();
81 // INATNetwork::EventSource
82 STDMETHOD(COMGETTER(EventSource))(IEventSource **IEventSource);
83 // INATNetwork properties
84 STDMETHOD(COMGETTER(Enabled))(BOOL *aEnabled);
85 STDMETHOD(COMSETTER(Enabled))(BOOL aEnabled);
86
87 STDMETHOD(COMGETTER(NetworkName))(BSTR *aName);
88 STDMETHOD(COMSETTER(NetworkName))(IN_BSTR aName);
89
90 STDMETHOD(COMGETTER(Gateway))(BSTR *aIPGateway);
91
92 STDMETHOD(COMGETTER(Network))(BSTR *aIPNetwork);
93 STDMETHOD(COMSETTER(Network))(IN_BSTR aIPNetwork);
94
95 STDMETHOD(COMGETTER(IPv6Enabled))(BOOL *aEnabled);
96 STDMETHOD(COMSETTER(IPv6Enabled))(BOOL aEnabled);
97
98 STDMETHOD(COMGETTER(IPv6Prefix))(BSTR *aName);
99 STDMETHOD(COMSETTER(IPv6Prefix))(IN_BSTR aName);
100
101 STDMETHOD(COMGETTER(AdvertiseDefaultIPv6RouteEnabled))(BOOL *aEnabled);
102 STDMETHOD(COMSETTER(AdvertiseDefaultIPv6RouteEnabled))(BOOL aEnabled);
103
104 STDMETHOD(COMGETTER(NeedDhcpServer))(BOOL *aEnabled);
105 STDMETHOD(COMSETTER(NeedDhcpServer))(BOOL aEnabled);
106
107 STDMETHOD(COMGETTER(LocalMappings))(ComSafeArrayOut(BSTR, aLocalMappings));
108 STDMETHOD(AddLocalMapping)(IN_BSTR aHostId, LONG aOffset);
109
110 STDMETHOD(COMGETTER(LoopbackIp6))(LONG *aLoopbackIp6);
111 STDMETHOD(COMSETTER(LoopbackIp6))(LONG aLoopbackIp6);
112
113 STDMETHOD(COMGETTER(PortForwardRules4))(ComSafeArrayOut(BSTR, aPortForwardRules4));
114 STDMETHOD(COMGETTER(PortForwardRules6))(ComSafeArrayOut(BSTR, aPortForwardRules6));
115
116 STDMETHOD(AddPortForwardRule)(BOOL aIsIpv6,
117 IN_BSTR aPortForwardRuleName,
118 NATProtocol_T aProto,
119 IN_BSTR aHostIp,
120 USHORT aHostPort,
121 IN_BSTR aGuestIp,
122 USHORT aGuestPort);
123 STDMETHOD(RemovePortForwardRule)(BOOL aIsIpv6, IN_BSTR aPortForwardRuleName);
124
125 STDMETHOD(Start)(IN_BSTR aTrunkType);
126 STDMETHOD(Stop)();
127
128private:
129 int recalculateIpv4AddressAssignments();
130 int findFirstAvailableOffset(uint32_t *);
131
132 typedef std::map<Utf8Str, settings::NATRule> NATRuleMap;
133 typedef NATRuleMap::const_iterator constNATRuleMapIterator;
134
135 void GetPortForwardRulesFromMap(ComSafeArrayOut(BSTR, aPortForwardRules), NATRuleMap& aRules);
136 /** weak VirtualBox parent */
137 VirtualBox * const mVirtualBox;
138
139 const Bstr mName;
140 struct Data;
141 struct Data *m;
142
143};
144
145#endif // !____H_H_NATNETWORKIMPL
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