|
join 1.0
lightweight network framework library
|
interface manager class. More...
#include <interfacemanager.hpp>


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. | |
| InterfaceManager & | operator= (const InterfaceManager &other)=delete |
| assign instance by copy. | |
| InterfaceManager & | operator= (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. | |
| NetlinkManager & | operator= (const NetlinkManager &)=delete |
| assign instance by copy. | |
| NetlinkManager & | operator= (NetlinkManager &&)=delete |
| assign instance by move. | |
| virtual | ~NetlinkManager ()=default |
| destroy instance. | |
| Reactor * | reactor () const noexcept |
| get the event loop reactor. | |
Static Public Member Functions | |
| static InterfaceManager & | instance () |
| 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. | |
interface manager class.
| using join::InterfaceManager::AddressNotify = std::function<void (const AddressInfo& info)> |
| using join::InterfaceManager::LinkNotify = std::function<void (const LinkInfo& info)> |
| using join::InterfaceManager::RouteNotify = std::function<void (const RouteInfo& info)> |
| InterfaceManager::InterfaceManager | ( | Reactor * | reactor = nullptr | ) |
create instance.
| reactor | event loop reactor. |
|
delete |
create instance by copy.
| other | other interface to copy. |
|
delete |
create instance by move.
| other | other interface to move. |
| InterfaceManager::~InterfaceManager | ( | ) |
destroy instance.
| uint64_t InterfaceManager::addAddressListener | ( | const AddressNotify & | cb | ) |
registers a callback to be invoked when a address update occurs.
| cb | the callback function to register. |
| uint64_t InterfaceManager::addLinkListener | ( | const LinkNotify & | cb | ) |
registers a callback to be invoked when a link update occurs.
| cb | the callback function to register. |
| uint64_t InterfaceManager::addRouteListener | ( | const RouteNotify & | cb | ) |
registers a callback to be invoked when a route update occurs.
| cb | the callback function to register. |
| int InterfaceManager::createBridgeInterface | ( | const std::string & | interfaceName, |
| bool | sync = false ) |
creates a bridge interface.
| interfaceName | name of the bridge interface to be created. |
| sync | wait for completion. |
| int InterfaceManager::createDummyInterface | ( | const std::string & | interfaceName, |
| bool | sync = false ) |
creates a dummy interface.
| interfaceName | name of the dummy interface to be created. |
| sync | wait for completion. |
| 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.
| tunnelName | name of the GRE tunnel interface to be created. |
| parentName | name of the physical interface to bind the tunnel to. |
| localAddress | local endpoint IP address for the tunnel. |
| remoteAddress | remote endpoint IP address for the tunnel. |
| ikey | optional inbound GRE key. |
| okey | optional outbound GRE key. |
| ttl | ttl/hop Limit for encapsulated packets (0-255) |
| sync | wait for completion. |
| 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.
| tunnelName | name of the GRE tunnel interface to be created. |
| parentIndex | index of the physical interface to bind the tunnel to. |
| localAddress | local endpoint IP address for the tunnel. |
| remoteAddress | remote endpoint IP address for the tunnel. |
| ikey | optional inbound GRE key. |
| okey | optional outbound GRE key. |
| ttl | ttl/hop Limit for encapsulated packets (0-255) |
| sync | wait for completion. |
| int InterfaceManager::createVethInterface | ( | const std::string & | hostName, |
| const std::string & | peerName, | ||
| pid_t * | pid = nullptr, | ||
| bool | sync = false ) |
creates a Virtual Ethernet nterface pair.
| hostName | name of the interface to be created in the current namespace. |
| peerName | name of the interface to be created in the target namespace. |
| pid | process id of target namespace. |
| sync | wait for completion. |
| 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.
| interfaceName | name of the VLAN interface to be created. |
| parentName | name of the physical interface to create VLAN on. |
| id | VLAN id (must be unique on the parent interface). |
| proto | VLAN protocol type. |
| sync | wait for completion. |
| 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.
| interfaceName | name of the VLAN interface to be created. |
| parentIndex | index of the physical interface to create VLAN on. |
| id | VLAN id (must be unique on the parent interface). |
| proto | VLAN protocol type. |
| sync | wait for completion. |
| InterfaceList InterfaceManager::enumerate | ( | ) |
enumerate all interfaces.
| Interface::Ptr InterfaceManager::findByIndex | ( | uint32_t | interfaceIndex | ) |
find interface by index.
| interfaceIndex | interface index. |
| Interface::Ptr InterfaceManager::findByName | ( | const std::string & | interfaceName | ) |
find interface by name.
| interfaceName | interface name. |
|
static |
get the a singleton instance.
|
delete |
assign instance by copy.
| other | other interface to copy. |
|
delete |
assign instance by move.
| other | other interface to move. |
| int InterfaceManager::refresh | ( | ) |
refresh all data.
| void InterfaceManager::removeAddressListener | ( | uint64_t | id | ) |
unregisters a previously registered address update callback.
| id | unique id of the callback function to remove. |
| int InterfaceManager::removeInterface | ( | const std::string & | interfaceName, |
| bool | sync = false ) |
deletes the specified network interface.
| interfaceName | interface name. |
| sync | wait for completion. |
| int InterfaceManager::removeInterface | ( | uint32_t | interfaceIndex, |
| bool | sync = false ) |
deletes the specified network interface.
| interfaceIndex | interface index. |
| sync | wait for completion. |
| void InterfaceManager::removeLinkListener | ( | uint64_t | id | ) |
unregisters a previously registered link update callback.
| id | unique id of the callback function to remove. |
| void InterfaceManager::removeRouteListener | ( | uint64_t | id | ) |
unregisters a previously registered route update callback.
| id | unique id of the callback function to remove. |
|
friend |