diff options
| author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-06-15 09:16:22 +0530 |
|---|---|---|
| committer | Ratan Gupta <ratagupt@in.ibm.com> | 2017-06-21 15:34:32 +0530 |
| commit | 34f96d6d2c2e293801861265c199f7f68fe5c324 (patch) | |
| tree | e76c6396235beccfe517f7962a87ca7dbb7c10ed | |
| parent | ed123a3a3363144b24c444be5527a3d7b56a72a4 (diff) | |
| download | phosphor-networkd-34f96d6d2c2e293801861265c199f7f68fe5c324.tar.gz phosphor-networkd-34f96d6d2c2e293801861265c199f7f68fe5c324.zip | |
Implement the DHCP support
During creation of ethernet interface dbus object,
read the DHCP from the conf file.
Write the DHCP option in the conf file during
writing the network configuration file.
Change-Id: Ibead1ff91d30d14c475493d1ef2c877d14d0d915
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
| -rw-r--r-- | network_manager.cpp | 43 | ||||
| -rw-r--r-- | network_manager.hpp | 5 |
2 files changed, 46 insertions, 2 deletions
diff --git a/network_manager.cpp b/network_manager.cpp index aff86a0..ee88c3f 100644 --- a/network_manager.cpp +++ b/network_manager.cpp @@ -1,4 +1,5 @@ #include "config.h" +#include "config_parser.hpp" #include "network_manager.hpp" #include "network_config.hpp" #include "xyz/openbmc_project/Common/error.hpp" @@ -50,13 +51,15 @@ void Manager::createInterfaces() fs::path objPath = objectPath; objPath /= intfInfo.first; + auto dhcp = getDHCPValue(intfInfo.first); + this->interfaces.emplace(std::make_pair( intfInfo.first, std::make_unique< phosphor::network::EthernetInterface> (bus, objPath.string(), - false, + dhcp, *this))); interfaces[intfInfo.first]->setAddressList(intfInfo.second); @@ -136,7 +139,6 @@ IntfAddrMap Manager::getInterfaceAddrs() const AddrList addrList{}; struct ifaddrs* ifaddr = nullptr; - using namespace sdbusplus::xyz::openbmc_project::Common::Error; // attempt to fill struct with ifaddrs if (getifaddrs(&ifaddr) == -1) { @@ -249,6 +251,17 @@ void Manager::writeToConfigurationFile() // write the network section stream << "[" << "Network" << "]\n"; + // DHCP + if (intf.second->dHCPEnabled() == true) + { + stream << "DHCP=true\n"; + // write the dhcp section + stream << "[DHCP]\n"; + stream << "ClientIdentifier=mac\n"; + stream.close(); + continue; + } + // Static for (const auto& addr : addrs) { if (addr.second->origin() == AddressOrigin::Static) @@ -312,5 +325,31 @@ void Manager::restartSystemdNetworkd() bus.call_noreply(method); } +bool Manager::getDHCPValue(const std::string& intf) +{ + bool dhcp = false; + // Get the interface mode value from systemd conf + using namespace std::string_literals; + fs::path confPath = confDir; + std::string fileName = "00-bmc-"s + intf + ".network"s; + confPath /= fileName; + + try + { + config::Parser parser(confPath.string()); + auto values = parser.getValues("Network","DHCP"); + // There will be only single value for DHCP key. + if (values[0] == "true") + { + dhcp = true; + } + } + catch (InternalFailure& e) + { + commit<InternalFailure>(); + } + return dhcp; +} + }//namespace network }//namespace phosphor diff --git a/network_manager.hpp b/network_manager.hpp index 2d4afe7..5c6358b 100644 --- a/network_manager.hpp +++ b/network_manager.hpp @@ -117,6 +117,11 @@ class Manager : public details::VLANCreateIface /** @brief BMC network reset - resets network configuration for BMC. */ void reset() override; + /** @brief read the DHCP value from the configuration file + * @param[in] intf - Interface name. + */ + bool getDHCPValue(const std::string& intf); + /** @brief Path of Object. */ std::string objectPath; |

