xref: /openbmc/phosphor-networkd/src/types.hpp (revision c9900079)
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 
39     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 
58     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 
75     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 /** @brief Contains all of the object information about the interface */
83 struct AllIntfInfo
84 {
85     InterfaceInfo intf;
86     std::optional<stdplus::In4Addr> defgw4 = std::nullopt;
87     std::optional<stdplus::In6Addr> defgw6 = std::nullopt;
88     std::unordered_map<stdplus::SubnetAny, AddressInfo> addrs = {};
89     std::unordered_map<stdplus::InAnyAddr, NeighborInfo> staticNeighs = {};
90 };
91 
92 } // namespace phosphor::network
93