| 1 | package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/" |
| 5 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 6 | ) |
| 7 | |
| 8 | const ( |
| 9 | year68scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/year68. = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits. |
| 10 | defaultTtlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultTtl. = 3600 // Default internal TTL. |
| 11 | |
| 12 | // DefaultMsgSize is the standard default for messages larger than 512 bytes. |
| 13 | DefaultMsgSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultMsgSize. = 4096 |
| 14 | // MinMsgSize is the minimal size of a DNS packet. |
| 15 | MinMsgSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MinMsgSize. = 512 |
| 16 | // MaxMsgSize is the largest possible DNS packet. |
| 17 | MaxMsgSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MaxMsgSize. = 65535 |
| 18 | ) |
| 19 | |
| 20 | // Error represents a DNS error. |
| 21 | type Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error# struct{ errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err. string } |
| 22 | |
| 23 | func (e *Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#) Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#Error().() string { |
| 24 | if e == nil { |
| 25 | return "dns: <nil>" |
| 26 | } |
| 27 | return "dns: " + e.errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err. |
| 28 | } |
| 29 | |
| 30 | // An RR represents a resource record. |
| 31 | type RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR# interface { |
| 32 | // Header returns the header of an resource record. The header contains |
| 33 | // everything up to the rdata. |
| 34 | Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.() *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header# |
| 35 | // String returns the text representation of the resource record. |
| 36 | Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#String.() string |
| 37 | |
| 38 | // copy returns a copy of the RR |
| 39 | copyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#copy.() RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR# |
| 40 | |
| 41 | // len returns the length (in octets) of the compressed or uncompressed RR in wire format. |
| 42 | // |
| 43 | // If compression is nil, the uncompressed size will be returned, otherwise the compressed |
| 44 | // size will be returned and domain names will be added to the map for future compression. |
| 45 | lenscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#len.(off int, compression map[string]struct{}) int |
| 46 | |
| 47 | // pack packs the records RDATA into wire format. The header will |
| 48 | // already have been packed into msg. |
| 49 | packscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#pack.(msg []byte, off int, compression compressionMapscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/compressionMap#, compress bool) (off1 int, err error) |
| 50 | |
| 51 | // unpack unpacks an RR from wire format. |
| 52 | // |
| 53 | // This will only be called on a new and empty RR type with only the header populated. It |
| 54 | // will only be called if the record's RDATA is non-empty. |
| 55 | unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#unpack.(msg []byte, off int) (off1 int, err error) |
| 56 | |
| 57 | // parse parses an RR from zone file format. |
| 58 | // |
| 59 | // This will only be called on a new and empty RR type with only the header populated. |
| 60 | parsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#parse.(c *zlexerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/zlexer#, origin string) *ParseErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ParseError# |
| 61 | |
| 62 | // isDuplicate returns whether the two RRs are duplicates. |
| 63 | isDuplicatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#isDuplicate.(r2 RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#) bool |
| 64 | } |
| 65 | |
| 66 | // RR_Header is the header all DNS resource records share. |
| 67 | type RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header# struct { |
| 68 | Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name. string `dns:"cdomain-name"` |
| 69 | Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype. uint16 |
| 70 | Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class. uint16 |
| 71 | Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl. uint32 |
| 72 | Rdlengthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rdlength. uint16 // Length of data after header. |
| 73 | } |
| 74 | |
| 75 | // Header returns itself. This is here to make RR_Header implements the RR interface. |
| 76 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Header().() *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header# { return h } |
| 77 | |
| 78 | // Just to implement the RR interface. |
| 79 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) copyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#copy().() RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR# { return nil } |
| 80 | |
| 81 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#String().() string { |
| 82 | var s string |
| 83 | |
| 84 | if h.Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype. == TypeOPTscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeOPT. { |
| 85 | s = ";" |
| 86 | // and maybe other things |
| 87 | } |
| 88 | |
| 89 | s += sprintNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/sprintName().(h.Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.) + "\t" |
| 90 | s += strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.FormatIntscip-go gomod github.com/golang/go/src go1.25.0 strconv/FormatInt().(int64(h.Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.), 10) + "\t" |
| 91 | s += Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Class#(h.Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.).Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Class#String().() + "\t" |
| 92 | s += Typescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Type#(h.Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.).Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Type#String().() + "\t" |
| 93 | return s |
| 94 | } |
| 95 | |
| 96 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) lenscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#len().(off int, compression map[string]struct{}) int { |
| 97 | l := domainNameLenscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/domainNameLen().(h.Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name., off, compression, true) |
| 98 | l += 10 // rrtype(2) + class(2) + ttl(4) + rdlength(2) |
| 99 | return l |
| 100 | } |
| 101 | |
| 102 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) packscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#pack().(msg []byte, off int, compression compressionMapscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/compressionMap#, compress bool) (off1 int, err error) { |
| 103 | // RR_Header has no RDATA to pack. |
| 104 | return off, nil |
| 105 | } |
| 106 | |
| 107 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#unpack().(msg []byte, off int) (int, error) { |
| 108 | panic("dns: internal error: unpack should never be called on RR_Header") |
| 109 | } |
| 110 | |
| 111 | func (h *RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#) parsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#parse().(c *zlexerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/zlexer#, origin string) *ParseErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ParseError# { |
| 112 | panic("dns: internal error: parse should never be called on RR_Header") |
| 113 | } |
| 114 | |
| 115 | // ToRFC3597 converts a known RR to the unknown RR representation from RFC 3597. |
| 116 | func (rr *RFC3597scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#) ToRFC3597scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#ToRFC3597().(r RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#) error { |
| 117 | buf := make([]byte, Lenscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Len().(r)) |
| 118 | headerEnd, off, err := packRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/packRR().(r, buf, 0, compressionMapscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/compressionMap#{}, false) |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | buf = buf[:off] |
| 123 | |
| 124 | *rr = RFC3597scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#Hdr.: *r.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.()} |
| 125 | rr.Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#Hdr..Rdlengthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rdlength. = uint16(off - headerEnd) |
| 126 | |
| 127 | if noRdatascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/noRdata().(rr.Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#Hdr.) { |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | _, err = rr.unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#unpack().(buf, headerEnd) |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | // fromRFC3597 converts an unknown RR representation from RFC 3597 to the known RR type. |
| 136 | func (rr *RFC3597scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#) fromRFC3597scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#fromRFC3597().(r RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#) error { |
| 137 | hdr := r.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.() |
| 138 | *hdr = rr.Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#Hdr. |
| 139 | |
| 140 | // Can't overflow uint16 as the length of Rdata is validated in (*RFC3597).parse. |
| 141 | // We can only get here when rr was constructed with that method. |
| 142 | hdr.Rdlengthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rdlength. = uint16(hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.DecodedLenscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/DecodedLen().(len(rr.Rdatascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#Rdata.))) |
| 143 | |
| 144 | if noRdatascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/noRdata().(*hdr) { |
| 145 | // Dynamic update. |
| 146 | return nil |
| 147 | } |
| 148 | |
| 149 | // rr.pack requires an extra allocation and a copy so we just decode Rdata |
| 150 | // manually, it's simpler anyway. |
| 151 | msg, err := hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.DecodeStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/DecodeString().(rr.Rdatascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RFC3597#Rdata.) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | _, err = r.unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#unpack.(msg, 0) |
| 157 | return err |
| 158 | } |