| 1 |
package dns |
| 2 |
|
| 3 |
import "codeberg.org/miekg/dns/internal/dnslex" |
| 4 |
|
| 5 |
func (*OPT) parse(_ *dnslex.Lexer, _ string) *ParseError { |
| 6 |
return &ParseError{err: "OPT records do not have a presentation format"} |
| 7 |
} |
| 8 |
|
| 9 |
// version returns the EDNS version used. Only version zero is currently defined. See [Msg.Version]. |
| 10 |
func (rr *OPT) version() uint8 { return uint8(rr.Hdr.TTL & 0x00FF0000 >> 16) } |
| 11 |
|
| 12 |
// setVersion sets the version of EDNS. This is usually zero. See [Msg.Version]. |
| 13 |
func (rr *OPT) setVersion(v uint8) { rr.Hdr.TTL = rr.Hdr.TTL&0xFF00FFFF | uint32(v)<<16 } |
| 14 |
|
| 15 |
// udpSize returns the UDP buffer size. See [Msg.UDPSize]. |
| 16 |
func (rr *OPT) udpSize() uint16 { return rr.Hdr.Class } |
| 17 |
|
| 18 |
// setUDPSize sets the UDP buffer size. See [Msg.UDPSize]. |
| 19 |
func (rr *OPT) setUDPSize(size uint16) { rr.Hdr.Class = size } |
| 20 |
|
| 21 |
// security returns the value of the DO (DNSSEC OK) bit. See [Msg.Security]. |
| 22 |
func (rr *OPT) security() bool { return rr.Hdr.TTL&_DO == _DO } |
| 23 |
|
| 24 |
// setSecurity sets the security (DNSSEC OK) bit. See [Msg.Security]. |
| 25 |
func (rr *OPT) setSecurity(do bool) { |
| 26 |
if do { |
| 27 |
rr.Hdr.TTL |= _DO |
| 28 |
} else { |
| 29 |
rr.Hdr.TTL &^= _DO |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// compactAnswers returns the value of the CO (Compact Answers OK) bit. See [Msg.CompactAnswers]. |
| 34 |
func (rr *OPT) compactAnswers() bool { return rr.Hdr.TTL&_CO == _CO } |
| 35 |
|
| 36 |
// setCompactAnswers sets the CO (Compact Answers OK) bit. See [Msg.CompactAnswers]. |
| 37 |
func (rr *OPT) setCompactAnswers(co bool) { |
| 38 |
if co { |
| 39 |
rr.Hdr.TTL |= _CO |
| 40 |
} else { |
| 41 |
rr.Hdr.TTL &^= _CO |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
// delegation returns the value of the delegation (DE OK) bit. See [Msg.Delegation]. |
| 46 |
func (rr *OPT) delegation() bool { return rr.Hdr.TTL&_DE == _DE } |
| 47 |
|
| 48 |
// setDelegation sets the delegation (DE OK) bit. See [Msg.Delegation]. |
| 49 |
func (rr *OPT) setDelegation(de bool) { |
| 50 |
if de { |
| 51 |
rr.Hdr.TTL |= _DE |
| 52 |
} else { |
| 53 |
rr.Hdr.TTL &^= _DE |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
// rcode returns the EDNS extended Rcode field (the upper 8 bits of the TTL). See [Msg.Rcode]. |
| 58 |
func (rr *OPT) rcode() uint16 { |
| 59 |
return uint16(rr.Hdr.TTL&0xFF000000>>24) << 4 |
| 60 |
} |
| 61 |
|
| 62 |
// setRcode sets the EDNS extended Rcode field. |
| 63 |
// If the Rcode is not an extended Rcode, will reset the extended Rcode field to 0. See [Msg.Rcode]. |
| 64 |
func (rr *OPT) setRcode(v uint16) { |
| 65 |
rr.Hdr.TTL = rr.Hdr.TTL&0x00FFFFFF | uint32(v>>4)<<24 |
| 66 |
} |
| 67 |
|
| 68 |
// z returns the Z part of the OPT RR as a uint16 with only the 13 least significant bits used. |
| 69 |
func (rr *OPT) z() uint16 { |
| 70 |
return uint16(rr.Hdr.TTL & 0x1FFF) |
| 71 |
} |
| 72 |
|
| 73 |
// setZ sets the Z part of the OPT RR, note only the 13 significant bits of z are used. |
| 74 |
func (rr *OPT) setZ(z uint16) { |
| 75 |
rr.Hdr.TTL = rr.Hdr.TTL&^0x1FFF | uint32(z&0x1FFF) |
| 76 |
} |