Commit 66dc74ca authored by Chris O'Haver's avatar Chris O'Haver Committed by GitHub

plugin/etcd+kubernetes: Persist truncated state to client if CNAME lookup...

plugin/etcd+kubernetes: Persist truncated state to client if CNAME lookup response is truncated (#4715)

Persist the TC bit to client response for truncated CNAME lookups.
Signed-off-by: default avatarChris O'Haver <cohaver@infoblox.com>
parent d3a118e1
...@@ -14,10 +14,10 @@ import ( ...@@ -14,10 +14,10 @@ import (
) )
// A returns A records from Backend or an error. // A returns A records from Backend or an error.
func A(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) { func A(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error) {
services, err := checkForApex(ctx, b, zone, state, opt) services, err := checkForApex(ctx, b, zone, state, opt)
if err != nil { if err != nil {
return nil, err return nil, false, err
} }
dup := make(map[string]struct{}) dup := make(map[string]struct{})
...@@ -44,7 +44,7 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request ...@@ -44,7 +44,7 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request
if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) { if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) {
state1 := state.NewWithQuestion(serv.Host, state.QType()) state1 := state.NewWithQuestion(serv.Host, state.QType())
state1.Zone = zone state1.Zone = zone
nextRecords, err := A(ctx, b, zone, state1, append(previousRecords, newRecord), opt) nextRecords, tc, err := A(ctx, b, zone, state1, append(previousRecords, newRecord), opt)
if err == nil { if err == nil {
// Not only have we found something we should add the CNAME and the IP addresses. // Not only have we found something we should add the CNAME and the IP addresses.
...@@ -53,6 +53,9 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request ...@@ -53,6 +53,9 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request
records = append(records, nextRecords...) records = append(records, nextRecords...)
} }
} }
if tc {
truncated = true
}
continue continue
} }
// This means we can not complete the CNAME, try to look else where. // This means we can not complete the CNAME, try to look else where.
...@@ -62,6 +65,9 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request ...@@ -62,6 +65,9 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request
if e1 != nil { if e1 != nil {
continue continue
} }
if m1.Truncated {
truncated = true
}
// Len(m1.Answer) > 0 here is well? // Len(m1.Answer) > 0 here is well?
records = append(records, newRecord) records = append(records, newRecord)
records = append(records, m1.Answer...) records = append(records, m1.Answer...)
...@@ -77,14 +83,14 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request ...@@ -77,14 +83,14 @@ func A(ctx context.Context, b ServiceBackend, zone string, state request.Request
// nada // nada
} }
} }
return records, nil return records, truncated, nil
} }
// AAAA returns AAAA records from Backend or an error. // AAAA returns AAAA records from Backend or an error.
func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) { func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error) {
services, err := checkForApex(ctx, b, zone, state, opt) services, err := checkForApex(ctx, b, zone, state, opt)
if err != nil { if err != nil {
return nil, err return nil, false, err
} }
dup := make(map[string]struct{}) dup := make(map[string]struct{})
...@@ -112,7 +118,7 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ ...@@ -112,7 +118,7 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ
if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) { if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) {
state1 := state.NewWithQuestion(serv.Host, state.QType()) state1 := state.NewWithQuestion(serv.Host, state.QType())
state1.Zone = zone state1.Zone = zone
nextRecords, err := AAAA(ctx, b, zone, state1, append(previousRecords, newRecord), opt) nextRecords, tc, err := AAAA(ctx, b, zone, state1, append(previousRecords, newRecord), opt)
if err == nil { if err == nil {
// Not only have we found something we should add the CNAME and the IP addresses. // Not only have we found something we should add the CNAME and the IP addresses.
...@@ -121,6 +127,9 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ ...@@ -121,6 +127,9 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ
records = append(records, nextRecords...) records = append(records, nextRecords...)
} }
} }
if tc {
truncated = true
}
continue continue
} }
// This means we can not complete the CNAME, try to look else where. // This means we can not complete the CNAME, try to look else where.
...@@ -129,6 +138,9 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ ...@@ -129,6 +138,9 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ
if e1 != nil { if e1 != nil {
continue continue
} }
if m1.Truncated {
truncated = true
}
// Len(m1.Answer) > 0 here is well? // Len(m1.Answer) > 0 here is well?
records = append(records, newRecord) records = append(records, newRecord)
records = append(records, m1.Answer...) records = append(records, m1.Answer...)
...@@ -145,7 +157,7 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ ...@@ -145,7 +157,7 @@ func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Requ
} }
} }
} }
return records, nil return records, truncated, nil
} }
// SRV returns SRV records from the Backend. // SRV returns SRV records from the Backend.
...@@ -223,7 +235,7 @@ func SRV(ctx context.Context, b ServiceBackend, zone string, state request.Reque ...@@ -223,7 +235,7 @@ func SRV(ctx context.Context, b ServiceBackend, zone string, state request.Reque
// Internal name, we should have some info on them, either v4 or v6 // Internal name, we should have some info on them, either v4 or v6
// Clients expect a complete answer, because we are a recursor in their view. // Clients expect a complete answer, because we are a recursor in their view.
state1 := state.NewWithQuestion(srv.Target, dns.TypeA) state1 := state.NewWithQuestion(srv.Target, dns.TypeA)
addr, e1 := A(ctx, b, zone, state1, nil, opt) addr, _, e1 := A(ctx, b, zone, state1, nil, opt)
if e1 == nil { if e1 == nil {
extra = append(extra, addr...) extra = append(extra, addr...)
} }
...@@ -289,7 +301,7 @@ func MX(ctx context.Context, b ServiceBackend, zone string, state request.Reques ...@@ -289,7 +301,7 @@ func MX(ctx context.Context, b ServiceBackend, zone string, state request.Reques
} }
// Internal name // Internal name
state1 := state.NewWithQuestion(mx.Mx, dns.TypeA) state1 := state.NewWithQuestion(mx.Mx, dns.TypeA)
addr, e1 := A(ctx, b, zone, state1, nil, opt) addr, _, e1 := A(ctx, b, zone, state1, nil, opt)
if e1 == nil { if e1 == nil {
extra = append(extra, addr...) extra = append(extra, addr...)
} }
...@@ -329,11 +341,11 @@ func CNAME(ctx context.Context, b ServiceBackend, zone string, state request.Req ...@@ -329,11 +341,11 @@ func CNAME(ctx context.Context, b ServiceBackend, zone string, state request.Req
} }
// TXT returns TXT records from Backend or an error. // TXT returns TXT records from Backend or an error.
func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) { func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error) {
services, err := b.Services(ctx, state, true, opt) services, err := b.Services(ctx, state, true, opt)
if err != nil { if err != nil {
return nil, err return nil, false, err
} }
dup := make(map[string]struct{}) dup := make(map[string]struct{})
...@@ -360,8 +372,10 @@ func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Reque ...@@ -360,8 +372,10 @@ func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Reque
if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) { if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) {
state1 := state.NewWithQuestion(serv.Host, state.QType()) state1 := state.NewWithQuestion(serv.Host, state.QType())
state1.Zone = zone state1.Zone = zone
nextRecords, err := TXT(ctx, b, zone, state1, append(previousRecords, newRecord), opt) nextRecords, tc, err := TXT(ctx, b, zone, state1, append(previousRecords, newRecord), opt)
if tc {
truncated = true
}
if err == nil { if err == nil {
// Not only have we found something we should add the CNAME and the IP addresses. // Not only have we found something we should add the CNAME and the IP addresses.
if len(nextRecords) > 0 { if len(nextRecords) > 0 {
...@@ -386,13 +400,13 @@ func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Reque ...@@ -386,13 +400,13 @@ func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Reque
case dns.TypeTXT: case dns.TypeTXT:
if _, ok := dup[serv.Host]; !ok { if _, ok := dup[serv.Host]; !ok {
dup[serv.Host] = struct{}{} dup[serv.Host] = struct{}{}
return append(records, serv.NewTXT(state.QName())), nil return append(records, serv.NewTXT(state.QName())), truncated, nil
} }
} }
} }
return records, nil return records, truncated, nil
} }
// PTR returns the PTR records from the backend, only services that have a domain name as host are included. // PTR returns the PTR records from the backend, only services that have a domain name as host are included.
......
...@@ -21,16 +21,17 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( ...@@ -21,16 +21,17 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
var ( var (
records, extra []dns.RR records, extra []dns.RR
truncated bool
err error err error
) )
switch state.QType() { switch state.QType() {
case dns.TypeA: case dns.TypeA:
records, err = plugin.A(ctx, e, zone, state, nil, opt) records, truncated, err = plugin.A(ctx, e, zone, state, nil, opt)
case dns.TypeAAAA: case dns.TypeAAAA:
records, err = plugin.AAAA(ctx, e, zone, state, nil, opt) records, truncated, err = plugin.AAAA(ctx, e, zone, state, nil, opt)
case dns.TypeTXT: case dns.TypeTXT:
records, err = plugin.TXT(ctx, e, zone, state, nil, opt) records, truncated, err = plugin.TXT(ctx, e, zone, state, nil, opt)
case dns.TypeCNAME: case dns.TypeCNAME:
records, err = plugin.CNAME(ctx, e, zone, state, opt) records, err = plugin.CNAME(ctx, e, zone, state, opt)
case dns.TypePTR: case dns.TypePTR:
...@@ -49,7 +50,7 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( ...@@ -49,7 +50,7 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
fallthrough fallthrough
default: default:
// Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN // Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN
_, err = plugin.A(ctx, e, zone, state, nil, opt) _, _, err = plugin.A(ctx, e, zone, state, nil, opt)
} }
if err != nil && e.IsNameError(err) { if err != nil && e.IsNameError(err) {
if e.Fall.Through(state.Name()) { if e.Fall.Through(state.Name()) {
...@@ -68,6 +69,7 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( ...@@ -68,6 +69,7 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
m := new(dns.Msg) m := new(dns.Msg)
m.SetReply(r) m.SetReply(r)
m.Truncated = truncated
m.Authoritative = true m.Authoritative = true
m.Answer = append(m.Answer, records...) m.Answer = append(m.Answer, records...)
m.Extra = append(m.Extra, extra...) m.Extra = append(m.Extra, extra...)
......
...@@ -22,18 +22,19 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M ...@@ -22,18 +22,19 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
state.Zone = zone state.Zone = zone
var ( var (
records []dns.RR records []dns.RR
extra []dns.RR extra []dns.RR
err error truncated bool
err error
) )
switch state.QType() { switch state.QType() {
case dns.TypeA: case dns.TypeA:
records, err = plugin.A(ctx, &k, zone, state, nil, plugin.Options{}) records, truncated, err = plugin.A(ctx, &k, zone, state, nil, plugin.Options{})
case dns.TypeAAAA: case dns.TypeAAAA:
records, err = plugin.AAAA(ctx, &k, zone, state, nil, plugin.Options{}) records, truncated, err = plugin.AAAA(ctx, &k, zone, state, nil, plugin.Options{})
case dns.TypeTXT: case dns.TypeTXT:
records, err = plugin.TXT(ctx, &k, zone, state, nil, plugin.Options{}) records, truncated, err = plugin.TXT(ctx, &k, zone, state, nil, plugin.Options{})
case dns.TypeCNAME: case dns.TypeCNAME:
records, err = plugin.CNAME(ctx, &k, zone, state, plugin.Options{}) records, err = plugin.CNAME(ctx, &k, zone, state, plugin.Options{})
case dns.TypePTR: case dns.TypePTR:
...@@ -58,7 +59,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M ...@@ -58,7 +59,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
// Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN // Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN
fake := state.NewWithQuestion(state.QName(), dns.TypeA) fake := state.NewWithQuestion(state.QName(), dns.TypeA)
fake.Zone = state.Zone fake.Zone = state.Zone
_, err = plugin.A(ctx, &k, zone, fake, nil, plugin.Options{}) _, _, err = plugin.A(ctx, &k, zone, fake, nil, plugin.Options{})
} }
if k.IsNameError(err) { if k.IsNameError(err) {
...@@ -81,6 +82,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M ...@@ -81,6 +82,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
m := new(dns.Msg) m := new(dns.Msg)
m.SetReply(r) m.SetReply(r)
m.Truncated = truncated
m.Authoritative = true m.Authoritative = true
m.Answer = append(m.Answer, records...) m.Answer = append(m.Answer, records...)
m.Extra = append(m.Extra, extra...) m.Extra = append(m.Extra, extra...)
......
This diff is collapsed.
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"github.com/coredns/coredns/plugin/kubernetes/object" "github.com/coredns/coredns/plugin/kubernetes/object"
"github.com/coredns/coredns/plugin/pkg/dnsutil" "github.com/coredns/coredns/plugin/pkg/dnsutil"
"github.com/coredns/coredns/plugin/pkg/fall" "github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
...@@ -35,7 +34,7 @@ import ( ...@@ -35,7 +34,7 @@ import (
type Kubernetes struct { type Kubernetes struct {
Next plugin.Handler Next plugin.Handler
Zones []string Zones []string
Upstream *upstream.Upstream Upstream Upstreamer
APIServerList []string APIServerList []string
APICertAuth string APICertAuth string
APIClientCert string APIClientCert string
...@@ -53,6 +52,11 @@ type Kubernetes struct { ...@@ -53,6 +52,11 @@ type Kubernetes struct {
autoPathSearch []string // Local search path from /etc/resolv.conf. Needed for autopath. autoPathSearch []string // Local search path from /etc/resolv.conf. Needed for autopath.
} }
// Upstreamer is used to resolve CNAME or other external targets
type Upstreamer interface {
Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error)
}
// New returns a initialized Kubernetes. It default interfaceAddrFunc to return 127.0.0.1. All other // New returns a initialized Kubernetes. It default interfaceAddrFunc to return 127.0.0.1. All other
// values default to their zero value, primaryZoneIndex will thus point to the first zone. // values default to their zero value, primaryZoneIndex will thus point to the first zone.
func New(zones []string) *Kubernetes { func New(zones []string) *Kubernetes {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment