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

interface class. More...

#include <interface.hpp>

Public Types

using Ptr = std::shared_ptr<Interface>
 
using Address = std::tuple<IpAddress, uint32_t, IpAddress>
 
using AddressList = std::vector<Address>
 
using Route = std::tuple<IpAddress, uint32_t, IpAddress, uint32_t>
 
using RouteList = std::vector<Route>
 

Public Member Functions

 Interface ()=delete
 create instance.
 
 ~Interface ()=default
 destroy instance.
 
uint32_t index () const noexcept
 get interface index.
 
uint32_t master () const
 get master index if bridged.
 
std::string name () const
 get interface name.
 
int mtu (uint32_t mtuBytes, bool sync=false) const
 set interface mtu.
 
uint32_t mtu () const
 get interface mtu.
 
std::string kind () const
 get interface kind.
 
int mac (const MacAddress &macAddress, bool sync=false) const
 set interface mac address.
 
MacAddress mac () const
 get interface mac address.
 
int addAddress (const IpAddress &ipAddress, uint32_t prefix, const IpAddress &broadcast={}, bool sync=false) const
 add address to interface.
 
int addAddress (const Address &address, bool sync=false) const
 add address to interface.
 
int removeAddress (const IpAddress &ipAddress, uint32_t prefix, const IpAddress &broadcast={}, bool sync=false) const
 remove address from interface.
 
int removeAddress (const Address &address, bool sync=false) const
 remove address from interface.
 
AddressList addressList () const
 get interface ip addresses.
 
bool hasAddress (const IpAddress &ipAddress) const
 check if interface has address stored.
 
bool hasLocalAddress () const
 check if interface has link local address stored.
 
int addRoute (const IpAddress &dest, uint32_t prefix, const IpAddress &gateway={}, uint32_t metric=0, bool sync=false) const
 add route to interface.
 
int addRoute (const Route &route, bool sync=false) const
 add route to interface.
 
int removeRoute (const IpAddress &dest, uint32_t prefix, const IpAddress &gateway={}, uint32_t metric=0, bool sync=false) const
 remove route from interface.
 
int removeRoute (const Route &route, bool sync=false) const
 remove route from interface.
 
RouteList routeList () const
 get interface routes.
 
bool hasRoute (const IpAddress &dest, uint32_t prefix, const IpAddress &gateway, uint32_t metric) const
 check if interface has route stored.
 
bool hasRoute (const Route &route) const
 check if interface has route stored.
 
int addToBridge (uint32_t masterIndex, bool sync=false) const
 add interface to bridge.
 
int addToBridge (const std::string &masterName, bool sync=false) const
 add interface to bridge.
 
int removeFromBridge (bool sync=false) const
 remove interface from bridge.
 
uint32_t flags () const
 get interface flags.
 
int enable (bool enabled=true, bool sync=false) const
 enable interface.
 
bool isEnabled () const
 is interface enabled.
 
bool isRunning () const
 is interface running.
 
bool isLoopback () const
 is interface a loopback interface.
 
bool isPointToPoint () const
 is interface a point to point interface.
 
bool isDummy () const
 is interface a dummy interface.
 
bool isBridge () const
 is interface a bridge interface.
 
bool isVlan () const
 is interface a vlan interface.
 
bool isVeth () const
 is interface a veth interface.
 
bool isGre () const
 is interface a gre interface.
 
bool isTun () const
 is interface a tun interface.
 
bool supportsBroadcast () const
 is interface supporting broadcast.
 
bool supportsMulticast () const
 is interface supporting multicast.
 
bool supportsIpv4 () const
 is interface supporting IPv4.
 
bool supportsIpv6 () const
 is interface supporting IPv6.
 

Friends

class InterfaceManager
 
bool operator== (const Interface::Ptr &lhs, const Interface::Ptr &rhs)
 compare if two interfaces are equals.
 
bool operator< (const Interface::Ptr &lhs, const Interface::Ptr &rhs)
 compare if interface is inferior.
 

