$ show google/packetdrill
Packetdrill is a command-line tool for testing TCP/UDP/IP network stacks by scripting precise packet events and system calls. It operates in two modes: local testing via a TUN virtual device, and remote testing over real NICs using a wire server/client protocol. The tool parses a domain-specific language (DSL) with flex/bison, executes events with microsecond timing, and verifies kernel behavior through packet injection, sniffing, and in-script assertions (including TCP_INFO queries). It supports multiple platforms (Linux, FreeBSD, OpenBSD, NetBSD) and protocols (TCP, UDP, ICMP, GRE, MPLS, PSP). The architecture is a single C binary with a modular design: a parser/lexer for test scripts, a run-time engine that manages state (socket, sequence numbers, timestamps), and a network device abstraction layer. Key entry points include `packetdrill.c` (main), `run.c` (script execution), `wire_server.c` (remote testing), and `run_all.py` (test runner). External dependencies are minimal: standard POSIX libraries, optional OpenSSL for PSP, and a YNL submodule for netlink. The test suite consists of hundreds of `.pkt` scripts covering TCP features like fast open, congestion control, SACK, and zerocopy. The codebase demonstrates strong engineering with clean abstractions (vtable for netdev, hash map for timestamp mapping, threading model for blocking syscalls) and deep networking expertise. However, it carries maintenance risks from extensive platform ifdefs, custom kernel header definitions, and tight coupling to specific kernel behaviors. The last commit date (2026-05-14) appears anomalous and may indicate a data error, but the repository shows signs of ongoing development.
The LLM identified 3 files worth highlighting for reuse:
A generic u32-to-u32 hash map implementation with open addressing and linear probing. It is self-contained, has no internal dependencies beyond standard C, and can be extracted for any project needing a simple integer hash map. Demonstrates clean API design with create, insert, lookup, and free operations.
Implements checksum calculations for IPv4, IPv6, TCP, UDP, and SCTP (CRC32C). Includes pseudo-header computation and incremental update support. The module is isolated, well-tested (has a unit test), and can be reused in any network-related project requiring protocol checksums.
A robust iterator for parsing TCP option bytes into structured fields (MSS, window scale, SACK, timestamps, etc.). Handles malformed options gracefully and supports all standard TCP options. The code is self-contained and can be extracted for any TCP packet inspection or generation tool.