From 87a65e63bac789bca0607e0b4ab09d62517b95e7 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Wed, 29 May 2019 10:29:58 -0700 Subject: Update to internal Signed-off-by: Ed Tanous --- ...ep-consistent-MAC-and-IP-address-inbetwee.patch | 456 --------------------- ...Pv6-Network-changes-to-configuration-file.patch | 68 ++- ...ing-channel-specific-privilege-to-network.patch | 452 ++------------------ .../network/phosphor-network_%.bbappend | 4 +- .../recipes-network/network/static-mac-addr.bb | 24 ++ .../network/static-mac-addr/mac-check | 78 ++++ .../static-mac-addr/static-mac-addr.service | 11 + 7 files changed, 176 insertions(+), 917 deletions(-) delete mode 100644 meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0001-Patch-to-keep-consistent-MAC-and-IP-address-inbetwee.patch mode change 100755 => 100644 meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0003-Adding-channel-specific-privilege-to-network.patch create mode 100644 meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr.bb create mode 100644 meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check create mode 100644 meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/static-mac-addr.service (limited to 'meta-openbmc-mods/meta-common/recipes-network/network') diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0001-Patch-to-keep-consistent-MAC-and-IP-address-inbetwee.patch b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0001-Patch-to-keep-consistent-MAC-and-IP-address-inbetwee.patch deleted file mode 100644 index 03460302d..000000000 --- a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0001-Patch-to-keep-consistent-MAC-and-IP-address-inbetwee.patch +++ /dev/null @@ -1,456 +0,0 @@ -From 15f9ba436815307c1df7ace505e6f6ee04a4762b Mon Sep 17 00:00:00 2001 -From: David Cobbley -Date: Thu, 8 Mar 2018 12:18:00 -0800 -Subject: [PATCH 1/3] Patch to keep consistent MAC and IP address inbetween - power cycles - -Currently, your mac will reset upon AC cycle unless you ask systemd use -a MAC provided in your network configuration file. This will write your -randomly generate MAC to the config file upond first boot up. - -Change-Id: Id47d24c62e459cde101add18be2f46c0b010e7fe -Signed-off-by: David Cobbley -Signed-off-by: James Feist ---- - ethernet_interface.cpp | 4 +- - ethernet_interface.hpp | 360 +++++++++++++++++++++-------------------- - network_config.cpp | 22 +-- - 3 files changed, 195 insertions(+), 191 deletions(-) - -diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp -index 3fd7835..fd09b7a 100644 ---- a/ethernet_interface.cpp -+++ b/ethernet_interface.cpp -@@ -200,8 +200,8 @@ InterfaceInfo EthernetInterface::getInterfaceInfo() const - * @return macaddress on success - */ - --std::string -- EthernetInterface::getMACAddress(const std::string& interfaceName) const -+std::string EthernetInterface::getMACAddress( -+ const std::string& interfaceName) - { - ifreq ifr{}; - char macAddress[mac_address::size]{}; -diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp -index bfe1d54..d62ca34 100644 ---- a/ethernet_interface.hpp -+++ b/ethernet_interface.hpp -@@ -59,185 +59,187 @@ using VlanInterfaceMap = - */ - class EthernetInterface : public Ifaces - { -- public: -- EthernetInterface() = delete; -- EthernetInterface(const EthernetInterface&) = delete; -- EthernetInterface& operator=(const EthernetInterface&) = delete; -- EthernetInterface(EthernetInterface&&) = delete; -- EthernetInterface& operator=(EthernetInterface&&) = delete; -- virtual ~EthernetInterface() = default; -- -- /** @brief Constructor to put object onto bus at a dbus path. -- * @param[in] bus - Bus to attach to. -- * @param[in] objPath - Path to attach at. -- * @param[in] dhcpEnabled - is dhcp enabled(true/false). -- * @param[in] parent - parent object. -- * @param[in] emitSignal - true if the object added signal needs to be -- * send. -- */ -- EthernetInterface(sdbusplus::bus::bus& bus, const std::string& objPath, -- bool dhcpEnabled, Manager& parent, -- bool emitSignal = true); -- -- /** @brief Function to create ipaddress dbus object. -- * @param[in] addressType - Type of ip address. -- * @param[in] ipaddress- IP address. -- * @param[in] prefixLength - Length of prefix. -- * @param[in] gateway - Gateway ip address. -- */ -- -- void iP(IP::Protocol addressType, std::string ipaddress, -- uint8_t prefixLength, std::string gateway) override; -- -- /* @brief delete the dbus object of the given ipaddress. -- * @param[in] ipaddress - IP address. -- */ -- void deleteObject(const std::string& ipaddress); -- -- /* @brief delete the vlan dbus object of the given interface. -- * Also deletes the device file and the network file. -- * @param[in] interface - VLAN Interface. -- */ -- void deleteVLANObject(const std::string& interface); -- -- /* @brief creates the dbus object(IPaddres) given in the address list. -- * @param[in] addrs - address list for which dbus objects needs -- * to create. -- */ -- void createIPAddressObjects(); -- -- /* @brief Gets all the ip addresses. -- * @returns the list of ipaddress. -- */ -- const AddressMap& getAddresses() const -- { -- return addrs; -- } -- -- /** Set value of DHCPEnabled */ -- bool dHCPEnabled(bool value) override; -- -- /** @brief sets the MAC address. -- * @param[in] value - MAC address which needs to be set on the system. -- * @returns macAddress of the interface or throws an error. -- */ -- std::string mACAddress(std::string value) override; -- -- /** @brief sets the NTP servers. -- * @param[in] value - vector of NTP servers. -- */ -- ServerList nTPServers(ServerList value) override; -- -- /** @brief sets the DNS/nameservers. -- * @param[in] value - vector of DNS servers. -- */ -- ServerList nameservers(ServerList value) override; -- -- /** @brief create Vlan interface. -- * @param[in] id- VLAN identifier. -- */ -- void createVLAN(VlanId id); -- -- /** @brief load the vlan info from the system -- * and creates the ip address dbus objects. -- * @param[in] vlanID- VLAN identifier. -- */ -- void loadVLAN(VlanId vlanID); -- -- /** @brief write the network conf file with the in-memory objects. -- */ -- void writeConfigurationFile(); -- -- /** @brief delete all dbus objects. -- */ -- void deleteAll(); -- -- using EthernetInterfaceIntf::dHCPEnabled; -- using EthernetInterfaceIntf::interfaceName; -- using MacAddressIntf::mACAddress; -- -- /** @brief Absolute path of the resolv conf file */ -- static constexpr auto resolvConfFile = "/etc/resolv.conf"; -- -- protected: -- /** @brief get the info of the ethernet interface. -- * @return tuple having the link speed,autonegotiation,duplexmode . -- */ -- InterfaceInfo getInterfaceInfo() const; -- -- /* @brief delete the vlan interface from system. -- * @param[in] interface - vlan Interface. -- */ -- void deleteVLANFromSystem(const std::string& interface); -- -- /** @brief get the mac address of the interface. -- * @param[in] interfaceName - Network interface name. -- * @return macaddress on success -- */ -- -- std::string getMACAddress(const std::string& interfaceName) const; -- -- /** @brief construct the ip address dbus object path. -- * @param[in] addressType - Type of ip address. -- * @param[in] ipaddress - IP address. -- * @param[in] prefixLength - Length of prefix. -- * @param[in] gateway - Gateway address. -- -- * @return path of the address object. -- */ -- -- std::string generateObjectPath(IP::Protocol addressType, -- const std::string& ipaddress, -- uint8_t prefixLength, -- const std::string& gateway) const; -- -- /** @brief generates the id by doing hash of ipaddress, -- * prefixlength and the gateway. -- * @param[in] ipaddress - IP address. -- * @param[in] prefixLength - Length of prefix. -- * @param[in] gateway - Gateway address. -- * @return hash string. -- */ -- -- static std::string generateId(const std::string& ipaddress, -- uint8_t prefixLength, -- const std::string& gateway); -- -- /** @brief write the dhcp section **/ -- void writeDHCPSection(std::fstream& stream); -- -- /** @brief get the NTP server list from the network conf -- * -- */ -- ServerList getNTPServersFromConf(); -- -- /** @brief write the DNS entries to resolver file. -- * @param[in] dnsList - DNS server list which needs to be written. -- * @param[in] file - File to write the name server entries to. -- */ -- void writeDNSEntries(const ServerList& dnsList, const std::string& file); -- -- /** @brief get the name server details from the network conf -- * -- */ -- ServerList getNameServerFromConf(); -- -- /** @brief Persistent sdbusplus DBus bus connection. */ -- sdbusplus::bus::bus& bus; -- -- /** @brief Network Manager object. */ -- Manager& manager; -- -- /** @brief Persistent map of IPAddress dbus objects and their names */ -- AddressMap addrs; -- -- /** @brief Persistent map of VLAN interface dbus objects and their names */ -- VlanInterfaceMap vlanInterfaces; -- -- /** @brief Dbus object path */ -- std::string objPath; -- -- friend class TestEthernetInterface; -+ public: -+ EthernetInterface() = delete; -+ EthernetInterface(const EthernetInterface&) = delete; -+ EthernetInterface& operator=(const EthernetInterface&) = delete; -+ EthernetInterface(EthernetInterface&&) = delete; -+ EthernetInterface& operator=(EthernetInterface&&) = delete; -+ virtual ~EthernetInterface() = default; -+ -+ /** @brief Constructor to put object onto bus at a dbus path. -+ * @param[in] bus - Bus to attach to. -+ * @param[in] objPath - Path to attach at. -+ * @param[in] dhcpEnabled - is dhcp enabled(true/false). -+ * @param[in] parent - parent object. -+ * @param[in] emitSignal - true if the object added signal needs to be -+ * send. -+ */ -+ EthernetInterface(sdbusplus::bus::bus& bus, -+ const std::string& objPath, -+ bool dhcpEnabled, -+ Manager& parent, -+ bool emitSignal = true); -+ -+ /** @brief Function to create ipaddress dbus object. -+ * @param[in] addressType - Type of ip address. -+ * @param[in] ipaddress- IP address. -+ * @param[in] prefixLength - Length of prefix. -+ * @param[in] gateway - Gateway ip address. -+ */ -+ -+ void iP(IP::Protocol addressType, -+ std::string ipaddress, -+ uint8_t prefixLength, -+ std::string gateway) override; -+ -+ /* @brief delete the dbus object of the given ipaddress. -+ * @param[in] ipaddress - IP address. -+ */ -+ void deleteObject(const std::string& ipaddress); -+ -+ /* @brief delete the vlan dbus object of the given interface. -+ * Also deletes the device file and the network file. -+ * @param[in] interface - VLAN Interface. -+ */ -+ void deleteVLANObject(const std::string& interface); -+ -+ /* @brief creates the dbus object(IPaddres) given in the address list. -+ * @param[in] addrs - address list for which dbus objects needs -+ * to create. -+ */ -+ void createIPAddressObjects(); -+ -+ /* @brief Gets all the ip addresses. -+ * @returns the list of ipaddress. -+ */ -+ const AddressMap& getAddresses() const { return addrs; } -+ -+ /** Set value of DHCPEnabled */ -+ bool dHCPEnabled(bool value) override; -+ -+ /** @brief sets the MAC address. -+ * @param[in] value - MAC address which needs to be set on the system. -+ * @returns macAddress of the interface or throws an error. -+ */ -+ std::string mACAddress(std::string value) override; -+ -+ /** @brief sets the NTP servers. -+ * @param[in] value - vector of NTP servers. -+ */ -+ ServerList nTPServers(ServerList value) override; -+ -+ /** @brief sets the DNS/nameservers. -+ * @param[in] value - vector of DNS servers. -+ */ -+ ServerList nameservers(ServerList value) override; -+ -+ /** @brief create Vlan interface. -+ * @param[in] id- VLAN identifier. -+ */ -+ void createVLAN(VlanId id); -+ -+ /** @brief load the vlan info from the system -+ * and creates the ip address dbus objects. -+ * @param[in] vlanID- VLAN identifier. -+ */ -+ void loadVLAN(VlanId vlanID); -+ -+ /** @brief write the network conf file with the in-memory objects. -+ */ -+ void writeConfigurationFile(); -+ -+ /** @brief delete all dbus objects. -+ */ -+ void deleteAll(); -+ -+ /** @brief get the mac address of the interface. -+ * @param[in] interfaceName - Network interface name. -+ * @return macaddress on success -+ */ -+ -+ static std::string getMACAddress(const std::string& interfaceName); -+ -+ using EthernetInterfaceIntf::dHCPEnabled; -+ using EthernetInterfaceIntf::interfaceName; -+ using MacAddressIntf::mACAddress; -+ -+ /** @brief Absolute path of the resolv conf file */ -+ static constexpr auto resolvConfFile = "/etc/resolv.conf"; -+ -+ protected: -+ /** @brief get the info of the ethernet interface. -+ * @return tuple having the link speed,autonegotiation,duplexmode . -+ */ -+ InterfaceInfo getInterfaceInfo() const; -+ -+ /* @brief delete the vlan interface from system. -+ * @param[in] interface - vlan Interface. -+ */ -+ void deleteVLANFromSystem(const std::string& interface); -+ -+ /** @brief construct the ip address dbus object path. -+ * @param[in] addressType - Type of ip address. -+ * @param[in] ipaddress - IP address. -+ * @param[in] prefixLength - Length of prefix. -+ * @param[in] gateway - Gateway address. -+ -+ * @return path of the address object. -+ */ -+ -+ std::string generateObjectPath(IP::Protocol addressType, -+ const std::string& ipaddress, -+ uint8_t prefixLength, -+ const std::string& gateway) const; -+ -+ /** @brief generates the id by doing hash of ipaddress, -+ * prefixlength and the gateway. -+ * @param[in] ipaddress - IP address. -+ * @param[in] prefixLength - Length of prefix. -+ * @param[in] gateway - Gateway address. -+ * @return hash string. -+ */ -+ -+ static std::string generateId(const std::string& ipaddress, -+ uint8_t prefixLength, -+ const std::string& gateway); -+ -+ /** @brief write the dhcp section **/ -+ void writeDHCPSection(std::fstream& stream);; -+ -+ /** @brief get the NTP server list from the network conf -+ * -+ */ -+ ServerList getNTPServersFromConf(); -+ -+ /** @brief write the DNS entries to resolver file. -+ * @param[in] dnsList - DNS server list which needs to be written. -+ * @param[in] file - File to write the name server entries to. -+ */ -+ void writeDNSEntries(const ServerList& dnsList, -+ const std::string& file); -+ -+ /** @brief get the name server details from the network conf -+ * -+ */ -+ ServerList getNameServerFromConf(); -+ -+ /** @brief Persistent sdbusplus DBus bus connection. */ -+ sdbusplus::bus::bus& bus; -+ -+ /** @brief Network Manager object. */ -+ Manager& manager; -+ -+ /** @brief Persistent map of IPAddress dbus objects and their names */ -+ AddressMap addrs; -+ -+ /** @brief Persistent map of VLAN interface dbus objects and their names */ -+ VlanInterfaceMap vlanInterfaces; -+ -+ /** @brief Dbus object path */ -+ std::string objPath; -+ -+ friend class TestEthernetInterface; - }; - - } // namespace network -diff --git a/network_config.cpp b/network_config.cpp -index e83b16c..8ebad54 100644 ---- a/network_config.cpp -+++ b/network_config.cpp -@@ -1,3 +1,5 @@ -+#include "network_config.hpp" -+#include "ethernet_interface.hpp" - #include "config.h" - - #include "network_config.hpp" -@@ -5,27 +7,27 @@ - #include - #include - --namespace phosphor --{ --namespace network --{ -+namespace phosphor { -+namespace network { - --namespace bmc --{ --void writeDHCPDefault(const std::string& filename, const std::string& interface) -+namespace bmc { -+void writeDHCPDefault(const std::string &filename, const std::string &interface) - { -+ - std::ofstream filestream; - - filestream.open(filename); - filestream << "[Match]\nName=" << interface << -- "\n[Network]\nDHCP=true\n" -+ "\n[Network]\nDHCP=true\n" - #ifdef LINK_LOCAL_AUTOCONFIGURATION - "LinkLocalAddressing=yes\n" - #else - "LinkLocalAddressing=no\n" - #endif -- "IPv6AcceptRA=false\n" -- "[DHCP]\nClientIdentifier=mac\n"; -+ "IPv6AcceptRA=false\n" -+ "[DHCP]\nClientIdentifier=mac\n" -+ "[Link]\nMACAddress=" -+ << EthernetInterface::getMACAddress(interface) << "\n"; - filestream.close(); - } - } // namespace bmc --- -2.17.1 - diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0002-IPv6-Network-changes-to-configuration-file.patch b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0002-IPv6-Network-changes-to-configuration-file.patch index 251f68319..b46702902 100644 --- a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0002-IPv6-Network-changes-to-configuration-file.patch +++ b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0002-IPv6-Network-changes-to-configuration-file.patch @@ -1,19 +1,19 @@ -From ebb359773b8a5c03a25c3a48c5080bb246c07c71 Mon Sep 17 00:00:00 2001 +From 53dbefc9f31dcfca06d7c7705ea3dcfc5e93ae72 Mon Sep 17 00:00:00 2001 From: David Cobbley Date: Wed, 6 Jun 2018 11:11:43 -0700 -Subject: [PATCH 2/3] IPv6 Network changes to configuration file +Subject: [PATCH 1/2] IPv6 Network changes to configuration file Allow Additional parameters to be set for IPv6 Change-Id: If662f1ce2d265bc525073890c49231bf6f2b8a30 --- ethernet_interface.cpp | 109 +++++++++++++++++++++++++++++++++++++++-- - ethernet_interface.hpp | 19 ++++++- + ethernet_interface.hpp | 17 +++++++ util.cpp | 3 +- - 3 files changed, 124 insertions(+), 7 deletions(-) + 3 files changed, 123 insertions(+), 6 deletions(-) diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp -index fd09b7a..63f1160 100644 +index 154efcb..aa1c895 100644 --- a/ethernet_interface.cpp +++ b/ethernet_interface.cpp @@ -46,6 +46,8 @@ EthernetInterface::EthernetInterface(sdbusplus::bus::bus& bus, @@ -25,7 +25,7 @@ index fd09b7a..63f1160 100644 MacAddressIntf::mACAddress(getMACAddress(intfName)); EthernetInterfaceIntf::nTPServers(getNTPServersFromConf()); EthernetInterfaceIntf::nameservers(getNameServerFromConf()); -@@ -322,7 +324,16 @@ std::string EthernetInterface::generateObjectPath( +@@ -329,7 +331,16 @@ std::string EthernetInterface::generateObjectPath( objectPath /= generateId(ipaddress, prefixLength, gateway); return objectPath.string(); } @@ -43,9 +43,9 @@ index fd09b7a..63f1160 100644 bool EthernetInterface::dHCPEnabled(bool value) { if (value == EthernetInterfaceIntf::dHCPEnabled()) -@@ -433,7 +444,80 @@ void EthernetInterface::createVLAN(VlanId id) - // write the new vlan device entry to the configuration(network) file. - manager.writeToConfigurationFile(); +@@ -442,7 +453,80 @@ ObjectPath EthernetInterface::createVLAN(VlanId id) + + return path; } +bool EthernetInterface::getIPv6AcceptRAFromConf() +{ @@ -124,7 +124,7 @@ index fd09b7a..63f1160 100644 ServerList EthernetInterface::getNTPServersFromConf() { fs::path confPath = manager.getConfDir(); -@@ -515,7 +599,8 @@ void EthernetInterface::writeConfigurationFile() +@@ -524,7 +608,8 @@ void EthernetInterface::writeConfigurationFile() #else stream << "LinkLocalAddressing=no\n"; #endif @@ -134,7 +134,7 @@ index fd09b7a..63f1160 100644 // Add the VLAN entry for (const auto& intf : vlanInterfaces) -@@ -524,8 +609,24 @@ void EthernetInterface::writeConfigurationFile() +@@ -533,8 +618,24 @@ void EthernetInterface::writeConfigurationFile() << "\n"; } // Add the DHCP entry @@ -162,40 +162,38 @@ index fd09b7a..63f1160 100644 // When the interface configured as dhcp, we don't need below given entries // in config file. diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp -index d62ca34..7116b47 100644 +index c65726a..55fd7d9 100644 --- a/ethernet_interface.hpp +++ b/ethernet_interface.hpp -@@ -205,7 +205,24 @@ class EthernetInterface : public Ifaces - const std::string& gateway); +@@ -207,6 +207,23 @@ class EthernetInterface : public Ifaces + /** @brief write the dhcp section **/ + void writeDHCPSection(std::fstream& stream); - /** @brief write the dhcp section **/ -- void writeDHCPSection(std::fstream& stream);; -+ void writeDHCPSection(std::fstream& stream); ++ /** @brief get the IPv6AcceptRA flag from the network configuration file ++ * ++ */ ++ bool getIPv6AcceptRAFromConf(); + -+ /** @brief get the IPv6AcceptRA flag from the network configuration file -+ * -+ */ -+ bool getIPv6AcceptRAFromConf(); ++ /** @brief check conf file for Router Advertisements ++ * ++ */ ++ bool iPv6AcceptRA(bool value) override; + -+ /** @brief check conf file for Router Advertisements -+ * -+ */ -+ bool iPv6AcceptRA(bool value) override; ++ /** @brief get the allowed network modes. Similar to DHCP enabled, but ++ * more specific ++ */ ++ IPAllowed getIPAddressEnablesFromConf(); + -+ /** @brief get the allowed network modes. Similar to DHCP enabled, but -+ * more specific -+ */ -+ IPAllowed getIPAddressEnablesFromConf(); ++ IPAllowed iPAddressEnables(IPAllowed) override; + -+ IPAllowed iPAddressEnables(IPAllowed) override; - - /** @brief get the NTP server list from the network conf - * + /** @brief get the NTP server list from the network conf + * + */ diff --git a/util.cpp b/util.cpp -index b66f908..9f06e2e 100644 +index 6bc1497..6c60d54 100644 --- a/util.cpp +++ b/util.cpp -@@ -405,8 +405,7 @@ bool getDHCPValue(const std::string& confDir, const std::string& intf) +@@ -461,8 +461,7 @@ bool getDHCPValue(const std::string& confDir, const std::string& intf) entry("RC=%d", rc)); return dhcp; } diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0003-Adding-channel-specific-privilege-to-network.patch b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0003-Adding-channel-specific-privilege-to-network.patch old mode 100755 new mode 100644 index 4610b8b32..79e8d96cc --- a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0003-Adding-channel-specific-privilege-to-network.patch +++ b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network/0003-Adding-channel-specific-privilege-to-network.patch @@ -1,7 +1,7 @@ -From 64fff77b31de705a42c5061e9d14946255c6aca1 Mon Sep 17 00:00:00 2001 +From f28e3694f4b15c6eee58733f57213d360fc5ac7a Mon Sep 17 00:00:00 2001 From: AppaRao Puli Date: Wed, 5 Sep 2018 14:16:54 +0530 -Subject: [PATCH] Adding channel specific privilege to network +Subject: [PATCH 2/2] Adding channel specific privilege to network - Adding the channel access information to the network interface object. This privilege will be used in @@ -18,14 +18,14 @@ Change-Id: I3b592a19363eef684e31d5f7c34dad8f2f9211df Signed-off-by: AppaRao Puli Signed-off-by: Yong Li --- - ethernet_interface.cpp | 119 +++++++++++++- - ethernet_interface.hpp | 433 ++++++++++++++++++++++++++----------------------- - network_manager.cpp | 104 ++++++++++++ - network_manager.hpp | 9 + - 4 files changed, 464 insertions(+), 201 deletions(-) + ethernet_interface.cpp | 116 +++++++++++++++++++++++++++++++++++++++++ + ethernet_interface.hpp | 39 +++++++++++++- + network_manager.cpp | 104 ++++++++++++++++++++++++++++++++++++ + network_manager.hpp | 9 ++++ + 4 files changed, 267 insertions(+), 1 deletion(-) diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp -index 9437b4c..6d23b3d 100644 +index aa1c895..e3ea33c 100644 --- a/ethernet_interface.cpp +++ b/ethernet_interface.cpp @@ -35,6 +35,9 @@ using namespace phosphor::logging; @@ -46,17 +46,7 @@ index 9437b4c..6d23b3d 100644 // Emit deferred signal. if (emitSignal) -@@ -208,8 +212,7 @@ InterfaceInfo EthernetInterface::getInterfaceInfo() const - * @return macaddress on success - */ - --std::string EthernetInterface::getMACAddress( -- const std::string& interfaceName) -+std::string EthernetInterface::getMACAddress(const std::string& interfaceName) - { - ifreq ifr{}; - char macAddress[mac_address::size]{}; -@@ -829,5 +832,117 @@ void EthernetInterface::deleteAll() +@@ -837,5 +841,117 @@ void EthernetInterface::deleteAll() manager.writeToConfigurationFile(); } @@ -175,7 +165,7 @@ index 9437b4c..6d23b3d 100644 } // namespace network } // namespace phosphor diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp -index 7116b47..7b1da9a 100644 +index 55fd7d9..7bf93a6 100644 --- a/ethernet_interface.hpp +++ b/ethernet_interface.hpp @@ -2,10 +2,13 @@ @@ -202,7 +192,7 @@ index 7116b47..7b1da9a 100644 using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; -@@ -29,9 +33,14 @@ using EthernetInterfaceIntf = +@@ -29,10 +33,15 @@ using EthernetInterfaceIntf = sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface; using MacAddressIntf = sdbusplus::xyz::openbmc_project::Network::server::MACAddress; @@ -210,6 +200,7 @@ index 7116b47..7b1da9a 100644 + sdbusplus::xyz::openbmc_project::Channel::server::ChannelAccess; using ServerList = std::vector; + using ObjectPath = sdbusplus::message::object_path; +using DbusVariant = + sdbusplus::message::variant>; @@ -217,308 +208,10 @@ index 7116b47..7b1da9a 100644 namespace fs = std::experimental::filesystem; class Manager; // forward declaration of network manager. -@@ -59,204 +68,230 @@ using VlanInterfaceMap = - */ - class EthernetInterface : public Ifaces - { -- public: -- EthernetInterface() = delete; -- EthernetInterface(const EthernetInterface&) = delete; -- EthernetInterface& operator=(const EthernetInterface&) = delete; -- EthernetInterface(EthernetInterface&&) = delete; -- EthernetInterface& operator=(EthernetInterface&&) = delete; -- virtual ~EthernetInterface() = default; -- -- /** @brief Constructor to put object onto bus at a dbus path. -- * @param[in] bus - Bus to attach to. -- * @param[in] objPath - Path to attach at. -- * @param[in] dhcpEnabled - is dhcp enabled(true/false). -- * @param[in] parent - parent object. -- * @param[in] emitSignal - true if the object added signal needs to be -- * send. -- */ -- EthernetInterface(sdbusplus::bus::bus& bus, -- const std::string& objPath, -- bool dhcpEnabled, -- Manager& parent, -- bool emitSignal = true); -- -- /** @brief Function to create ipaddress dbus object. -- * @param[in] addressType - Type of ip address. -- * @param[in] ipaddress- IP address. -- * @param[in] prefixLength - Length of prefix. -- * @param[in] gateway - Gateway ip address. -- */ -- -- void iP(IP::Protocol addressType, -- std::string ipaddress, -- uint8_t prefixLength, -- std::string gateway) override; -- -- /* @brief delete the dbus object of the given ipaddress. -- * @param[in] ipaddress - IP address. -- */ -- void deleteObject(const std::string& ipaddress); -- -- /* @brief delete the vlan dbus object of the given interface. -- * Also deletes the device file and the network file. -- * @param[in] interface - VLAN Interface. -- */ -- void deleteVLANObject(const std::string& interface); -- -- /* @brief creates the dbus object(IPaddres) given in the address list. -- * @param[in] addrs - address list for which dbus objects needs -- * to create. -- */ -- void createIPAddressObjects(); -- -- /* @brief Gets all the ip addresses. -- * @returns the list of ipaddress. -- */ -- const AddressMap& getAddresses() const { return addrs; } -- -- /** Set value of DHCPEnabled */ -- bool dHCPEnabled(bool value) override; -- -- /** @brief sets the MAC address. -- * @param[in] value - MAC address which needs to be set on the system. -- * @returns macAddress of the interface or throws an error. -- */ -- std::string mACAddress(std::string value) override; -- -- /** @brief sets the NTP servers. -- * @param[in] value - vector of NTP servers. -- */ -- ServerList nTPServers(ServerList value) override; -- -- /** @brief sets the DNS/nameservers. -- * @param[in] value - vector of DNS servers. -- */ -- ServerList nameservers(ServerList value) override; -- -- /** @brief create Vlan interface. -- * @param[in] id- VLAN identifier. -- */ -- void createVLAN(VlanId id); -- -- /** @brief load the vlan info from the system -- * and creates the ip address dbus objects. -- * @param[in] vlanID- VLAN identifier. -- */ -- void loadVLAN(VlanId vlanID); -- -- /** @brief write the network conf file with the in-memory objects. -- */ -- void writeConfigurationFile(); -- -- /** @brief delete all dbus objects. -- */ -- void deleteAll(); -- -- /** @brief get the mac address of the interface. -- * @param[in] interfaceName - Network interface name. -- * @return macaddress on success -- */ -- -- static std::string getMACAddress(const std::string& interfaceName); -- -- using EthernetInterfaceIntf::dHCPEnabled; -- using EthernetInterfaceIntf::interfaceName; -- using MacAddressIntf::mACAddress; -- -- /** @brief Absolute path of the resolv conf file */ -- static constexpr auto resolvConfFile = "/etc/resolv.conf"; -- -- protected: -- /** @brief get the info of the ethernet interface. -- * @return tuple having the link speed,autonegotiation,duplexmode . -- */ -- InterfaceInfo getInterfaceInfo() const; -- -- /* @brief delete the vlan interface from system. -- * @param[in] interface - vlan Interface. -- */ -- void deleteVLANFromSystem(const std::string& interface); -- -- /** @brief construct the ip address dbus object path. -- * @param[in] addressType - Type of ip address. -- * @param[in] ipaddress - IP address. -- * @param[in] prefixLength - Length of prefix. -- * @param[in] gateway - Gateway address. -- -- * @return path of the address object. -- */ -- -- std::string generateObjectPath(IP::Protocol addressType, -- const std::string& ipaddress, -- uint8_t prefixLength, -- const std::string& gateway) const; -- -- /** @brief generates the id by doing hash of ipaddress, -- * prefixlength and the gateway. -- * @param[in] ipaddress - IP address. -- * @param[in] prefixLength - Length of prefix. -- * @param[in] gateway - Gateway address. -- * @return hash string. -- */ -- -- static std::string generateId(const std::string& ipaddress, -- uint8_t prefixLength, -- const std::string& gateway); -- -- /** @brief write the dhcp section **/ -- void writeDHCPSection(std::fstream& stream); -- -- /** @brief get the IPv6AcceptRA flag from the network configuration file -- * -- */ -- bool getIPv6AcceptRAFromConf(); -- -- /** @brief check conf file for Router Advertisements -- * -- */ -- bool iPv6AcceptRA(bool value) override; -- -- /** @brief get the allowed network modes. Similar to DHCP enabled, but -- * more specific -- */ -- IPAllowed getIPAddressEnablesFromConf(); -- -- IPAllowed iPAddressEnables(IPAllowed) override; -- -- /** @brief get the NTP server list from the network conf -- * -- */ -- ServerList getNTPServersFromConf(); -- -- /** @brief write the DNS entries to resolver file. -- * @param[in] dnsList - DNS server list which needs to be written. -- * @param[in] file - File to write the name server entries to. -- */ -- void writeDNSEntries(const ServerList& dnsList, -- const std::string& file); -- -- /** @brief get the name server details from the network conf -- * -- */ -- ServerList getNameServerFromConf(); -- -- /** @brief Persistent sdbusplus DBus bus connection. */ -- sdbusplus::bus::bus& bus; -- -- /** @brief Network Manager object. */ -- Manager& manager; -- -- /** @brief Persistent map of IPAddress dbus objects and their names */ -- AddressMap addrs; -- -- /** @brief Persistent map of VLAN interface dbus objects and their names */ -- VlanInterfaceMap vlanInterfaces; -- -- /** @brief Dbus object path */ -- std::string objPath; -- -- friend class TestEthernetInterface; -+ public: -+ EthernetInterface() = delete; -+ EthernetInterface(const EthernetInterface&) = delete; -+ EthernetInterface& operator=(const EthernetInterface&) = delete; -+ EthernetInterface(EthernetInterface&&) = delete; -+ EthernetInterface& operator=(EthernetInterface&&) = delete; -+ virtual ~EthernetInterface() = default; -+ -+ /** @brief Constructor to put object onto bus at a dbus path. -+ * @param[in] bus - Bus to attach to. -+ * @param[in] objPath - Path to attach at. -+ * @param[in] dhcpEnabled - is dhcp enabled(true/false). -+ * @param[in] parent - parent object. -+ * @param[in] emitSignal - true if the object added signal needs to be -+ * send. -+ */ -+ EthernetInterface(sdbusplus::bus::bus& bus, const std::string& objPath, -+ bool dhcpEnabled, Manager& parent, -+ bool emitSignal = true); -+ -+ /** @brief Function to create ipaddress dbus object. -+ * @param[in] addressType - Type of ip address. -+ * @param[in] ipaddress- IP address. -+ * @param[in] prefixLength - Length of prefix. -+ * @param[in] gateway - Gateway ip address. -+ */ -+ -+ void iP(IP::Protocol addressType, std::string ipaddress, -+ uint8_t prefixLength, std::string gateway) override; -+ -+ /* @brief delete the dbus object of the given ipaddress. -+ * @param[in] ipaddress - IP address. -+ */ -+ void deleteObject(const std::string& ipaddress); -+ -+ /* @brief delete the vlan dbus object of the given interface. -+ * Also deletes the device file and the network file. -+ * @param[in] interface - VLAN Interface. -+ */ -+ void deleteVLANObject(const std::string& interface); -+ -+ /* @brief creates the dbus object(IPaddres) given in the address list. -+ * @param[in] addrs - address list for which dbus objects needs -+ * to create. -+ */ -+ void createIPAddressObjects(); -+ -+ /* @brief Gets all the ip addresses. -+ * @returns the list of ipaddress. -+ */ -+ const AddressMap& getAddresses() const -+ { -+ return addrs; -+ } -+ -+ /** Set value of DHCPEnabled */ -+ bool dHCPEnabled(bool value) override; -+ -+ /** @brief sets the MAC address. -+ * @param[in] value - MAC address which needs to be set on the system. -+ * @returns macAddress of the interface or throws an error. -+ */ -+ std::string mACAddress(std::string value) override; -+ -+ /** @brief sets the NTP servers. -+ * @param[in] value - vector of NTP servers. -+ */ -+ ServerList nTPServers(ServerList value) override; -+ -+ /** @brief sets the DNS/nameservers. -+ * @param[in] value - vector of DNS servers. -+ */ -+ ServerList nameservers(ServerList value) override; -+ -+ /** @brief create Vlan interface. -+ * @param[in] id- VLAN identifier. -+ */ -+ void createVLAN(VlanId id); -+ -+ /** @brief load the vlan info from the system -+ * and creates the ip address dbus objects. -+ * @param[in] vlanID- VLAN identifier. -+ */ -+ void loadVLAN(VlanId vlanID); -+ -+ /** @brief write the network conf file with the in-memory objects. -+ */ -+ void writeConfigurationFile(); -+ -+ /** @brief delete all dbus objects. -+ */ -+ void deleteAll(); -+ -+ /** @brief get the mac address of the interface. -+ * @param[in] interfaceName - Network interface name. -+ * @return macaddress on success -+ */ -+ -+ static std::string getMACAddress(const std::string& interfaceName); -+ +@@ -153,6 +162,14 @@ class EthernetInterface : public Ifaces + */ + void deleteAll(); + + /** @brief sets the channel maxium privilege. + * @param[in] value - Channel privilege which needs to be set on the + * system. @@ -527,102 +220,13 @@ index 7116b47..7b1da9a 100644 + std::string maxPrivilege(std::string value) override; + + using ChannelAccessIntf::maxPrivilege; -+ using EthernetInterfaceIntf::dHCPEnabled; -+ using EthernetInterfaceIntf::interfaceName; -+ using MacAddressIntf::mACAddress; -+ -+ /** @brief Absolute path of the resolv conf file */ -+ static constexpr auto resolvConfFile = "/etc/resolv.conf"; -+ -+ protected: -+ /** @brief get the info of the ethernet interface. -+ * @return tuple having the link speed,autonegotiation,duplexmode . -+ */ -+ InterfaceInfo getInterfaceInfo() const; -+ -+ /* @brief delete the vlan interface from system. -+ * @param[in] interface - vlan Interface. -+ */ -+ void deleteVLANFromSystem(const std::string& interface); -+ -+ /** @brief construct the ip address dbus object path. -+ * @param[in] addressType - Type of ip address. -+ * @param[in] ipaddress - IP address. -+ * @param[in] prefixLength - Length of prefix. -+ * @param[in] gateway - Gateway address. -+ -+ * @return path of the address object. -+ */ -+ -+ std::string generateObjectPath(IP::Protocol addressType, -+ const std::string& ipaddress, -+ uint8_t prefixLength, -+ const std::string& gateway) const; -+ -+ /** @brief generates the id by doing hash of ipaddress, -+ * prefixlength and the gateway. -+ * @param[in] ipaddress - IP address. -+ * @param[in] prefixLength - Length of prefix. -+ * @param[in] gateway - Gateway address. -+ * @return hash string. -+ */ -+ -+ static std::string generateId(const std::string& ipaddress, -+ uint8_t prefixLength, -+ const std::string& gateway); -+ -+ /** @brief write the dhcp section **/ -+ void writeDHCPSection(std::fstream& stream); -+ -+ /** @brief get the IPv6AcceptRA flag from the network configuration file -+ * -+ */ -+ bool getIPv6AcceptRAFromConf(); -+ -+ /** @brief check conf file for Router Advertisements -+ * -+ */ -+ bool iPv6AcceptRA(bool value) override; -+ -+ /** @brief get the allowed network modes. Similar to DHCP enabled, but -+ * more specific -+ */ -+ IPAllowed getIPAddressEnablesFromConf(); -+ -+ IPAllowed iPAddressEnables(IPAllowed) override; -+ -+ /** @brief get the NTP server list from the network conf -+ * -+ */ -+ ServerList getNTPServersFromConf(); -+ -+ /** @brief write the DNS entries to resolver file. -+ * @param[in] dnsList - DNS server list which needs to be written. -+ * @param[in] file - File to write the name server entries to. -+ */ -+ void writeDNSEntries(const ServerList& dnsList, const std::string& file); -+ -+ /** @brief get the name server details from the network conf -+ * -+ */ -+ ServerList getNameServerFromConf(); -+ -+ /** @brief Persistent sdbusplus DBus bus connection. */ -+ sdbusplus::bus::bus& bus; -+ -+ /** @brief Network Manager object. */ -+ Manager& manager; -+ -+ /** @brief Persistent map of IPAddress dbus objects and their names */ -+ AddressMap addrs; -+ -+ /** @brief Persistent map of VLAN interface dbus objects and their names */ -+ VlanInterfaceMap vlanInterfaces; -+ -+ /** @brief Dbus object path */ -+ std::string objPath; -+ -+ friend class TestEthernetInterface; + using EthernetInterfaceIntf::dHCPEnabled; + using EthernetInterfaceIntf::interfaceName; + using MacAddressIntf::mACAddress; +@@ -256,6 +273,26 @@ class EthernetInterface : public Ifaces + std::string objPath; + + friend class TestEthernetInterface; + + /** @brief gets the channel privilege. + * @param[in] interfaceName - Network interface name. @@ -647,10 +251,10 @@ index 7116b47..7b1da9a 100644 } // namespace network diff --git a/network_manager.cpp b/network_manager.cpp -index c4ab0da..c573d01 100644 +index fa5da0f..a5020f0 100644 --- a/network_manager.cpp +++ b/network_manager.cpp -@@ -30,6 +30,13 @@ extern std::unique_ptr restartTimer; +@@ -34,6 +34,13 @@ extern std::unique_ptr restartTimer; using namespace phosphor::logging; using namespace sdbusplus::xyz::openbmc_project::Common::Error; @@ -664,7 +268,7 @@ index c4ab0da..c573d01 100644 Manager::Manager(sdbusplus::bus::bus& bus, const char* objPath, const std::string& path) : details::VLANCreateIface(bus, objPath, true), -@@ -37,6 +44,103 @@ Manager::Manager(sdbusplus::bus::bus& bus, const char* objPath, +@@ -41,6 +48,103 @@ Manager::Manager(sdbusplus::bus::bus& bus, const char* objPath, { fs::path confDir(path); setConfDir(confDir); @@ -769,7 +373,7 @@ index c4ab0da..c573d01 100644 bool Manager::createDefaultNetworkFiles(bool force) diff --git a/network_manager.hpp b/network_manager.hpp -index e2dfea9..22eef04 100644 +index edb341f..e16b205 100644 --- a/network_manager.hpp +++ b/network_manager.hpp @@ -137,6 +137,9 @@ class Manager : public details::VLANCreateIface @@ -796,5 +400,5 @@ index e2dfea9..22eef04 100644 } // namespace network -- -2.7.4 +2.17.1 diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network_%.bbappend b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network_%.bbappend index 275051e19..afec5d41f 100644 --- a/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network_%.bbappend +++ b/meta-openbmc-mods/meta-common/recipes-network/network/phosphor-network_%.bbappend @@ -2,8 +2,8 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" DEPENDS += "nlohmann-json" -SRC_URI += "file://0001-Patch-to-keep-consistent-MAC-and-IP-address-inbetwee.patch \ - file://0002-IPv6-Network-changes-to-configuration-file.patch \ +SRC_URI += "file://0002-IPv6-Network-changes-to-configuration-file.patch \ file://0003-Adding-channel-specific-privilege-to-network.patch \ " +SRCREV = "f273d2b5629d2a7d96802dc7a7ddb92e303ac8de" diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr.bb b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr.bb new file mode 100644 index 000000000..0dab0fc1a --- /dev/null +++ b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr.bb @@ -0,0 +1,24 @@ +SUMMARY = "Enforce static MAC addresses" +DESCRIPTION = "Set a priority on MAC addresses to run with: \ + factory-specified > u-boot-specified > random" + +FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" + +PV = "1.0" + +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${INTELBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658" + +SRC_URI = "\ + file://mac-check \ + file://${PN}.service \ + " + +inherit obmc-phosphor-systemd + +SYSTEMD_SERVICE_${PN} += "${PN}.service" + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${WORKDIR}/mac-check ${D}${bindir} +} diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check new file mode 100644 index 000000000..67b8afd5e --- /dev/null +++ b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check @@ -0,0 +1,78 @@ +#!/bin/sh +# Copyright 2018 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +read_hw_mac() { + local iface="$1" + cat /sys/class/net/"$iface"/address +} + +set_hw_mac() { + local iface="$1" + local mac="$2" + ip link show dev "$iface" | grep -q "${iface}:.*\" 2>/dev/null + local up=$? + [[ $up -eq 0 ]] && ip link set dev "$iface" down + ip link set dev "$iface" address "$mac" + [[ $up -eq 0 ]] && ip link set dev "$iface" up +} + +SOFS_MNT=/var/sofs +read_sofs_mac() { + local iface="$1" + cat "${SOFS_MNT}/factory-settings/network/mac/${iface}" 2>/dev/null +} + +read_fw_env_mac() { + local envname="$1" + fw_printenv "$envname" 2>/dev/null | sed "s/^$envname=//" +} + +set_fw_env_mac() { + local envname="$1" + local mac="$2" + fw_setenv "$envname" "$mac" +} + +mac_check() { + local iface="$1" + local envname="$2" + + # read current HW MAC addr + local hw_mac=$(read_hw_mac "$iface") + + # read saved sofs MAC addr + local sofs_mac=$(read_sofs_mac "$iface") + + # if set and not the same as HW addr, set HW addr + if [ -n "$sofs_mac" ] && [ "$hw_mac" != "$sofs_mac" ]; then + set_hw_mac "$iface" "$sofs_mac" + hw_mac="$sofs_mac" + fi + + # read saved fw_env MAC addr + local fw_env_mac=$(read_fw_env_mac "$envname") + + # save to fw_env if not the same as HW addr + if [ -z "$fw_env_mac" ] || [ "$fw_env_mac" != "$hw_mac" ]; then + set_fw_env_mac "$envname" "$hw_mac" + fi +} + +while read IFACE UBDEV; do + mac_check "$IFACE" "$UBDEV" +done <<-END_CONF + eth0 eth1addr + eth1 ethaddr +END_CONF diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/static-mac-addr.service b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/static-mac-addr.service new file mode 100644 index 000000000..86371db11 --- /dev/null +++ b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/static-mac-addr.service @@ -0,0 +1,11 @@ +[Unit] +Description=Enforce Static MAC addr mapping + +[Service] +Type=oneshot +Restart=no +ExecStart=/usr/bin/mac-check + +[Install] +WantedBy=network.target + -- cgit v1.2.3