11bbe3d1eSWilliam A. Kennington III #include "dhcp_configuration.hpp"
21bbe3d1eSWilliam A. Kennington III
3e94c9ffcSWilliam A. Kennington III #include "config_parser.hpp"
41bbe3d1eSWilliam A. Kennington III #include "network_manager.hpp"
51bbe3d1eSWilliam A. Kennington III
61bbe3d1eSWilliam A. Kennington III #include <phosphor-logging/elog-errors.hpp>
7a2947b4bSJagpal Singh Gill #include <phosphor-logging/lg2.hpp>
81bbe3d1eSWilliam A. Kennington III #include <xyz/openbmc_project/Common/error.hpp>
91bbe3d1eSWilliam A. Kennington III
101bbe3d1eSWilliam A. Kennington III namespace phosphor
111bbe3d1eSWilliam A. Kennington III {
121bbe3d1eSWilliam A. Kennington III namespace network
131bbe3d1eSWilliam A. Kennington III {
141bbe3d1eSWilliam A. Kennington III namespace dhcp
151bbe3d1eSWilliam A. Kennington III {
161bbe3d1eSWilliam A. Kennington III
171bbe3d1eSWilliam A. Kennington III using namespace phosphor::network;
181bbe3d1eSWilliam A. Kennington III using namespace sdbusplus::xyz::openbmc_project::Common::Error;
19e94c9ffcSWilliam A. Kennington III
Configuration(sdbusplus::bus_t & bus,stdplus::const_zstring objPath,stdplus::PinnedRef<EthernetInterface> parent,DHCPType type)20*ad205028SPatrick Williams Configuration::Configuration(
21*ad205028SPatrick Williams sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
22*ad205028SPatrick Williams stdplus::PinnedRef<EthernetInterface> parent, DHCPType type) :
23*ad205028SPatrick Williams Iface(bus, objPath.c_str(), Iface::action::defer_emit), parent(parent)
24e94c9ffcSWilliam A. Kennington III {
25c3c6b4c3SWilliam A. Kennington III config::Parser conf(config::pathForIntfConf(
26c3c6b4c3SWilliam A. Kennington III parent.get().manager.get().getConfDir(), parent.get().interfaceName()));
27b6595b29SRavi Teja ConfigIntf::domainEnabled(getDHCPProp(conf, type, "UseDomains"), true);
2857dfea94SJishnu CM ConfigIntf::dnsEnabled(getDHCPProp(conf, type, "UseDNS"), true);
2957dfea94SJishnu CM ConfigIntf::ntpEnabled(getDHCPProp(conf, type, "UseNTP"), true);
3057dfea94SJishnu CM ConfigIntf::hostNameEnabled(getDHCPProp(conf, type, "UseHostname"), true);
3157dfea94SJishnu CM ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, type, "SendHostname"),
3257dfea94SJishnu CM true);
3357dfea94SJishnu CM
34e94c9ffcSWilliam A. Kennington III emit_object_added();
35e94c9ffcSWilliam A. Kennington III }
36e94c9ffcSWilliam A. Kennington III
sendHostNameEnabled(bool value)371bbe3d1eSWilliam A. Kennington III bool Configuration::sendHostNameEnabled(bool value)
381bbe3d1eSWilliam A. Kennington III {
391bbe3d1eSWilliam A. Kennington III if (value == sendHostNameEnabled())
401bbe3d1eSWilliam A. Kennington III {
411bbe3d1eSWilliam A. Kennington III return value;
421bbe3d1eSWilliam A. Kennington III }
431bbe3d1eSWilliam A. Kennington III
441bbe3d1eSWilliam A. Kennington III auto name = ConfigIntf::sendHostNameEnabled(value);
4557dfea94SJishnu CM parent.get().writeConfigurationFile();
4657dfea94SJishnu CM parent.get().reloadConfigs();
471bbe3d1eSWilliam A. Kennington III return name;
481bbe3d1eSWilliam A. Kennington III }
491bbe3d1eSWilliam A. Kennington III
hostNameEnabled(bool value)501bbe3d1eSWilliam A. Kennington III bool Configuration::hostNameEnabled(bool value)
511bbe3d1eSWilliam A. Kennington III {
521bbe3d1eSWilliam A. Kennington III if (value == hostNameEnabled())
531bbe3d1eSWilliam A. Kennington III {
541bbe3d1eSWilliam A. Kennington III return value;
551bbe3d1eSWilliam A. Kennington III }
561bbe3d1eSWilliam A. Kennington III
571bbe3d1eSWilliam A. Kennington III auto name = ConfigIntf::hostNameEnabled(value);
5857dfea94SJishnu CM parent.get().writeConfigurationFile();
5957dfea94SJishnu CM parent.get().reloadConfigs();
601bbe3d1eSWilliam A. Kennington III
611bbe3d1eSWilliam A. Kennington III return name;
621bbe3d1eSWilliam A. Kennington III }
631bbe3d1eSWilliam A. Kennington III
ntpEnabled(bool value)641bbe3d1eSWilliam A. Kennington III bool Configuration::ntpEnabled(bool value)
651bbe3d1eSWilliam A. Kennington III {
661bbe3d1eSWilliam A. Kennington III if (value == ntpEnabled())
671bbe3d1eSWilliam A. Kennington III {
681bbe3d1eSWilliam A. Kennington III return value;
691bbe3d1eSWilliam A. Kennington III }
701bbe3d1eSWilliam A. Kennington III
711bbe3d1eSWilliam A. Kennington III auto ntp = ConfigIntf::ntpEnabled(value);
7257dfea94SJishnu CM parent.get().writeConfigurationFile();
7357dfea94SJishnu CM parent.get().reloadConfigs();
741bbe3d1eSWilliam A. Kennington III
751bbe3d1eSWilliam A. Kennington III return ntp;
761bbe3d1eSWilliam A. Kennington III }
771bbe3d1eSWilliam A. Kennington III
dnsEnabled(bool value)781bbe3d1eSWilliam A. Kennington III bool Configuration::dnsEnabled(bool value)
791bbe3d1eSWilliam A. Kennington III {
801bbe3d1eSWilliam A. Kennington III if (value == dnsEnabled())
811bbe3d1eSWilliam A. Kennington III {
821bbe3d1eSWilliam A. Kennington III return value;
831bbe3d1eSWilliam A. Kennington III }
841bbe3d1eSWilliam A. Kennington III
851bbe3d1eSWilliam A. Kennington III auto dns = ConfigIntf::dnsEnabled(value);
8657dfea94SJishnu CM parent.get().writeConfigurationFile();
8757dfea94SJishnu CM parent.get().reloadConfigs();
881bbe3d1eSWilliam A. Kennington III
891bbe3d1eSWilliam A. Kennington III return dns;
901bbe3d1eSWilliam A. Kennington III }
911bbe3d1eSWilliam A. Kennington III
domainEnabled(bool value)92b6595b29SRavi Teja bool Configuration::domainEnabled(bool value)
93b6595b29SRavi Teja {
94b6595b29SRavi Teja if (value == domainEnabled())
95b6595b29SRavi Teja {
96b6595b29SRavi Teja return value;
97b6595b29SRavi Teja }
98b6595b29SRavi Teja
99b6595b29SRavi Teja auto domain = ConfigIntf::domainEnabled(value);
100b6595b29SRavi Teja parent.get().writeConfigurationFile();
101b6595b29SRavi Teja parent.get().reloadConfigs();
102b6595b29SRavi Teja
103b6595b29SRavi Teja return domain;
104b6595b29SRavi Teja }
105b6595b29SRavi Teja
1061bbe3d1eSWilliam A. Kennington III } // namespace dhcp
1071bbe3d1eSWilliam A. Kennington III } // namespace network
1081bbe3d1eSWilliam A. Kennington III } // namespace phosphor
109