blob: f180ece754095d0863fca7eef188ca472a134971 [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;
20constexpr auto networkChangeTimeout = 1s;
21
Ratan Guptabc886292017-07-25 18:29:57 +053022namespace systemd
23{
24namespace config
25{
26
27constexpr auto networkFilePrefix = "00-bmc-";
28constexpr auto networkFileSuffix = ".network";
29constexpr auto deviceFileSuffix = ".netdev";
30
31}// namespace config
32}// namespace systemd
Ratan Gupta82549cc2017-04-21 08:45:23 +053033
34using IntfName = std::string;
35
36struct AddrInfo {
37 uint8_t addrType;
38 std::string ipaddress;
39 uint16_t prefix;
40};
41
Ratan Gupta3681a502017-06-17 19:20:04 +053042using Addr_t = ifaddrs*;
43
44struct AddrDeleter
45{
46 void operator()(Addr_t ptr) const
47 {
48 freeifaddrs(ptr);
49 }
50};
51
52using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
53
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053054/* Need a custom deleter for freeing up sd_event */
55struct EventDeleter
56{
57 void operator()(sd_event* event) const
58 {
59 event = sd_event_unref(event);
60 }
61};
62using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
63
64template<typename T>
65using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
Ratan Gupta3681a502017-06-17 19:20:04 +053066
Ratan Gupta82549cc2017-04-21 08:45:23 +053067using AddrList = std::list<AddrInfo>;
68using IntfAddrMap = std::map<IntfName, AddrList>;
Ratan Guptafd4b0f02017-09-16 06:01:24 +053069using InterfaceList = std::set<IntfName>;
Ratan Gupta82549cc2017-04-21 08:45:23 +053070
71}//namespace network
72}//namespace phosphor