1 #include "dhcp_configuration.hpp"
2
3 #include "config_parser.hpp"
4 #include "network_manager.hpp"
5
6 #include <phosphor-logging/elog-errors.hpp>
7 #include <phosphor-logging/lg2.hpp>
8 #include <xyz/openbmc_project/Common/error.hpp>
9
10 namespace phosphor
11 {
12 namespace network
13 {
14 namespace dhcp
15 {
16
17 using namespace phosphor::network;
18 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
19
Configuration(sdbusplus::bus_t & bus,stdplus::const_zstring objPath,stdplus::PinnedRef<EthernetInterface> parent,DHCPType type)20 Configuration::Configuration(
21 sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
22 stdplus::PinnedRef<EthernetInterface> parent, DHCPType type) :
23 Iface(bus, objPath.c_str(), Iface::action::defer_emit), parent(parent)
24 {
25 config::Parser conf(config::pathForIntfConf(
26 parent.get().manager.get().getConfDir(), parent.get().interfaceName()));
27 ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true);
28 ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true);
29 ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true);
30 ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true);
31 ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, type, "SendHostname"),
32 true);
33
34 emit_object_added();
35 }
36
sendHostNameEnabled(bool value)37 bool Configuration::sendHostNameEnabled(bool value)
38 {
39 if (value == sendHostNameEnabled())
40 {
41 return value;
42 }
43
44 auto name = ConfigIntf::sendHostNameEnabled(value);
45 parent.get().writeConfigurationFile();
46 parent.get().reloadConfigs();
47 return name;
48 }
49
hostNameEnabled(bool value)50 bool Configuration::hostNameEnabled(bool value)
51 {
52 if (value == hostNameEnabled())
53 {
54 return value;
55 }
56
57 auto name = ConfigIntf::hostNameEnabled(value);
58 parent.get().writeConfigurationFile();
59 parent.get().reloadConfigs();
60
61 return name;
62 }
63
ntpEnabled(bool value)64 bool Configuration::ntpEnabled(bool value)
65 {
66 if (value == ntpEnabled())
67 {
68 return value;
69 }
70
71 auto ntp = ConfigIntf::ntpEnabled(value);
72 parent.get().writeConfigurationFile();
73 parent.get().reloadConfigs();
74
75 return ntp;
76 }
77
dnsEnabled(bool value)78 bool Configuration::dnsEnabled(bool value)
79 {
80 if (value == dnsEnabled())
81 {
82 return value;
83 }
84
85 auto dns = ConfigIntf::dnsEnabled(value);
86 parent.get().writeConfigurationFile();
87 parent.get().reloadConfigs();
88
89 return dns;
90 }
91
domainEnabled(bool value)92 bool Configuration::domainEnabled(bool value)
93 {
94 if (value == domainEnabled())
95 {
96 return value;
97 }
98
99 auto domain = ConfigIntf::domainEnabled(value);
100 parent.get().writeConfigurationFile();
101 parent.get().reloadConfigs();
102
103 return domain;
104 }
105
106 } // namespace dhcp
107 } // namespace network
108 } // namespace phosphor
109