llmx-rtaco 0.0.1
RTNL-only netlink control-plane library for Linux (C++23).
Loading...
Searching...
No Matches
nl_link_task.hxx
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <span>
5
6#include <linux/netlink.h>
7#include <linux/rtnetlink.h>
8
10
11namespace llmx {
12namespace rtaco {
13
15 nlmsghdr header;
16 ifinfomsg message;
17};
18
26template<typename Derived, typename Result>
27class LinkTask : public RequestTask<Derived, Result> {
28protected:
30
31public:
32 using RequestTask<Derived, Result>::RequestTask;
33
35 auto request_payload() const -> std::span<const uint8_t> {
36 return {reinterpret_cast<const uint8_t*>(&request_), request_.header.nlmsg_len};
37 }
38
39protected:
40 void build_request(uint16_t msg_flags = NLM_F_REQUEST | NLM_F_DUMP,
41 uint8_t family = AF_UNSPEC, uint16_t type = 0, uint32_t flags = 0,
42 uint32_t change = 0) {
43 request_.header.nlmsg_len = NLMSG_LENGTH(sizeof(ifinfomsg));
44 request_.header.nlmsg_type = RTM_GETLINK;
45 request_.header.nlmsg_flags = msg_flags;
46 request_.header.nlmsg_seq = this->sequence();
47 request_.header.nlmsg_pid = 0;
48
49 request_.message.ifi_family = family;
50 request_.message.ifi_type = type;
51 request_.message.ifi_index = this->ifindex();
52 request_.message.ifi_flags = flags;
53 request_.message.ifi_change = change;
54 }
55};
56
57} // namespace rtaco
58} // namespace llmx
Base task type for link-related netlink operations.
Definition nl_link_task.hxx:27
void build_request(uint16_t msg_flags=NLM_F_REQUEST|NLM_F_DUMP, uint8_t family=AF_UNSPEC, uint16_t type=0, uint32_t flags=0, uint32_t change=0)
Definition nl_link_task.hxx:40
auto request_payload() const -> std::span< const uint8_t >
Get the serialized payload for the link request.
Definition nl_link_task.hxx:35
LinkRequest request_
Definition nl_link_task.hxx:29
Base template for single-request netlink tasks.
Definition nl_request_task.hxx:46
RequestTask(SocketGuard &socket_guard, uint16_t ifindex, uint32_t sequence) noexcept
Construct a RequestTask.
Definition nl_request_task.hxx:61
auto ifindex() const noexcept -> uint16_t
Definition nl_request_task.hxx:93
auto sequence() const noexcept -> uint32_t
Definition nl_request_task.hxx:89
Definition nl_common.hxx:21
Definition nl_common.hxx:20
Definition nl_link_task.hxx:14
ifinfomsg message
Definition nl_link_task.hxx:16
nlmsghdr header
Definition nl_link_task.hxx:15