llmx-rtaco 0.0.1
RTNL-only netlink control-plane library for Linux (C++23).
Loading...
Searching...
No Matches
nl_control.hxx
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <expected>
6#include <span>
7#include <system_error>
8
9#include <boost/asio/awaitable.hpp>
10#include <boost/asio/io_context.hpp>
11#include <boost/asio/strand.hpp>
12#include <boost/asio/steady_timer.hpp>
13
19
20namespace llmx {
21namespace rtaco {
22
31class Control {
32 using route_list_result_t = std::expected<RouteEventList, std::error_code>;
33 using address_list_result_t = std::expected<AddressEventList, std::error_code>;
34 using link_list_result_t = std::expected<LinkEventList, std::error_code>;
35 using neighbor_result_t = std::expected<NeighborEvent, std::error_code>;
36 using neighbor_list_result = std::expected<NeighborEventList, std::error_code>;
37 using void_result_t = std::expected<void, std::error_code>;
38
39public:
44 Control(boost::asio::io_context& io) noexcept;
45
48
49 Control(const Control&) = delete;
50 Control& operator=(const Control&) = delete;
51 Control(Control&&) = delete;
53
59
62
65
68
73 auto async_dump_routes() -> boost::asio::awaitable<route_list_result_t>;
74
76 auto async_dump_addresses() -> boost::asio::awaitable<address_list_result_t>;
77
79 auto async_dump_links() -> boost::asio::awaitable<link_list_result_t>;
80
82 auto async_dump_neighbors() -> boost::asio::awaitable<neighbor_list_result>;
83
90 auto probe_neighbor(uint16_t ifindex, std::span<uint8_t, 16> address)
92
94 auto flush_neighbor(uint16_t ifindex, std::span<uint8_t, 16> address)
96
98 auto get_neighbor(uint16_t ifindex, std::span<uint8_t, 16> address)
100
102 auto async_probe_neighbor(uint16_t ifindex, std::span<uint8_t, 16> address)
103 -> boost::asio::awaitable<void_result_t>;
104
106 auto async_flush_neighbor(uint16_t ifindex, std::span<uint8_t, 16> address)
107 -> boost::asio::awaitable<void_result_t>;
108
110 auto async_get_neighbor(uint16_t ifindex, std::span<uint8_t, 16> address)
111 -> boost::asio::awaitable<neighbor_result_t>;
112
114 void stop();
115
116private:
117 auto acquire_socket_token() -> boost::asio::awaitable<void>;
118
119 auto async_dump_routes_impl() -> boost::asio::awaitable<route_list_result_t>;
120 auto async_dump_addresses_impl() -> boost::asio::awaitable<address_list_result_t>;
121 auto async_dump_links_impl() -> boost::asio::awaitable<link_list_result_t>;
122 auto async_dump_neighbors_impl() -> boost::asio::awaitable<neighbor_list_result>;
123
124 auto async_probe_neighbor_impl(uint16_t ifindex, std::span<uint8_t, 16> address)
125 -> boost::asio::awaitable<void_result_t>;
126
127 auto async_flush_neighbor_impl(uint16_t ifindex, std::span<uint8_t, 16> address)
128 -> boost::asio::awaitable<void_result_t>;
129
130 auto async_get_neighbor_impl(uint16_t ifindex, std::span<uint8_t, 16> address)
131 -> boost::asio::awaitable<neighbor_result_t>;
132
133 boost::asio::io_context& io_;
134 boost::asio::strand<boost::asio::io_context::executor_type> strand_;
135 boost::asio::steady_timer gate_;
137 std::atomic_uint32_t sequence_{1U};
138};
139
140} // namespace rtaco
141} // namespace llmx
auto acquire_socket_token() -> boost::asio::awaitable< void >
Definition nl_control.cxx:242
auto async_dump_routes_impl() -> boost::asio::awaitable< route_list_result_t >
Definition nl_control.cxx:141
std::expected< RouteEventList, std::error_code > route_list_result_t
Definition nl_control.hxx:32
auto dump_neighbors() -> neighbor_list_result
Synchronously dump neighbor entries from the kernel.
Definition nl_control.cxx:61
auto async_dump_neighbors() -> boost::asio::awaitable< neighbor_list_result >
Asynchronously dump neighbors.
Definition nl_control.cxx:89
std::expected< NeighborEventList, std::error_code > neighbor_list_result
Definition nl_control.hxx:36
Control(Control &&)=delete
auto get_neighbor(uint16_t ifindex, std::span< uint8_t, 16 > address) -> neighbor_result_t
Get a neighbor entry synchronously.
Definition nl_control.cxx:123
boost::asio::io_context & io_
Definition nl_control.hxx:133
boost::asio::steady_timer gate_
Definition nl_control.hxx:135
std::expected< LinkEventList, std::error_code > link_list_result_t
Definition nl_control.hxx:34
auto async_dump_addresses_impl() -> boost::asio::awaitable< address_list_result_t >
Definition nl_control.cxx:155
Control(const Control &)=delete
auto async_flush_neighbor(uint16_t ifindex, std::span< uint8_t, 16 > address) -> boost::asio::awaitable< void_result_t >
Asynchronously flush a neighbor.
Definition nl_control.cxx:103
auto async_probe_neighbor_impl(uint16_t ifindex, std::span< uint8_t, 16 > address) -> boost::asio::awaitable< void_result_t >
Definition nl_control.cxx:200
~Control()
Destroy the Control object and release resources.
auto async_get_neighbor(uint16_t ifindex, std::span< uint8_t, 16 > address) -> boost::asio::awaitable< neighbor_result_t >
Asynchronously get a neighbor.
Definition nl_control.cxx:131
Control & operator=(Control &&)=delete
auto async_dump_routes() -> boost::asio::awaitable< route_list_result_t >
Asynchronously dump routes.
Definition nl_control.cxx:71
std::expected< void, std::error_code > void_result_t
Definition nl_control.hxx:37
auto async_probe_neighbor(uint16_t ifindex, std::span< uint8_t, 16 > address) -> boost::asio::awaitable< void_result_t >
Asynchronously probe a neighbor.
Definition nl_control.cxx:117
auto async_get_neighbor_impl(uint16_t ifindex, std::span< uint8_t, 16 > address) -> boost::asio::awaitable< neighbor_result_t >
Definition nl_control.cxx:228
void stop()
Stop ongoing operations and release control resources.
Definition nl_control.cxx:137
Control & operator=(const Control &)=delete
auto dump_routes() -> route_list_result_t
Synchronously dump routes from the kernel.
Definition nl_control.cxx:51
auto dump_addresses() -> address_list_result_t
Synchronously dump addresses from the kernel.
Definition nl_control.cxx:56
boost::asio::strand< boost::asio::io_context::executor_type > strand_
Definition nl_control.hxx:134
auto flush_neighbor(uint16_t ifindex, std::span< uint8_t, 16 > address) -> void_result_t
Flush a neighbour entry (synchronous).
Definition nl_control.cxx:95
auto async_dump_links_impl() -> boost::asio::awaitable< link_list_result_t >
Definition nl_control.cxx:185
std::expected< AddressEventList, std::error_code > address_list_result_t
Definition nl_control.hxx:33
auto probe_neighbor(uint16_t ifindex, std::span< uint8_t, 16 > address) -> void_result_t
Probe a neighbor entry (synchronous).
Definition nl_control.cxx:109
std::expected< NeighborEvent, std::error_code > neighbor_result_t
Definition nl_control.hxx:35
std::atomic_uint32_t sequence_
Definition nl_control.hxx:137
Control(boost::asio::io_context &io) noexcept
Construct a Control instance attached to an io_context.
auto dump_links() -> link_list_result_t
Synchronously dump links from the kernel.
Definition nl_control.cxx:66
auto async_flush_neighbor_impl(uint16_t ifindex, std::span< uint8_t, 16 > address) -> boost::asio::awaitable< void_result_t >
Definition nl_control.cxx:214
auto async_dump_links() -> boost::asio::awaitable< link_list_result_t >
Asynchronously dump links.
Definition nl_control.cxx:83
auto async_dump_neighbors_impl() -> boost::asio::awaitable< neighbor_list_result >
Definition nl_control.cxx:170
SocketGuard socket_guard_
Definition nl_control.hxx:136
auto async_dump_addresses() -> boost::asio::awaitable< address_list_result_t >
Asynchronously dump addresses.
Definition nl_control.cxx:77
Thread-safe guard owning a labeled Socket.
Definition nl_socket_guard.hxx:25
Definition nl_common.hxx:21
Definition nl_common.hxx:20