Link

Virtual Devices

References:

Table of contents

  1. tap / tun
  2. Bridge
  3. Bonding
  4. VLAN

tap / tun

  • tap: link layer (like raw socket)
  • tun: network layer (ip packets)
fd = open("/dev/net/tun", O_RDWR)
 /* Flags: IFF_TUN   - TUN device (no Ethernet headers)
  *        IFF_TAP   - TAP device
  *        IFF_NO_PI - Do not provide packet information
  */
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
ioctl(fd, TUNSETIFF, (void *) &ifr)

Bridge

ip link add br0 type bridge
ip link set eth0 master br0
ip link set tap1 master br0
ip link set tap2 master br0
ip link set veth1 master br0

Bonding

bundle a set of interfaces and make them look like a single one. Traffic can be distributed between them. Documentation /networking/bonding.txt

ip link add bond1 type bond miimon 100 mode active-backup
# miimon: Specifies the MII link monitoring frequency in milliseconds. This determines how often the link state of each slave is inspected for link failures.
ip link set eth0 master bond1
ip link set eth1 master bond1

VLAN

820.1Q protocol: Preamble + Dest MAC + Src MAC + VLAN related + EtherType + Data + CRC

When configuring a VLAN, you need to make sure the switch connected to the host is able to handle VLAN tags, for example, by setting the switch port to trunk mode.

ip link add link eth0 name eth0.2 type vlan id 2
ip link add link eth0 name eth0.3 type vlan id 3