blob: c155e40541d6435e18d0e67c72d6796aafe4ab90 [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
38}// namespace config
39}// namespace systemd
Ratan Gupta82549cc2017-04-21 08:45:23 +053040
41using IntfName = std::string;
42
43struct AddrInfo {
44 uint8_t addrType;
45 std::string ipaddress;
46 uint16_t prefix;
47};
48
Ratan Gupta3681a502017-06-17 19:20:04 +053049using Addr_t = ifaddrs*;
50
51struct AddrDeleter
52{
53 void operator()(Addr_t ptr) const
54 {
55 freeifaddrs(ptr);
56 }
57};
58
59using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
60
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053061/* Need a custom deleter for freeing up sd_event */
62struct EventDeleter
63{
64 void operator()(sd_event* event) const
65 {
66 event = sd_event_unref(event);
67 }
68};
69using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
70
71template<typename T>
72using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053073
Ratan Gupta82549cc2017-04-21 08:45:23 +053074using AddrList = std::list<AddrInfo>;
75using IntfAddrMap = std::map<IntfName, AddrList>;
Ratan Guptafd4b0f02017-09-16 06:01:24 +053076using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053077
78}//namespace network
79}//namespace phosphor