Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stream isolation via EDNS0 #4

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions madns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var log, Log = xlog.New("madns")

const version string = "1.0.0"

const EDNS0STREAMISOLATION uint16 = 65312

var (
cNumQueries = expvar.NewInt("madns.numQueries")
cNumQueriesNoEDNS = expvar.NewInt("madns.numQueriesNoEDNS")
Expand All @@ -33,7 +35,7 @@ type Backend interface {
// The existence of wildcard records will be determined by doing a lookup for a name
// like "*.example.com", so there is no need to process the wildcard logic other than
// to make sure such a lookup functions correctly.
Lookup(qname string) (rrs []dns.RR, err error)
Lookup(qname, streamIsolationID string) (rrs []dns.RR, err error)
}

// DNS query engine implementing dns.Handler. Suitable for exposure directly to
Expand Down Expand Up @@ -92,8 +94,15 @@ func (e *engine) ServeDNS(rw dns.ResponseWriter, reqMsg *dns.Msg) {
tx.typesAtQname = map[uint16]struct{}{}
tx.additionalQueue = map[string]struct{}{}

tx.streamIsolationID = []byte{}

opt := tx.req.IsEdns0()
if opt != nil {
for _, edns0 := range opt.Option {
if edns0.Option() == EDNS0STREAMISOLATION {
tx.streamIsolationID = edns0.(*dns.EDNS0_LOCAL).Data
}
}
tx.res.Extra = append(tx.res.Extra, opt)
} else {
cNumQueriesNoEDNS.Add(1)
Expand Down Expand Up @@ -145,6 +154,8 @@ type stx struct {
e *engine
rcode int

streamIsolationID []byte

typesAtQname map[uint16]struct{}
additionalQueue map[string]struct{}
soa *dns.SOA
Expand All @@ -170,7 +181,7 @@ type stx struct {
func (tx *stx) blookup(qname string) (rrs []dns.RR, err error) {
cBackendLookups.Add(1)

rrs, err = tx.e.cfg.Backend.Lookup(qname)
rrs, err = tx.e.cfg.Backend.Lookup(qname, string(tx.streamIsolationID))
if err == nil && len(rrs) == 0 {
err = merr.ErrNoResults
}
Expand Down