feat: RFC-8427 #171

Merged
sam merged 16 commits from RFC-8427 into master 2022-12-27 20:07:09 +00:00
3 changed files with 18 additions and 8 deletions
Showing only changes of commit 5e0ca30b2e - Show all commits

View file

@ -303,7 +303,7 @@ func MakePrintable(res util.Response, opts *util.Options) (*Message, error) {
}
if opts.Display.Additional {
ret.displayAdditional(msg, opts, opt)
err = ret.displayAdditional(msg, opts, opt)
if err != nil {
return nil, fmt.Errorf("unable to display additional: %w", err)
}

View file

@ -8,7 +8,7 @@ import (
// Message is for overall DNS responses.
//
//nolint:govet // Better looking output is worth a few bytes.
//nolint:govet,tagliatelle // Better looking output is worth a few bytes.
type Message struct {
DateString string `json:"dateString,omitempty" xml:"dateString,omitempty" yaml:"dateString,omitempty"`
DateSeconds string `json:"dateSeconds,omitempty" xml:"dateSeconds,omitempty" yaml:"dateSeconds,omitempty"`
@ -45,6 +45,8 @@ type Message struct {
}
// Question is a DNS Query.
//
//nolint:govet,tagliatelle
type Question struct {
Name string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty" example:"localhost"`
Type uint16 `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty" example:"IN"`
@ -53,7 +55,9 @@ type Question struct {
ClassName string `json:"CLASSname,omitempty" xml:"CLASSname,omitempty" yaml:"CLASSname,omitempty" example:"1"`
}
// RRHeader is for DNS Resource Headers.
// Answer is for DNS Resource Headers.
//
//nolint:govet,tagliatelle
type Answer struct {
Name string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty" example:"127.0.0.1"`
Type uint16 `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty" example:"IN"`

View file

@ -17,6 +17,7 @@ func (message *Message) displayQuestion(msg *dns.Msg, opts *util.Options, opt *d
name string
err error
)
for _, question := range msg.Question {
if opts.Display.UcodeTranslate {
name, err = idna.ToUnicode(question.Name)
@ -33,6 +34,7 @@ func (message *Message) displayQuestion(msg *dns.Msg, opts *util.Options, opt *d
message.Class = dns.ClassToString[question.Qclass]
message.ClassName = dns.TypeToString[question.Qtype]
}
return nil
}
@ -42,6 +44,7 @@ func (message *Message) displayAnswers(msg *dns.Msg, opts *util.Options, opt *dn
name string
err error
)
for _, answer := range msg.Answer {
temp := strings.Split(answer.String(), "\t")
@ -63,7 +66,6 @@ func (message *Message) displayAnswers(msg *dns.Msg, opts *util.Options, opt *dn
}
message.AnswerRRs = append(message.AnswerRRs, Answer{
Name: name,
TypeName: dns.TypeToString[answer.Header().Rrtype],
Type: answer.Header().Rrtype,
@ -73,7 +75,8 @@ func (message *Message) displayAnswers(msg *dns.Msg, opts *util.Options, opt *dn
Value: temp[len(temp)-1],
})
}
return err
return nil
}
func (message *Message) displayAuthority(msg *dns.Msg, opts *util.Options, opt *dns.OPT) error {
@ -104,7 +107,6 @@ func (message *Message) displayAuthority(msg *dns.Msg, opts *util.Options, opt *
}
message.AuthoritativeRRs = append(message.AuthoritativeRRs, Answer{
Name: name,
TypeName: dns.TypeToString[ns.Header().Rrtype],
Type: ns.Header().Rrtype,
@ -116,7 +118,8 @@ func (message *Message) displayAuthority(msg *dns.Msg, opts *util.Options, opt *
Value: temp[len(temp)-1],
})
}
return err
return nil
}
func (message *Message) displayAdditional(msg *dns.Msg, opts *util.Options, opt *dns.OPT) error {
@ -125,6 +128,7 @@ func (message *Message) displayAdditional(msg *dns.Msg, opts *util.Options, opt
name string
err error
)
for _, additional := range msg.Extra {
if additional.Header().Rrtype == dns.StringToType["OPT"] {
continue
@ -160,9 +164,11 @@ func (message *Message) displayAdditional(msg *dns.Msg, opts *util.Options, opt
})
}
}
return err
return nil
}
// ParseOpt parses opts.
func (message *Message) ParseOpt(rr dns.OPT) ([]Opts, error) {
ret := []Opts{}
// Most of this is taken from https://github.com/miekg/dns/blob/master/edns.go#L76