blob: 46ce02025d9c7413dcdee69c11d3accb14765e2b [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>
4
Brad Bishopced35922018-02-21 12:57:21 -05005#include <functional>
Ratan Gupta82549cc2017-04-21 08:45:23 +05306#include <list>
7#include <string>
8#include <vector>
9#include <map>
Ratan Gupta3681a502017-06-17 19:20:04 +053010#include <memory>
Ratan Guptafd4b0f02017-09-16 06:01:24 +053011#include <set>
Ratan Guptae05083a2017-09-16 07:12:11 +053012#include <chrono>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053013#include <systemd/sd-event.h>
14
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