75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync/* $Id$ */
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync/** @file
ae7831c5adb71bdf2ef86aa7aa8dc19402b3345evboxsync * INATNetwork implementation header, lives in VBoxSVC.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync */
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync/*
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync * Copyright (C) 2006-2013 Oracle Corporation
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync *
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * available from http://www.virtualbox.org. This file is free software;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * you can redistribute it and/or modify it under the terms of the GNU
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * General Public License (GPL) as published by the Free Software
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync */
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync#ifndef ____H_H_NATNETWORKIMPL
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync#define ____H_H_NATNETWORKIMPL
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync#include "VBoxEvents.h"
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync#include "NATNetworkWrap.h"
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync#ifdef VBOX_WITH_HOSTNETIF_API
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncstruct NETIFINFO;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync#endif
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncnamespace settings
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync{
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync struct NATNetwork;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync struct NATRule;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync}
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync#ifdef RT_OS_WINDOWS
20fc4a350a4a8e56ffaac6cf57dcd677a7ac36c5vboxsync# define NATSR_EXECUTABLE_NAME "VBoxNetNAT.exe"
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync#else
20fc4a350a4a8e56ffaac6cf57dcd677a7ac36c5vboxsync# define NATSR_EXECUTABLE_NAME "VBoxNetNAT"
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync#endif
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsyncenum ADDRESSLOOKUPTYPE
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync{
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync ADDR_GATEWAY,
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync ADDR_DHCP,
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync ADDR_DHCPLOWERIP,
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync ADDR_ANY
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync};
b2ce45796dce5018f423e5b3909eb4b36f83f073vboxsync
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsyncclass NATNetworkServiceRunner: public NetworkServiceRunner
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync{
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsyncpublic:
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync NATNetworkServiceRunner(): NetworkServiceRunner(NATSR_EXECUTABLE_NAME){}
f98c5a21f7e8e4c698e3a6937c2798378d4664bevboxsync ~NATNetworkServiceRunner(){}
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync};
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncclass ATL_NO_VTABLE NATNetwork :
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync public NATNetworkWrap
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync{
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncpublic:
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync DECLARE_EMPTY_CTOR_DTOR(NATNetwork)
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync HRESULT FinalConstruct();
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync void FinalRelease();
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync HRESULT init(VirtualBox *aVirtualBox,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync com::Utf8Str aName);
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync HRESULT init(VirtualBox *aVirtualBox,
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync const settings::NATNetwork &data);
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync void uninit();
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT i_saveSettings(settings::NATNetwork &data);
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncprivate:
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync // Wrapped INATNetwork properties
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getNetworkName(com::Utf8Str &aNetworkName);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setNetworkName(const com::Utf8Str &aNetworkName);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getEnabled(BOOL *aEnabled);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setEnabled(BOOL aEnabled);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getNetwork(com::Utf8Str &aNetwork);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setNetwork(const com::Utf8Str &aNetwork);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getGateway(com::Utf8Str &aGateway);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getIPv6Enabled(BOOL *aIPv6Enabled);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setIPv6Enabled(BOOL aIPv6Enabled);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getIPv6Prefix(com::Utf8Str &aIPv6Prefix);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setIPv6Prefix(const com::Utf8Str &aIPv6Prefix);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getAdvertiseDefaultIPv6RouteEnabled(BOOL *aAdvertiseDefaultIPv6RouteEnabled);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setAdvertiseDefaultIPv6RouteEnabled(BOOL aAdvertiseDefaultIPv6RouteEnabled);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getNeedDhcpServer(BOOL *aNeedDhcpServer);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setNeedDhcpServer(BOOL aNeedDhcpServer);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getPortForwardRules4(std::vector<com::Utf8Str> &aPortForwardRules4);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getLocalMappings(std::vector<com::Utf8Str> &aLocalMappings);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getLoopbackIp6(LONG *aLoopbackIp6);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT setLoopbackIp6(LONG aLoopbackIp6);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT getPortForwardRules6(std::vector<com::Utf8Str> &aPortForwardRules6);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync // wrapped INATNetwork methods
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT addLocalMapping(const com::Utf8Str &aHostid,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync LONG aOffset);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT addPortForwardRule(BOOL aIsIpv6,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync const com::Utf8Str &aRuleName,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync NATProtocol_T aProto,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync const com::Utf8Str &aHostIP,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync USHORT aHostPort,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync const com::Utf8Str &aGuestIP,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync USHORT aGuestPort);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT removePortForwardRule(BOOL aISipv6,
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync const com::Utf8Str &aRuleName);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT start(const com::Utf8Str &aTrunkType);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync HRESULT stop();
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync // Internal methods
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync int i_recalculateIpv4AddressAssignments();
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync int i_findFirstAvailableOffset(ADDRESSLOOKUPTYPE, uint32_t *);
6d73c66200a04223ae56a22ff221ec32193717a5vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync typedef std::map<Utf8Str, settings::NATRule> NATRuleMap;
6d73c66200a04223ae56a22ff221ec32193717a5vboxsync typedef NATRuleMap::const_iterator constNATRuleMapIterator;
6d73c66200a04223ae56a22ff221ec32193717a5vboxsync
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync void i_getPortForwardRulesFromMap(std::vector<Utf8Str> &aPortForwardRules, NATRuleMap& aRules);
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync /** weak VirtualBox parent */
79207ebc7bef44216ecdbe520de76317c713ada6vboxsync VirtualBox * const mVirtualBox;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync const com::Utf8Str mName;
4b8518be25a866f7de85889a2d827d7a479e1411vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync struct Data;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync struct Data *m;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync};
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync
ae7831c5adb71bdf2ef86aa7aa8dc19402b3345evboxsync#endif // !____H_H_NATNETWORKIMPL