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 noexcept
 get master index if bridged.
 
const std::string & name () const noexcept
 get interface name.
 
int mtu (uint32_t mtuBytes, bool sync=false)
 set interface mtu.
 
uint32_t mtu () const noexcept
 get interface mtu.
 
const std::string & kind () const noexcept
 get interface kind.
 
int mac (const MacAddress &macAddress, bool sync=false)
 set interface mac address.
 
const MacAddressmac () const noexcept
 get interface mac address.
 
int addAddress (const IpAddress &ipAddress, uint32_t prefix, const IpAddress &broadcast={}, bool sync=false)
 add address to interface.
 
int addAddress (const Address &address, bool sync=false)
 add address to interface.
 
int removeAddress (const IpAddress &ipAddress, uint32_t prefix, const IpAddress &broadcast={}, bool sync=false)
 remove address from interface.
 
int removeAddress (const Address &address, bool sync=false)
 remove address from interface.
 
const AddressListaddressList () const noexcept
 get interface ip addresses.
 
bool hasAddress (const IpAddress &ipAddress)
 check if interface has address stored.
 
bool hasLocalAddress ()
 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)
 add route to interface.
 
int addRoute (const Route &route, bool sync=false)
 add route to interface.
 
int removeRoute (const IpAddress &dest, uint32_t prefix, const IpAddress &gateway={}, uint32_t metric=0, bool sync=false)
 remove route from interface.
 
int removeRoute (const Route &route, bool sync=false)
 remove route from interface.
 
const RouteListrouteList () const noexcept
 get interface routes.
 
bool hasRoute (const IpAddress &dest, uint32_t prefix, const IpAddress &gateway, uint32_t metric)
 check if interface has route stored.
 
bool hasRoute (const Route &route)
 check if interface has route stored.
 
int addToBridge (uint32_t masterIndex, bool sync=false)
 add interface to bridge.
 
int addToBridge (const std::string &masterName, bool sync=false)
 add interface to bridge.
 
int removeFromBridge (bool sync=false)
 remove interface from bridge.
 
uint32_t flags () const noexcept
 get interface flags.
 
int enable (bool enabled=true, bool sync=false)
 enable interface.
 
bool isEnabled () const noexcept
 is interface enabled.
 
bool isRunning () const noexcept
 is interface running.
 
bool isLoopback () const noexcept
 is interface a loopback interface.
 
bool isPointToPoint () const noexcept
 is interface a point to point interface.
 
bool isDummy () const noexcept
 is interface a dummy interface.
 
bool isBridge () const noexcept
 is interface a bridge interface.
 
bool isVlan () const noexcept
 is interface a vlan interface.
 
bool isVeth () const noexcept
 is interface a veth interface.
 
bool isGre () const noexcept
 is interface a gre interface.
 
bool isTun () const noexcept
 is interface a tun interface.
 
bool supportsBroadcast () const noexcept
 is interface supporting broadcast.
 
bool supportsMulticast () const noexcept
 is interface supporting multicast.
 
bool supportsIpv4 ()
 is interface supporting IPv4.
 
bool supportsIpv6 ()
 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 )

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 )

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()

const Interface::AddressList & Interface::addressList ( ) const
noexcept

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 )

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 )

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 )

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 )

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 )

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
noexcept

get interface flags.

Returns
interface flags.

◆ hasAddress()

bool Interface::hasAddress ( const IpAddress & ipAddress)

check if interface has address stored.

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

◆ hasLocalAddress()

bool Interface::hasLocalAddress ( )

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 )

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)

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
noexcept

is interface a bridge interface.

Returns
true if bridge interface.

◆ isDummy()

bool Interface::isDummy ( ) const
noexcept

is interface a dummy interface.

Returns
true if dummy interface.

◆ isEnabled()

bool Interface::isEnabled ( ) const
noexcept

is interface enabled.

Returns
true if enabled.

◆ isGre()

bool Interface::isGre ( ) const
noexcept

is interface a gre interface.

Returns
true if gre interface.

◆ isLoopback()

bool Interface::isLoopback ( ) const
noexcept

is interface a loopback interface.

Returns
true if loopback interface.

◆ isPointToPoint()

bool Interface::isPointToPoint ( ) const
noexcept

is interface a point to point interface.

Returns
true if point to point interface.

◆ isRunning()

bool Interface::isRunning ( ) const
noexcept

is interface running.

Returns
true if running.

◆ isTun()

bool Interface::isTun ( ) const
noexcept

is interface a tun interface.

Returns
true if tun interface.

◆ isVeth()

bool Interface::isVeth ( ) const
noexcept

is interface a veth interface.

Returns
true if veth interface.

◆ isVlan()

bool Interface::isVlan ( ) const
noexcept

is interface a vlan interface.

Returns
true if vlan interface.

◆ kind()

const std::string & Interface::kind ( ) const
noexcept

get interface kind.

Returns
interface kind.

◆ mac() [1/2]

const MacAddress & Interface::mac ( ) const
noexcept

get interface mac address.

Returns
interface mac address.

◆ mac() [2/2]

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

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
noexcept

get master index if bridged.

Returns
master index.

◆ mtu() [1/2]

uint32_t Interface::mtu ( ) const
noexcept

get interface mtu.

Returns
interface mtu.

◆ mtu() [2/2]

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

set interface mtu.

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

◆ name()

const std::string & Interface::name ( ) const
noexcept

get interface name.

Returns
interface name.

◆ removeAddress() [1/2]

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

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 )

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)

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 )

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 )

remove route from interface.

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

◆ routeList()

const Interface::RouteList & Interface::routeList ( ) const
noexcept

get interface routes.

Returns
interface routes.

◆ supportsBroadcast()

bool Interface::supportsBroadcast ( ) const
noexcept

is interface supporting broadcast.

Returns
true if supporting broadcast.

◆ supportsIpv4()

bool Interface::supportsIpv4 ( )

is interface supporting IPv4.

Returns
true if supporting IPv4.

◆ supportsIpv6()

bool Interface::supportsIpv6 ( )

is interface supporting IPv6.

Returns
true if supporting IPv6.

◆ supportsMulticast()

bool Interface::supportsMulticast ( ) const
noexcept

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
aInterface to compare.
bInterface 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
aInterface to compare.
bInterface to compare to.
Returns
true if equal.

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