util.cpp (150753f3d8b585a37f8886f06e0e034c1db66dfd) | util.cpp (a520a39d1155cc5852fa6929aa9c772802505457) |
---|---|
1#include "util.hpp" 2 3#include "config_parser.hpp" 4#include "types.hpp" 5 6#include <arpa/inet.h> 7#include <dirent.h> 8#include <fmt/compile.h> --- 350 unchanged lines hidden (view full) --- 359 } 360 if (idx == 0) 361 { 362 return "ethaddr"; 363 } 364 return "eth" + std::to_string(idx) + "addr"; 365} 366 | 1#include "util.hpp" 2 3#include "config_parser.hpp" 4#include "types.hpp" 5 6#include <arpa/inet.h> 7#include <dirent.h> 8#include <fmt/compile.h> --- 350 unchanged lines hidden (view full) --- 359 } 360 if (idx == 0) 361 { 362 return "ethaddr"; 363 } 364 return "eth" + std::to_string(idx) + "addr"; 365} 366 |
367EthernetInterfaceIntf::DHCPConf getDHCPValue(const std::string& confDir, 368 const std::string& intf) | 367bool getIPv6AcceptRA(const config::Parser& config) |
369{ | 368{ |
370 // Get the interface mode value from systemd conf 371 // using namespace std::string_literals; 372 fs::path confPath = confDir; 373 std::string fileName = systemd::config::networkFilePrefix + intf + 374 systemd::config::networkFileSuffix; 375 confPath /= fileName; | 369 const auto& values = config.getValues("Network", "IPv6AcceptRA"); 370 if (values.empty()) 371 { 372 auto msg = fmt::format( 373 "Unable to get the value for Network[IPv6AcceptRA] from {}", 374 config.getFilename().native()); 375 log<level::NOTICE>(msg.c_str(), 376 entry("FILE=%s", config.getFilename().c_str())); 377 return false; 378 } 379 auto ret = config::parseBool(values.back()); 380 if (!ret.has_value()) 381 { 382 auto msg = fmt::format( 383 "Failed to parse section Network[IPv6AcceptRA] from {}: `{}`", 384 config.getFilename().native(), values.back()); 385 log<level::NOTICE>(msg.c_str(), 386 entry("FILE=%s", config.getFilename().c_str()), 387 entry("VALUE=%s", values.back().c_str())); 388 } 389 return ret.value_or(false); 390} |
376 | 391 |
377 config::Parser parser(confPath.string()); 378 const auto& values = parser.getValues("Network", "DHCP"); | 392EthernetInterfaceIntf::DHCPConf getDHCPValue(const config::Parser& config) 393{ 394 const auto& values = config.getValues("Network", "DHCP"); |
379 if (values.empty()) 380 { | 395 if (values.empty()) 396 { |
381 log<level::NOTICE>("Unable to get the value for Network[DHCP]"); | 397 auto msg = 398 fmt::format("Unable to get the value for Network[DHCP] from {}", 399 config.getFilename().native()); 400 log<level::NOTICE>(msg.c_str(), 401 entry("FILE=%s", config.getFilename().c_str())); |
382 return EthernetInterfaceIntf::DHCPConf::none; 383 } 384 if (config::icaseeq(values.back(), "ipv4")) 385 { 386 return EthernetInterfaceIntf::DHCPConf::v4; 387 } 388 if (config::icaseeq(values.back(), "ipv6")) 389 { 390 return EthernetInterfaceIntf::DHCPConf::v6; 391 } 392 auto ret = config::parseBool(values.back()); 393 if (!ret.has_value()) 394 { | 402 return EthernetInterfaceIntf::DHCPConf::none; 403 } 404 if (config::icaseeq(values.back(), "ipv4")) 405 { 406 return EthernetInterfaceIntf::DHCPConf::v4; 407 } 408 if (config::icaseeq(values.back(), "ipv6")) 409 { 410 return EthernetInterfaceIntf::DHCPConf::v6; 411 } 412 auto ret = config::parseBool(values.back()); 413 if (!ret.has_value()) 414 { |
395 auto str = 396 fmt::format("Unable to parse Network[DHCP]: `{}`", values.back()); 397 log<level::NOTICE>(str.c_str()); | 415 auto str = fmt::format("Unable to parse Network[DHCP] from {}: `{}`", 416 config.getFilename().native(), values.back()); 417 log<level::NOTICE>(str.c_str(), 418 entry("FILE=%s", config.getFilename().c_str()), 419 entry("VALUE=%s", values.back().c_str())); |
398 } 399 return ret.value_or(false) ? EthernetInterfaceIntf::DHCPConf::both 400 : EthernetInterfaceIntf::DHCPConf::none; 401} 402 403namespace mac_address 404{ 405 --- 162 unchanged lines hidden --- | 420 } 421 return ret.value_or(false) ? EthernetInterfaceIntf::DHCPConf::both 422 : EthernetInterfaceIntf::DHCPConf::none; 423} 424 425namespace mac_address 426{ 427 --- 162 unchanged lines hidden --- |