Skip to content

Commit

Permalink
Use proper section names when producing dig-like output for UPDATEs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dnschecktool authored Sep 12, 2023
1 parent 48f38eb commit a36acb4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
33 changes: 26 additions & 7 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,31 +896,50 @@ func (dns *Msg) String() string {
return "<nil> MsgHdr"
}
s := dns.MsgHdr.String() + " "
s += "QUERY: " + strconv.Itoa(len(dns.Question)) + ", "
s += "ANSWER: " + strconv.Itoa(len(dns.Answer)) + ", "
s += "AUTHORITY: " + strconv.Itoa(len(dns.Ns)) + ", "
s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n"
if dns.MsgHdr.Opcode == OpcodeUpdate {
s += "ZONE: " + strconv.Itoa(len(dns.Question)) + ", "
s += "PREREQ: " + strconv.Itoa(len(dns.Answer)) + ", "
s += "UPDATE: " + strconv.Itoa(len(dns.Ns)) + ", "
s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n"
} else {
s += "QUERY: " + strconv.Itoa(len(dns.Question)) + ", "
s += "ANSWER: " + strconv.Itoa(len(dns.Answer)) + ", "
s += "AUTHORITY: " + strconv.Itoa(len(dns.Ns)) + ", "
s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n"
}
opt := dns.IsEdns0()
if opt != nil {
// OPT PSEUDOSECTION
s += opt.String() + "\n"
}
if len(dns.Question) > 0 {
s += "\n;; QUESTION SECTION:\n"
if dns.MsgHdr.Opcode == OpcodeUpdate {
s += "\n;; ZONE SECTION:\n"
} else {
s += "\n;; QUESTION SECTION:\n"
}
for _, r := range dns.Question {
s += r.String() + "\n"
}
}
if len(dns.Answer) > 0 {
s += "\n;; ANSWER SECTION:\n"
if dns.MsgHdr.Opcode == OpcodeUpdate {
s += "\n;; PREREQUISITE SECTION:\n"
} else {
s += "\n;; ANSWER SECTION:\n"
}
for _, r := range dns.Answer {
if r != nil {
s += r.String() + "\n"
}
}
}
if len(dns.Ns) > 0 {
s += "\n;; AUTHORITY SECTION:\n"
if dns.MsgHdr.Opcode == OpcodeUpdate {
s += "\n;; UPDATE SECTION:\n"
} else {
s += "\n;; AUTHORITY SECTION:\n"
}
for _, r := range dns.Ns {
if r != nil {
s += r.String() + "\n"
Expand Down
8 changes: 4 additions & 4 deletions update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ func TestPreReqAndRemovals(t *testing.T) {
// end and the Example function trim these, thus they never match.
// TODO(miek): don't print these tabs and make this into an Example function.
expect := `;; opcode: UPDATE, status: NOERROR, id: 1234
;; flags:; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 0
;; flags:; ZONE: 1, PREREQ: 5, UPDATE: 4, ADDITIONAL: 0
;; QUESTION SECTION:
;; ZONE SECTION:
;example.org. IN SOA
;; ANSWER SECTION:
;; PREREQUISITE SECTION:
name_used. 0 CLASS255 ANY
name_not_used. 0 NONE ANY
rrset_used1. 0 CLASS255 A
rrset_used2. 0 IN A 127.0.0.1
rrset_not_used. 0 NONE A
;; AUTHORITY SECTION:
;; UPDATE SECTION:
remove1. 0 CLASS255 ANY
remove2. 0 CLASS255 A
remove3. 0 NONE A 127.0.0.1
Expand Down

0 comments on commit a36acb4

Please sign in to comment.