Skip to content

Commit a36acb4

Browse files
author
dnschecktool
authored
Use proper section names when producing dig-like output for UPDATEs (miekg#1479)
1 parent 48f38eb commit a36acb4

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

msg.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -896,31 +896,50 @@ func (dns *Msg) String() string {
896896
return "<nil> MsgHdr"
897897
}
898898
s := dns.MsgHdr.String() + " "
899-
s += "QUERY: " + strconv.Itoa(len(dns.Question)) + ", "
900-
s += "ANSWER: " + strconv.Itoa(len(dns.Answer)) + ", "
901-
s += "AUTHORITY: " + strconv.Itoa(len(dns.Ns)) + ", "
902-
s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n"
899+
if dns.MsgHdr.Opcode == OpcodeUpdate {
900+
s += "ZONE: " + strconv.Itoa(len(dns.Question)) + ", "
901+
s += "PREREQ: " + strconv.Itoa(len(dns.Answer)) + ", "
902+
s += "UPDATE: " + strconv.Itoa(len(dns.Ns)) + ", "
903+
s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n"
904+
} else {
905+
s += "QUERY: " + strconv.Itoa(len(dns.Question)) + ", "
906+
s += "ANSWER: " + strconv.Itoa(len(dns.Answer)) + ", "
907+
s += "AUTHORITY: " + strconv.Itoa(len(dns.Ns)) + ", "
908+
s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n"
909+
}
903910
opt := dns.IsEdns0()
904911
if opt != nil {
905912
// OPT PSEUDOSECTION
906913
s += opt.String() + "\n"
907914
}
908915
if len(dns.Question) > 0 {
909-
s += "\n;; QUESTION SECTION:\n"
916+
if dns.MsgHdr.Opcode == OpcodeUpdate {
917+
s += "\n;; ZONE SECTION:\n"
918+
} else {
919+
s += "\n;; QUESTION SECTION:\n"
920+
}
910921
for _, r := range dns.Question {
911922
s += r.String() + "\n"
912923
}
913924
}
914925
if len(dns.Answer) > 0 {
915-
s += "\n;; ANSWER SECTION:\n"
926+
if dns.MsgHdr.Opcode == OpcodeUpdate {
927+
s += "\n;; PREREQUISITE SECTION:\n"
928+
} else {
929+
s += "\n;; ANSWER SECTION:\n"
930+
}
916931
for _, r := range dns.Answer {
917932
if r != nil {
918933
s += r.String() + "\n"
919934
}
920935
}
921936
}
922937
if len(dns.Ns) > 0 {
923-
s += "\n;; AUTHORITY SECTION:\n"
938+
if dns.MsgHdr.Opcode == OpcodeUpdate {
939+
s += "\n;; UPDATE SECTION:\n"
940+
} else {
941+
s += "\n;; AUTHORITY SECTION:\n"
942+
}
924943
for _, r := range dns.Ns {
925944
if r != nil {
926945
s += r.String() + "\n"

update_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ func TestPreReqAndRemovals(t *testing.T) {
126126
// end and the Example function trim these, thus they never match.
127127
// TODO(miek): don't print these tabs and make this into an Example function.
128128
expect := `;; opcode: UPDATE, status: NOERROR, id: 1234
129-
;; flags:; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 0
129+
;; flags:; ZONE: 1, PREREQ: 5, UPDATE: 4, ADDITIONAL: 0
130130
131-
;; QUESTION SECTION:
131+
;; ZONE SECTION:
132132
;example.org. IN SOA
133133
134-
;; ANSWER SECTION:
134+
;; PREREQUISITE SECTION:
135135
name_used. 0 CLASS255 ANY
136136
name_not_used. 0 NONE ANY
137137
rrset_used1. 0 CLASS255 A
138138
rrset_used2. 0 IN A 127.0.0.1
139139
rrset_not_used. 0 NONE A
140140
141-
;; AUTHORITY SECTION:
141+
;; UPDATE SECTION:
142142
remove1. 0 CLASS255 ANY
143143
remove2. 0 CLASS255 A
144144
remove3. 0 NONE A 127.0.0.1

0 commit comments

Comments
 (0)