VirtualBox

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

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

Dhcpd: Made the lease database filename configurable so Main can decide exactly where it is and what's it called in order to correctly implement IDCHPServer::FindLeaseByMAC. Use RTPathPurgeFilename to create the default lease filename. Added a todo regarding a bogus looking message option in an ACK. bugref:9288

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: Config.h 79613 2019-07-08 23:50:48Z 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 RTCString m_strLeaseFilename; /**< The lease filename if one given. Dhcpd will pick a default if empty. */
49
50 RTCString m_strTrunk; /**< The trunk name of the internal network. */
51 INTNETTRUNKTYPE m_enmTrunkType; /**< The trunk type of the internal network. */
52
53 RTMAC m_MacAddress; /**< The MAC address for the DHCP server. */
54
55 RTNETADDRIPV4 m_IPv4Address; /**< The IPv4 address of the DHCP server. */
56 RTNETADDRIPV4 m_IPv4Netmask; /**< The IPv4 netmask for the DHCP server. */
57
58 RTNETADDRIPV4 m_IPv4PoolFirst; /**< The first IPv4 address in the pool. */
59 RTNETADDRIPV4 m_IPv4PoolLast; /**< The last IPV4 address in the pool (inclusive like all other 'last' variables). */
60
61
62 optmap_t m_GlobalOptions; /**< Global DHCP option. */
63 vmmap_t m_VMMap; /**< Per MAC address (VM) DHCP options. */
64 /** @todo r=bird: optmap_t is too narrow for adding configuration options such
65 * as max-lease-time, min-lease-time, default-lease-time and such like
66 * that does not translate directly to any specific DHCP option. */
67 /** @todo r=bird: Additionally, I'd like to have a more generic option groups
68 * that fits inbetween m_VMMap (mac based) and m_GlobalOptions.
69 * Pattern/wildcard matching on MAC address, possibly also client ID,
70 * vendor class and user class, including simple lists of these. */
71
72private:
73 Config();
74
75 int i_init() RT_NOEXCEPT;
76 int i_homeInit() RT_NOEXCEPT;
77 static Config *i_createInstanceAndCallInit() RT_NOEXCEPT;
78 int i_logInit() RT_NOEXCEPT;
79 int i_complete() RT_NOEXCEPT;
80
81public:
82 /** @name Factory methods
83 * @{ */
84 static Config *hardcoded() RT_NOEXCEPT; /**< For testing. */
85 static Config *create(int argc, char **argv) RT_NOEXCEPT; /**< --config */
86 static Config *compat(int argc, char **argv);
87 /** @} */
88
89 /** @name Accessors
90 * @{ */
91 const RTCString &getHome() const RT_NOEXCEPT { return m_strHome; }
92
93 const RTCString &getNetwork() const RT_NOEXCEPT { return m_strNetwork; }
94 const RTCString &getBaseName() const RT_NOEXCEPT { return m_strBaseName; }
95 const RTCString &getLeaseFilename() const RT_NOEXCEPT { return m_strLeaseFilename; }
96
97 const RTCString &getTrunk() const RT_NOEXCEPT { return m_strTrunk; }
98 INTNETTRUNKTYPE getTrunkType() const RT_NOEXCEPT { return m_enmTrunkType; }
99
100 const RTMAC &getMacAddress() const RT_NOEXCEPT { return m_MacAddress; }
101
102 RTNETADDRIPV4 getIPv4Address() const RT_NOEXCEPT { return m_IPv4Address; }
103 RTNETADDRIPV4 getIPv4Netmask() const RT_NOEXCEPT { return m_IPv4Netmask; }
104
105 RTNETADDRIPV4 getIPv4PoolFirst() const RT_NOEXCEPT { return m_IPv4PoolFirst; }
106 RTNETADDRIPV4 getIPv4PoolLast() const RT_NOEXCEPT { return m_IPv4PoolLast; }
107 /** @} */
108
109 optmap_t &getOptions(optmap_t &a_rRetOpts, const OptParameterRequest &reqOpts, const ClientId &id,
110 const OptVendorClassId &idVendorClass = OptVendorClassId(),
111 const OptUserClassId &idUserClass = OptUserClassId()) const;
112
113private:
114 /** @name Configuration file reading and parsing
115 * @{ */
116 static Config *i_read(const char *pszFileName) RT_NOEXCEPT;
117 void i_parseConfig(const xml::ElementNode *root);
118 void i_parseServer(const xml::ElementNode *server);
119 void i_parseGlobalOptions(const xml::ElementNode *options);
120 void i_parseVMConfig(const xml::ElementNode *config);
121 void i_parseOption(const xml::ElementNode *option, optmap_t &optmap);
122
123 static void i_getIPv4AddrAttribute(const xml::ElementNode *pElm, const char *pcszAttrName, PRTNETADDRIPV4 pAddr);
124 static void i_getMacAddressAttribute(const xml::ElementNode *pElm, const char *pszAttrName, PRTMAC pMacAddr);
125 /** @} */
126
127 void i_setNetwork(const RTCString &aStrNetwork);
128 void i_sanitizeBaseName();
129};
130
131#endif /* !VBOX_INCLUDED_SRC_Dhcpd_Config_h */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette