rdatafields

package
v5.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rdatafields classifies the fields of an RDATA struct so that code can normalize them without a hand-maintained switch statement per rtype.

The classification is derived from the struct tags that codeberg.org/miekg/dns/rdata already puts on its fields, plus a small exclusion list (tagged fields that are domain names but are NOT hostnames) and a small inclusion list (fields that are hostnames but carry no usable tag, mostly in pkg/privatetypes/rdata).

build/normalizergen uses Fields to generate models.normalizeRDATA without runtime reflection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsObsolete

func IsObsolete(structName string) bool

IsObsolete reports whether structName is on the skip list above. Exported so a generator can log what it left out.

Types

type Field

type Field struct {
	Name  string // Go field name, e.g. "Target"
	Index int    // index into the struct, for reflect.Value.Field
	Kind  Kind
	Slice bool // true if the field is a []string, e.g. HIP.RendezvousServers
}

Field is one classified field of an rdata struct.

func Fields

func Fields(rd any) []Field

Fields returns the classified fields of rd's struct type. rd may be a struct or a pointer to one. Results are cached per type.

type Kind

type Kind int

Kind says how a field must be normalized before it is compared.

const (
	// KindOther means "leave it alone".
	KindOther Kind = iota

	// KindTargetHost is a domain name that names a host: CNAME.Target,
	// MX.Mx, SRV.Target, ALIAS.Target, and so on. It is case-insensitive
	// and fully qualified, so we store it downcased and ending in ".".
	KindTargetHost

	// KindMailbox is an email address encoded as a domain name
	// (SOA.Mbox, RP.Mbox). It is case-insensitive on the wire, but the
	// local part is conventionally preserved, and it does not name a
	// host. We do not rewrite these.
	KindMailbox

	// KindHexLower is a hex-encoded blob (DS.Digest, SSHFP.FingerPrint,
	// TLSA.Certificate). Case-insensitive; we store it downcased.
	KindHexLower

	// KindOpaqueName is a domain name that is neither a host nor a
	// mailbox: a DNSSEC internal (RRSIG.SignerName, NSEC.NextDomain) or
	// an identifier that merely borrows the wire format
	// (TSIG.Algorithm). These must be preserved byte for byte.
	KindOpaqueName
)

func Classify

func Classify(structName string, f reflect.StructField) Kind

Classify returns the Kind of one field of the rdata struct named structName. structName is the Go struct name ("CNAME"), not the rtype name, so that types which share a struct (HTTPS and SVCB, CDS and DS) are classified once.

func (Kind) String

func (k Kind) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL