Skip to content

Commit ca3b34e

Browse files
authored
Document how to create RRs without rdata (miekg#1642)
Put docs on the ANY type, also reference this from the dynamic updates stuff. Signed-off-by: Miek Gieben <[email protected]>
1 parent f83d075 commit ca3b34e

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

scan.go

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ type ttlState struct {
108108
// origin for resolving relative domain names defaults to the DNS root (.).
109109
// Full zone file syntax is supported, including directives like $TTL and $ORIGIN.
110110
// All fields of the returned RR are set from the read data, except RR.Header().Rdlength which is set to 0.
111+
// Is you need a partial resource record with no rdata - for instance - for dynamic updates, see the [ANY]
112+
// documentation.
111113
func NewRR(s string) (RR, error) {
112114
if len(s) > 0 && s[len(s)-1] != '\n' { // We need a closing newline
113115
return ReadRR(strings.NewReader(s+"\n"), "")

types.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,20 @@ func (q *Question) String() (s string) {
268268
return s
269269
}
270270

271-
// ANY is a wild card record. See RFC 1035, Section 3.2.3. ANY
272-
// is named "*" there.
271+
// ANY is a wild card record. See RFC 1035, Section 3.2.3. ANY is named "*" there.
272+
// The ANY records can be (ab)used to create resource records without any rdata, that
273+
// can be used in dynamic update requests. Basic use pattern:
274+
//
275+
// a := &ANY{RR_Header{
276+
// Name: "example.org.",
277+
// Rrtype: TypeA,
278+
// Class: ClassINET,
279+
// }}
280+
//
281+
// Results in an A record without rdata.
273282
type ANY struct {
274283
Hdr RR_Header
275-
// Does not have any rdata
284+
// Does not have any rdata.
276285
}
277286

278287
func (rr *ANY) String() string { return rr.Hdr.String() }

update.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dns
22

33
// NameUsed sets the RRs in the prereq section to
44
// "Name is in use" RRs. RFC 2136 section 2.4.4.
5+
// See [ANY] on how to make RRs without rdata.
56
func (u *Msg) NameUsed(rr []RR) {
67
if u.Answer == nil {
78
u.Answer = make([]RR, 0, len(rr))
@@ -41,6 +42,7 @@ func (u *Msg) Used(rr []RR) {
4142

4243
// RRsetUsed sets the RRs in the prereq section to
4344
// "RRset exists (value independent -- no rdata)" RRs. RFC 2136 section 2.4.1.
45+
// See [ANY] on how to make RRs without rdata.
4446
func (u *Msg) RRsetUsed(rr []RR) {
4547
if u.Answer == nil {
4648
u.Answer = make([]RR, 0, len(rr))
@@ -53,6 +55,7 @@ func (u *Msg) RRsetUsed(rr []RR) {
5355

5456
// RRsetNotUsed sets the RRs in the prereq section to
5557
// "RRset does not exist" RRs. RFC 2136 section 2.4.3.
58+
// See [ANY] on how to make RRs without rdata.
5659
func (u *Msg) RRsetNotUsed(rr []RR) {
5760
if u.Answer == nil {
5861
u.Answer = make([]RR, 0, len(rr))
@@ -64,6 +67,7 @@ func (u *Msg) RRsetNotUsed(rr []RR) {
6467
}
6568

6669
// Insert creates a dynamic update packet that adds an complete RRset, see RFC 2136 section 2.5.1.
70+
// See [ANY] on how to make RRs without rdata.
6771
func (u *Msg) Insert(rr []RR) {
6872
if len(u.Question) == 0 {
6973
panic("dns: empty question section")
@@ -78,6 +82,7 @@ func (u *Msg) Insert(rr []RR) {
7882
}
7983

8084
// RemoveRRset creates a dynamic update packet that deletes an RRset, see RFC 2136 section 2.5.2.
85+
// See [ANY] on how to make RRs without rdata.
8186
func (u *Msg) RemoveRRset(rr []RR) {
8287
if u.Ns == nil {
8388
u.Ns = make([]RR, 0, len(rr))
@@ -89,6 +94,7 @@ func (u *Msg) RemoveRRset(rr []RR) {
8994
}
9095

9196
// RemoveName creates a dynamic update packet that deletes all RRsets of a name, see RFC 2136 section 2.5.3
97+
// See [ANY] on how to make RRs without rdata.
9298
func (u *Msg) RemoveName(rr []RR) {
9399
if u.Ns == nil {
94100
u.Ns = make([]RR, 0, len(rr))
@@ -99,6 +105,7 @@ func (u *Msg) RemoveName(rr []RR) {
99105
}
100106

101107
// Remove creates a dynamic update packet deletes RR from a RRSset, see RFC 2136 section 2.5.4
108+
// See [ANY] on how to make RRs without rdata.
102109
func (u *Msg) Remove(rr []RR) {
103110
if u.Ns == nil {
104111
u.Ns = make([]RR, 0, len(rr))

0 commit comments

Comments
 (0)