Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lxcpp::NetworkInterface Class Reference

Network operations to be performed on given container and interface operates on netlink device. More...

#include <network.hpp>

Public Member Functions

 NetworkInterface (const std::string &ifname, pid_t pid=0)
 Create network interface object for the ifname in the container (network namespace) More...
 
const std::string & getName () const
 
bool exists () const noexcept
 
NetStatus status () const
 Retrieve network interface status (UP or DOWN) More...
 
void create (InterfaceType type, const std::string &peerif="", MacVLanMode mode=MacVLanMode::PRIVATE)
 Create network interface in container identified by mContainerPid. More...
 
void destroy ()
 Delete interface. More...
 
void moveToContainer (pid_t pid)
 Move interface to container. More...
 
void renameFrom (const std::string &oldif)
 Rename interface name. More...
 
void addToBridge (const std::string &bridge)
 Add interface to the bridge. More...
 
void delFromBridge ()
 Remove insterface from the bridge. More...
 
void setAttrs (const Attrs &attrs)
 Set or get interface attributes in one netlink call. More...
 
Attrs getAttrs () const
 
void addInetAddr (const InetAddr &addr)
 Add inet address to the interface. More...
 
void delInetAddr (const InetAddr &addr)
 Remove inet address from the interface. More...
 
std::vector< InetAddrgetInetAddressList () const
 Retrieve all inet addresses for the interface. More...
 
void addRoute (const Route &route, const RoutingTable rt=RoutingTable::MAIN)
 Add route to specified routing table. More...
 
void delRoute (const Route &route, const RoutingTable rt=RoutingTable::MAIN)
 Remove route from specified routing table. More...
 
std::vector< RoutegetRoutes (const RoutingTable rt=RoutingTable::MAIN) const
 Retrieve routing table for the interface. More...
 
void up ()
 Set interface up. More...
 
void down ()
 Set interface down. More...
 
void setMACAddress (const std::string &macaddr)
 Set MAC address attribute. More...
 
void setMTU (int mtu)
 Set MTU attribute. More...
 
void setTxLength (int txlen)
 Set TxQ attribute. More...
 

Static Public Member Functions

static std::vector< std::string > getInterfaces (pid_t initpid)
 Get list of network interafece names. More...
 
static std::vector< RoutegetRoutes (pid_t initpid, const RoutingTable rt=RoutingTable::MAIN)
 Get list of routes (specified routing table). More...
 

Private Member Functions

void createVeth (const std::string &peerif)
 
void createBridge ()
 
void createMacVLan (const std::string &masterif, MacVLanMode mode)
 
void modifyRoute (int cmd, const InetAddr &src, const InetAddr &dst)
 

Private Attributes

const std::string mIfname
 network interface name inside zone More...
 
pid_t mContainerPid
 Container pid to operate on (0 means kernel) More...
 

Detailed Description

Network operations to be performed on given container and interface operates on netlink device.

Constructor & Destructor Documentation

lxcpp::NetworkInterface::NetworkInterface ( const std::string &  ifname,
pid_t  pid = 0 
)
inline

Create network interface object for the ifname in the container (network namespace)

Member Function Documentation

void lxcpp::NetworkInterface::addInetAddr ( const InetAddr addr)

Add inet address to the interface.

Equivalent to: ip addr add addr dev mIfname

void lxcpp::NetworkInterface::addRoute ( const Route route,
const RoutingTable  rt = RoutingTable::MAIN 
)

Add route to specified routing table.

Equivalent to: ip route add route.dst.addr/route.dst.prefix dev mIfname (if route.src.prefix=0)

void lxcpp::NetworkInterface::addToBridge ( const std::string &  bridge)

Add interface to the bridge.

Equivalent to: ip link set mIfname master bridge

void lxcpp::NetworkInterface::create ( InterfaceType  type,
const std::string &  peerif = "",
MacVLanMode  mode = MacVLanMode::PRIVATE 
)

Create network interface in container identified by mContainerPid.

Equivalent to: ip link add mIfname type type [...]

Create pair of virtual ethernet interfaces:

  • ip link add mIfname type veth peer name peerif

