$ show NLnetLabs/unbound
Unbound is a production-grade, modular, recursive DNS resolver with extensive DNSSEC validation, caching, and policy enforcement. It functions as a system daemon that iteratively resolves DNS queries from root servers or forwards to upstream resolvers, caches results in multi-layered caches (message, RRset, infrastructure), and validates responses according to DNSSEC. The daemon supports multiple transport protocols: UDP, TCP, TLS (DoT), HTTPS (DoH), and QUIC (DoQ), as well as experimental DNSCrypt encryption. It includes a modular processing pipeline where the iterator, validator, response-IP modification (respip), DNS64 synthesis, and other modules are composable at startup. An embedded library (libunbound) provides a public C and Python API for synchronous and asynchronous DNS lookups, enabling integration into other applications.
The LLM identified 8 files worth highlighting for reuse:
Self-contained, generic red-black tree implementation with insertion, deletion, and traversal. Used throughout Unbound for ordered data structures (caches, zone trees, pending queries). Can be extracted and used in any C project requiring a balanced binary search tree.
Partitioned hash table (slab hash) with per-slab locking for concurrency and LRU eviction per entry. Provides a generic interface for size, compare, delete, and memory functions. Extracts as a reusable concurrent cache pattern, applicable to any multithreaded C program.
Region-based (arena) allocator that allocates memory in large chunks and frees all at once. Designed for per-query temporary memory to reduce malloc overhead. Highly reusable as a fast allocator for short-lived data in any C server or parser.
Minimal event loop implementation using the POSIX select() system call, supporting file descriptor events and timers. It is a standalone replacement for libevent when the latter is unavailable. Can be reused in small C projects needing a simple, dependency-free event-driven I/O loop.
Portable implementation of arc4random(), a CSPRNG derived from OpenBSD's ChaCha20-based RNG. Includes fallbacks for OS-specific entropy sources (Linux getrandom, /dev/urandom, Windows CryptGenRandom). Easily extractable for any C project needing secure random numbers across platforms.
Radix tree implementation for IP address prefix lookup and longest-prefix matching, used for EDNS Client Subnet cache. Supports LRU eviction of subtrees. Reusable in any networking project that requires efficient IP prefix storage and lookup with memory management.
Dynamic buffer abstraction optimized for DNS wire format: supports reading/writing 16-bit and 32-bit values, compression pointers, and fixed-size blocks. Provides position tracking, capacity management, and clear/rewind operations. Can be extracted for any wire-format parsing library.
Public domain implementation of SipHash-2-4, a fast and secure pseudorandom function suitable for hash tables to prevent hash-flooding DoS. Small, self-contained, and easily reusable in any C project needing a high-quality keyed hash.