blob: e0d768d36372a1b0dd531cdfce39f02b730a9746 [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 Gupta82549cc2017-04-21 08:45:23 +053031using IntfName = std::string;
32
Ratan Gupta3681a502017-06-17 19:20:04 +053033using Addr_t = ifaddrs*;
34
35struct AddrDeleter
36{
37 void operator()(Addr_t ptr) const
38 {
39 freeifaddrs(ptr);
40 }
41};
42
43using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
44
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053045/* Need a custom deleter for freeing up sd_event */
46struct EventDeleter
47{
48 void operator()(sd_event* event) const
49 {
William A. Kennington IIIdc2f1b62021-05-13 21:20:19 -070050 sd_event_unref(event);
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053051 }
52};
53using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
54
Gunnar Mills57d9c502018-09-14 14:42:34 -050055template <typename T>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053056using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053057
William A. Kennington III0d7ce482019-01-30 17:14:23 -080058// Byte representations for common address types in network byte order
59using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
William A. Kennington III0d7ce482019-01-30 17:14:23 -080060
Ratan Guptafd4b0f02017-09-16 06:01:24 +053061using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053062
William A. Kennington III3a70fa22018-09-20 18:48:20 -070063using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
64
Gunnar Mills57d9c502018-09-14 14:42:34 -050065} // namespace network
66} // namespace phosphor