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

Return SERVFAIL if unbound result is nil or missing question #30

Closed
Closed
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
21 changes: 19 additions & 2 deletions unbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package unbound

import (
"context"
"errors"
"fmt"
"strconv"

Expand All @@ -14,7 +15,12 @@ import (
"github.com/miekg/unbound"
)

var log = clog.NewWithPlugin("unbound")
var (
log = clog.NewWithPlugin("unbound")
errNilResult = errors.New("nil result from unbound")
errNilMessage = errors.New("nil message from unbound")
errMissingQuestion = errors.New("missing question in result from unbound")
)

// Unbound is a plugin that resolves requests using libunbound.
type Unbound struct {
Expand Down Expand Up @@ -116,11 +122,22 @@ func (u *Unbound) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg

server := metrics.WithServer(ctx)
RcodeCount.WithLabelValues(server, rc).Add(1)
RequestDuration.WithLabelValues(server).Observe(res.Rtt.Seconds())
if res != nil {
RequestDuration.WithLabelValues(server).Observe(res.Rtt.Seconds())
}

if err != nil {
return dns.RcodeServerFailure, err
}
if res == nil {
return dns.RcodeServerFailure, errNilResult
}
if res.AnswerPacket == nil {
return dns.RcodeServerFailure, errNilMessage
}
if len(res.AnswerPacket.Question) == 0 {
return dns.RcodeServerFailure, errMissingQuestion
}

// If the client *didn't* set the opt record, and specifically not the DO bit,
// strip this from the reply (unbound default to setting DO).
Expand Down