blob: e14cac4b8cc5815d1b7381338eba507d985b0f23 [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>
William A. Kennington III0d7ce482019-01-30 17:14:23 -080012#include <variant>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053013
Ratan Gupta82549cc2017-04-21 08:45:23 +053014namespace phosphor
15{
16namespace network
17{
Ratan Guptae05083a2017-09-16 07:12:11 +053018
19using namespace std::chrono_literals;
Ratan Gupta16f12882017-09-22 18:26:11 +053020
William A. Kennington IIIc7cf25f2021-11-09 16:16:59 -080021// wait for three seconds before reloading systemd-networkd
22constexpr auto reloadTimeout = 3s;
Ratan Gupta16f12882017-09-22 18:26:11 +053023
William A. Kennington IIId41db382021-11-09 20:42:29 -080024// refresh the objets after four seconds as network
25// configuration takes 3-4 sec to reconfigure at most.
26constexpr auto refreshTimeout = 4s;
Ratan Guptae05083a2017-09-16 07:12:11 +053027
Ratan Gupta82549cc2017-04-21 08:45:23 +053028using IntfName = std::string;
29
Ratan Gupta3681a502017-06-17 19:20:04 +053030using Addr_t = ifaddrs*;
31
32struct AddrDeleter
33{
34 void operator()(Addr_t ptr) const
35 {
36 freeifaddrs(ptr);
37 }
38};
39
40using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
41
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053042/* Need a custom deleter for freeing up sd_event */
43struct EventDeleter
44{
45 void operator()(sd_event* event) const
46 {
William A. Kennington IIIdc2f1b62021-05-13 21:20:19 -070047 sd_event_unref(event);
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053048 }
49};
50using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
51
William A. Kennington III0d7ce482019-01-30 17:14:23 -080052// Byte representations for common address types in network byte order
53using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
William A. Kennington III0d7ce482019-01-30 17:14:23 -080054
William A. Kennington III95530ec2022-08-19 01:44:39 -070055using InterfaceList = std::vector<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053056
William A. Kennington III3a70fa22018-09-20 18:48:20 -070057using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
58
Gunnar Mills57d9c502018-09-14 14:42:34 -050059} // namespace network
60} // namespace phosphor