plugin/secondary: serve catalog member zones (#8230)

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
houyuwushang
2026-07-10 08:42:30 +08:00
committed by GitHub
parent e4990abfa3
commit 1e01c0ad7c
9 changed files with 368 additions and 67 deletions

View File

@@ -24,11 +24,15 @@ type (
Next plugin.Handler
Zones
Xfer *transfer.Transfer
ZoneLookupFunc
TransferInFunc
Fall fall.F
}
// ZoneLookupFunc looks up the authoritative zone for qname.
ZoneLookupFunc func(qname string) (zone string, z *Zone, ok bool)
// Zones maps zone names to a *Zone.
Zones struct {
Z map[string]*Zone // A map mapping zone (origin) to the Zone's data
@@ -41,9 +45,8 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
state := request.Request{W: w, Req: r}
qname := state.Name()
// TODO(miek): match the qname better in the map
zone := plugin.Zones(f.Zones.Names).Matches(qname)
if zone == "" {
zone, z, ok := f.lookupZone(qname)
if !ok {
// If no next plugin is configured, it's more correct to return REFUSED as file acts as an authoritative server
if f.Next == nil {
return dns.RcodeRefused, nil
@@ -51,8 +54,7 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
return plugin.NextOrFailure(f.Name(), f.Next, ctx, w, r)
}
z, ok := f.Z[zone]
if !ok || z == nil {
if z == nil {
return dns.RcodeServerFailure, nil
}
@@ -134,6 +136,22 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
// Name implements the Handler interface.
func (f File) Name() string { return "file" }
func (f File) lookupZone(qname string) (string, *Zone, bool) {
if f.ZoneLookupFunc != nil {
return f.ZoneLookupFunc(qname)
}
// TODO(miek): match the qname better in the map
zone := plugin.Zones(f.Zones.Names).Matches(qname)
if zone == "" {
return "", nil, false
}
z, ok := f.Z[zone]
if !ok {
return zone, nil, true
}
return zone, z, true
}
func (f File) transferIn(z *Zone, t *transfer.Transfer) error {
if f.TransferInFunc != nil {
return f.TransferInFunc(z, t)