diff options
| author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-06-15 08:57:54 +0530 |
|---|---|---|
| committer | Ratan Gupta <ratagupt@in.ibm.com> | 2017-06-21 15:34:19 +0530 |
| commit | ef85eb9c0e1859f8c420e753341a18ddaa2f8cbb (patch) | |
| tree | 713af0e9528027ebcf2f7ef498bc013e9449322c | |
| parent | 82e1ef999fc207b0f307f4161e95d41d3d5f014a (diff) | |
| download | phosphor-networkd-ef85eb9c0e1859f8c420e753341a18ddaa2f8cbb.tar.gz phosphor-networkd-ef85eb9c0e1859f8c420e753341a18ddaa2f8cbb.zip | |
Create the system conf Dbus Object
Also put extra checks while writing the gateway
and the destination to the conf file.
Change-Id: I8f24b3f293e6f978b655f061a198a32690dd44f3
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
| -rw-r--r-- | network_manager.cpp | 41 | ||||
| -rw-r--r-- | network_manager.hpp | 21 | ||||
| -rw-r--r-- | network_manager_main.cpp | 2 | ||||
| -rw-r--r-- | test/Makefile.am | 1 |
4 files changed, 52 insertions, 13 deletions
diff --git a/network_manager.cpp b/network_manager.cpp index a635952..aff86a0 100644 --- a/network_manager.cpp +++ b/network_manager.cpp @@ -8,7 +8,6 @@ #include <algorithm> #include <bitset> -#include <experimental/filesystem> #include <map> #include <fstream> @@ -24,17 +23,25 @@ namespace network { using namespace phosphor::logging; -namespace fs = std::experimental::filesystem; +using namespace sdbusplus::xyz::openbmc_project::Common::Error; Manager::Manager(sdbusplus::bus::bus& bus, const char* objPath): details::VLANCreateIface(bus, objPath, true), bus(bus), objectPath(objPath) { + confDir = NETWORK_CONF_DIR; +} + +void Manager::setConfDir(const fs::path& dir) +{ + confDir = dir; } void Manager::createInterfaces() { + //clear all the interfaces first + interfaces.clear(); auto interfaceInfoList = getInterfaceAddrs(); @@ -56,6 +63,18 @@ void Manager::createInterfaces() } } +void Manager::createChildObjects() +{ + // creates the ethernet interface dbus object. + createInterfaces(); + // create the system conf object. + fs::path objPath = objectPath; + objPath /= "config"; + systemConf = std::make_unique<phosphor::network::SystemConfiguration>( + bus, objPath.string(), *this); + +} + void Manager::vLAN(IntfName interfaceName, uint16_t id) { } @@ -216,7 +235,7 @@ void Manager::writeToConfigurationFile() for (const auto& intf : interfaces) { - fs::path confPath {NETWORK_CONF_DIR}; + fs::path confPath = confDir; std::string fileName = "00-bmc-"s + intf.first + ".network"s; confPath /= fileName; std::fstream stream; @@ -238,12 +257,16 @@ void Manager::writeToConfigurationFile() addr.second->prefixLength()); stream << "Address=" << address << "\n"; - stream << "Gateway=" << addr.second->gateway() << "\n"; + if (addr.second->gateway() != "0.0.0.0" && + addr.second->gateway() != "") + { + stream << "Gateway=" << addr.second->gateway() << "\n"; + } } } - - stream << "Gateway=" << this->defaultGateway << "\n"; + stream << "Gateway=" << systemConf->defaultGateway() << "\n"; + // write the route section stream << "[" << "Route" << "]\n"; for(const auto& addr : addrs) { @@ -255,8 +278,10 @@ void Manager::writeToConfigurationFile() addr.second->address(), addr.second->prefixLength()); - if (addr.second->gateway() != "0.0.0.0" || - addr.second->gateway() != "") + if (addr.second->gateway() != "0.0.0.0" && + addr.second->gateway() != "" && + destination != "0.0.0.0" && + destination != "") { stream << "Gateway=" << addr.second->gateway() << "\n"; diff --git a/network_manager.hpp b/network_manager.hpp index b19ec72..2d4afe7 100644 --- a/network_manager.hpp +++ b/network_manager.hpp @@ -1,6 +1,7 @@ #pragma once #include "ethernet_interface.hpp" +#include "system_configuration.hpp" #include "types.hpp" #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> @@ -12,12 +13,14 @@ #include <memory> #include <string> #include <vector> +#include <experimental/filesystem> namespace phosphor { namespace network { +namespace fs = std::experimental::filesystem; namespace details { @@ -86,11 +89,15 @@ class Manager : public details::VLANCreateIface */ void createInterfaces(); - /** TODO: would remove it once we implement the system - * conf dbus object. - * openbmc/openbmc#1295 + /** @brief create child interface object and the system conf object. */ - std::string defaultGateway; // default gateway + void createChildObjects(); + + /** @brief sets the network conf directory. + * @param[in] dirName - Absolute path of the directory. + */ + void setConfDir(const fs::path& dir); + private: /** @brief Get all the interfaces from the system. * @returns list of interface names. @@ -113,6 +120,12 @@ class Manager : public details::VLANCreateIface /** @brief Path of Object. */ std::string objectPath; + /** @brief pointer to system conf object. */ + std::unique_ptr<SystemConfiguration> systemConf = nullptr; + + /** @brief Network Configuration directory. */ + fs::path confDir; + friend class TestNetworkManager; }; diff --git a/network_manager_main.cpp b/network_manager_main.cpp index a53d32c..d98ab0d 100644 --- a/network_manager_main.cpp +++ b/network_manager_main.cpp @@ -12,7 +12,7 @@ int main(int argc, char *argv[]) phosphor::network::Manager manager(bus, OBJ_NETWORK); - manager.createInterfaces(); + manager.createChildObjects(); bus.request_name(BUSNAME_NETWORK); diff --git a/test/Makefile.am b/test/Makefile.am index 9736ccd..8f951bf 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -31,5 +31,6 @@ test_LDADD = $(top_builddir)/ethernet_interface.cpp \ $(top_builddir)/ipaddress.cpp \ $(top_builddir)/routing_table.cpp \ $(top_builddir)/util.cpp \ + $(top_builddir)/system_configuration.cpp \ $(top_builddir)/xyz/openbmc_project/Network/VLAN/Create/phosphor_network_manager-server.o \ $(top_builddir)/xyz/openbmc_project/Network/IP/Create/phosphor_network_manager-server.o |

