blob: 3fcbe2ee9fb7bcdc8db934c701f596041e67760e [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
Ratan Gupta82549cc2017-04-21 08:45:23 +05305#include <list>
6#include <string>
7#include <vector>
8#include <map>
Ratan Gupta3681a502017-06-17 19:20:04 +05309#include <memory>
Ratan Guptafd4b0f02017-09-16 06:01:24 +053010#include <set>
Ratan Guptae05083a2017-09-16 07:12:11 +053011#include <chrono>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053012#include <systemd/sd-event.h>
13
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
21// wait for three seconds before restarting the networkd
22constexpr auto restartTimeout = 3s;
23
24// refresh the objets after five seconds as network
25// configuration takes 3-4 sec after systemd-networkd restart.
26constexpr auto refreshTimeout = restartTimeout + 5s;
Ratan Guptae05083a2017-09-16 07:12:11 +053027
Ratan Guptabc886292017-07-25 18:29:57 +053028namespace systemd
29{
30namespace config
31{
32
33constexpr auto networkFilePrefix = "00-bmc-";
34constexpr auto networkFileSuffix = ".network";
35constexpr auto deviceFileSuffix = ".netdev";
36
37}// namespace config
38}// namespace systemd
Ratan Gupta82549cc2017-04-21 08:45:23 +053039
40using IntfName = std::string;
41
42struct AddrInfo {
43 uint8_t addrType;
44 std::string ipaddress;
45 uint16_t prefix;
46};
47
Ratan Gupta3681a502017-06-17 19:20:04 +053048using Addr_t = ifaddrs*;
49
50struct AddrDeleter
51{
52 void operator()(Addr_t ptr) const
53 {
54 freeifaddrs(ptr);
55 }
56};
57
58using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
59
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053060/* Need a custom deleter for freeing up sd_event */
61struct EventDeleter
62{
63 void operator()(sd_event* event) const
64 {
65 event = sd_event_unref(event);
66 }
67};
68using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
69
70template<typename T>
71using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053072
Ratan Gupta82549cc2017-04-21 08:45:23 +053073using AddrList = std::list<AddrInfo>;
74using IntfAddrMap = std::map<IntfName, AddrList>;
Ratan Guptafd4b0f02017-09-16 06:01:24 +053075using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053076
77}//namespace network
78}//namespace phosphor