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

interface manager class. More...

#include <interfacemanager.hpp>

Inheritance diagram for join::InterfaceManager:
Collaboration diagram for join::InterfaceManager:

Public Types

using LinkNotify = std::function<void (const LinkInfo& info)>
 
using AddressNotify = std::function<void (const AddressInfo& info)>
 
using RouteNotify = std::function<void (const RouteInfo& info)>
 

Public Member Functions

 InterfaceManager (Reactor *reactor=nullptr)
 create instance.
 
 InterfaceManager (const InterfaceManager &other)=delete
 create instance by copy.
 
 InterfaceManager (InterfaceManager &&other)=delete
 create instance by move.
 
InterfaceManageroperator= (const InterfaceManager &other)=delete
 assign instance by copy.
 
InterfaceManageroperator= (InterfaceManager &&other)=delete
 assign instance by move.
 
 ~InterfaceManager ()
 destroy instance.
 
Interface::Ptr findByIndex (uint32_t interfaceIndex)
 find interface by index.
 
Interface::Ptr findByName (const std::string &interfaceName)
 find interface by name.
 
InterfaceList enumerate ()
 enumerate all interfaces.
 
int refresh ()
 refresh all data.
 
uint64_t addLinkListener (const LinkNotify &cb)
 registers a callback to be invoked when a link update occurs.
 
void removeLinkListener (uint64_t id)
 unregisters a previously registered link update callback.
 
uint64_t addAddressListener (const AddressNotify &cb)
 registers a callback to be invoked when a address update occurs.
 
void removeAddressListener (uint64_t id)
 unregisters a previously registered address update callback.
 
uint64_t addRouteListener (const RouteNotify &cb)
 registers a callback to be invoked when a route update occurs.
 
void removeRouteListener (uint64_t id)
 unregisters a previously registered route update callback.
 
int createDummyInterface (const std::string &interfaceName, bool sync=false)
 creates a dummy interface.
 
int createBridgeInterface (const std::string &interfaceName, bool sync=false)
 creates a bridge interface.
 
int createVlanInterface (const std::string &interfaceName, uint32_t parentIndex, uint16_t id, uint16_t proto=ETH_P_8021Q, bool sync=false)
 creates a VLAN interface.
 
int createVlanInterface (const std::string &interfaceName, const std::string &parentName, uint16_t id, uint16_t proto=ETH_P_8021Q, bool sync=false)
 creates a VLAN interface.
 
int createVethInterface (const std::string &hostName, const std::string &peerName, pid_t *pid=nullptr, bool sync=false)
 creates a Virtual Ethernet nterface pair.
 
int createGreInterface (const std::string &tunnelName, uint32_t parentIndex, const IpAddress &localAddress, const IpAddress &remoteAddress, const uint32_t *ikey=nullptr, const uint32_t *okey=nullptr, uint8_t ttl=64, bool sync=false)
 creates a a GRE tunnel interface.
 
int createGreInterface (const std::string &tunnelName, const std::string &parentName, const IpAddress &localAddress, const IpAddress &remoteAddress, const uint32_t *ikey=nullptr, const uint32_t *okey=nullptr, uint8_t ttl=64, bool sync=false)
 creates a a GRE tunnel interface.
 
int removeInterface (uint32_t interfaceIndex, bool sync=false)
 deletes the specified network interface.
 
int removeInterface (const std::string &interfaceName, bool sync=false)
 deletes the specified network 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 InterfaceManagerinstance ()
 get the a singleton instance.
 

Friends

class Interface
 

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

interface manager class.

Member Typedef Documentation

◆ AddressNotify

using join::InterfaceManager::AddressNotify = std::function<void (const AddressInfo& info)>

◆ LinkNotify

using join::InterfaceManager::LinkNotify = std::function<void (const LinkInfo& info)>

◆ RouteNotify

using join::InterfaceManager::RouteNotify = std::function<void (const RouteInfo& info)>

Constructor & Destructor Documentation

◆ InterfaceManager() [1/3]

InterfaceManager::InterfaceManager ( Reactor * reactor = nullptr)

create instance.

Parameters
reactorevent loop reactor.

◆ InterfaceManager() [2/3]

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

create instance by copy.

Parameters
otherother interface to copy.

◆ InterfaceManager() [3/3]

join::InterfaceManager::InterfaceManager ( InterfaceManager && other)
delete

create instance by move.

Parameters
otherother interface to move.

◆ ~InterfaceManager()

InterfaceManager::~InterfaceManager ( )

destroy instance.

Member Function Documentation

◆ addAddressListener()

uint64_t InterfaceManager::addAddressListener ( const AddressNotify & cb)

registers a callback to be invoked when a address update occurs.

Parameters
cbthe callback function to register.
Returns
unique id for the callback.

◆ addLinkListener()

uint64_t InterfaceManager::addLinkListener ( const LinkNotify & cb)

registers a callback to be invoked when a link update occurs.

Parameters
cbthe callback function to register.
Returns
unique id for the callback.

◆ addRouteListener()

uint64_t InterfaceManager::addRouteListener ( const RouteNotify & cb)

registers a callback to be invoked when a route update occurs.

