Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ratan Gupta | 3681a50 | 2017-06-17 19:20:04 +0530 | [diff] [blame] | 3 | #include <ifaddrs.h> |
| 4 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 5 | #include <list> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | #include <map> |
Ratan Gupta | 3681a50 | 2017-06-17 19:20:04 +0530 | [diff] [blame] | 9 | #include <memory> |
Ratan Gupta | fd4b0f0 | 2017-09-16 06:01:24 +0530 | [diff] [blame] | 10 | #include <set> |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 11 | #include <chrono> |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 12 | #include <systemd/sd-event.h> |
| 13 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 14 | namespace phosphor |
| 15 | { |
| 16 | namespace network |
| 17 | { |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 18 | |
| 19 | using namespace std::chrono_literals; |
Ratan Gupta | 16f1288 | 2017-09-22 18:26:11 +0530 | [diff] [blame] | 20 | |
| 21 | // wait for three seconds before restarting the networkd |
| 22 | constexpr auto restartTimeout = 3s; |
| 23 | |
| 24 | // refresh the objets after five seconds as network |
| 25 | // configuration takes 3-4 sec after systemd-networkd restart. |
| 26 | constexpr auto refreshTimeout = restartTimeout + 5s; |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 27 | |
Ratan Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 28 | namespace systemd |
| 29 | { |
| 30 | namespace config |
| 31 | { |
| 32 | |
| 33 | constexpr auto networkFilePrefix = "00-bmc-"; |
| 34 | constexpr auto networkFileSuffix = ".network"; |
| 35 | constexpr auto deviceFileSuffix = ".netdev"; |
| 36 | |
| 37 | }// namespace config |
| 38 | }// namespace systemd |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 39 | |
| 40 | using IntfName = std::string; |
| 41 | |
| 42 | struct AddrInfo { |
| 43 | uint8_t addrType; |
| 44 | std::string ipaddress; |
| 45 | uint16_t prefix; |
| 46 | }; |
| 47 | |
Ratan Gupta | 3681a50 | 2017-06-17 19:20:04 +0530 | [diff] [blame] | 48 | using Addr_t = ifaddrs*; |
| 49 | |
| 50 | struct AddrDeleter |
| 51 | { |
| 52 | void operator()(Addr_t ptr) const |
| 53 | { |
| 54 | freeifaddrs(ptr); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>; |
| 59 | |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 60 | /* Need a custom deleter for freeing up sd_event */ |
| 61 | struct EventDeleter |
| 62 | { |
| 63 | void operator()(sd_event* event) const |
| 64 | { |
| 65 | event = sd_event_unref(event); |
| 66 | } |
| 67 | }; |
| 68 | using EventPtr = std::unique_ptr<sd_event, EventDeleter>; |
| 69 | |
| 70 | template<typename T> |
| 71 | using UniquePtr = std::unique_ptr<T, std::function<void(T*)>>; |
Ratan Gupta | 3681a50 | 2017-06-17 19:20:04 +0530 | [diff] [blame] | 72 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 73 | using AddrList = std::list<AddrInfo>; |
| 74 | using IntfAddrMap = std::map<IntfName, AddrList>; |
Ratan Gupta | fd4b0f0 | 2017-09-16 06:01:24 +0530 | [diff] [blame] | 75 | using InterfaceList = std::set<IntfName>; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 76 | |
| 77 | }//namespace network |
| 78 | }//namespace phosphor |