From f8fe689a81f906d1b91bb3220acde2a4ecb14c5b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 05:01:46 +0200 Subject: Adding upstream version 6.0.4-dfsg. Signed-off-by: Daniel Baumann --- src/VBox/NetworkServices/DHCP/ClientDataInt.h | 70 + src/VBox/NetworkServices/DHCP/Config.cpp | 1493 ++++++++++++++++++++ src/VBox/NetworkServices/DHCP/Config.h | 845 +++++++++++ src/VBox/NetworkServices/DHCP/Makefile.kmk | 72 + .../NetworkServices/DHCP/NetworkManagerDhcp.cpp | 189 +++ src/VBox/NetworkServices/DHCP/README.customoptions | 23 + src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp | 885 ++++++++++++ src/VBox/NetworkServices/DHCP/VBoxNetDHCP.rc | 55 + .../NetworkServices/DHCP/VBoxNetDHCPHardened.cpp | 25 + 9 files changed, 3657 insertions(+) create mode 100644 src/VBox/NetworkServices/DHCP/ClientDataInt.h create mode 100644 src/VBox/NetworkServices/DHCP/Config.cpp create mode 100644 src/VBox/NetworkServices/DHCP/Config.h create mode 100644 src/VBox/NetworkServices/DHCP/Makefile.kmk create mode 100644 src/VBox/NetworkServices/DHCP/NetworkManagerDhcp.cpp create mode 100644 src/VBox/NetworkServices/DHCP/README.customoptions create mode 100644 src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp create mode 100644 src/VBox/NetworkServices/DHCP/VBoxNetDHCP.rc create mode 100644 src/VBox/NetworkServices/DHCP/VBoxNetDHCPHardened.cpp (limited to 'src/VBox/NetworkServices/DHCP') diff --git a/src/VBox/NetworkServices/DHCP/ClientDataInt.h b/src/VBox/NetworkServices/DHCP/ClientDataInt.h new file mode 100644 index 00000000..74879523 --- /dev/null +++ b/src/VBox/NetworkServices/DHCP/ClientDataInt.h @@ -0,0 +1,70 @@ +/* $Id: ClientDataInt.h $ */ +/** @file + * Config.h + */ + +/* + * Copyright (C) 2013-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef VBOX_INCLUDED_SRC_DHCP_ClientDataInt_h +#define VBOX_INCLUDED_SRC_DHCP_ClientDataInt_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +class ClientData +{ +public: + ClientData() + { + m_address.u = 0; + m_network.u = 0; + fHasLease = false; + fHasClient = false; + fBinding = true; + u64TimestampBindingStarted = 0; + u64TimestampLeasingStarted = 0; + u32LeaseExpirationPeriod = 0; + u32BindExpirationPeriod = 0; + pCfg = NULL; + + } + ~ClientData(){} + + /* client information */ + RTNETADDRIPV4 m_address; + RTNETADDRIPV4 m_network; + RTMAC m_mac; + + bool fHasClient; + + /* Lease part */ + bool fHasLease; + /** lease isn't commited */ + bool fBinding; + + /** Timestamp when lease commited. */ + uint64_t u64TimestampLeasingStarted; + /** Period when lease is expired in secs. */ + uint32_t u32LeaseExpirationPeriod; + + /** timestamp when lease was bound */ + uint64_t u64TimestampBindingStarted; + /* Period when binding is expired in secs. */ + uint32_t u32BindExpirationPeriod; + + MapOptionId2RawOption options; + + NetworkConfigEntity *pCfg; +}; + +#endif /* !VBOX_INCLUDED_SRC_DHCP_ClientDataInt_h */ diff --git a/src/VBox/NetworkServices/DHCP/Config.cpp b/src/VBox/NetworkServices/DHCP/Config.cpp new file mode 100644 index 00000000..b1d09c78 --- /dev/null +++ b/src/VBox/NetworkServices/DHCP/Config.cpp @@ -0,0 +1,1493 @@ +/* $Id: Config.cpp $ */ +/** @file + * Configuration for DHCP. + */ + +/* + * Copyright (C) 2013-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + + +/** + * XXX: license. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define BASE_SERVICES_ONLY +#include "../NetLib/VBoxNetBaseService.h" +#include "../NetLib/VBoxNetLib.h" +#include "../NetLib/shared_ptr.h" + +#include +#include +#include +#include + +#include "Config.h" +#include "ClientDataInt.h" + +bool operator== (const Lease& lhs, const Lease& rhs) +{ + return (lhs.m.get() == rhs.m.get()); +} + + +bool operator!= (const Lease& lhs, const Lease& rhs) +{ + return !(lhs == rhs); +} + + +bool operator< (const Lease& lhs, const Lease& rhs) +{ + return ( (lhs.getAddress() < rhs.getAddress()) + || (lhs.issued() < rhs.issued())); +} +/* consts */ + +const NullConfigEntity *g_NullConfig = new NullConfigEntity(); +RootConfigEntity *g_RootConfig = new RootConfigEntity(std::string("ROOT"), 1200 /* 20 min. */); +const ClientMatchCriteria *g_AnyClient = new AnyClientMatchCriteria(); + +static ConfigurationManager *g_ConfigurationManager = ConfigurationManager::getConfigurationManager(); + +NetworkManager *NetworkManager::g_NetworkManager; + +bool MACClientMatchCriteria::check(const Client& client) const +{ + return (client == m_mac); +} + + +int BaseConfigEntity::match(Client& client, BaseConfigEntity **cfg) +{ + int iMatch = (m_criteria && m_criteria->check(client) ? m_MatchLevel : 0); + if (m_children.empty()) + { + if (iMatch > 0) + { + *cfg = this; + return iMatch; + } + } + else + { + *cfg = this; + /* XXX: hack */ + BaseConfigEntity *matching = this; + int matchingLevel = m_MatchLevel; + + for (std::vector::iterator it = m_children.begin(); + it != m_children.end(); + ++it) + { + iMatch = (*it)->match(client, &matching); + if (iMatch > matchingLevel) + { + *cfg = matching; + matchingLevel = iMatch; + } + } + return matchingLevel; + } + return iMatch; +} + +/* Client */ +/* Configs + NetworkConfigEntity(std::string name, + ConfigEntity* pCfg, + ClientMatchCriteria* criteria, + RTNETADDRIPV4& networkID, + RTNETADDRIPV4& networkMask) +*/ +static const RTNETADDRIPV4 g_AnyIpv4 = {0}; +static const RTNETADDRIPV4 g_AllIpv4 = {0xffffffff}; +RootConfigEntity::RootConfigEntity(std::string name, uint32_t expPeriod): + NetworkConfigEntity(name, g_NullConfig, g_AnyClient, g_AnyIpv4, g_AllIpv4) +{ + m_MatchLevel = 2; + m_u32ExpirationPeriod = expPeriod; +} + +/* Configuration Manager */ +struct ConfigurationManager::Data +{ + Data():fFileExists(false){} + + MapLease2Ip4Address m_allocations; + Ipv4AddressContainer m_nameservers; + Ipv4AddressContainer m_routers; + + std::string m_domainName; + VecClient m_clients; + com::Utf8Str m_leaseStorageFilename; + bool fFileExists; +}; + +ConfigurationManager *ConfigurationManager::getConfigurationManager() +{ + if (!g_ConfigurationManager) + + + { + g_ConfigurationManager = new ConfigurationManager(); + g_ConfigurationManager->init(); + } + + return g_ConfigurationManager; +} + + +const std::string tagXMLLeases = "Leases"; +const std::string tagXMLLeasesAttributeVersion = "version"; +const std::string tagXMLLeasesVersion_1_0 = "1.0"; +const std::string tagXMLLease = "Lease"; +const std::string tagXMLLeaseAttributeMac = "mac"; +const std::string tagXMLLeaseAttributeNetwork = "network"; +const std::string tagXMLLeaseAddress = "Address"; +const std::string tagXMLAddressAttributeValue = "value"; +const std::string tagXMLLeaseTime = "Time"; +const std::string tagXMLTimeAttributeIssued = "issued"; +const std::string tagXMLTimeAttributeExpiration = "expiration"; +const std::string tagXMLLeaseOptions = "Options"; + +/** + * @verbatim + + +
+