From First Principles to Production-Grade Systems
Introduction: Why Network Stack Depth Matters
- The thesis
- What this book assumes
- The scope
- How to use this book
- What this book is not
- The performance focus
Chapter 1: The Physics and Mathematics of Network Communication
- Signals, bandwidth and the Nyquist theorem
- Shannon capacity and fundamental limits
- Bit error rates and error detection codes
- Encoding schemes: NRZ, Manchester, 8b/10b, 64b/66b
- From analog to digital: modulation, sampling and clock recovery
- How physical constraints shape protocol design
Chapter 2: Ethernet: The Foundation of Modern Networking
- Ethernet history and design philosophy
- Frame format: preamble, MAC addresses, EtherType, payload, FCS
- CSMA/CD legacy and why modern Ethernet abandoned collision detection
- MAC addresses and switch forwarding
- Speed evolution: from 10 Mbps to 800 Gbps and beyond
- Why Ethernet endures
Chapter 3: Internet Protocol: Addressing and Routing
- IPv4 header structure and field semantics
- IP addressing, subnet masks, CIDR and hierarchical allocation
- The design goals of IP: simplicity, universality, best-effort semantics
- IPv6: header redesign, extension headers and adoption reality
- Routing fundamentals: longest prefix match, routing tables, BGP basics
- Fragmentation, MTU and Path MTU Discovery
Chapter 4: Transmission Control Protocol: Reliable Byte Streams
- The TCP header and every flag and field
- The three-way handshake and connection teardown
- Sequence numbers, acknowledgments and reliable reassembly
- Flow control via the receive window
- Retransmission strategies: timeout, fast retransmit, fast recovery
- State machine: every state and transition
Chapter 5: User Datagram Protocol and Transport Alternatives
- UDP header and semantics: why unreliable can be desirable
- Checksums and reliability without ordering
- QUIC architecture: multiplexing, 0-RTT, connection migration
- SCTP: multi-homing and multi-streaming for telephony
- DCCP and rate-limited unreliable delivery
- Choosing a transport: decision framework
Chapter 6: The Socket Interface and Application Programming
- Socket types: STREAM, DGRAM, RAW, SEQUENTIAL PACKET
- Domain addressing: AF_INET, AF_INET6, AF_UNIX, AF_PACKET
- The Berkeley sockets API: bind, listen, accept, connect, send, recv
- Blocking vs non-blocking semantics
- Socket options: tuning socket behavior
- The design philosophy of sockets and where it breaks down
Chapter 7: The Linux Kernel Networking Architecture
- Overview of net/ directory structure and subsystem layout
- The packet journey: ingress and egress flow through the kernel
- Protocol registration and family initialization
- Network namespaces and virtualization foundations
- The net_device structure and device abstraction layer
- sysctl and runtime tuning knobs
Chapter 8: The Complete Packet Lifecycle: Reception Path
- PHY reception and MAC frame validation
- NIC descriptor rings and DMA buffer management
- MSI-X interrupt vectors and affinity
- Interrupt moderation and coalescing
- NAPI: poll mode and its performance implications
- sk_buff allocation, initialization and metadata population
- GRO and packet coalescing in the driver
Chapter 9: The Complete Packet Lifecycle: Transmission Path
- Application write: copy from user to kernel
- Socket buffers: sk_buff construction and queuing
- TCP segmentation: MSS, SACK blocks, options
- IP header construction and checksum offload
- Queue discipline: fq_codel, pfifo_fast, HTB
- TSO/LRO/GSO offloads and their interactions
- TX completion paths and buffer recycling
Chapter 10: TCP Implementation in the Linux Kernel
- TCP socket structure: struct tcp_sock and its fields
- The receive path: tcp_v4_rcv and packet reassembly
- The send path: tcp_sendmsg and queue management
- Timers: RTO, keepalive, delay ACK, time-wait
- Retransmission queue management and fast retransmit
- Congestion control hooks: tcp_cong_ops and algorithm selection
Chapter 11: TCP Congestion Control Algorithms
- The congestion control problem and the AIMD principle
- Reno, NewReno: congestion window and slow start
- SACK and its transformations on recovery behavior
- CUBIC: the Linux default and its cubic growth curve
- BBR: bandwidth probing and model-based control
- Algorithm selection and interaction with middleboxes
Chapter 12: Networking Performance Measurement
- Metrics: throughput, latency, jitter, packet loss, CPU utilization
- Percentiles and tail latency: p50, p95, p99, p99.9 distributions
- Measurement tools: perf, ftrace, bpftrace, bpftool
- Network measurement: iproute2, ethtool, tcpdump, Wireshark
- Traffic generators: pktgen, Tcpreplay, TRex
- Methodology: baselines, controlled variables, reproducibility
Chapter 13: Processor-Architecture Foundations for Networking
- Cache hierarchy: L1, L2, L3, TLB and their costs
- NUMA topology and its impact on packet processing
- False sharing and cacheline padding in networking structures
- Memory barriers, acquire-release semantics, lock-free programming
- Branch prediction and its impact on hot packet paths
- SIMD acceleration for crypto and checksum computation
Chapter 14: High-Performance I/O: epoll, io_uring and Beyond
- The evolution of event notification: select, poll, epoll
- epoll internals: red-black trees, ready lists, EPOLLET
- io_uring architecture: submission/completion rings, fixed buffers
- Comparing latency and throughput across I/O interfaces
- Application design patterns for high-concurrency networking
Chapter 15: Zero-Copy Techniques and Memory Efficiency
- The cost of copying in the traditional path
- sendfile and splice: kernel-level file-to-socket transfer
- MSG_ZEROCOPY: zero-copy send
- UDP zerocopy and its limitations
- Pinning pages and getting memory to the NIC
- Buffer management strategies for high-performance stacks
Chapter 16: Kernel Bypass: DPDK, AF_XDP and Direct NIC Access
- Why kernel bypass: eliminating overhead for extreme performance
- DPDK architecture: EAL, poll mode drivers, memory pools
- Building a DPDK application: lifecycle and memory management
- AF_XDP: in-kernel ring-based socket interface
- Comparing DPDK, AF_XDP and XDP for production use
Chapter 17: eBPF in Networking: Programmability at Scale
- eBPF origins and virtual machine architecture
- BPF programs for networking: XDP, socket filters, TC, kprobe
- Map types and their networking applications
- Verifier constraints and safe kernel execution
- Observability with bpftrace and custom eBPF programs
- Production patterns: traffic steering, DDoS mitigation, load balancing
Chapter 18: RDMA and Hardware Offloading
- RDMA principles: zero-copy, kernel bypass, CPU offload
- InfiniBand protocol architecture and verbs API
- RoCEv2: RDMA over Converged Ethernet
- iWARP: RDMA over TCP and its trade-offs
- Hardware offloads: checksums, TSO, RSS, flow steering
- When RDMA makes sense: cluster interconnects and storage
Chapter 19: Programmable NICs, SmartNICs and DPU Architectures
- NIC evolution: from passive DMA to programmable engines
- SmartNIC architecture and compute fabric
- Data Processing Units (DPUs) and offloading servers
- P4 and programmable packet processing
- Production use cases: encryption offload, protocol acceleration
- Trade-offs: flexibility, cost, vendor lock-in
Chapter 20: Virtualization and Container Networking
- Virtual switches: Linux bridge, Open vSwitch, DPDK-based switches
- Tunnels and overlays: VXLAN, Geneve, GRE, IPIP
- Network namespaces and veth pairs
- Container networking: CNI, kube-proxy, service meshes
- SR-IOV: direct device assignment to guests
- Performance impact: overhead measurement and mitigation
Chapter 21: Designing a Network Stack from Scratch: Architecture
- Defining requirements: protocols, platforms, performance targets
- Layered architecture and module boundaries
- Buffer management design: owning, sharing and recycling packets
- Event-driven vs synchronous processing models
- Platform abstraction: porting across operating systems
- Testing strategy: unit tests, fuzzing, protocol verification
Chapter 22: Implementing the Data Link and Network Layers
- Packet buffer abstraction in C
- Ethernet frame parsing and construction
- Raw socket packet I/O on Linux
- ARP implementation with caching and timeout
- IPv4 header parsing, checksums and fragmentation handling
- Basic routing table and longest prefix match
Chapter 23: Implementing Transport Protocols: UDP and TCP
- UDP socket abstraction and datagram handling
- TCP connection table and lookup structures
- The TCP state machine: SYN_SENT, ESTABLISHED, FIN_WAIT_2, etc.
- Sequence number management and wraparound handling
- Retransmission logic: timers, RTO calculation, fast retransmit
- Congestion control: slow start, congestion avoidance, cubic
- Flow control and window updates
Chapter 24: Building a User-Space TCP/IP Stack
- Architecture choices: raw sockets vs kernel bypass
- Integration with a packet capture interface
- Complete socket API implementation
- Concurrency model for the stack
- Integration testing with real networks
- Performance comparison with kernel TCP
Chapter 25: Implementing an AF_XDP Packet Processing Engine
- Setting up AF_XDP sockets and ring buffers
- Batch receive and transmit for throughput
- Zero-copy receive mode configuration
- eBPF program for redirecting packets to AF_XDP
- Application logic: filtering, modification, forwarding
- Performance benchmarking and optimization
Chapter 26: Implementing a DPDK-Based Router
- DPDK setup: EAL initialization, memory pools, port configuration
- Poll loop architecture for multi-core forwarding
- LPM table implementation and lookup
- NAT translation table management
- Load balancing: consistent hashing and flow affinity
- Performance optimization and scalability testing
Chapter 27: Building a High-Performance HTTP Server
- Request/response parsing and state management
- Connection handling with io_uring or epoll
- Memory management and zero-copy file serving
- TLS acceleration and session resumption
- Benchmarking against nginx and specialized servers
Chapter 28: Implementing a Custom Load Balancer
- Layer 4 vs layer 7 load balancing architecture
- Health check implementation and failure detection
- Load balancing algorithms: round-robin, least connections, consistent hashing
- Connection tracking and session affinity
- Failover and high availability design
- Integration with service discovery and orchestration
Chapter 29: Optimizing a Linux TCP Service for Production
- Baseline measurement and profiling with perf
- Identifying hot paths with flame graphs
- Kernel parameter tuning: somaxconn, tcp_tw_reuse, tcp_max_syn_backlog
- Application optimization: buffer sizes, batching, batching writes
- eBPF-based observability for production diagnosis
- Continuous performance monitoring in production
Chapter 30: Production Networking: Reliability, Security and Operations
- Observability pillars for networking: metrics, logs, traces
- Packet loss and congestion in production environments
- Denial-of-service: types, detection, mitigation strategies
- Resource exhaustion: SYN floods, memory pressure, file descriptors
- Fault isolation: circuit breakers, timeouts, bulkheads
- Long-term evolution: protocol upgrades, security patches, capacity planning
Conclusion: The Future of Network Stack Engineering
- The lessons
- Where the field is heading
- What to focus on
References
- Protocol Specifications (RFCs)
- Ethernet and Link Layer
- Linux Kernel Networking Documentation
- Kernel Bypass and High-Performance Frameworks
- Congestion Control Research
- Performance Measurement and Profiling
- Hardware and NIC Documentation
- Virtualization and Container Networking
- RDMA and High-Performance Transports
- General Networking and Systems References