Detailed Description

interface class.

Member Typedef Documentation

◆ Address

using join::Interface::Address = std::tuple<IpAddress, uint32_t, IpAddress>

◆ AddressList

using join::Interface::AddressList = std::vector<Address>

◆ Ptr

using join::Interface::Ptr = std::shared_ptr<Interface>

◆ Route

using join::Interface::Route = std::tuple<IpAddress, uint32_t, IpAddress, uint32_t>

◆ RouteList

using join::Interface::RouteList = std::vector<Route>

Constructor & Destructor Documentation

◆ Interface()

join::Interface::Interface ( )
delete

create instance.

◆ ~Interface()

join::Interface::~Interface ( )
default

destroy instance.

Member Function Documentation

◆ addAddress() [1/2]

int Interface::addAddress ( const Address & address,
bool sync = false ) const

add address to interface.

Parameters
addressaddress to add.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ addAddress() [2/2]

int Interface::addAddress ( const IpAddress & ipAddress,
uint32_t prefix,
const IpAddress & broadcast = {},
bool sync = false ) const

add address to interface.

Parameters
ipAddressip address to add.
prefixprefix length.
broadcastbroadcast address .
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ addressList()

Interface::AddressList Interface::addressList ( ) const

get interface ip addresses.

Returns
interface ip addresses.

◆ addRoute() [1/2]

int Interface::addRoute ( const IpAddress & dest,
uint32_t prefix,
const IpAddress & gateway = {},
uint32_t metric = 0,
bool sync = false ) const

add route to interface.

Parameters
destdestination network.
prefixprefix length.
gatewaygateway address.
metricroute metric.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ addRoute() [2/2]

int Interface::addRoute ( const Route & route,
bool sync = false ) const

add route to interface.

Parameters
routeroute.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ addToBridge() [1/2]

int Interface::addToBridge ( const std::string & masterName,
bool sync = false ) const

add interface to bridge.

Parameters
masterNamebridge name.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ addToBridge() [2/2]

int Interface::addToBridge ( uint32_t masterIndex,
bool sync = false ) const

add interface to bridge.

Parameters
masterIndexbridge index.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ enable()

int Interface::enable ( bool enabled = true,
bool sync = false ) const

enable interface.

Parameters
enabledtrue to enable interface, false otherwise.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ flags()

uint32_t Interface::flags ( ) const

get interface flags.

Returns
interface flags.

◆ hasAddress()

bool Interface::hasAddress ( const IpAddress & ipAddress) const

check if interface has address stored.

Parameters
ipAddressip address to delete.
Returns
true if interface has address stored, false otherwise

◆ hasLocalAddress()

bool Interface::hasLocalAddress ( ) const

check if interface has link local address stored.

Returns
true if interface has link local address stored, false otherwise

◆ hasRoute() [1/2]

bool Interface::hasRoute ( const IpAddress & dest,
uint32_t prefix,
const IpAddress & gateway,
uint32_t metric ) const

check if interface has route stored.

Parameters
destdestination network.
prefixprefix length.
gatewaygateway address.
metricroute metric.
Returns
0 on success, -1 on failure.

◆ hasRoute() [2/2]

bool Interface::hasRoute ( const Route & route) const

check if interface has route stored.

Parameters
routeroute.
Returns
true if interface has route stored, false otherwise

◆ index()

uint32_t Interface::index ( ) const
noexcept

get interface index.

Returns
interface index.

◆ isBridge()

bool Interface::isBridge ( ) const

is interface a bridge interface.

Returns
true if bridge interface.

◆ isDummy()

bool Interface::isDummy ( ) const

is interface a dummy interface.

Returns
true if dummy interface.

◆ isEnabled()

bool Interface::isEnabled ( ) const

is interface enabled.

Returns
true if enabled.

◆ isGre()

bool Interface::isGre ( ) const

is interface a gre interface.

Returns
true if gre interface.

◆ isLoopback()

