blob: 2e27298dcde0e00eeb9ba1d21f36e64bc7eaff89 [file] [log] [blame]
Ratan Gupta82549cc2017-04-21 08:45:23 +05301#pragma once
2
Ratan Gupta3681a502017-06-17 19:20:04 +05303#include <ifaddrs.h>
William A. Kennington III0d7ce482019-01-30 17:14:23 -08004#include <netinet/in.h>
Patrick Venture189d44e2018-07-09 12:30:59 -07005#include <systemd/sd-event.h>
Ratan Gupta3681a502017-06-17 19:20:04 +05306
Patrick Venture189d44e2018-07-09 12:30:59 -07007#include <chrono>
William A. Kennington III0d7ce482019-01-30 17:14:23 -08008#include <cstddef>
Brad Bishopced35922018-02-21 12:57:21 -05009#include <functional>
Ratan Gupta3681a502017-06-17 19:20:04 +053010#include <memory>
William A. Kennington III3a70fa22018-09-20 18:48:20 -070011#include <sdeventplus/clock.hpp>
12#include <sdeventplus/utility/timer.hpp>
Ratan Guptafd4b0f02017-09-16 06:01:24 +053013#include <set>
Patrick Venture189d44e2018-07-09 12:30:59 -070014#include <string>
William A. Kennington III0d7ce482019-01-30 17:14:23 -080015#include <variant>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053016
Ratan Gupta82549cc2017-04-21 08:45:23 +053017namespace phosphor
18{
19namespace network
20{
Ratan Guptae05083a2017-09-16 07:12:11 +053021
22using namespace std::chrono_literals;
Ratan Gupta16f12882017-09-22 18:26:11 +053023
William A. Kennington IIIc7cf25f2021-11-09 16:16:59 -080024// wait for three seconds before reloading systemd-networkd
25constexpr auto reloadTimeout = 3s;
Ratan Gupta16f12882017-09-22 18:26:11 +053026
William A. Kennington IIId41db382021-11-09 20:42:29 -080027// refresh the objets after four seconds as network
28// configuration takes 3-4 sec to reconfigure at most.
29constexpr auto refreshTimeout = 4s;
Ratan Guptae05083a2017-09-16 07:12:11 +053030
Ratan Guptabc886292017-07-25 18:29:57 +053031namespace systemd
32{
33namespace config
34{
35
36constexpr auto networkFilePrefix = "00-bmc-";
37constexpr auto networkFileSuffix = ".network";
38constexpr auto deviceFileSuffix = ".netdev";
39
Gunnar Mills57d9c502018-09-14 14:42:34 -050040} // namespace config
41} // namespace systemd
Ratan Gupta82549cc2017-04-21 08:45:23 +053042
43using IntfName = std::string;
44
Ratan Gupta3681a502017-06-17 19:20:04 +053045using Addr_t = ifaddrs*;
46
47struct AddrDeleter
48{
49 void operator()(Addr_t ptr) const
50 {
51 freeifaddrs(ptr);
52 }
53};
54
55using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
56
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053057/* Need a custom deleter for freeing up sd_event */
58struct EventDeleter
59{
60 void operator()(sd_event* event) const
61 {
William A. Kennington IIIdc2f1b62021-05-13 21:20:19 -070062 sd_event_unref(event);
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053063 }
64};
65using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
66
Gunnar Mills57d9c502018-09-14 14:42:34 -050067template <typename T>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053068using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053069
William A. Kennington III0d7ce482019-01-30 17:14:23 -080070// Byte representations for common address types in network byte order
71using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
William A. Kennington III0d7ce482019-01-30 17:14:23 -080072
Ratan Guptafd4b0f02017-09-16 06:01:24 +053073using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053074
William A. Kennington III3a70fa22018-09-20 18:48:20 -070075using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
76
Gunnar Mills57d9c502018-09-14 14:42:34 -050077} // namespace network
78} // namespace phosphor