---
title: Other Network Topics
url: https://doc.liz6.com/en/linux-kernel/06-network-subsystem/04-other-network-topics
locale: en
area: linux-kernel
tags:
- linux-kernel
- network-subsystem
date: 2026-06-30
modified: 2026-07-16
description: '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'
---

# 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

```c
// 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: Link Aggregation

```
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

```bash
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 Type | Encapsulation | Use Case |
|---------|------|------|
| GRE | IP-in-IP (GRE header) | Site-to-site interconnection |
| VXLAN | L2 over UDP | Data center overlay |
| IPIP | IP-in-IP (no GRE header) | Lightweight tunnel |
| WireGuard | UDP + Noise + ChaCha20 | VPN |

```bash
# VXLAN example
ip link add vxlan0 type vxlan id 100 remote 10.0.0.2 dstport 4789 dev eth0
```

## Routing

```c
// 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)

```c
// 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

```c
// 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

```c
// 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*