bool Interface::isLoopback ( ) const

is interface a loopback interface.

Returns
true if loopback interface.

◆ isPointToPoint()

bool Interface::isPointToPoint ( ) const

is interface a point to point interface.

Returns
true if point to point interface.

◆ isRunning()

bool Interface::isRunning ( ) const

is interface running.

Returns
true if running.

◆ isTun()

bool Interface::isTun ( ) const

is interface a tun interface.

Returns
true if tun interface.

◆ isVeth()

bool Interface::isVeth ( ) const

is interface a veth interface.

Returns
true if veth interface.

◆ isVlan()

bool Interface::isVlan ( ) const

is interface a vlan interface.

Returns
true if vlan interface.

◆ kind()

std::string Interface::kind ( ) const

get interface kind.

Returns
interface kind.

◆ mac() [1/2]

MacAddress Interface::mac ( ) const

get interface mac address.

Returns
interface mac address.

◆ mac() [2/2]

int Interface::mac ( const MacAddress & macAddress,
bool sync = false ) const

set interface mac address.

Parameters
macAddressnew mac address.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ master()

uint32_t Interface::master ( ) const

get master index if bridged.

Returns
master index.

◆ mtu() [1/2]

uint32_t Interface::mtu ( ) const

get interface mtu.

Returns
interface mtu.

◆ mtu() [2/2]

int Interface::mtu ( uint32_t mtuBytes,
bool sync = false ) const

set interface mtu.

Parameters
mtuBytesnew mtu value.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ name()

std::string Interface::name ( ) const

get interface name.

Returns
interface name.

◆ removeAddress() [1/2]

int Interface::removeAddress ( const Address & address,
bool sync = false ) const

remove address from interface.

Parameters
addressaddress to delete.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ removeAddress() [2/2]

int Interface::removeAddress ( const IpAddress & ipAddress,
uint32_t prefix,
const IpAddress & broadcast = {},
bool sync = false ) const

remove address from interface.

Parameters
ipAddressip address to delete.
prefixprefix length.
broadcastbroadcast address .
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ removeFromBridge()

int Interface::removeFromBridge ( bool sync = false) const

remove interface from bridge.

Parameters
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ removeRoute() [1/2]

int Interface::removeRoute ( const IpAddress & dest,
uint32_t prefix,
const IpAddress & gateway = {},
uint32_t metric = 0,
bool sync = false ) const

remove route from interface.

Parameters
destdestination network.
prefixprefix length.
gatewaygateway address.
metricroute metric.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ removeRoute() [2/2]

int Interface::removeRoute ( const Route & route,
bool sync = false ) const

remove route from interface.

Parameters
routeroute.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ routeList()

Interface::RouteList Interface::routeList ( ) const

get interface routes.

Returns
interface routes.

◆ supportsBroadcast()

bool Interface::supportsBroadcast ( ) const

is interface supporting broadcast.

Returns
true if supporting broadcast.

◆ supportsIpv4()

bool Interface::supportsIpv4 ( ) const

is interface supporting IPv4.

Returns
true if supporting IPv4.

◆ supportsIpv6()

bool Interface::supportsIpv6 ( ) const

is interface supporting IPv6.

Returns
true if supporting IPv6.

◆ supportsMulticast()

bool Interface::supportsMulticast ( ) const

is interface supporting multicast.

Returns
true if supporting multicast.

Friends And Related Symbol Documentation

◆ InterfaceManager

friend class InterfaceManager
friend

◆ operator<

bool operator< ( const Interface::Ptr & lhs,
const Interface::Ptr & rhs )
friend

compare if interface is inferior.

Parameters
lhsinterface to compare.
rhsinterface to compare to.
Returns
true if inferior.

◆ operator==

bool operator== ( const Interface::Ptr & lhs,
const Interface::Ptr & rhs )
friend

compare if two interfaces are equals.

Parameters
lhsinterface to compare.
rhsinterface to compare to.
Returns
true if equal.

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