VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/Dhcpd/Config.h@ 79787

Last change on this file since 79787 was 79761, checked in by vboxsync, 6 years ago

Main/DHCPServer,Dhcpd,VBoxManage: Added --log option to the DHCP server so we can start logging early. Added log rotation and limits. Put the config file next to the log and leases file. Validate DHCP options by reusing the parser code from the server, adding a bunch more DHCP options to the parser. Removed legacy and hardcoded configuration options from the dhcp server, it's all config file now. Fixed a bug in the option parsing of the VBoxManage dhcpserver add/modify commands. bugref:9288

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/* $Id: Config.h 79761 2019-07-14 03:18:41Z vboxsync $ */
2/** @file
3 * DHCP server - server configuration
4 */
5
6/*
7 * Copyright (C) 2017-2019 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 VBOX_INCLUDED_SRC_Dhcpd_Config_h
19#define VBOX_INCLUDED_SRC_Dhcpd_Config_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "DhcpdInternal.h"
25#include <iprt/types.h>
26#include <iprt/net.h>
27#include <iprt/cpp/xml.h>
28#include <iprt/cpp/ministring.h>
29
30#include <VBox/intnet.h>
31
32#include "DhcpOptions.h"
33#include "ClientId.h"
34
35
36/**
37 * DHCP server configuration.
38 */
39class Config
40{
41 /** @todo XXX: also store fixed address assignments, etc? */
42 typedef std::map<RTMAC, optmap_t> vmmap_t;
43
44 RTCString m_strHome; /**< path of ~/.VirtualBox or equivalent, */
45
46 RTCString m_strNetwork; /**< The name of the internal network the DHCP server is connected to. */
47 RTCString m_strLeasesFilename;/**< The lease DB filename. */
48
49 RTCString m_strTrunk; /**< The trunk name of the internal network. */
50 INTNETTRUNKTYPE m_enmTrunkType; /**< The trunk type of the internal network. */
51
52 RTMAC m_MacAddress; /**< The MAC address for the DHCP server. */
53
54 RTNETADDRIPV4 m_IPv4Address; /**< The IPv4 address of the DHCP server. */
55 RTNETADDRIPV4 m_IPv4Netmask; /**< The IPv4 netmask for the DHCP server. */
56
57 RTNETADDRIPV4 m_IPv4PoolFirst; /**< The first IPv4 address in the pool. */
58 RTNETADDRIPV4 m_IPv4PoolLast; /**< The last IPV4 address in the pool (inclusive like all other 'last' variables). */
59
60
61 optmap_t m_GlobalOptions; /**< Global DHCP option. */
62 vmmap_t m_VMMap; /**< Per MAC address (VM) DHCP options. */
63 /** @todo r=bird: optmap_t is too narrow for adding configuration options such
64 * as max-lease-time, min-lease-time, default-lease-time and such like
65 * that does not translate directly to any specific DHCP option. */
66 /** @todo r=bird: Additionally, I'd like to have a more generic option groups
67 * that fits inbetween m_VMMap (mac based) and m_GlobalOptions.
68 * Pattern/wildcard matching on MAC address, possibly also client ID,
69 * vendor class and user class, including simple lists of these. */
70
71 /** Set if we've initialized the log already (via command line). */
72 static bool g_fInitializedLog;
73
74private:
75 Config();
76
77 int i_init() RT_NOEXCEPT;
78 int i_homeInit() RT_NOEXCEPT;
79 static Config *i_createInstanceAndCallInit() RT_NOEXCEPT;
80 int i_logInit() RT_NOEXCEPT;
81 static int i_logInitWithFilename(const char *pszFilename) RT_NOEXCEPT;
82 int i_complete() RT_NOEXCEPT;
83
84public:
85 /** @name Factory methods
86 * @{ */
87 static Config *hardcoded() RT_NOEXCEPT; /**< For testing. */
88 static Config *create(int argc, char **argv) RT_NOEXCEPT; /**< --config */
89 static Config *compat(int argc, char **argv);
90 /** @} */
91
92 /** @name Accessors
93 * @{ */
94 const RTCString &getHome() const RT_NOEXCEPT { return m_strHome; }
95
96 const RTCString &getNetwork() const RT_NOEXCEPT { return m_strNetwork; }
97 const RTCString &getLeasesFilename() const RT_NOEXCEPT { return m_strLeasesFilename; }
98
99 const RTCString &getTrunk() const RT_NOEXCEPT { return m_strTrunk; }
100 INTNETTRUNKTYPE getTrunkType() const RT_NOEXCEPT { return m_enmTrunkType; }
101
102 const RTMAC &getMacAddress() const RT_NOEXCEPT { return m_MacAddress; }
103
104 RTNETADDRIPV4 getIPv4Address() const RT_NOEXCEPT { return m_IPv4Address; }
105 RTNETADDRIPV4 getIPv4Netmask() const RT_NOEXCEPT { return m_IPv4Netmask; }
106
107 RTNETADDRIPV4 getIPv4PoolFirst() const RT_NOEXCEPT { return m_IPv4PoolFirst; }
108 RTNETADDRIPV4 getIPv4PoolLast() const RT_NOEXCEPT { return m_IPv4PoolLast; }
109 /** @} */
110
111 optmap_t &getOptions(optmap_t &a_rRetOpts, const OptParameterRequest &reqOpts, const ClientId &id,
112 const OptVendorClassId &idVendorClass = OptVendorClassId(),
113 const OptUserClassId &idUserClass = OptUserClassId()) const;
114
115private:
116 /** @name Configuration file reading and parsing
117 * @{ */
118 static Config *i_read(const char *pszFileName) RT_NOEXCEPT;
119 void i_parseConfig(const xml::ElementNode *root);
120 void i_parseServer(const xml::ElementNode *server);
121 void i_parseGlobalOptions(const xml::ElementNode *options);
122 void i_parseVMConfig(const xml::ElementNode *config);
123 void i_parseOption(const xml::ElementNode *option, optmap_t &optmap);
124
125 static void i_getIPv4AddrAttribute(const xml::ElementNode *pElm, const char *pcszAttrName, PRTNETADDRIPV4 pAddr);
126 static void i_getMacAddressAttribute(const xml::ElementNode *pElm, const char *pszAttrName, PRTMAC pMacAddr);
127 /** @} */
128};
129
130#endif /* !VBOX_INCLUDED_SRC_Dhcpd_Config_h */
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