How acassen/keepalived works
Project type and purpose
• keepalived is an open-source C daemon providing Linux Layer-4 load-balancing (via IPVS), health-checking, and high-availability (via VRRP and BFD).
• It bundles multiple protocol engines (VRRP, BFD), checkers (HTTP, TCP, DNS, …), a scheduler/event multiplexer, and integrations (netlink, systemd, DBus, SNMP).
File structure
• Top-level build/config: configure.ac, Makefile.am, autogen.sh, m4/, Dockerfile.in, snap/ (snapcraft.yaml), bin_install/, bin/.
• Documentation: doc/, README.md, INSTALL, COPYING.
• Core code in keepalived/: subdivided into modules
• keepalived/core – daemon bootstrap, I/O multiplexer, config parser, global data, reload monitor, namespaces, netlink wrapper, scheduler
• keepalived/check – health-check implementations (HTTP, SMTP, PING, FILE, SSL, DNS, BFD, NFTables, …) and check API
• keepalived/vrrp – VRRP FSM, ARP, firewall rules, IP rules/routes, JSON serialization, notifications, SNMP hooks, sync
• keepalived/bfd – BFD protocol engine for fast link-failure detection
• keepalived/dbus – DBus interface templates for VRRP instances
• keepalived/etc – init scripts, systemd service templates, sample keepalived.conf
• keepalived/include – all public and internal headers
• Shared library code in lib/: utilities for parsing, JSON, logging, scheduling, event timers, process management, rbtree, vector, sockets, systemd support
• Tools & tests: tools/, test/, snap-tools/, goodies/
README for additional insights
• Describes architecture: I/O multiplexer at core, independent modules can be “used separately or together”
• Lists key protocols: IPVS (kernel), VRRP, BFD, plus health-check hooks
• keepalived Daemon
• Configuration Parser & Reload Monitor
• Event Multiplexer / Scheduler
• Health-Check Engine (check modules)
• VRRP Engine (FSM, ARP, firewall rules)
• BFD Engine
• Notification / Hooks (JSON, SNMP, custom scripts, DBus)
• IPVS Kernel Module (Layer-4 load-balancing)
• Netlink Interface (kernel communication)
• External Dependencies
• Configuration File (keepalived.conf)
• System Init (systemd / SysV scripts)
• DBus Bus
• SNMP Subsystem
• Logging subsystem (syslog)
• Client/Server Pools (backend servers, virtual IPs, real servers)
b. Relationships and interactions
• Daemon reads keepalived.conf → parser → internal data structures
• Scheduler drives I/O Multiplexer → triggers events for checkers, VRRP advertisements, BFD sessions
• Health-Check Engine → polls real servers → updates IPVS virtual server pool via Netlink/IPVS API
• VRRP Engine → sends/receives multicast VRRP packets → manages virtual router state → updates kernel ARP or iptables via Netlink
• BFD Engine → participates in BFD neighbor sessions → signals scheduler/VRRP for fast failover
• Notification Hooks → on state changes or check failures → emit JSON/SNMP or invoke scripts → optionally over DBus
c. Architectural patterns & principles
• Modular plugin-style checkers and protocol engines
• Central event loop (I/O multiplexer) with cooperative multi-threading
• Clear separation of concerns: config, core, checks, protocols, OS integration
d. Key technologies & libraries
• C99, libnl (netlink), IPVS kernel module, POSIX sockets, epoll/select, systemd unit interface, DBus XML templates
Final advice
• Be detailed: break out each module (core, check, vrrp, bfd, lib, dbus)
• Essential OS integration points (netlink, systemd, DBus, SNMP, syslog)