blob: 9ffe5ad33b8e5cdf4f8349cca882c73fba7c8b47 [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>
Patrick Venture189d44e2018-07-09 12:30:59 -07004#include <systemd/sd-event.h>
Ratan Gupta3681a502017-06-17 19:20:04 +05305
Patrick Venture189d44e2018-07-09 12:30:59 -07006#include <chrono>
Brad Bishopced35922018-02-21 12:57:21 -05007#include <functional>
Ratan Gupta82549cc2017-04-21 08:45:23 +05308#include <list>
Ratan Gupta82549cc2017-04-21 08:45:23 +05309#include <map>
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>
15#include <vector>
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
24// wait for three seconds before restarting the networkd
25constexpr auto restartTimeout = 3s;
26
27// refresh the objets after five seconds as network
28// configuration takes 3-4 sec after systemd-networkd restart.
Ratan Gupta310a0b12017-11-15 17:40:24 +053029constexpr auto refreshTimeout = restartTimeout + 7s;
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
Gunnar Mills57d9c502018-09-14 14:42:34 -050045struct AddrInfo
46{
Ratan Gupta82549cc2017-04-21 08:45:23 +053047 uint8_t addrType;
48 std::string ipaddress;
49 uint16_t prefix;
50};
51
Ratan Gupta3681a502017-06-17 19:20:04 +053052using Addr_t = ifaddrs*;
53
54struct AddrDeleter
55{
56 void operator()(Addr_t ptr) const
57 {
58 freeifaddrs(ptr);
59 }
60};
61
62using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
63
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053064/* Need a custom deleter for freeing up sd_event */
65struct EventDeleter
66{
67 void operator()(sd_event* event) const
68 {
69 event = sd_event_unref(event);
70 }
71};
72using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
73
Gunnar Mills57d9c502018-09-14 14:42:34 -050074template <typename T>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053075using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053076
Ratan Gupta82549cc2017-04-21 08:45:23 +053077using AddrList = std::list<AddrInfo>;
78using IntfAddrMap = std::map<IntfName, AddrList>;
Ratan Guptafd4b0f02017-09-16 06:01:24 +053079using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053080
William A. Kennington III3a70fa22018-09-20 18:48:20 -070081using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
82
Gunnar Mills57d9c502018-09-14 14:42:34 -050083} // namespace network
84} // namespace phosphor