summaryrefslogtreecommitdiff
path: root/source/static.go
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-08-20 06:18:05 +0200
committerMel <mel@rnrd.eu>2026-08-20 06:18:05 +0200
commitb52c860a7b1d3f57abc442bb8c1257f228d49536 (patch)
tree524865405ba3b972d684ded62d7ab67547bb9040 /source/static.go
downloadddnnss-b52c860a7b1d3f57abc442bb8c1257f228d49536.tar.zst
ddnnss-b52c860a7b1d3f57abc442bb8c1257f228d49536.zip
ddnnss
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'source/static.go')
-rw-r--r--source/static.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/source/static.go b/source/static.go
new file mode 100644
index 0000000..d2645d6
--- /dev/null
+++ b/source/static.go
@@ -0,0 +1,44 @@
+package source
+
+import (
+ "fmt"
+ "log/slog"
+ "net/netip"
+)
+
+// a simple source that returns the configured address.
+// useful when a record needs to have one specific value,
+// that is known in advance, and for debugging.
+type staticSource struct {
+ log *slog.Logger
+ addr netip.Addr
+}
+
+var _ Source = (*staticSource)(nil)
+
+func newStatic(log *slog.Logger, cfg Config) (*staticSource, error) {
+ log = log.With("source", "static")
+ addr, err := parse(cfg.Value, cfg.Family)
+ if err != nil {
+ log.Error(
+ "static source can't be created from value",
+ slog.String("family", string(cfg.Family)),
+ slog.String("value", cfg.Value),
+ )
+ return nil, fmt.Errorf("can't create static source from value: %w", err)
+ }
+
+ return &staticSource{log: log, addr: addr}, nil
+}
+
+func (s *staticSource) Supports(f Family) bool {
+ return (s.addr.Is4() && f == IPv4) || (s.addr.Is6() && f == IPv6)
+}
+
+func (s *staticSource) Lookup(Family) (netip.Addr, error) {
+ s.log.Info(
+ "looked up address from static source",
+ slog.String("addr", s.addr.String()),
+ )
+ return s.addr, nil
+}