blob: 14de360e88de1da8c73044fe3cd4de9a41726cbe [file] [log] [blame]
Ratan Gupta82549cc2017-04-21 08:45:23 +05301#pragma once
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -07002#include <stdplus/net/addr/ether.hpp>
William A. Kennington III9b2a20d2023-06-17 14:05:48 -07003#include <stdplus/net/addr/ip.hpp>
4#include <stdplus/net/addr/subnet.hpp>
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -07005
William A. Kennington IIIbb0eacc2022-10-21 15:22:06 -07006#include <array>
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -08007#include <optional>
Patrick Venture189d44e2018-07-09 12:30:59 -07008#include <string>
William A. Kennington IIIdd9ef812022-10-05 02:08:02 -07009#include <unordered_map>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053010
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070011namespace phosphor::network
William A. Kennington III454a0de2022-11-12 01:01:04 -080012{
William A. Kennington III0d7ce482019-01-30 17:14:23 -080013
William A. Kennington III454a0de2022-11-12 01:01:04 -080014/** @class InterfaceInfo
15 * @brief Information about interfaces from the kernel
16 */
17struct InterfaceInfo
18{
William A. Kennington III9c441fd2023-02-24 13:40:01 -080019 unsigned short type;
William A. Kennington III454a0de2022-11-12 01:01:04 -080020 unsigned idx;
21 unsigned flags;
22 std::optional<std::string> name = std::nullopt;
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -070023 std::optional<stdplus::EtherAddr> mac = std::nullopt;
William A. Kennington III454a0de2022-11-12 01:01:04 -080024 std::optional<unsigned> mtu = std::nullopt;
25 std::optional<unsigned> parent_idx = std::nullopt;
26 std::optional<std::string> kind = std::nullopt;
27 std::optional<uint16_t> vlan_id = std::nullopt;
28
29 constexpr bool operator==(const InterfaceInfo& rhs) const noexcept
30 {
31 return idx == rhs.idx && flags == rhs.flags && name == rhs.name &&
32 mac == rhs.mac && mtu == rhs.mtu &&
33 parent_idx == rhs.parent_idx && kind == rhs.kind &&
34 vlan_id == rhs.vlan_id;
35 }
36};
37
William A. Kennington III6a923632022-11-06 18:17:33 -080038/** @class AddressInfo
39 * @brief Information about a addresses from the kernel
40 */
41struct AddressInfo
42{
43 unsigned ifidx;
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070044 stdplus::SubnetAny ifaddr;
William A. Kennington III6a923632022-11-06 18:17:33 -080045 uint8_t scope;
46 uint32_t flags;
William A. Kennington III454a0de2022-11-12 01:01:04 -080047
48 constexpr bool operator==(const AddressInfo& rhs) const noexcept
49 {
50 return ifidx == rhs.ifidx && ifaddr == rhs.ifaddr &&
51 scope == rhs.scope && flags == rhs.flags;
52 }
William A. Kennington III6a923632022-11-06 18:17:33 -080053};
54
William A. Kennington IIIa8426902022-11-07 15:37:41 -080055/** @class NeighborInfo
56 * @brief Information about a neighbor from the kernel
57 */
58struct NeighborInfo
59{
60 unsigned ifidx;
William A. Kennington III454a0de2022-11-12 01:01:04 -080061 uint16_t state;
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070062 std::optional<stdplus::InAnyAddr> addr;
William A. Kennington IIIb7d6a1a2023-06-17 02:00:53 -070063 std::optional<stdplus::EtherAddr> mac;
William A. Kennington III454a0de2022-11-12 01:01:04 -080064
65 constexpr bool operator==(const NeighborInfo& rhs) const noexcept
66 {
67 return ifidx == rhs.ifidx && state == rhs.state && addr == rhs.addr &&
68 mac == rhs.mac;
69 }
William A. Kennington IIIa8426902022-11-07 15:37:41 -080070};
71
William A. Kennington III13d665c2022-11-15 20:34:40 -080072/** @brief Contains all of the object information about the interface */
73struct AllIntfInfo
74{
75 InterfaceInfo intf;
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070076 std::optional<stdplus::In4Addr> defgw4 = std::nullopt;
77 std::optional<stdplus::In6Addr> defgw6 = std::nullopt;
78 std::unordered_map<stdplus::SubnetAny, AddressInfo> addrs = {};
79 std::unordered_map<stdplus::InAnyAddr, NeighborInfo> staticNeighs = {};
William A. Kennington III13d665c2022-11-15 20:34:40 -080080};
81
82} // namespace phosphor::network