blob: c64407a9b4a34ba2ff2b3e3075bb983360220810 [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>
Ratan Gupta3681a502017-06-17 19:20:04 +05308#include <memory>
William A. Kennington III3a70fa22018-09-20 18:48:20 -07009#include <sdeventplus/clock.hpp>
10#include <sdeventplus/utility/timer.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -070011#include <string>
Willy Tuf7dce2e2022-10-07 05:48:08 +000012#include <unordered_set>
William A. Kennington III0d7ce482019-01-30 17:14:23 -080013#include <variant>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053014
Ratan Gupta82549cc2017-04-21 08:45:23 +053015namespace phosphor
16{
17namespace network
18{
Ratan Guptae05083a2017-09-16 07:12:11 +053019
20using namespace std::chrono_literals;
Ratan Gupta16f12882017-09-22 18:26:11 +053021
William A. Kennington IIIc7cf25f2021-11-09 16:16:59 -080022// wait for three seconds before reloading systemd-networkd
23constexpr auto reloadTimeout = 3s;
Ratan Gupta16f12882017-09-22 18:26:11 +053024
William A. Kennington IIId41db382021-11-09 20:42:29 -080025// refresh the objets after four seconds as network
26// configuration takes 3-4 sec to reconfigure at most.
27constexpr auto refreshTimeout = 4s;
Ratan Guptae05083a2017-09-16 07:12:11 +053028
Ratan Gupta82549cc2017-04-21 08:45:23 +053029using IntfName = std::string;
30
Ratan Gupta3681a502017-06-17 19:20:04 +053031using Addr_t = ifaddrs*;
32
33struct AddrDeleter
34{
35 void operator()(Addr_t ptr) const
36 {
37 freeifaddrs(ptr);
38 }
39};
40
41using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
42
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053043/* Need a custom deleter for freeing up sd_event */
44struct EventDeleter
45{
46 void operator()(sd_event* event) const
47 {
William A. Kennington IIIdc2f1b62021-05-13 21:20:19 -070048 sd_event_unref(event);
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053049 }
50};
51using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
52
William A. Kennington III0d7ce482019-01-30 17:14:23 -080053// Byte representations for common address types in network byte order
54using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
William A. Kennington III0d7ce482019-01-30 17:14:23 -080055
Willy Tuf7dce2e2022-10-07 05:48:08 +000056using InterfaceList = std::unordered_set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053057
William A. Kennington III3a70fa22018-09-20 18:48:20 -070058using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
59
Gunnar Mills57d9c502018-09-14 14:42:34 -050060} // namespace network
61} // namespace phosphor