Skip to content

Creating an RR instance with empty RDATA #1601

@mattias-p

Description

@mattias-p

I have a domain name and an rrtype and I want to construct a corresponding fully functional dns.RR instance with empty RDATA. This is required for dns.Msg.RemoveRRset(), and I also need to perform some other processing on these records. However, I couldn’t find any documentation on the intended way to do this.

I tried using a plain *dns.RR_Header. This mostly works since *dns.RR_Header formally implements dns.RR, but its dns.RR.copy implementation just returns nil, so dns.Copy doesn't work with such instances.

I also tried using dns.NewRR(fmt.Sprintf("%s %d IN %s", domain, ttl, dns.TypeToString[rrtype])). This also mostly works but for TXT records it seems dns.PackRR needs a larger buffer than what's reported by dns.Len.

I had a look at the source code for dns.RemoveRRset and realized that wrapping the dns.RR_Header in a dns.ANY might be a solution. So far I haven't stumbled on any surprising behaviors with this solution, but I'm not confident about its robustness either.

What is the recommended way to construct a dns.RR instance with empty RDATA?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions