VirtualBox

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

Last change on this file since 79553 was 79553, checked in by vboxsync, 5 years ago

Dhcpd: Went over the Config code adding comments, eliminating unnecessary copying (xml string getting, ++) and such. bugref:9288

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: Config.h 79553 2019-07-05 10:59:01Z 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_strBaseName; /**< m_strNetwork sanitized to be usable in a path component. */
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
71private:
72 Config();
73
74 int i_init();
75 int i_homeInit();
76 static Config *i_createInstanceAndCallInit();
77 int i_logInit();
78 int i_complete();
79
80public:
81 /** @name Factory methods
82 * @{ */
83 static Config *hardcoded(); /**< For testing. */
84 static Config *create(int argc, char **argv); /**< --config */
85 static Config *compat(int argc, char **argv); /**< Old VBoxNetDHCP command line parsing. */
86 /** @} */
87
88 /** @name Accessors
89 * @{ */
90 const RTCString &getHome() const { return m_strHome; }
91
92 const RTCString &getNetwork() const { return m_strNetwork; }
93
94 const RTCString &getBaseName() const { return m_strBaseName; }
95 const RTCString &getTrunk() const { return m_strTrunk; }
96 INTNETTRUNKTYPE getTrunkType() const { return m_enmTrunkType; }
97
98 const RTMAC &getMacAddress() const { return m_MacAddress; }
99
100 RTNETADDRIPV4 getIPv4Address() const { return m_IPv4Address; }
101 RTNETADDRIPV4 getIPv4Netmask() const { return m_IPv4Netmask; }
102
103 RTNETADDRIPV4 getIPv4PoolFirst() const { return m_IPv4PoolFirst; }
104 RTNETADDRIPV4 getIPv4PoolLast() const { return m_IPv4PoolLast; }
105 /** @} */
106
107 optmap_t &getOptions(optmap_t &a_rRetOpts, const OptParameterRequest &reqOpts, const ClientId &id,
108 const OptVendorClassId &idVendorClass = OptVendorClassId(),
109 const OptUserClassId &idUserClass = OptUserClassId()) const;
110
111private:
112 /** @name Configuration file reading and parsing
113 * @{ */
114 static Config *i_read(const char *pszFileName);
115 void i_parseConfig(const xml::ElementNode *root);
116 void i_parseServer(const xml::ElementNode *server);
117 void i_parseGlobalOptions(const xml::ElementNode *options);
118 void i_parseVMConfig(const xml::ElementNode *config);
119 void i_parseOption(const xml::ElementNode *option, optmap_t &optmap);
120
121 static void i_getIPv4AddrAttribute(const xml::ElementNode *pElm, const char *pcszAttrName, PRTNETADDRIPV4 pAddr);
122 static void i_getMacAddressAttribute(const xml::ElementNode *pElm, const char *pszAttrName, PRTMAC pMacAddr);
123 /** @} */
124
125 void i_setNetwork(const RTCString &aStrNetwork);
126 void i_sanitizeBaseName();
127};
128
129#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