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

proxy dns with NOTIMP error #2954

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 deletions proxy/dns/dns.go
Expand Up @@ -197,12 +197,13 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
if isIPQuery {
if domain, err := strmatcher.ToDomain(domain); err == nil {
go h.handleIPQuery(id, qType, domain, writer)
continue
} else {
h.handleDNSError(id, dnsmessage.RCodeFormatError, writer)
}
} else {
h.handleDNSError(id, dnsmessage.RCodeNotImplemented, writer)
}
}

if err := connWriter.WriteMessage(b); err != nil {
} else if err := connWriter.WriteMessage(b); err != nil {
return err
}
}
Expand Down Expand Up @@ -296,6 +297,35 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
}
}

func (h *Handler) handleDNSError(id uint16, rCode dnsmessage.RCode, writer dns_proto.MessageWriter) {
var err error

b := buf.New()
rawBytes := b.Extend(buf.Size)
builder := dnsmessage.NewBuilder(rawBytes[:0], dnsmessage.Header{
ID: id,
RCode: rCode,
RecursionAvailable: true,
RecursionDesired: true,
Response: true,
})
builder.EnableCompression()
common.Must(builder.StartQuestions())
common.Must(builder.StartAnswers())

msgBytes, err := builder.Finish()
if err != nil {
newError("pack message").Base(err).WriteToLog()
b.Release()
return
}
b.Resize(0, int32(len(msgBytes)))

if err := writer.WriteMessage(b); err != nil {
newError("write IP answer").Base(err).WriteToLog()
}
}

type outboundConn struct {
access sync.Mutex
dialer func() (internet.Connection, error)
Expand Down