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