$ show acassen/keepalived
Keepalived is a production-grade Linux daemon for high-availability and load balancing. It implements VRRP v2/v3 for router failover, integrates with the Linux Virtual Server (IPVS) kernel module for Layer 4 load balancing, and includes a suite of health checkers (HTTP, SSL, TCP, UDP, SMTP, DNS, PING, MISC) plus BFD for fast failure detection. The architecture is multi-process: a parent process manages dedicated children for VRRP, checkers, and BFD, coordinating reloads and termination via signals and eventfd. It deeply interacts with the Linux kernel through netlink, nftables/iptables, raw sockets, and proc connector, and exposes operational interfaces via SNMP, D-Bus, JSON state dumps, SMTP alerts, and notification scripts. The codebase is written in C with careful attention to Linux-specific features, including network namespaces, VRFs, VMAC/macvlan, and multicast group handling. It is a mature, widely deployed critical infrastructure component rather than a research artifact or library.
The LLM identified 6 files worth highlighting for reuse:
A generic event-driven scheduler supporting timers, read/write I/O, child process termination, and signal events. Built on epoll with a red-black tree for timer management. It is cleanly abstracted and can be extracted for any single-threaded asynchronous C program without internal dependencies.
A powerful, reusable configuration file parser with hierarchical keyword registration, sublevels, macro expansion ($VAR), sequence/lookup definitions, glob includes, and precise file/line error reporting. It is the backbone of keepalived's config system and could be lifted wholesale into another C project needing a flexible, non-boilerplate config language.
A custom memory allocation wrapper with optional leak tracking, double-free and buffer-overrun detection using a red-black tree of allocated blocks. When enabled, it provides production-grade diagnostics; when disabled it degrades to fast raw libc calls. Demonstrates an elegant compile-time-switchable memory debugging pattern.
Implementation of RFC 2338/5798 HMAC authentication with constant-time memcmp, replay protection, and clock-step recovery handling. It is a well-isolated protocol component that can be reused or studied for correctly implementing authenticated VRRP advertisements.
Vendored and adapted Linux kernel red-black tree implementation with augmented subtree support. Provides robust, well-tested tree operations used throughout the project for timers, process tracking, and VRID lookup. Reusable in any C project needing self-balancing binary search trees.
A set of low-level netlink helpers for building and completing nftables batches without libnftnl. Includes attribute nesting, payload/meta/lookup/cmp/bitwise expression constructors, and set management. This demonstrates a performant, dependency-light pattern for directly talking to the kernel's nftables subsystem.