xref: /openbmc/phosphor-networkd/src/types.hpp (revision 3bf1c74e)
1 #pragma once
2 
3 #include "ipaddress.hpp"
4 
5 #include <ifaddrs.h>
6 #include <netinet/in.h>
7 #include <systemd/sd-event.h>
8 
9 #include <array>
10 #include <chrono>
11 #include <cstddef>
12 #include <functional>
13 #include <list>
14 #include <map>
15 #include <memory>
16 #include <sdeventplus/clock.hpp>
17 #include <sdeventplus/utility/timer.hpp>
18 #include <set>
19 #include <string>
20 #include <variant>
21 #include <vector>
22 
23 namespace phosphor
24 {
25 namespace network
26 {
27 
28 using namespace std::chrono_literals;
29 
30 // wait for three seconds before restarting the networkd
31 constexpr auto restartTimeout = 3s;
32 
33 // refresh the objets after five seconds as network
34 // configuration takes 3-4 sec after systemd-networkd restart.
35 constexpr auto refreshTimeout = restartTimeout + 7s;
36 
37 namespace systemd
38 {
39 namespace config
40 {
41 
42 constexpr auto networkFilePrefix = "00-bmc-";
43 constexpr auto networkFileSuffix = ".network";
44 constexpr auto deviceFileSuffix = ".netdev";
45 
46 } // namespace config
47 } // namespace systemd
48 
49 using IntfName = std::string;
50 
51 struct AddrInfo
52 {
53     uint8_t addrType;
54     std::string ipaddress;
55     uint16_t prefix;
56 };
57 
58 using Addr_t = ifaddrs*;
59 
60 struct AddrDeleter
61 {
62     void operator()(Addr_t ptr) const
63     {
64         freeifaddrs(ptr);
65     }
66 };
67 
68 using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
69 
70 /* Need a custom deleter for freeing up sd_event */
71 struct EventDeleter
72 {
73     void operator()(sd_event* event) const
74     {
75         sd_event_unref(event);
76     }
77 };
78 using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
79 
80 template <typename T>
81 using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
82 
83 // Byte representations for common address types in network byte order
84 using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
85 
86 using AddrList = std::list<AddrInfo>;
87 using IntfAddrMap = std::map<IntfName, AddrList>;
88 using InterfaceList = std::set<IntfName>;
89 
90 using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
91 
92 } // namespace network
93 } // namespace phosphor
94