diff options
author | Nagaraju Goruganti <ngorugan@in.ibm.com> | 2018-03-07 09:22:28 -0600 |
---|---|---|
committer | Ratan Gupta <ratagupt@in.ibm.com> | 2018-03-15 00:20:31 +0530 |
commit | 210420aac714483ea4c1e8a303280df9c1b4e5c9 (patch) | |
tree | be8d04f464bdf8666ba78e5725cf679f9af5a62f /ethernet_interface.cpp | |
parent | c27170ab2747f7854a06c4dc533c2ad3c88dd758 (diff) | |
download | phosphor-networkd-210420aac714483ea4c1e8a303280df9c1b4e5c9.tar.gz phosphor-networkd-210420aac714483ea4c1e8a303280df9c1b4e5c9.zip |
Get DHCP configuration values form n/w config file while creating
DHCP config object.
Each time when we update config file we recreate DHCP config object,
with existing code DHCP configuration values are getting initialized
to default values.
With these changes we get DHCP configuration values from n/w config.
Resolves openbmc/openbmc#2891
Change-Id: I95d50d52a8aa569493739a46b88e4a378e399698
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
Diffstat (limited to 'ethernet_interface.cpp')
-rw-r--r-- | ethernet_interface.cpp | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp index 7d13c1c..74c30c5 100644 --- a/ethernet_interface.cpp +++ b/ethernet_interface.cpp @@ -564,77 +564,78 @@ void EthernetInterface::writeConfigurationFile() stream << "VLAN=" << intf.second->EthernetInterface::interfaceName() << "\n"; } - - // DHCP - if (dHCPEnabled() == true) + // When the interface configured as dhcp, we don't need below given entries + // in config file. + if (dHCPEnabled() == false) { - // write the dhcp section if interface is - // configured as dhcp. - writeDHCPSection(stream); - stream.close(); - return; - } - - //Add the NTP server - for(const auto& ntp: EthernetInterfaceIntf::nTPServers()) - { - stream << "NTP=" << ntp << "\n"; - } + //Add the NTP server + for (const auto& ntp : EthernetInterfaceIntf::nTPServers()) + { + stream << "NTP=" << ntp << "\n"; + } - //Add the DNS entry - for(const auto& dns: EthernetInterfaceIntf::nameservers()) - { - stream << "DNS=" << dns << "\n"; - } + //Add the DNS entry + for (const auto& dns : EthernetInterfaceIntf::nameservers()) + { + stream << "DNS=" << dns << "\n"; + } - // Static - for (const auto& addr : addrs) - { - if (addr.second->origin() == AddressOrigin::Static) + // Static + for (const auto& addr : addrs) { - std::string address = addr.second->address() + "/" + std::to_string( - addr.second->prefixLength()); + if (addr.second->origin() == AddressOrigin::Static) + { + std::string address = addr.second->address() + "/" + + std::to_string(addr.second->prefixLength()); - stream << "Address=" << address << "\n"; - } - } + stream << "Address=" << address << "\n"; + } + } - if (manager.getSystemConf()) - { - stream << "Gateway=" << manager.getSystemConf()->defaultGateway() - << "\n"; - } - // write the route section - stream << "[" << "Route" << "]\n"; - for(const auto& addr : addrs) - { - if (addr.second->origin() == AddressOrigin::Static) + if (manager.getSystemConf()) { - int addressFamily = addr.second->type() == IP::Protocol::IPv4 ? AF_INET : AF_INET6; - std::string destination = getNetworkID( - addressFamily, - addr.second->address(), - addr.second->prefixLength()); - - if (addr.second->gateway() != "0.0.0.0" && - addr.second->gateway() != "" && - destination != "0.0.0.0" && - destination != "") + stream << "Gateway=" << manager.getSystemConf()->defaultGateway() + << "\n"; + } + + // write the route section + stream << "[" << "Route" << "]\n"; + for (const auto& addr : addrs) + { + if (addr.second->origin() == AddressOrigin::Static) { - stream << "Gateway=" << addr.second->gateway() << "\n"; - stream << "Destination=" << destination << "\n"; + int addressFamily = addr.second->type() == IP::Protocol::IPv4 ? + AF_INET : AF_INET6; + + std::string destination = getNetworkID( + addressFamily, + addr.second->address(), + addr.second->prefixLength()); + + if (addr.second->gateway() != "0.0.0.0" && + addr.second->gateway() != "" && + destination != "0.0.0.0" && + destination != "") + { + stream << "Gateway=" << addr.second->gateway() << "\n"; + stream << "Destination=" << destination << "\n"; + } } - } } + auto value = dHCPEnabled() ? "true"s : "false"s; + stream << "DHCP="s + value + "\n"; + + // Write the dhcp section irrespective of whether DHCP is enabled or not + writeDHCPSection(stream); + stream.close(); } void EthernetInterface::writeDHCPSection(std::fstream& stream) { using namespace std::string_literals; - stream << "DHCP=true\n"; // write the dhcp section stream << "[DHCP]\n"; |