1 | /* $Id: Config.h 71353 2018-03-15 14:11:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DHCP server - server configuration
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2018 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 _DHCPD_CONFIG_H_
|
---|
19 | #define _DHCPD_CONFIG_H_
|
---|
20 |
|
---|
21 | #include <iprt/types.h>
|
---|
22 | #include <iprt/net.h>
|
---|
23 |
|
---|
24 | #include <VBox/intnet.h>
|
---|
25 |
|
---|
26 | #include <string>
|
---|
27 |
|
---|
28 | #include "Defs.h"
|
---|
29 | #include "DhcpOptions.h"
|
---|
30 | #include "ClientId.h"
|
---|
31 |
|
---|
32 |
|
---|
33 | class Config
|
---|
34 | {
|
---|
35 | std::string m_strHome;
|
---|
36 |
|
---|
37 | std::string m_strNetwork;
|
---|
38 | std::string m_strBaseName; /* m_strNetwork sanitized to be usable in a path component */
|
---|
39 |
|
---|
40 | std::string m_strTrunk;
|
---|
41 | INTNETTRUNKTYPE m_enmTrunkType;
|
---|
42 |
|
---|
43 | RTMAC m_MacAddress;
|
---|
44 |
|
---|
45 | RTNETADDRIPV4 m_IPv4Address;
|
---|
46 | RTNETADDRIPV4 m_IPv4Netmask;
|
---|
47 |
|
---|
48 | RTNETADDRIPV4 m_IPv4PoolFirst;
|
---|
49 | RTNETADDRIPV4 m_IPv4PoolLast;
|
---|
50 |
|
---|
51 | private:
|
---|
52 | bool isSane();
|
---|
53 |
|
---|
54 | public: /* factory methods */
|
---|
55 | static Config *hardcoded(); /* for testing */
|
---|
56 | static Config *create(int argc, char **argv); /* --config */
|
---|
57 | static Config *compat(int argc, char **argv); /* old VBoxNetDHCP flags */
|
---|
58 |
|
---|
59 | public: /* accessors */
|
---|
60 | void setHome(const std::string &strHome) { m_strHome = strHome; }
|
---|
61 |
|
---|
62 | const std::string &getHome() const { return m_strHome; }
|
---|
63 | const std::string &getNetwork() const { return m_strNetwork; }
|
---|
64 | const std::string &getBaseName() const { return m_strBaseName; }
|
---|
65 | const std::string &getTrunk() const { return m_strTrunk; }
|
---|
66 | INTNETTRUNKTYPE getTrunkType() const { return m_enmTrunkType; }
|
---|
67 |
|
---|
68 | const RTMAC &getMacAddress() const { return m_MacAddress; }
|
---|
69 |
|
---|
70 | RTNETADDRIPV4 getIPv4Address() const { return m_IPv4Address; }
|
---|
71 | RTNETADDRIPV4 getIPv4Netmask() const { return m_IPv4Netmask; }
|
---|
72 |
|
---|
73 | RTNETADDRIPV4 getIPv4PoolFirst() const { return m_IPv4PoolFirst; }
|
---|
74 | RTNETADDRIPV4 getIPv4PoolLast() const { return m_IPv4PoolLast; }
|
---|
75 |
|
---|
76 | public:
|
---|
77 | optmap_t getOptions(const OptParameterRequest &reqOpts, const ClientId &id,
|
---|
78 | const OptVendorClassId &vendor = OptVendorClassId()) const;
|
---|
79 |
|
---|
80 | private:
|
---|
81 | static Config *read(const char *pszFileName);
|
---|
82 |
|
---|
83 | void sanitizeBaseName();
|
---|
84 |
|
---|
85 | void fillDefaultOptions(optmap_t &optmap,
|
---|
86 | const OptParameterRequest &reqOpts) const;
|
---|
87 | void fillVendorOptions(optmap_t &optmap,
|
---|
88 | const OptParameterRequest &reqOpts,
|
---|
89 | const OptVendorClassId &vendor) const;
|
---|
90 | void fillHostOptions(optmap_t &optmap,
|
---|
91 | const OptParameterRequest &reqOpts,
|
---|
92 | const ClientId &id) const;
|
---|
93 | };
|
---|
94 |
|
---|
95 | #endif /* _DHCPD_CONFIG_H_ */
|
---|