/* $Id: Config.cpp 50587 2014-02-25 16:37:29Z vboxsync $ */ /** @file * Configuration for DHCP. */ /* * Copyright (C) 2013-2014 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 #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(); static NetworkManager *g_NetworkManager = NetworkManager::getNetworkManager(); 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"; /** * * *
*