llmx-rtaco 0.0.1
RTNL-only netlink control-plane library for Linux (C++23).
Loading...
Searching...
No Matches
nl_common.hxx File Reference
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <unordered_map>
#include <arpa/inet.h>
#include <net/if.h>
#include <linux/netlink.h>
#include <linux/neighbour.h>
#include <linux/rtnetlink.h>

Go to the source code of this file.

Namespaces

namespace  llmx
namespace  llmx::rtaco

Concepts

concept  llmx::rtaco::IsEnumeration
concept  llmx::rtaco::IsNetlinkEvent

Functions

constexpr auto llmx::rtaco::trim_string (std::string_view sv) -> std::string
 Remove trailing NUL characters and return an owning string.
template<size_t N>
constexpr auto llmx::rtaco::trim_string (const std::array< char, N > &arr) -> std::string
 Remove trailing NULs from a fixed-size char array and return a string.
template<typename MsgT>
auto llmx::rtaco::checked_attr_begin (const nlmsghdr &header, const MsgT *info, int &attr_length) -> const rtattr *
 Return the aligned first attribute pointer and payload length.
auto llmx::rtaco::checked_attr_ok (const rtattr *attr, int attr_length) -> bool
 Validate the current attribute against remaining message length.
auto llmx::rtaco::checked_attr_next (const rtattr *attr, int &attr_length) -> const rtattr *
 Advance to the next attribute and update remaining length.
template<typename T>
auto llmx::rtaco::checked_payload (const rtattr &attr) -> const T *
 Read a typed rtattr payload only when the payload is large enough.
template<typename T>
auto llmx::rtaco::checked_payload_copy (const rtattr &attr) -> std::optional< T >
 Read a typed rtattr payload by value when the payload is large enough.
auto llmx::rtaco::extract_ifname (const nlmsghdr &header) -> std::string
 Extract the interface name from a netlink header.
auto llmx::rtaco::attribute_string (const rtattr &attr) -> std::string
 Convert an rtattr payload to a trimmed std::string.
auto llmx::rtaco::attribute_address (const rtattr &attr, uint8_t family) -> std::string
 Convert an rtattr payload to a text representation of an IP address.
auto llmx::rtaco::attribute_uint32 (const rtattr &attr) -> uint32_t
 Read a uint32_t value from an rtattr payload.
auto llmx::rtaco::attribute_hwaddr (const rtattr &attr) -> std::string
 Format a hardware address (MAC) from an rtattr payload as a string.
template<typename MsgT>
const MsgT * llmx::rtaco::get_msg_payload (const nlmsghdr &header)
 Get a typed pointer to the message payload in a netlink header.
auto llmx::rtaco::checked_nlmsgerr (const nlmsghdr &header) -> const nlmsgerr *
 Extract a checked nlmsgerr payload from an NLMSG_ERROR message.
template<typename MsgT, typename Fn>
void llmx::rtaco::for_each_attr (const nlmsghdr &header, const MsgT *info, Fn &&fn)
 Iterate over rtattr attributes for a given message payload.
auto llmx::rtaco::type_to_string (IsNetlinkEvent auto &&type) noexcept -> std::string_view
 Convert a netlink message or event type to a readable name.
auto llmx::rtaco::family_to_string (uint8_t family) noexcept -> std::string_view
 Convert an address family constant to a human-readable name.
auto llmx::rtaco::protocol_to_string (uint8_t protocol) noexcept -> std::string_view
 Convert a protocol identifier to a readable name.
auto llmx::rtaco::route_type_to_string (uint8_t route_type) noexcept -> std::string_view
 Convert a route type constant to a string.