From: Dan Fuhry Date: Sun, 30 Mar 2025 02:06:15 +0000 (-0400) Subject: coredns_plugin: wildcard support for DNS records X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=779475eb3e30cecf6a8f925d2058d450a5ca0b47;p=runtime.git coredns_plugin: wildcard support for DNS records --- diff --git a/machines/coredns_plugin/registry.go b/machines/coredns_plugin/registry.go index 43c4d19..0b6b608 100644 --- a/machines/coredns_plugin/registry.go +++ b/machines/coredns_plugin/registry.go @@ -292,7 +292,16 @@ func (r *registry) LookupRecord(ques dns.Question) (int, []dns.RR) { records, ok := r.store.Records[domain.ID()][key] if !ok { - continue + for _, wc := range key.Wildcards() { + records, ok = r.store.Records[domain.ID()][wc] + if ok { + r.log.V(2).Debugf(" query for %q matched on wildcard candidate %s", key, wc) + break + } + } + if !ok { + continue + } } answers := make([]dns.RR, 0) diff --git a/machines/coredns_plugin/registry_store.go b/machines/coredns_plugin/registry_store.go index 2fbece8..8958365 100644 --- a/machines/coredns_plugin/registry_store.go +++ b/machines/coredns_plugin/registry_store.go @@ -32,6 +32,16 @@ type registryStore struct { type recordKey string +func (rk recordKey) Wildcards() []recordKey { + parts := strings.Split(string(rk), ".") + wildcards := make([]recordKey, len(parts)) + for i, _ := range parts { + parts[i] = "*" + wildcards = append(wildcards, recordKey(strings.Join(parts[i:], "."))) + } + return wildcards +} + var machinesRegistryStorePath string func init() {