Create bridge interface:

Create pseudo-ethernet interface on existing one:

  • ip link add mIfname type macvlan link peerif [mode mode]
void lxcpp::NetworkInterface::createBridge ( )
private
void lxcpp::NetworkInterface::createMacVLan ( const std::string &  masterif,
MacVLanMode  mode 
)
private
void lxcpp::NetworkInterface::createVeth ( const std::string &  peerif)
private
void lxcpp::NetworkInterface::delFromBridge ( )

Remove insterface from the bridge.

Equivalent to: ip link set mIfname nomaster

void lxcpp::NetworkInterface::delInetAddr ( const InetAddr addr)

Remove inet address from the interface.

Equivalent to: ip addr del addr dev mIfname

void lxcpp::NetworkInterface::delRoute ( const Route route,
const RoutingTable  rt = RoutingTable::MAIN 
)

Remove route from specified routing table.

Equivalent to: ip route del route.dst.addr dev mIfname

void lxcpp::NetworkInterface::destroy ( )

Delete interface.

Equivalent to: ip link delete mIfname

void lxcpp::NetworkInterface::down ( )

Set interface down.

Equivalent to: ip link set mIfname down

bool lxcpp::NetworkInterface::exists ( ) const
noexcept
Attrs lxcpp::NetworkInterface::getAttrs ( ) const
std::vector< InetAddr > lxcpp::NetworkInterface::getInetAddressList ( ) const

Retrieve all inet addresses for the interface.

Equivalent to: ip addr show, ip -6 addr show

std::vector< std::string > lxcpp::NetworkInterface::getInterfaces ( pid_t  initpid)
static

Get list of network interafece names.

Equivalent to: ip link show

const std::string& lxcpp::NetworkInterface::getName ( ) const
inline
std::vector< Route > lxcpp::NetworkInterface::getRoutes ( const RoutingTable  rt = RoutingTable::MAIN) const

Retrieve routing table for the interface.

Equivalent to: ip route show dev mIfname table rt

std::vector< Route > lxcpp::NetworkInterface::getRoutes ( pid_t  initpid,
const RoutingTable  rt = RoutingTable::MAIN 
)
static

Get list of routes (specified routing table).

Equivalent to: ip route show table rt

void lxcpp::NetworkInterface::modifyRoute ( int  cmd,
const InetAddr src,
const InetAddr dst 
)
private
void lxcpp::NetworkInterface::moveToContainer ( pid_t  pid)

Move interface to container.

Equivalent to: ip link set dev mIfname netns pid

void lxcpp::NetworkInterface::renameFrom ( const std::string &  oldif)

Rename interface name.

Equivalent to: ip link set dev oldif name mIfname

void lxcpp::NetworkInterface::setAttrs ( const Attrs attrs)

Set or get interface attributes in one netlink call.

Supported attributes: see AttrName

void lxcpp::NetworkInterface::setMACAddress ( const std::string &  macaddr)

Set MAC address attribute.

Equivalent to: ip link set mIfname address macaddr (macaddr in format AA:BB:CC:DD:FF:GG)

Note: two lower bits of first byte (leftmost) specifies MAC address class:

  • b1: 0=unicast, 1=broadcast
  • b2: 0=global, 1=local

In most cases should be b2=0, b1=1, (see: https://en.wikipedia.org/wiki/MAC_address)

void lxcpp::NetworkInterface::setMTU ( int  mtu)

Set MTU attribute.

Equivalent to: ip link set mIfname mtu mtu

void lxcpp::NetworkInterface::setTxLength ( int  txlen)

Set TxQ attribute.

Equivalent to: ip link set mIfname txqueue txlen

NetStatus lxcpp::NetworkInterface::status ( ) const

Retrieve network interface status (UP or DOWN)

void lxcpp::NetworkInterface::up ( )

Set interface up.

Equivalent to: ip link set mIfname up

Member Data Documentation

pid_t lxcpp::NetworkInterface::mContainerPid
private

Container pid to operate on (0 means kernel)

const std::string lxcpp::NetworkInterface::mIfname
private

network interface name inside zone


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