Parameters
cbthe callback function to register.
Returns
unique id for the callback.

◆ createBridgeInterface()

int InterfaceManager::createBridgeInterface ( const std::string & interfaceName,
bool sync = false )

creates a bridge interface.

Parameters
interfaceNamename of the bridge interface to be created.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ createDummyInterface()

int InterfaceManager::createDummyInterface ( const std::string & interfaceName,
bool sync = false )

creates a dummy interface.

Parameters
interfaceNamename of the dummy interface to be created.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ createGreInterface() [1/2]

int InterfaceManager::createGreInterface ( const std::string & tunnelName,
const std::string & parentName,
const IpAddress & localAddress,
const IpAddress & remoteAddress,
const uint32_t * ikey = nullptr,
const uint32_t * okey = nullptr,
uint8_t ttl = 64,
bool sync = false )

creates a a GRE tunnel interface.

Parameters
tunnelNamename of the GRE tunnel interface to be created.
parentNamename of the physical interface to bind the tunnel to.
localAddresslocal endpoint IP address for the tunnel.
remoteAddressremote endpoint IP address for the tunnel.
ikeyoptional inbound GRE key.
okeyoptional outbound GRE key.
ttlttl/hop Limit for encapsulated packets (0-255)
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ createGreInterface() [2/2]

int InterfaceManager::createGreInterface ( const std::string & tunnelName,
uint32_t parentIndex,
const IpAddress & localAddress,
const IpAddress & remoteAddress,
const uint32_t * ikey = nullptr,
const uint32_t * okey = nullptr,
uint8_t ttl = 64,
bool sync = false )

creates a a GRE tunnel interface.

Parameters
tunnelNamename of the GRE tunnel interface to be created.
parentIndexindex of the physical interface to bind the tunnel to.
localAddresslocal endpoint IP address for the tunnel.
remoteAddressremote endpoint IP address for the tunnel.
ikeyoptional inbound GRE key.
okeyoptional outbound GRE key.
ttlttl/hop Limit for encapsulated packets (0-255)
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ createVethInterface()

int InterfaceManager::createVethInterface ( const std::string & hostName,
const std::string & peerName,
pid_t * pid = nullptr,
bool sync = false )

creates a Virtual Ethernet nterface pair.

Parameters
hostNamename of the interface to be created in the current namespace.
peerNamename of the interface to be created in the target namespace.
pidprocess id of target namespace.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ createVlanInterface() [1/2]

int InterfaceManager::createVlanInterface ( const std::string & interfaceName,
const std::string & parentName,
uint16_t id,
uint16_t proto = ETH_P_8021Q,
bool sync = false )

creates a VLAN interface.

Parameters
interfaceNamename of the VLAN interface to be created.
parentNamename of the physical interface to create VLAN on.
idVLAN id (must be unique on the parent interface).
protoVLAN protocol type.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ createVlanInterface() [2/2]

int InterfaceManager::createVlanInterface ( const std::string & interfaceName,
uint32_t parentIndex,
uint16_t id,
uint16_t proto = ETH_P_8021Q,
bool sync = false )

creates a VLAN interface.

Parameters
interfaceNamename of the VLAN interface to be created.
parentIndexindex of the physical interface to create VLAN on.
idVLAN id (must be unique on the parent interface).
protoVLAN protocol type.
syncwait for completion.
Returns
0 on success, -1 on failure.

◆ enumerate()

InterfaceList InterfaceManager::enumerate ( )

enumerate all interfaces.

Returns
all interfaces.

◆ findByIndex()

Interface::Ptr InterfaceManager::findByIndex ( uint32_t interfaceIndex)

find interface by index.

Parameters
interfaceIndexinterface index.
Returns
interface.

◆ findByName()

Interface::Ptr InterfaceManager::findByName ( const std::string & interfaceName)

find interface by name.

Parameters
interfaceNameinterface name.
Returns
interface.

◆ instance()

InterfaceManager & InterfaceManager::instance ( )
static

get the a singleton instance.

Returns
reference to the singleton instance.

◆ operator=() [1/2]

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

assign instance by copy.

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

◆ operator=() [2/2]

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

assign instance by move.

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

◆ refresh()

int InterfaceManager::refresh ( )

refresh all data.

Returns
0 on success, -1 on failure.

◆ removeAddressListener()

void InterfaceManager::removeAddressListener ( uint64_t id)

unregisters a previously registered address update callback.

Parameters
idunique id of the callback function to remove.

◆ removeInterface() [1/2]

int InterfaceManager::removeInterface ( const std::string & interfaceName,
bool sync = false )

deletes the specified network interface.

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

◆ removeInterface() [2/2]

int InterfaceManager::removeInterface ( uint32_t interfaceIndex,
bool sync = false )

deletes the specified network interface.

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

◆ removeLinkListener()

void InterfaceManager::removeLinkListener ( uint64_t id)

unregisters a previously registered link update callback.

Parameters
idunique id of the callback function to remove.

◆ removeRouteListener()

void InterfaceManager::removeRouteListener ( uint64_t id)

unregisters a previously registered route update callback.

Parameters
idunique id of the callback function to remove.

Friends And Related Symbol Documentation

◆ Interface

friend class Interface
friend

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