blob: b8038b4b2f98942a247e6d26c898856343a140d6 [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>
Ratan Guptafd4b0f02017-09-16 06:01:24 +053011#include <set>
Patrick Venture189d44e2018-07-09 12:30:59 -070012#include <string>
13#include <vector>
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
22// wait for three seconds before restarting the networkd
23constexpr auto restartTimeout = 3s;
24
25// refresh the objets after five seconds as network
26// configuration takes 3-4 sec after systemd-networkd restart.
Ratan Gupta310a0b12017-11-15 17:40:24 +053027constexpr auto refreshTimeout = restartTimeout + 7s;
Ratan Guptae05083a2017-09-16 07:12:11 +053028
Ratan Guptabc886292017-07-25 18:29:57 +053029namespace systemd
30{
31namespace config
32{
33
34constexpr auto networkFilePrefix = "00-bmc-";
35constexpr auto networkFileSuffix = ".network";
36constexpr auto deviceFileSuffix = ".netdev";
37
Gunnar Mills57d9c502018-09-14 14:42:34 -050038} // namespace config
39} // namespace systemd
Ratan Gupta82549cc2017-04-21 08:45:23 +053040
41using IntfName = std::string;
42
Gunnar Mills57d9c502018-09-14 14:42:34 -050043struct AddrInfo
44{
Ratan Gupta82549cc2017-04-21 08:45:23 +053045 uint8_t addrType;
46 std::string ipaddress;
47 uint16_t prefix;
48};
49
Ratan Gupta3681a502017-06-17 19:20:04 +053050using Addr_t = ifaddrs*;
51
52struct AddrDeleter
53{
54 void operator()(Addr_t ptr) const
55 {
56 freeifaddrs(ptr);
57 }
58};
59
60using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
61
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053062/* Need a custom deleter for freeing up sd_event */
63struct EventDeleter
64{
65 void operator()(sd_event* event) const
66 {
67 event = sd_event_unref(event);
68 }
69};
70using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
71
Gunnar Mills57d9c502018-09-14 14:42:34 -050072template <typename T>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053073using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053074
Ratan Gupta82549cc2017-04-21 08:45:23 +053075using AddrList = std::list<AddrInfo>;
76using IntfAddrMap = std::map<IntfName, AddrList>;
Ratan Guptafd4b0f02017-09-16 06:01:24 +053077using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053078
Gunnar Mills57d9c502018-09-14 14:42:34 -050079} // namespace network
80} // namespace phosphor