15#include <system_error>
18#include <linux/netlink.h>
20#include <sys/socket.h>
22#include <boost/asio/detail/socket_option.hpp>
50 using native_t =
typename socket_t::native_handle_type;
53 explicit Socket(boost::asio::io_context& io, std::string_view label)
noexcept;
65 auto
is_open() const noexcept ->
bool;
72 auto
close() -> std::expected<
void, std::error_code>;
79 auto
cancel() -> std::expected<
void, std::error_code>;
92 auto
open(
int proto, uint32_t groups) -> std::expected<
void, std::error_code>;
94 template<typename Option>
99 template<
typename Endpo
int>
104 template<
typename Endpo
int>
109 template<
typename MutableBufferSequence,
typename CompletionToken>
110 auto async_receive(
const MutableBufferSequence& buffers, CompletionToken&& token)
111 ->
decltype(std::declval<socket_t>().async_receive(buffers,
112 std::forward<CompletionToken>(token))) {
113 return socket_.async_receive(buffers, std::forward<CompletionToken>(token));
116 template<
typename MutableBufferSequence>
117 auto receive(
const MutableBufferSequence& buffers, boost::system::error_code& ec)
119 return socket_.receive(buffers, 0, ec);
122 template<
typename ConstBufferSequence,
typename CompletionToken>
123 auto async_send(
const ConstBufferSequence& buffers, CompletionToken&& token)
124 ->
decltype(std::declval<socket_t>()
125 .async_send(buffers, std::forward<CompletionToken>(token))) {
126 return socket_.async_send(buffers, std::forward<CompletionToken>(token));
129 template<
typename ConstBufferSequence>
130 auto send(
const ConstBufferSequence& buffers, boost::system::error_code& ec)
132 return socket_.send(buffers, 0, ec);
144 boost::asio::detail::socket_option::integer<SOL_NETLINK, NETLINK_EXT_ACK>;
147 NETLINK_GET_STRICT_CHK>;
150 boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVBUF>;
153 boost::asio::detail::socket_option::integer<SOL_NETLINK, NETLINK_NO_ENOBUFS>;
Netlink-specific endpoint wrapper for Boost.Asio.
Definition nl_protocol.hxx:23
boost::asio::basic_raw_socket< Protocol > socket
Definition nl_protocol.hxx:108
Endpoint< Protocol > endpoint
Definition nl_protocol.hxx:107
std::string label_
Definition nl_socket.hxx:156
~Socket() noexcept
Destroy the Socket object and ensure underlying socket is closed.
Definition nl_socket.cxx:25
auto async_send(const ConstBufferSequence &buffers, CompletionToken &&token) -> decltype(std::declval< socket_t >() .async_send(buffers, std::forward< CompletionToken >(token)))
Definition nl_socket.hxx:123
boost::asio::detail::socket_option::integer< SOL_SOCKET, SO_RCVBUF > recv_buf_option
Definition nl_socket.hxx:149
auto close() -> std::expected< void, std::error_code >
Close the underlying socket.
Definition nl_socket.cxx:35
boost::asio::detail::socket_option::integer< SOL_NETLINK, NETLINK_NO_ENOBUFS > no_enobufs_option
Definition nl_socket.hxx:152
boost::asio::detail::socket_option::integer< SOL_NETLINK, NETLINK_GET_STRICT_CHK > strict_chk_option
Definition nl_socket.hxx:146
auto open(int proto, uint32_t groups) -> std::expected< void, std::error_code >
Open and configure the netlink socket.
Definition nl_socket.cxx:55
boost::asio::detail::socket_option::integer< SOL_NETLINK, NETLINK_EXT_ACK > ext_ack_option
Definition nl_socket.hxx:143
void bind(const Endpoint &endpoint, boost::system::error_code &ec)
Definition nl_socket.hxx:100
socket_t socket_
Definition nl_socket.hxx:155
auto receive(const MutableBufferSequence &buffers, boost::system::error_code &ec) -> size_t
Definition nl_socket.hxx:117
auto is_open() const noexcept -> bool
Check whether the socket is currently open.
Definition nl_socket.cxx:31
auto async_receive(const MutableBufferSequence &buffers, CompletionToken &&token) -> decltype(std::declval< socket_t >().async_receive(buffers, std::forward< CompletionToken >(token)))
Definition nl_socket.hxx:110
typename socket_t::native_handle_type native_t
Definition nl_socket.hxx:50
Socket(boost::asio::io_context &io, std::string_view label) noexcept
Construct a netlink Socket with an io_context and label.
Definition nl_socket.cxx:21
Protocol::endpoint endpoint_t
Definition nl_socket.hxx:49
void connect(const Endpoint &endpoint, boost::system::error_code &ec)
Definition nl_socket.hxx:105
auto send(const ConstBufferSequence &buffers, boost::system::error_code &ec) -> size_t
Definition nl_socket.hxx:130
void set_option(const Option &option, boost::system::error_code &ec)
Definition nl_socket.hxx:95
auto native_handle() -> native_t
Get the native socket handle.
Definition nl_socket.cxx:113
Protocol::socket socket_t
Definition nl_socket.hxx:48
auto cancel() -> std::expected< void, std::error_code >
Cancel any asynchronous operations on the socket.
Definition nl_socket.cxx:45
Definition nl_socket.hxx:27
Definition nl_socket.hxx:32
Definition nl_socket.hxx:26
Definition nl_common.hxx:20