diff options
Diffstat (limited to 'meta-ibs/meta-cp2-5422/recipes-phosphor/network/phosphor-network/0002-Added-check-of-sync-status-with-NTP-servers.patch')
-rw-r--r-- | meta-ibs/meta-cp2-5422/recipes-phosphor/network/phosphor-network/0002-Added-check-of-sync-status-with-NTP-servers.patch | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/meta-ibs/meta-cp2-5422/recipes-phosphor/network/phosphor-network/0002-Added-check-of-sync-status-with-NTP-servers.patch b/meta-ibs/meta-cp2-5422/recipes-phosphor/network/phosphor-network/0002-Added-check-of-sync-status-with-NTP-servers.patch new file mode 100644 index 0000000000..0b18b594ba --- /dev/null +++ b/meta-ibs/meta-cp2-5422/recipes-phosphor/network/phosphor-network/0002-Added-check-of-sync-status-with-NTP-servers.patch @@ -0,0 +1,210 @@ +From e4492d4f1e29731db6ac278ecb121cb47a8e204f Mon Sep 17 00:00:00 2001 +From: Nikita Kosenkov <NKosenkov@IBS.RU> +Date: Tue, 23 Aug 2022 10:00:35 +0300 +Subject: [PATCH] Added check of synchronization status with NTP servers + +This functionality provides users with an additional log +about the state of synchronization with NTP servers. + +The definition occurs on an indirect basis: +If the 'ServerAddress' property is empty, +then we consider that it was not possible +to obtain the IP address of the NTP server. + +Similarly, 'timedatectl show-timesync --property ServerAddress --value'. +--- + src/network_manager_main.cpp | 115 ++++++++++++++++++++++++++++++++++- + src/types.hpp | 4 ++ + 2 files changed, 116 insertions(+), 3 deletions(-) + +diff --git a/src/network_manager_main.cpp b/src/network_manager_main.cpp +index 349c2ea..5d47c0c 100644 +--- a/src/network_manager_main.cpp ++++ b/src/network_manager_main.cpp +@@ -6,11 +6,13 @@ + #include "watch.hpp" + + #include <linux/netlink.h> ++#include <systemd/sd-journal.h> + + #include <filesystem> + #include <fstream> + #include <functional> + #include <memory> ++#include <algorithm> + #ifdef SYNC_MAC_FROM_INVENTORY + #include <nlohmann/json.hpp> + #endif +@@ -49,6 +51,7 @@ namespace network + std::unique_ptr<phosphor::network::Manager> manager = nullptr; + std::unique_ptr<Timer> refreshObjectTimer = nullptr; + std::unique_ptr<Timer> reloadTimer = nullptr; ++std::unique_ptr<Timer> checkNtpSyncStatusTimer = nullptr; + + #ifdef SYNC_MAC_FROM_INVENTORY + std::unique_ptr<sdbusplus::bus::match::match> EthInterfaceMatch = nullptr; +@@ -230,17 +233,66 @@ void watchEthernetInterface(sdbusplus::bus::bus& bus, + } + } + } +- + #endif + ++void watchNTPServers(sdbusplus::bus::bus& bus) ++{ ++ static std::unique_ptr<sdbusplus::bus::match::match> NTPServersMatch; ++ ++ auto callback = [](sdbusplus::message::message& message) { ++ std::string intfName; ++ std::map<std::string, std::variant<std::string>> properties; ++ ++ try ++ { ++ message.read(intfName, properties); ++ } ++ catch (const std::exception& e) ++ { ++ log<level::ERR>("Unable to read properties from" ++ "xyz.openbmc_project.Network.EthernetInterface"); ++ ++ return; ++ } ++ if (properties.empty()) ++ { ++ log<level::ERR>("Empty PropertiesChanged signal received"); ++ return; ++ } ++ ++ // we only want to check for NTPServers ++ if (properties.begin()->first != "NTPServers") ++ { ++ return; ++ } ++ ++ std::string* NTPServers = std::get_if<std::string>(&(properties.begin()->second)); ++ if (NTPServers == nullptr) ++ { ++ log<level::ERR>("NTPServers - property invalid"); ++ return; ++ } ++ ++ // call check sync status ++ checkNtpSyncStatusTimer->restartOnce(ntpSyncTimeout); ++ }; ++ ++ NTPServersMatch = std::make_unique<sdbusplus::bus::match::match>( ++ bus, ++ "type='signal',member='PropertiesChanged', " ++ "interface='org.freedesktop.DBus.Properties', " ++ "arg0='xyz.openbmc_project.Network.EthernetInterface'", ++ callback); ++} ++ + /** @brief refresh the network objects. */ + void refreshObjects() + { + if (manager) + { +- log<level::INFO>("Refreshing the objects."); ++ log<level::INFO>("Refreshing the objects"); + manager->createChildObjects(); +- log<level::INFO>("Refreshing complete."); ++ log<level::INFO>("Refreshing complete"); + } + } + +@@ -254,12 +306,67 @@ void reloadNetworkd() + } + } + ++void checkNtpSyncStatus() ++{ ++ log<level::INFO>("Checking NTP sync status"); ++ ++ // DBUS - ServerAddress property (iay) ++ using ServerAddress = std::tuple<int32_t, std::vector<uint8_t>>; ++ std::variant<ServerAddress> propServerAddress; ++ ++ auto getProperty = [](auto propName, auto &result) -> bool { ++ try ++ { ++ auto b = sdbusplus::bus::new_default_system(); ++ auto method = ++ b.new_method_call( ++ "org.freedesktop.timesync1", ++ "/org/freedesktop/timesync1", ++ "org.freedesktop.DBus.Properties", "Get"); ++ ++ method.append("org.freedesktop.timesync1.Manager", propName); ++ auto reply = b.call(method); ++ reply.read(result); ++ } ++ catch (const sdbusplus::exception::exception& ex) ++ { ++ log<level::ERR>("Exception occurred during getting of " ++ "property from org.freedesktop.timesync1.Manager"); ++ return false; ++ } ++ return true; ++ }; ++ ++ if(getProperty("ServerAddress", propServerAddress)) ++ { ++ auto serverAddress = std::get<ServerAddress>(propServerAddress); ++ ++ // get first value from "ServerAddress property (iay)" ++ // using this parameter, you can understand whether ++ // it was possible to resolve the NTP address ++ if(std::get<int32_t>(serverAddress) <= 0) ++ { ++ sd_journal_send( ++ "MESSAGE=BMC Failed to resolve NTP server addresses", ++ "PRIORITY=%i", LOG_WARNING, ++ "REDFISH_MESSAGE_ID=%s", ++ "OpenBMC.0.1.BMCTimeNotResolvedNTPServers", ++ NULL); ++ } ++ } ++ ++ log<level::INFO>("Checking NTP sync status complete"); ++} ++ + void initializeTimers() + { + auto event = sdeventplus::Event::get_default(); + refreshObjectTimer = + std::make_unique<Timer>(event, std::bind(refreshObjects)); + reloadTimer = std::make_unique<Timer>(event, std::bind(reloadNetworkd)); ++ ++ checkNtpSyncStatusTimer = ++ std::make_unique<Timer>(event, std::bind(checkNtpSyncStatus)); + } + + } // namespace network +@@ -329,6 +436,8 @@ int main(int /*argc*/, char** /*argv*/) + phosphor::network::watchEthernetInterface(bus, configJson); + #endif + ++ phosphor::network::watchNTPServers(bus); ++ + // Trigger the initial object scan + // This is intentionally deferred, to ensure that systemd-networkd is + // fully configured. +diff --git a/src/types.hpp b/src/types.hpp +index 69a314d..0de7a3f 100644 +--- a/src/types.hpp ++++ b/src/types.hpp +@@ -34,6 +34,10 @@ constexpr auto reloadTimeout = 3s; + // configuration takes 3-4 sec after systemd-networkd restart. + constexpr auto refreshTimeout = reloadTimeout + 7s; + ++// check the synchronization status ++// after updating the list of NTP servers after 60 seconds ++constexpr auto ntpSyncTimeout = 60s; ++ + namespace systemd + { + namespace config +-- +2.35.1 + |