llmx-rtaco 0.0.1
RTNL-only netlink control-plane library for Linux (C++23).
Loading...
Searching...
No Matches
nl_neighbor_event.hxx
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <string>
6#include <string_view>
7#include <utility>
8#include <vector>
9
10#include <linux/neighbour.h>
11#include <linux/rtnetlink.h>
12
13struct nlmsghdr;
14
15namespace llmx {
16namespace rtaco {
17
19 enum class Type : uint16_t {
21 NEW_NEIGHBOR = RTM_NEWNEIGH,
22 DELETE_NEIGHBOR = RTM_DELNEIGH,
23 };
24
25 enum class State : uint16_t {
26 NONE = NUD_NONE,
27 INCOMPLETE = NUD_INCOMPLETE,
28 REACHABLE = NUD_REACHABLE,
29 STALE = NUD_STALE,
30 DELAY = NUD_DELAY,
31 PROBE = NUD_PROBE,
32 FAILED = NUD_FAILED,
33 NOARP = NUD_NOARP,
34 PERMANENT = NUD_PERMANENT,
35 };
36
38 int index{0};
39 uint8_t family{0U};
41 uint8_t flags{0U};
42 uint8_t neighbor_type{0U};
43 std::string address{};
44 std::string lladdr{};
45
50 auto state_to_string() const -> std::string {
51 if (std::to_underlying(state) == NUD_NONE) {
52 return "NUD_NONE";
53 }
54
55 struct StateName {
56 uint16_t mask;
57 std::string_view name;
58 };
59
60 static constexpr std::array<StateName, 8> state_names{{
61 {NUD_INCOMPLETE, "NUD_INCOMPLETE"},
62 {NUD_REACHABLE, "NUD_REACHABLE"},
63 {NUD_STALE, "NUD_STALE"},
64 {NUD_DELAY, "NUD_DELAY"},
65 {NUD_PROBE, "NUD_PROBE"},
66 {NUD_FAILED, "NUD_FAILED"},
67 {NUD_NOARP, "NUD_NOARP"},
68 {NUD_PERMANENT, "NUD_PERMANENT"},
69 }};
70
71 std::string result{};
72 for (const auto& entry : state_names) {
73 if ((std::to_underlying(state) & entry.mask) != 0U) {
74 if (!result.empty()) {
75 result += '|';
76 }
77 result.append(entry.name);
78 }
79 }
80
81 return result.empty() ? "UNKNOWN" : result;
82 }
83
85 static auto from_nlmsghdr(const nlmsghdr& header) -> NeighborEvent;
86};
87
88using NeighborEventList = std::pmr::vector<NeighborEvent>;
89
90} // namespace rtaco
91} // namespace llmx
Definition nl_common.hxx:21
std::pmr::vector< NeighborEvent > NeighborEventList
Definition nl_neighbor_event.hxx:88
Definition nl_common.hxx:20
Definition nl_neighbor_event.hxx:18
std::string lladdr
Definition nl_neighbor_event.hxx:44
auto state_to_string() const -> std::string
Convert the Neighbor state enum to a readable string.
Definition nl_neighbor_event.hxx:50
Type type
Definition nl_neighbor_event.hxx:37
Type
Definition nl_neighbor_event.hxx:19
@ UNKNOWN
Definition nl_neighbor_event.hxx:20
@ NEW_NEIGHBOR
Definition nl_neighbor_event.hxx:21
@ DELETE_NEIGHBOR
Definition nl_neighbor_event.hxx:22
int index
Definition nl_neighbor_event.hxx:38
uint8_t flags
Definition nl_neighbor_event.hxx:41
State
Definition nl_neighbor_event.hxx:25
@ INCOMPLETE
Definition nl_neighbor_event.hxx:27
@ STALE
Definition nl_neighbor_event.hxx:29
@ PERMANENT
Definition nl_neighbor_event.hxx:34
@ NOARP
Definition nl_neighbor_event.hxx:33
@ PROBE
Definition nl_neighbor_event.hxx:31
@ DELAY
Definition nl_neighbor_event.hxx:30
@ NONE
Definition nl_neighbor_event.hxx:26
@ FAILED
Definition nl_neighbor_event.hxx:32
@ REACHABLE
Definition nl_neighbor_event.hxx:28
static auto from_nlmsghdr(const nlmsghdr &header) -> NeighborEvent
Parse a NeighborEvent from a netlink message header.
Definition nl_neighbor_event.cxx:12
uint8_t neighbor_type
Definition nl_neighbor_event.hxx:42
std::string address
Definition nl_neighbor_event.hxx:43
uint8_t family
Definition nl_neighbor_event.hxx:39
State state
Definition nl_neighbor_event.hxx:40