$ show luigirizzo/netmap
Netmap is a high-performance packet I/O framework that bypasses the kernel network stack, providing memory-mapped rings for zero-copy packet processing. It consists of a kernel module (character device /dev/netmap), a user-space library (libnetmap), and a suite of applications (pkt-gen, bridge, nmreplay, lb, dedup, etc.). The architecture supports multiple NICs via native driver adapters (Intel, Mellanox, VMware, virtio, etc.) or a generic emulation layer, and includes an in-kernel virtual switch (VALE), inter-process pipes, and traffic monitors. Key entry points are the kernel module's ioctl/poll/mmap operations and the user-space library's port specification parser. Data flows involve memory-mapped rings synchronized via system calls or a lock-free Communication Status Block (CSB). External dependencies include kernel APIs, NIC driver internals, and standard C libraries. The project is cross-platform (FreeBSD, Linux, Windows) and originates from academic research at the University of Pisa.
The LLM identified 4 files worth highlighting for reuse:
Provides a modern, thread-safe user-space library for opening netmap ports. It parses port specifications (e.g., 'netmap:eth0-1@0') with options like extmem, offsets, and share, and manages memory regions. This is a self-contained abstraction that can be reused by any application needing netmap access without dealing with low-level ioctl/mmap details.
Implements a generic memory allocator for netmap buffers, rings, and interface descriptors. Uses a lookup table (LUT) for virtual-to-physical translation, bitmap-based free slot management, and cluster allocation with page alignment. Supports private, external, and ptnetmap memory pools. This pattern is reusable for any kernel or user-space project needing efficient, pre-allocated memory pools with physical address tracking.
Implements packet header parsing and symmetric hash functions (Toeplitz, CRC, XOR) for IPv4/IPv6, VLAN, and GRE encapsulated packets. Used by the load balancer application to distribute flows across CPU cores. The hash functions are self-contained and can be extracted for use in any network load-balancing or flow classification project.
Implements an in-kernel synchronization loop using a Communication Status Block (CSB) shared between kernel and user space. Provides lock-free exchange of ring pointers with careful memory barrier ordering. This pattern is reusable for any high-performance I/O framework that needs to avoid system call overhead for ring synchronization.