On this page

Other Network Topics

Coverage: VLAN/bridge/bonding → tunneling (GRE/VXLAN/IPIP) → routing (FIB/FIB rules) → QoS (tc qdisc) → network namespace → TUN/TAP Kernel versions: 2.6 ~ 6.x

Virtual Network Devices

bridge: Software Switch

// net/bridge/
// Linux bridge = virtual L2 switch
// Features: MAC learning, STP (optional), VLAN filtering
// Typical use case: L2 connectivity between VMs/containers, often used with veth pairs

brctl addbr br0
brctl addif br0 eth0  // Add physical interface to the bridge
ip link add veth0 type veth peer name veth1  // Create a virtual ethernet pair
brctl addif br0 veth0  // Connect one end to the bridge, the other to a container namespace
bonding modes:
  balance-rr:   Round-robin (TX load balancing)
  active-backup: Active-backup (failover)
  balance-xor:  Based on MAC hash
  802.3ad:      LACP dynamic aggregation

VLAN: 802.1Q

ip link add link eth0 name eth0.100 type vlan id 100
# → eth0.100: VLAN-tagged sub-interface
# Kernel automatically adds/removes VLAN tags

Tunneling

Tunnel TypeEncapsulationUse Case
GREIP-in-IP (GRE header)Site-to-site interconnection
VXLANL2 over UDPData center overlay
IPIPIP-in-IP (no GRE header)Lightweight tunnel
WireGuardUDP + Noise + ChaCha20VPN
# VXLAN example
ip link add vxlan0 type vxlan id 100 remote 10.0.0.2 dstport 4789 dev eth0

Routing

// net/ipv4/fib_trie.c (FIB = Forwarding Information Base)
// Linux routing consists of a two-layer structure: FIB + FIB rules

// FIB rules (Policy Routing):
//   ip rule: Selects routing table based on src IP, fwmark, iif
//   Default order: local (table 255) → main (table 254) → default (table 253)

// FIB (Forwarding Table):
//   Implemented using LC-trie (Longest Prefix Match, O(log n))
//   Entry format: prefix → nexthop + device

QoS: Traffic Control (tc)

// net/sched/
// tc's queuing discipline (qdisc) stack:
//   root qdisc: Entry point for outbound packets (may have child classes)
//   ingress qdisc: Entry point for inbound packets (rarely used)

// Common qdiscs:
//   fq_codel: Fair Queueing + CoDel (reduces bufferbloat, default)
//   cake:    Optimized for home gateways (bandwidth shaping + fairness)
//   htb:     Hierarchical Token Bucket (bandwidth limiting)
//   pfifo_fast: Simple FIFO (old default)

// BPF is also integrated into tc: BPF programs can be attached as classifiers/actions

Network Namespace

// net/core/net_namespace.c
// Each netns has its own independent:
//   - List of network interfaces
//   - Routing tables
//   - Netfilter rules
//   - Socket bindings

// Foundation for containers: 
//   CLONE_NEWNET → Creates a new netns
//   veth pair connects host and container netns
//   bridge connects multiple containers together

TUN/TAP

// drivers/net/tun.c
// TUN: L3 tunnel (IP packets, /dev/net/tun)
// TAP: L2 tunnel (Ethernet frames)

// User-space program opens /dev/net/tun → reads/writes IP packets
//   → VPNs (OpenVPN, WireGuard), VMs (QEMU, Firecracker)

References

  • Source Code: net/bridge/, net/core/rtnetlink.c, net/sched/, drivers/net/tun.c, net/core/net_namespace.c
  • Kernel Documentation: Documentation/networking/bridge.rst, Documentation/networking/ip-sysctl.rst

Keywords: bridge, VLAN, VXLAN, tc, qdisc, network namespace, TUN/TAP