util.cpp (e94c9ffcc639f6280972bb28b26bb357b830491f) | util.cpp (95530ec9fbfd478f85b1452571b9df21c76ec242) |
---|---|
1#include "config.h" 2 3#include "util.hpp" 4 5#include "config_parser.hpp" 6#include "types.hpp" 7 8#include <arpa/inet.h> 9#include <dirent.h> 10#include <fmt/compile.h> 11#include <fmt/format.h> 12#include <net/if.h> 13#include <sys/wait.h> 14 15#include <algorithm> 16#include <cctype> 17#include <cstdlib> 18#include <cstring> | 1#include "config.h" 2 3#include "util.hpp" 4 5#include "config_parser.hpp" 6#include "types.hpp" 7 8#include <arpa/inet.h> 9#include <dirent.h> 10#include <fmt/compile.h> 11#include <fmt/format.h> 12#include <net/if.h> 13#include <sys/wait.h> 14 15#include <algorithm> 16#include <cctype> 17#include <cstdlib> 18#include <cstring> |
19#include <filesystem> | |
20#include <fstream> 21#include <list> 22#ifdef SYNC_MAC_FROM_INVENTORY 23#include <nlohmann/json.hpp> 24#endif 25#include <phosphor-logging/elog-errors.hpp> 26#include <phosphor-logging/log.hpp> 27#include <stdexcept> --- 4 unchanged lines hidden (view full) --- 32 33namespace phosphor 34{ 35namespace network 36{ 37 38using namespace phosphor::logging; 39using namespace sdbusplus::xyz::openbmc_project::Common::Error; | 19#include <fstream> 20#include <list> 21#ifdef SYNC_MAC_FROM_INVENTORY 22#include <nlohmann/json.hpp> 23#endif 24#include <phosphor-logging/elog-errors.hpp> 25#include <phosphor-logging/log.hpp> 26#include <stdexcept> --- 4 unchanged lines hidden (view full) --- 31 32namespace phosphor 33{ 34namespace network 35{ 36 37using namespace phosphor::logging; 38using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
40namespace fs = std::filesystem; | |
41 42namespace internal 43{ 44 45void executeCommandinChildProcess(const char* path, char** args) 46{ 47 using namespace std::string_literals; 48 pid_t pid = fork(); --- 56 unchanged lines hidden (view full) --- 105 if (r == nullptr) 106 { 107 return ""; 108 } 109 return r; 110} 111 112/** @brief Parse the comma separated interface names */ | 39 40namespace internal 41{ 42 43void executeCommandinChildProcess(const char* path, char** args) 44{ 45 using namespace std::string_literals; 46 pid_t pid = fork(); --- 56 unchanged lines hidden (view full) --- 103 if (r == nullptr) 104 { 105 return ""; 106 } 107 return r; 108} 109 110/** @brief Parse the comma separated interface names */ |
113std::set<std::string_view> parseInterfaces(std::string_view interfaces) | 111std::unordered_set<std::string_view> 112 parseInterfaces(std::string_view interfaces) |
114{ | 113{ |
115 std::set<std::string_view> result; | 114 std::unordered_set<std::string_view> result; |
116 while (true) 117 { 118 auto sep = interfaces.find(','); 119 auto interface = interfaces.substr(0, sep); 120 while (!interface.empty() && std::isspace(interface.front())) 121 { 122 interface.remove_prefix(1); 123 } --- 10 unchanged lines hidden (view full) --- 134 break; 135 } 136 interfaces = interfaces.substr(sep + 1); 137 } 138 return result; 139} 140 141/** @brief Get the ignored interfaces */ | 115 while (true) 116 { 117 auto sep = interfaces.find(','); 118 auto interface = interfaces.substr(0, sep); 119 while (!interface.empty() && std::isspace(interface.front())) 120 { 121 interface.remove_prefix(1); 122 } --- 10 unchanged lines hidden (view full) --- 133 break; 134 } 135 interfaces = interfaces.substr(sep + 1); 136 } 137 return result; 138} 139 140/** @brief Get the ignored interfaces */ |
142const std::set<std::string_view>& getIgnoredInterfaces() | 141const std::unordered_set<std::string_view>& getIgnoredInterfaces() |
143{ 144 static auto ignoredInterfaces = parseInterfaces(getIgnoredInterfacesEnv()); 145 return ignoredInterfaces; 146} 147 148} // namespace internal 149 150std::string toMask(int addressFamily, uint8_t prefix) --- 138 unchanged lines hidden (view full) --- 289 { 290 // walk interfaces 291 // if loopback ignore 292 if (ifa->ifa_flags & IFF_LOOPBACK || 293 ignoredInterfaces.find(ifa->ifa_name) != ignoredInterfaces.end()) 294 { 295 continue; 296 } | 142{ 143 static auto ignoredInterfaces = parseInterfaces(getIgnoredInterfacesEnv()); 144 return ignoredInterfaces; 145} 146 147} // namespace internal 148 149std::string toMask(int addressFamily, uint8_t prefix) --- 138 unchanged lines hidden (view full) --- 288 { 289 // walk interfaces 290 // if loopback ignore 291 if (ifa->ifa_flags & IFF_LOOPBACK || 292 ignoredInterfaces.find(ifa->ifa_name) != ignoredInterfaces.end()) 293 { 294 continue; 295 } |
297 interfaces.emplace(ifa->ifa_name); | 296 interfaces.emplace_back(ifa->ifa_name); |
298 } 299 return interfaces; 300} 301 302void deleteInterface(const std::string& intf) 303{ 304 pid_t pid = fork(); 305 int status{}; --- 294 unchanged lines hidden --- | 297 } 298 return interfaces; 299} 300 301void deleteInterface(const std::string& intf) 302{ 303 pid_t pid = fork(); 304 int status{}; --- 294 unchanged lines hidden --- |