base class for netlink-based managers.
More...
#include <netlinkmanager.hpp>
|
| void | start () |
| | start listening for netlink events.
|
| |
| void | stop () |
| | stop listening for netlink events.
|
| |
| int | sendRequest (struct nlmsghdr *nlh, bool sync, std::chrono::milliseconds timeout=std::chrono::seconds(5)) |
| | send a netlink request, optionally waiting for the ack.
|
| |
| template<class Rep , class Period > |
| int | waitResponse (ScopedLock< Mutex > &lock, uint32_t seq, std::chrono::duration< Rep, Period > timeout) |
| | wait for specific netlink response.
|
| |
| virtual void | onReceive (int fd) override final |
| | method called when data are ready to be read on handle.
|
| |
| virtual void | onMessage (struct nlmsghdr *nlh)=0 |
| | dispatch a single RTM_* message to the derived class.
|
| |
| void | notifyRequest (uint32_t seq, int error=0) |
| | notify a pending synchronous request.
|
| |
|
| static void | addAttributes (struct nlmsghdr *nlh, int type, const void *data, int alen) |
| | add an attribute to a netlink message.
|
| |
| static struct rtattr * | startNestedAttributes (struct nlmsghdr *nlh, int type) |
| | open a nested attribute block.
|
| |
| static int | stopNestedAttributes (struct nlmsghdr *nlh, struct rtattr *nested) |
| | close a nested attribute block.
|
| |
| template<typename T , typename Flag > |
| static Flag | updateValue (T &oldVal, const T &newVal, Flag changed) |
| | update a value in place and report whether it changed.
|
| |
|
| static constexpr size_t | _bufferSize = 16384 |
| | internal buffer size.
|
| |
base class for netlink-based managers.
◆ NetlinkManager() [1/3]
| NetlinkManager::NetlinkManager |
( |
uint32_t | groups, |
|
|
Reactor * | reactor = nullptr ) |
create instance.
- Parameters
-
| groups | netlink multicast group bitmask to subscribe to. |
| reactor | event loop reactor. |
◆ NetlinkManager() [2/3]
◆ NetlinkManager() [3/3]
◆ ~NetlinkManager()
| virtual join::NetlinkManager::~NetlinkManager |
( |
| ) |
|
|
virtualdefault |
◆ addAttributes()
| void NetlinkManager::addAttributes |
( |
struct nlmsghdr * | nlh, |
|
|
int | type, |
|
|
const void * | data, |
|
|
int | alen ) |
|
staticprotected |
add an attribute to a netlink message.
- Parameters
-
| nlh | netlink message header. |
| type | attribute type (RTA_*, IFA_*, NDA_*, …). |
| data | attribute payload. |
| alen | payload length in bytes. |
◆ notifyRequest()
| void NetlinkManager::notifyRequest |
( |
uint32_t | seq, |
|
|
int | error = 0 ) |
|
protected |
notify a pending synchronous request.
- Parameters
-
| seq | sequence number of the completed request. |
| error | kernel error code (0 on success, positive errno). |
◆ onMessage()
| virtual void join::NetlinkManager::onMessage |
( |
struct nlmsghdr * | nlh | ) |
|
|
protectedpure virtual |
dispatch a single RTM_* message to the derived class.
- Parameters
-
| nlh | the netlink message to process. |
◆ onReceive()
| void NetlinkManager::onReceive |
( |
int | fd | ) |
|
|
finaloverrideprotectedvirtual |
method called when data are ready to be read on handle.
- Parameters
-
Reimplemented from join::EventHandler.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ reactor()
| Reactor * NetlinkManager::reactor |
( |
| ) |
const |
|
noexcept |
get the event loop reactor.
- Returns
- pointer to the reactor.
◆ sendRequest()
| int NetlinkManager::sendRequest |
( |
struct nlmsghdr * | nlh, |
|
|
bool | sync, |
|
|
std::chrono::milliseconds | timeout = std::chrono::seconds (5) ) |
|
protected |
send a netlink request, optionally waiting for the ack.
- Parameters
-
| nlh | netlink message to send. |
| sync | if true, block until NLMSG_ERROR/NLMSG_DONE is received. |
| timeout | maximum wait duration when sync is true (default: 5 seconds). |
- Returns
- 0 on success, -1 on failure.
◆ start()
| void NetlinkManager::start |
( |
| ) |
|
|
protected |
start listening for netlink events.
◆ startNestedAttributes()
| struct rtattr * NetlinkManager::startNestedAttributes |
( |
struct nlmsghdr * | nlh, |
|
|
int | type ) |
|
staticprotected |
open a nested attribute block.
- Parameters
-
| nlh | netlink message header. |
| type | container attribute type. |
- Returns
- pointer to the container rtattr (pass to stopNestedAttributes).
◆ stop()
| void NetlinkManager::stop |
( |
| ) |
|
|
protected |
stop listening for netlink events.
◆ stopNestedAttributes()
| int NetlinkManager::stopNestedAttributes |
( |
struct nlmsghdr * | nlh, |
|
|
struct rtattr * | nested ) |
|
staticprotected |
close a nested attribute block.
- Parameters
-
| nlh | netlink message header. |
| nested | pointer returned by startNestedAttributes. |
- Returns
- current message length.
◆ updateValue()
template<typename T , typename Flag >
| static Flag join::NetlinkManager::updateValue |
( |
T & | oldVal, |
|
|
const T & | newVal, |
|
|
Flag | changed ) |
|
inlinestaticprotected |
update a value in place and report whether it changed.
- Parameters
-
| oldVal | value to update. |
| newVal | candidate new value. |
- Returns
- true if the value was changed, false otherwise.
◆ waitResponse()
template<class Rep , class Period >
| int join::NetlinkManager::waitResponse |
( |
ScopedLock< Mutex > & | lock, |
|
|
uint32_t | seq, |
|
|
std::chrono::duration< Rep, Period > | timeout ) |
|
inlineprotected |
wait for specific netlink response.
- Parameters
-
| lock | mutex previously locked by the calling thread. |
| seq | sequence number to wait for. |
| timeout | maximum wait duration. |
- Returns
- 0 on success, -1 on failure.
◆ _buffer
| std::unique_ptr<char[]> join::NetlinkManager::_buffer |
|
protected |
◆ _bufferSize
| size_t join::NetlinkManager::_bufferSize = 16384 |
|
staticconstexprprotected |
◆ _pending
| std::unordered_map<uint32_t, std::unique_ptr<PendingRequest> > join::NetlinkManager::_pending |
|
protected |
synchronous requests indexed by sequence number.
◆ _reactor
| Reactor* join::NetlinkManager::_reactor |
|
protected |
◆ _seq
| std::atomic<uint32_t> join::NetlinkManager::_seq |
|
protected |
◆ _syncMutex
| Mutex join::NetlinkManager::_syncMutex |
|
protected |
The documentation for this class was generated from the following files: