join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::NeighborManager Class Reference

ARP / NDP neighbor manager class. More...

#include <neighbormanager.hpp>

Inheritance diagram for join::NeighborManager:
Collaboration diagram for join::NeighborManager:

Public Types

using NeighborNotify = std::function<void (const NeighborInfo& info)>
 

Public Member Functions

 NeighborManager (Reactor *reactor=nullptr)
 create instance.
 
 NeighborManager (const NeighborManager &other)=delete
 create instance by copy.
 
 NeighborManager (NeighborManager &&other)=delete
 create instance by move.
 
NeighborManageroperator= (const NeighborManager &other)=delete
 assign instance by copy.
 
NeighborManageroperator= (NeighborManager &&other)=delete
 assign instance by move.
 
 ~NeighborManager ()
 destroy instance.
 
Neighbor::Ptr findByIndex (uint32_t index, const IpAddress &ipAddress)
 find a neighbor entry by interface index and IP address.
 
Neighbor::Ptr findByName (const std::string &interfaceName, const IpAddress &ipAddress)
 find a neighbor entry by interface name and IP address.
 
NeighborList enumerate ()
 enumerate all cached neighbor entries.
 
NeighborList enumerate (uint32_t index)
 enumerate all cached neighbor entries for a given interface.
 
NeighborList enumerate (const std::string &interfaceName)
 enumerate all cached neighbor entries for a given interface.
 
int refresh ()
 refresh all data.
 
uint64_t addNeighborListener (const NeighborNotify &cb)
 register a callback invoked on any neighbor table change.
 
void removeNeighborListener (uint64_t id)
 unregister a previously registered callback.
 
int addNeighbor (uint32_t index, const IpAddress &ipAddress, const MacAddress &macAddress, uint16_t state=NUD_PERMANENT, bool sync=false)
 add or replace a neighbor entry in the kernel table.
 
int addNeighbor (const std::string &interfaceName, const IpAddress &ipAddress, const MacAddress &macAddress, uint16_t state=NUD_PERMANENT, bool sync=false)
 add or replace a neighbor entry in the kernel table.
 
int removeNeighbor (uint32_t index, const IpAddress &ipAddress, bool sync=false)
 remove a neighbor entry from the kernel table.
 
int removeNeighbor (const std::string &interfaceName, const IpAddress &ipAddress, bool sync=false)
 remove a neighbor entry from the kernel table.
 
int flushNeighbors (uint32_t index, bool sync=false)
 flush all neighbor entries for a given interface.
 
int flushNeighbors (const std::string &interfaceName, bool sync=false)
 flush all neighbor entries for a given interface.
 
- Public Member Functions inherited from join::NetlinkManager
 NetlinkManager (uint32_t groups, Reactor *reactor=nullptr)
 create instance.
 
 NetlinkManager (const NetlinkManager &)=delete
 create instance by copy.
 
 NetlinkManager (NetlinkManager &&)=delete
 create instance by move.
 
NetlinkManageroperator= (const NetlinkManager &)=delete
 assign instance by copy.
 
NetlinkManageroperator= (NetlinkManager &&)=delete
 assign instance by move.
 
virtual ~NetlinkManager ()=default
 destroy instance.
 
Reactorreactor () const noexcept
 get the event loop reactor.
 

Static Public Member Functions

static NeighborManagerinstance ()
 get the a singleton instance.
 

Friends

class Neighbor
 

Additional Inherited Members

- Protected Member Functions inherited from join::NetlinkManager
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.
 
void notifyRequest (uint32_t seq, int error=0)
 notify a pending synchronous request.
 
- Static Protected Member Functions inherited from join::NetlinkManager
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.
 
- Protected Attributes inherited from join::NetlinkManager
std::unique_ptr< char[]> _buffer
 internal read buffer.
 
std::atomic< uint32_t > _seq
 sequence number.
 
std::unordered_map< uint32_t, std::unique_ptr< PendingRequest > > _pending
 synchronous requests indexed by sequence number.
 
Mutex _syncMutex
 protection mutex.
 
Reactor_reactor
 event loop reactor.
 
- Static Protected Attributes inherited from join::NetlinkManager
static constexpr size_t _bufferSize = 16384
 internal buffer size.
 

Detailed Description

ARP / NDP neighbor manager class.

Member Typedef Documentation

◆ NeighborNotify

using join::NeighborManager::NeighborNotify = std::function<void (const NeighborInfo& info)>

Constructor & Destructor Documentation

◆ NeighborManager() [1/3]

NeighborManager::NeighborManager ( Reactor * reactor = nullptr)
explicit

create instance.

Parameters
reactorevent loop reactor (uses ReactorThread if nullptr).

◆ NeighborManager() [2/3]

join::NeighborManager::NeighborManager ( const NeighborManager & other)
delete

create instance by copy.

Parameters
otherother interface to copy.

◆ NeighborManager() [3/3]

join::NeighborManager::NeighborManager ( NeighborManager && other)
delete

create instance by move.

Parameters
otherother interface to move.

◆ ~NeighborManager()

NeighborManager::~NeighborManager ( )

destroy instance.

Member Function Documentation

◆ addNeighbor() [1/2]

int NeighborManager::addNeighbor ( const std::string & interfaceName,
const IpAddress & ipAddress,
const MacAddress & macAddress,
uint16_t state = NUD_PERMANENT,
bool sync = false )

add or replace a neighbor entry in the kernel table.

Parameters
interfaceNameinterface name.
ipAddressdestination address.
macAddressaddress to associate.
stateNUD state (default: NUD_PERMANENT).
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ addNeighbor() [2/2]

int NeighborManager::addNeighbor ( uint32_t index,
const IpAddress & ipAddress,
const MacAddress & macAddress,
uint16_t state = NUD_PERMANENT,
bool sync = false )

add or replace a neighbor entry in the kernel table.

Parameters
indexinterface index.
ipAddressdestination address.
macAddressaddress to associate.
stateNUD state (default: NUD_PERMANENT).
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ addNeighborListener()

uint64_t NeighborManager::addNeighborListener ( const NeighborNotify & cb)

register a callback invoked on any neighbor table change.

Parameters
cbcallback to register.
Returns
unique id for the callback.

◆ enumerate() [1/3]

NeighborList NeighborManager::enumerate ( )

enumerate all cached neighbor entries.

Returns
snapshot of the current neighbor list.

◆ enumerate() [2/3]

NeighborList NeighborManager::enumerate ( const std::string & interfaceName)

enumerate all cached neighbor entries for a given interface.

Parameters
interfaceNameinterface name.
Returns
snapshot of neighbor entries on that interface.

◆ enumerate() [3/3]

NeighborList NeighborManager::enumerate ( uint32_t index)

enumerate all cached neighbor entries for a given interface.

Parameters
indexinterface index.
Returns
snapshot of neighbor entries on that interface.

◆ findByIndex()

Neighbor::Ptr NeighborManager::findByIndex ( uint32_t index,
const IpAddress & ipAddress )

find a neighbor entry by interface index and IP address.

Parameters
indexinterface index.
ipAddressdestination address.
Returns
neighbor pointer, or nullptr if not found.

◆ findByName()

Neighbor::Ptr NeighborManager::findByName ( const std::string & interfaceName,
const IpAddress & ipAddress )

find a neighbor entry by interface name and IP address.

Parameters
interfaceNameinterface name.
ipAddressdestination address.
Returns
neighbor pointer, or nullptr if not found.

◆ flushNeighbors() [1/2]

int NeighborManager::flushNeighbors ( const std::string & interfaceName,
bool sync = false )

flush all neighbor entries for a given interface.

Parameters
interfaceNameinterface name.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ flushNeighbors() [2/2]

int NeighborManager::flushNeighbors ( uint32_t index,
bool sync = false )

flush all neighbor entries for a given interface.

Parameters
indexinterface index.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ instance()

NeighborManager & NeighborManager::instance ( )
static

get the a singleton instance.

Returns
reference to the singleton instance.

◆ operator=() [1/2]

NeighborManager & join::NeighborManager::operator= ( const NeighborManager & other)
delete

assign instance by copy.

Parameters
otherother interface to copy.
Returns
A reference of the current object.

◆ operator=() [2/2]

NeighborManager & join::NeighborManager::operator= ( NeighborManager && other)
delete

assign instance by move.

Parameters
otherother interface to move.
Returns
A reference of the current object.

◆ refresh()

int NeighborManager::refresh ( )

refresh all data.

Returns
0 on success, -1 on failure.

◆ removeNeighbor() [1/2]

int NeighborManager::removeNeighbor ( const std::string & interfaceName,
const IpAddress & ipAddress,
bool sync = false )

remove a neighbor entry from the kernel table.

Parameters
interfaceNameinterface name.
ipAddressdestination address.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ removeNeighbor() [2/2]

int NeighborManager::removeNeighbor ( uint32_t index,
const IpAddress & ipAddress,
bool sync = false )

remove a neighbor entry from the kernel table.

Parameters
indexinterface index.
ipAddressdestination address.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ removeNeighborListener()

void NeighborManager::removeNeighborListener ( uint64_t id)

unregister a previously registered callback.

Parameters
idunique id of the callback function to remove.

Friends And Related Symbol Documentation

◆ Neighbor

friend class Neighbor
friend

The documentation for this class was generated from the following files: