xref: /openbmc/phosphor-networkd/src/types.hpp (revision ab27a819bee0db24233f9d0e7e142b3e3424c5b8)
1 #pragma once
2 #include <function2/function2.hpp>
3 #include <stdplus/net/addr/ether.hpp>
4 #include <stdplus/net/addr/ip.hpp>
5 #include <stdplus/net/addr/subnet.hpp>
6 
7 #include <array>
8 #include <optional>
9 #include <string>
10 #include <unordered_map>
11 
12 namespace phosphor::network
13 {
14 
15 class DelayedExecutor
16 {
17   public:
18     virtual ~DelayedExecutor() = default;
19 
20     virtual void schedule() = 0;
21     virtual void setCallback(fu2::unique_function<void()>&& cb) = 0;
22 };
23 
24 /** @class InterfaceInfo
25  *  @brief Information about interfaces from the kernel
26  */
27 struct InterfaceInfo
28 {
29     unsigned short type;
30     unsigned idx;
31     unsigned flags;
32     std::optional<std::string> name = std::nullopt;
33     std::optional<stdplus::EtherAddr> mac = std::nullopt;
34     std::optional<unsigned> mtu = std::nullopt;
35     std::optional<unsigned> parent_idx = std::nullopt;
36     std::optional<std::string> kind = std::nullopt;
37     std::optional<uint16_t> vlan_id = std::nullopt;
38 
operator ==phosphor::network::InterfaceInfo39     constexpr bool operator==(const InterfaceInfo& rhs) const noexcept
40     {
41         return idx == rhs.idx && flags == rhs.flags && name == rhs.name &&
42                mac == rhs.mac && mtu == rhs.mtu &&
43                parent_idx == rhs.parent_idx && kind == rhs.kind &&
44                vlan_id == rhs.vlan_id;
45     }
46 };
47 
48 /** @class AddressInfo
49  *  @brief Information about a addresses from the kernel
50  */
51 struct AddressInfo
52 {
53     unsigned ifidx;
54     stdplus::SubnetAny ifaddr;
55     uint8_t scope;
56     uint32_t flags;
57 
operator ==phosphor::network::AddressInfo58     constexpr bool operator==(const AddressInfo& rhs) const noexcept
59     {
60         return ifidx == rhs.ifidx && ifaddr == rhs.ifaddr &&
61                scope == rhs.scope && flags == rhs.flags;
62     }
63 };
64 
65 /** @class NeighborInfo
66  *  @brief Information about a neighbor from the kernel
67  */
68 struct NeighborInfo
69 {
70     unsigned ifidx;
71     uint16_t state;
72     std::optional<stdplus::InAnyAddr> addr;
73     std::optional<stdplus::EtherAddr> mac;
74 
operator ==phosphor::network::NeighborInfo75     constexpr bool operator==(const NeighborInfo& rhs) const noexcept
76     {
77         return ifidx == rhs.ifidx && state == rhs.state && addr == rhs.addr &&
78                mac == rhs.mac;
79     }
80 };
81 
82 /** @class StaticGatewayInfo
83  *  @brief Information about a static gateway from the kernel
84  */
85 struct StaticGatewayInfo
86 {
87     unsigned ifidx;
88     std::optional<std::string> gateway;
89     std::optional<std::string> protocol;
90 
operator ==phosphor::network::StaticGatewayInfo91     constexpr bool operator==(const StaticGatewayInfo& rhs) const noexcept
92     {
93         return ifidx == rhs.ifidx && gateway == rhs.gateway;
94     }
95 };
96 
97 /** @brief Contains all of the object information about the interface */
98 struct AllIntfInfo
99 {
100     InterfaceInfo intf;
101     std::optional<stdplus::In4Addr> defgw4 = std::nullopt;
102     std::optional<stdplus::In6Addr> defgw6 = std::nullopt;
103     std::unordered_map<stdplus::SubnetAny, AddressInfo> addrs = {};
104     std::unordered_map<stdplus::InAnyAddr, NeighborInfo> staticNeighs = {};
105     std::unordered_map<std::string, StaticGatewayInfo> staticGateways = {};
106 };
107 
108 } // namespace phosphor::network
109