]> git.ipfire.org Git - thirdparty/systemd.git/commit
resolved: add configurable DNS cache size
authorishwarbb <ishwarbb23@gmail.com>
Mon, 23 Mar 2026 13:02:40 +0000 (13:02 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 18 May 2026 10:45:03 +0000 (11:45 +0100)
commit133909c8f65e49052e9e2bd413589095c1ab41fe
tree8a8d85b0b54fdb580a2ff312d5fc50ed5b9b66f9
parentdd2d04179b18e75c817c203a3b8c20ef0213820c
resolved: add configurable DNS cache size

Add CacheSize= option to [Resolve] section of resolved.conf to allow
configuring the maximum number of entries in the per-scope DNS cache.
The default remains 4096 entries. Setting this to 0 disables caching
(similar to Cache=no).

CacheSize= is only read when Cache=yes or Cache=no-negative. When
Cache=no, caching is fully disabled regardless of CacheSize=.

Changes:
- Add cache_size field to Manager struct
- Parse CacheSize= from resolved.conf via gperf
- Thread cache_size through dns_cache_put() and helper functions
- Replace hard-coded CACHE_MAX with the configurable cache_size
- When cache_size is 0 or Cache=no, flush cache and skip caching
- Add man page documentation for the new option
- Add unit tests for cache size enforcement

Co-developed-by: Claude <claude@anthropic.com>
man/resolved.conf.xml
src/resolve/resolved-conf.c
src/resolve/resolved-conf.h
src/resolve/resolved-dns-cache.c
src/resolve/resolved-dns-cache.h
src/resolve/resolved-dns-scope.c
src/resolve/resolved-gperf.gperf
src/resolve/resolved-manager.c
src/resolve/resolved-manager.h
src/resolve/resolved.conf.in
src/resolve/test-dns-cache.c