dsomessage

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 10 Imported by: 2

README

Go Reference Coverage Status CI

dsomessage

dsomessage provides RFC 8490 DNS Stateful Operations and RFC 8765 DNS Push Notifications primitives as well as parsing and building machinery.

The goal is minimal overhead and control over heap allocations and processing.

See Also

dsosession for session managemend and [coredns-dso][https://github.com/Kentzo/coredns-dso] for extended example.

Documentation

Index

Examples

Constants

View Source
const (
	LengthPrefixLen = 2
	// MsgHeaderLen is fixed wire length of DSO message header.
	MsgHeaderLen = 12
	// TLVHeaderLen is fixed wire length of [TLVHeader].
	TLVHeaderLen = 4

	// KeepAliveLen is fixed wire length of [KeepAlive] TLV.
	KeepAliveLen = 8
	// RetryDelayLen is fixed wire length of [RetryDelay] TLV.
	RetryDelayLen = 4
	// UnsubscribeLen is fixed wire length of [Unsubscribe] TLV.
	UnsubscribeLen = 2

	// TLSBlockLen is recommended multiple for padding.
	//
	// RFC 8467, Section 4.1: If a server receives a query that includes the EDNS(0) "Padding"
	// option, ... SHOULD pad the corresponding response to a multiple of 468 octets
	TLSBlockLen = 468

	// MaxMsgLen is maximum wire length of DSO message.
	MaxMsgLen = dns.MaxMsgSize
)
View Source
const (
	// TypeKeepAlive is type of KeepAlive TLV.
	TypeKeepAlive = Type(dns.StatefulTypeKeepAlive)
	// TypeRetryDelay is type of RetryDelay TLV.
	TypeRetryDelay = Type(dns.StatefulTypeRetryDelay)
	// TypeEncryptionPadding is type of EncryptionPadding TLV.
	TypeEncryptionPadding = Type(dns.StatefulTypeEncryptionPadding)

	// TypeSubscribe is type of Subscribe TLV.
	TypeSubscribe Type = 0x0040
	// TypePush is type of Push TLV.
	TypePush Type = 0x0041
	// TypeUnsubscribe is type of Unsubscribe TLV.
	TypeUnsubscribe Type = 0x0042
	// TypeReconfirm is type of Reconfirm TLV.
	TypeReconfirm Type = 0x0043
)
View Source
const (
	// InactivityTimeoutDefault is default inactivity timeout.
	//
	// RFC 8490, Section 6.2: On a new DSO Session, if no explicit DSO Keepalive message exchange
	// has taken place, the default value ... is 15 seconds.
	InactivityTimeoutDefault = 15 * 1000
	// InactivityTimeoutNever is special value that represents "infinity".
	//
	// RFC 8490, Section 6.4.2: An inactivity timeout of 0xFFFFFFFF represents "infinity"
	// and informs the client that it may keep an idle connection open as long as it wishes.
	InactivityTimeoutNever = 0xFFFFFFFF

	// KeepAliveIntervalDefault is default keepalive interval.
	//
	// RFC 8490, Section 6.2: On a new DSO Session, if no explicit DSO Keepalive message exchange
	// has taken place, the default value ... is 15 seconds.
	KeepAliveIntervalDefault = 15 * 1000
	// KeepAliveIntervalRecommended is recommended keepalive interval.
	//
	// RFC 8490, Section 6.5.2: By default, it is RECOMMENDED that clients request, and servers
	// grant, a keepalive interval of 60 minutes.
	KeepAliveIntervalRecommended = 60 * 60 * 1000
	// KeepAliveIntervalMin is minimum allowed keepalive interval.
	//
	// RFC 8490, Section 7.1: The keepalive interval MUST NOT be less than ten seconds.
	KeepAliveIntervalMin = 10 * 1000
	// KeepAliveIntervalNever is special value that represents "infinity".
	//
	// RFC 8490, Section 6.5.2: A keepalive interval value of 0xFFFFFFFF represents "infinity"
	// and informs the client that it should generate no DSO keepalive traffic.
	KeepAliveIntervalNever = 0xFFFFFFFF
)
View Source
const (
	// PushTTLRemove is special TTL value for removal.
	//
	// RFC 8765, Section 6.3.1: If the TTL has the value 0xFFFFFFFF, then the DNS Resource Record
	// with the given name, type, class, and RDATA is removed.
	PushTTLRemove = 0xFFFFFFFF
	// PushTTLCollectiveRemove is special TTL value for collective removal.
	//
	// RFC 8765, Section 6.3.1: If the TTL has the value 0xFFFFFFFE, then this is a 'collective'
	// remove notification.
	PushTTLCollectiveRemove = 0xFFFFFFFE
	// PushTTLAddMin is mininum allowd TTL for addition.
	//
	// RFC 8765, Section 6.3.1: If the TTL is in the range 0 to 2,147,483,647 seconds
	// (0 to 231 - 1, or 0x7FFFFFFF), then a new DNS Resource Record with the given name,
	// type, class, and RDATA is added.
	PushTTLAddMin = 0
	// PushTTLAddMax is maximum allowd TTL for addition.
	//
	// RFC 8765, Section 6.3.1: If the TTL is in the range 0 to 2,147,483,647 seconds
	// (0 to 2^(31) - 1, or 0x7FFFFFFF), then a new DNS Resource Record with the given name,
	// type, class, and RDATA is added.
	PushTTLAddMax = 0x7FFFFFFF
	// MaxPushMsgLen is maximum push message length.
	//
	// RFC 8765, Section 6.3.1: Servers may generate PUSH messages up to a maximum DNS message
	// length of 16,382 bytes, counting from the start of the DSO 12-byte header. Including
	// the two-byte length prefix that is used to frame DNS over a byte stream like TLS,
	// this makes a total of 16,384 bytes. Servers MUST NOT generate PUSH messages larger than this.
	MaxPushMsgLen = 16382

	// PushDomain is domain name of DSO Push server in given zone.
	PushDomain = "_dns-push-tls._tcp."
)

Variables

View Source
var (
	// ErrFormat indicates that DSO message content is invalid.
	ErrFormat = fmt.Errorf("dsomessage: bad message format")

	// ErrHeader indicates that DSO message header is invalid.
	ErrHeader = fmt.Errorf("%w - bad header", ErrFormat)

	// ErrTLV indicates that TLV's content or usage is invalid.
	ErrTLV = fmt.Errorf("%w - bad TLV", ErrFormat)

	// ErrBufferFull indicates that there is not enough space in buffer
	// to accomodate change in message layout.
	ErrBufferFull = fmt.Errorf("dsomessage.Builder: short buffer")

	// ErrShortWrite indicates that write required longer buffer than was supplied.
	ErrShortWrite = fmt.Errorf("dsomessage.Builder: short write")

	// ErrTooLong indicates that message is too long to set length prefix.
	ErrTooLong = fmt.Errorf("dsomessage.Builder: msg too long")

	// ErrDone indicates that all TLVs have been parsed.
	ErrDone = fmt.Errorf("dsomessage.Parser: done")
)

Functions

func CompareNames added in v0.2.0

func CompareNames(a, b string) int

CompareNames returns <0 when a is less than b, 0 when they are equal and >0 when a is larger than b.

Follows DNSSEC canonical ordering (RFC 4034, Section 6.1):

  • `\DDD` byte is decoded before comparison
  • Uppercase A-Z letters are treated as if they were lowercase
  • Absence of octet sorts before zero value octet

Quirks:

  • Trailing `\` that escapes nothing is ignored
  • Leading `\` in `\D` and `\DD` is ignored
  • Non-FQDN names are assumed to be root-terminated

func PaddedMsgLen

func PaddedMsgLen(msgLen int, blockLen uint16) int

PaddedMsgLen pads msgLen, if needed, up to multiple of blockLen.

func RRLen

func RRLen(rr dns.RR) (l int)

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder incrementally builds DSO message.

Errors are sticky. It's expected that callers take care allocating and growing buffers such that under normal program flow TLVs fit without fail. Thus when Builder.Message returns an error it's because user miscalculated buffer size, tried to write malformed data or some other programmer's error fatal to DSO session.

When padding is enabled, operations that change layout or length enforce requirement of having enough available space to pad message.

Example
b := NewBuilder(make([]byte, 128)).
	SetHeader(MsgHeader{42, false, dns.RcodeSuccess})
b.WriteKeepAlive(&KeepAlive{InactivityTimeoutDefault, KeepAliveIntervalDefault})
msg, err := b.Message()
if err != nil {
	panic(err.Error())
}
fmt.Printf("% x\n", msg)
Output:
00 2a 30 00 00 00 00 00 00 00 00 00 00 01 00 08 00 00 3a 98 00 00 3a 98

func NewBuilder

func NewBuilder(buf []byte) *Builder

NewBuilder returns new Builder that takes ownership of buf.

Will panic if buffer's length is less than MsgHeaderLen.

func (*Builder) Available

func (b *Builder) Available() int

Available returns how many more bytes can be written.

func (*Builder) Cap

func (b *Builder) Cap() int

Cap returns useful capacity of underlying buffer.

func (*Builder) Clear

func (b *Builder) Clear() *Builder

Clear clears error and resets message but maintains header and settings.

func (*Builder) EnableCompression

func (b *Builder) EnableCompression() *Builder

EnableCompression enables compression for dns.PackRR and dns.PackDomainName.

func (*Builder) EnableLengthPrefix

func (b *Builder) EnableLengthPrefix() *Builder

EnableLengthPrefix uses first two bytes to encode message length.

ErrBufferFull is set if there is not enough available space for adjustment.

func (*Builder) EnablePadding

func (b *Builder) EnablePadding(blockLen uint16) *Builder

EnablePadding aligns message length to multiple of blockLen.

If > 1 writes enforce that either message length is proper multiple or at least TLVHeaderLen bytes are available for EncryptionPadding TLV.

ErrBufferFull is set if there is not enough available space for adjustment.

func (*Builder) Err

func (b *Builder) Err() error

Err returns error of most recent sticky error.

func (*Builder) Grow

func (b *Builder) Grow(n int) *Builder

Grow resizes underlying buffer to guarantee space for another n bytes.

If n is negative, Grow will panic.

func (*Builder) Len

func (b *Builder) Len() int

Len returns number of written bytes.

func (*Builder) Message

func (b *Builder) Message() ([]byte, error)

Message returns subslice of underlying buffer with bytes written so far, padded if needed.

ErrTooLong is set if length prefix is requested, but message is longer than MaxMsgLen.

func (*Builder) Reset

func (b *Builder) Reset() *Builder

Reset resets builder to like new state.

func (*Builder) SetHeader

func (b *Builder) SetHeader(h MsgHeader) *Builder

SetHeader sets DSO message header.

func (*Builder) Write

func (b *Builder) Write(p []byte) (n int, err error)

Write implements io.Writer.Write. If underlying buffer is too small for entire input, n is 0 and err is set.

func (*Builder) WriteEncryptionPadding

func (b *Builder) WriteEncryptionPadding(tlv *EncryptionPadding) (int, error)

WriteEncryptionPadding writes EncryptionPadding TLV to underlying buffer.

func (*Builder) WriteKeepAlive

func (b *Builder) WriteKeepAlive(tlv *KeepAlive) (int, error)

WriteKeepAlive writes KeepAlive TLV to underlying buffer.

func (*Builder) WritePush

func (b *Builder) WritePush(tlv *Push) (int, error)

WritePush writes Push TLV to underlying buffer.

func (*Builder) WritePushChange

func (b *Builder) WritePushChange(change []dns.RR) (n int, err error)

WritePushChange writes Push TLV to underlying buffer with as many RRs from change as can fit.

Unlike Builder.WritePush it allows to write changes incrementally with non-sticky PackingError being returned on incomplete write with PackingError.Index pointing where to continue.

func (*Builder) WriteReconfirm

func (b *Builder) WriteReconfirm(tlv *Reconfirm) (int, error)

WriteReconfirm writes Reconfirm TLV to underlying buffer.

func (*Builder) WriteRetryDelay

func (b *Builder) WriteRetryDelay(tlv *RetryDelay) (int, error)

WriteRetryDelay writes RetryDelay TLV to underlying buffer.

func (*Builder) WriteSubscribe

func (b *Builder) WriteSubscribe(tlv *Subscribe) (int, error)

WriteSubscribe writes Subscribe TLV to underlying buffer.

func (*Builder) WriteTLV

func (b *Builder) WriteTLV(tlv TLV) (int, error)

WriteTLV writes TLV to underlying buffer.

func (*Builder) WriteTo

func (b *Builder) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

func (*Builder) WriteUnsubscribe

func (b *Builder) WriteUnsubscribe(tlv *Unsubscribe) (int, error)

WriteUnsubscribe writes Unsubscribe TLV to underlying buffer.

type EncryptionPadding

type EncryptionPadding struct {
	Padding uint16
}

EncryptionPadding is RFC 8490, Section 7.3 Encryption Padding TLV.

Even the empty TLV adds 4 bytes due to header. See also RFC 8467.

func (*EncryptionPadding) AppendBinary

func (tlv *EncryptionPadding) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender.

func (*EncryptionPadding) Clone

func (tlv *EncryptionPadding) Clone() TLV

Clone implements TLV.Clone

func (*EncryptionPadding) Equal

func (tlv *EncryptionPadding) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (EncryptionPadding) Len

func (tlv EncryptionPadding) Len() int

Len implements TLV.Len.

func (*EncryptionPadding) MarshalBinary

func (tlv *EncryptionPadding) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (EncryptionPadding) String

func (tlv EncryptionPadding) String() string

String implements TLV.String.

func (EncryptionPadding) Type

func (tlv EncryptionPadding) Type() Type

Type implements the TLV.Type.

func (*EncryptionPadding) UnmarshalBinary

func (tlv *EncryptionPadding) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*EncryptionPadding) Verify

func (tlv *EncryptionPadding) Verify(usage Usage) error

Verify implements TLV.Verify.

type KeepAlive

type KeepAlive struct {
	// This is the timeout at which the client MUST begin closing an inactive DSO Session.
	InactivityTimeout uint32
	// This is the interval at which a client MUST generate DSO keepalive traffic to maintain
	// connection state.
	KeepAliveInterval uint32
}

KeepAlive is RFC 8490, Section 7.1 Keepalive TLV.

func (*KeepAlive) AppendBinary

func (tlv *KeepAlive) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender.

func (*KeepAlive) Clone

func (tlv *KeepAlive) Clone() TLV

Clone implements TLV.Clone.

func (*KeepAlive) Equal

func (tlv *KeepAlive) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (KeepAlive) Len

func (tlv KeepAlive) Len() int

Len implements TLV.Len.

func (*KeepAlive) MarshalBinary

func (tlv *KeepAlive) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (KeepAlive) String

func (tlv KeepAlive) String() string

String implements TLV.String.

func (KeepAlive) Type

func (tlv KeepAlive) Type() Type

Type implements TLV.Type.

func (*KeepAlive) UnmarshalBinary

func (tlv *KeepAlive) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*KeepAlive) Verify

func (tlv *KeepAlive) Verify(usage Usage) error

Verify implements TLV.Verify.

type Msg

type Msg struct {
	MsgHeader
	TLV    []TLV
	Origin Origin
}

func NewErrorMsg

func NewErrorMsg(id uint16, rcode uint8, tlvs ...TLV) (m *Msg)

func NewRepMsg

func NewRepMsg(id uint16, tlvs ...TLV) *Msg

func NewReqMsg

func NewReqMsg(id uint16, tlvs ...TLV) *Msg

func NewUniMsg

func NewUniMsg(tlvs ...TLV) *Msg

func UnpackMsg

func UnpackMsg(buf []byte, origin Origin) (m *Msg, err error)

UnpackMsg parses message header and TLVs from wire representation.

func (*Msg) AppendBinary

func (m *Msg) AppendBinary(b []byte) ([]byte, error)

func (*Msg) Clone

func (m *Msg) Clone() (m1 *Msg)

Clone returns deep copy of message.

func (*Msg) Equal

func (m *Msg) Equal(m1 *Msg) bool

Equal returns true of messages have equal header and TLVs.

func (*Msg) Len

func (m *Msg) Len() (n int)

Len returns upper bound of message's wire length.

func (*Msg) MarshalBinary

func (m *Msg) MarshalBinary() ([]byte, error)

func (*Msg) Pack

func (m *Msg) Pack() (msg []byte, err error)

Pack packs message with default builder.

func (*Msg) PackTo

func (m *Msg) PackTo(b *Builder)

PackTo packs message with given builder.

func (*Msg) UnmarshalBinary

func (m *Msg) UnmarshalBinary(data []byte) error

func (*Msg) Verify

func (m *Msg) Verify(request *Msg) (err error)

Verify checks that usage of TLVs satisfy requirements with respect to origin and request, if any.

type MsgHeader

type MsgHeader struct {
	ID       uint16
	Response bool
	Rcode    uint8
}

MsgHeader represents DSO DNS message header fields.

func (MsgHeader) AppendBinary

func (h MsgHeader) AppendBinary(b []byte) ([]byte, error)

AppendBinary implements encoding.BinaryAppender.

func (MsgHeader) IsRequest

func (h MsgHeader) IsRequest() bool

IsRequest returns true if the message is a DSO request.

func (MsgHeader) IsResponse

func (h MsgHeader) IsResponse() bool

IsResponse returns true if the message is a DSO response.

func (MsgHeader) IsUnidirectional

func (h MsgHeader) IsUnidirectional() bool

IsUnidirectional returns true if the message is a DSO unidirectional.

func (MsgHeader) MarshalBinary

func (h MsgHeader) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*MsgHeader) UnmarshalBinary

func (h *MsgHeader) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (MsgHeader) Verify

func (h MsgHeader) Verify() error

Verify checks if header is valid DSO header.

type Origin

type Origin uint16

Origin indicates side message originated from for verification of RFC compliance.

const (
	OriginInvalid Origin = 0

	// OriginServer is origin of messages created on server.
	OriginServer Origin = Origin(UsageFromServer)
	// OriginClient is origin of messages created on client.
	OriginClient Origin = Origin(UsageFromClient)
)

func (Origin) Remote

func (o Origin) Remote() Origin

Remote returns counterparty to current origin.

type PackingError

type PackingError struct {
	Index  int // index of RR that failed to pack; -1 if method packs exactly one RR
	Offset int // offset where packing halted
	// contains filtered or unexported fields
}

PackingError wraps dns.PackRR error (available via PackingError.Unwrap) with offset and index of RR that failed to pack.

func (*PackingError) Error

func (e *PackingError) Error() string

func (*PackingError) Unwrap

func (e *PackingError) Unwrap() error

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser incrementally parses a DSO message.

  1. Parser.Start starts parsing and returns message MsgHeader
  2. Use Parser.TLVHeader to parse TLVHeader and, optionally, Parser.TLVUsage to get Usage context
  3. Use [Parser.XxxTLV] to fully parse the TLV, or Parser.SkipTLV to skip
  4. Continue 2-3 until ErrDone, or other error, is returned.

Parser is safe to copy to preserve the parsing state.

Note that there is no requirement to fully skip or parse the message.

Example
var (
	msg = []byte("\x00\x2a\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x08\x00\x00\x3a\x98\x00\x00\x3a\x98")

	p Parser

	header    MsgHeader
	tlvHeader TLVHeader
	usage     Usage
	tlv       TLV
	err       error
)
header, err = p.Start(msg, OriginClient)
fmt.Printf("%+v\n", header)
for err == nil {
	tlvHeader, err = p.TLVHeader()
	if err != nil {
		break
	}
	fmt.Printf("%+v\n", tlvHeader)

	usage = p.TLVUsage()
	fmt.Printf("Usage:%d\n", usage)
	tlv, err = p.TLV()
	if err != nil {
		break
	}
	fmt.Printf("%v\n", tlv)

	err = tlv.Verify(usage)
	if err != nil {
		break
	}
}
if err != nil && !errors.Is(err, ErrDone) {
	panic(err.Error())
}
Output:
{ID:42 Response:false Rcode:0}
{Type:KeepAlive Length:8}
Usage:32
timeout 15s, interval 15s

func (*Parser) EncryptionPadding

func (p *Parser) EncryptionPadding() (tlv EncryptionPadding, err error)

EncryptionPadding parses a single EncryptionPadding TLV.

func (*Parser) IsPadded

func (p *Parser) IsPadded() bool

IsPadded returns true if message contains EncryptionPadding. The result it cached.

func (*Parser) KeepAlive

func (p *Parser) KeepAlive() (tlv KeepAlive, err error)

KeepAlive parses a single KeepAlive TLV.

func (*Parser) Push

func (p *Parser) Push() (tlv Push, err error)

Push parses a single Push TLV.

If parser was able to partially

func (*Parser) Reconfirm

func (p *Parser) Reconfirm() (tlv Reconfirm, err error)

Reconfirm parses a single Reconfirm TLV.

func (*Parser) RetryDelay

func (p *Parser) RetryDelay() (tlv RetryDelay, err error)

RetryDelay parses a single RetryDelay TLV.

func (*Parser) SetResponseType

func (p *Parser) SetResponseType(t Type)

SetResponseType sets primary response type of message to distinguish response primary from response additional usage contexts.

func (*Parser) SkipTLV

func (p *Parser) SkipTLV() (err error)

SkipTLV skips a single TLV.

func (*Parser) Start

func (p *Parser) Start(msg []byte, origin Origin) (MsgHeader, error)

Start parses MsgHeader and enables the parsing of TLVs.

func (*Parser) Subscribe

func (p *Parser) Subscribe() (tlv Subscribe, err error)

Subscribe parses a single Subscribe TLV.

func (*Parser) TLV

func (p *Parser) TLV() (TLV, error)

func (*Parser) TLVHeader

func (p *Parser) TLVHeader() (h TLVHeader, err error)

TLVHeader parses a single TLVHeader.

func (*Parser) TLVUsage

func (p *Parser) TLVUsage() (u Usage)

TLVUsage returns Usage context of current TLV.

func (*Parser) Unsubscribe

func (p *Parser) Unsubscribe() (tlv Unsubscribe, err error)

Unsubscribe parses a single Unsubscribe TLV.

type Push

type Push struct {
	// Changes (at least one) in RRs the receiver is subscribed to.
	//
	// RR's TTL value may carry special meaning, see RFC 8765, Section 6.3.1 for details.
	Change []dns.RR
}

Push is RFC 8765, Section 6.3 Push TLV.

func (*Push) AppendBinary

func (tlv *Push) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender by writing uncompressed wire representation.

func (*Push) Clone

func (tlv *Push) Clone() TLV

Clone implements TLV.Clone.

func (*Push) Equal

func (tlv *Push) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (*Push) Len

func (tlv *Push) Len() (l int)

Len implements TLV.Len.

func (*Push) MarshalBinary

func (tlv *Push) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler by writing uncompressed wire representation.

func (Push) String

func (tlv Push) String() string

String implements TLV.String.

func (Push) Type

func (tlv Push) Type() Type

Type implements TLV.Type.

func (*Push) UnmarshalBinary

func (tlv *Push) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler for uncompressed wire representation.

func (*Push) Verify

func (tlv *Push) Verify(usage Usage) error

Verify implements TLV.Verify.

type Reconfirm

type Reconfirm struct {
	// RR that the sender belives to be stale.
	//
	// RR's type must not be TypeANY (255), class must not be ClassANY (255), wildcarding
	// is not supported, case insensitivity applies, CNAME matches only a CNAME record.
	// RR's TTL is ignored and Rdlength is re-calculated.
	RR dns.RR
}

Reconfirm is RFC 8765, Section 6.5 Reconfirm TLV.

func (*Reconfirm) AppendBinary

func (tlv *Reconfirm) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender by writing uncompressed wire representation.

func (*Reconfirm) Clone

func (tlv *Reconfirm) Clone() TLV

Clone implements TLV.Clone.

func (*Reconfirm) Equal

func (tlv *Reconfirm) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (*Reconfirm) Len

func (tlv *Reconfirm) Len() int

Len implements TLV.Len.

func (*Reconfirm) MarshalBinary

func (tlv *Reconfirm) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler by writing uncompressed wire representation.

func (Reconfirm) String

func (tlv Reconfirm) String() string

String implements TLV.String.

func (Reconfirm) Type

func (tlv Reconfirm) Type() Type

Type implements TLV.Type.

func (*Reconfirm) UnmarshalBinary

func (tlv *Reconfirm) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler for uncompressed wire representation.

func (*Reconfirm) Verify

func (tlv *Reconfirm) Verify(usage Usage) error

Verify implements TLV.Verify.

type RetryDelay

type RetryDelay struct {
	// A time value within which the initiator MUST NOT retry this operation or retry connecting
	// to this server.
	RetryDelay uint32
}

RetryDelay is RFC 8490, Section 7.2 Retry Delay TLV.

func (*RetryDelay) AppendBinary

func (tlv *RetryDelay) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender.

func (*RetryDelay) Clone

func (tlv *RetryDelay) Clone() TLV

Clone implements TLV.Clone.

func (*RetryDelay) Equal

func (tlv *RetryDelay) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (RetryDelay) Len

func (tlv RetryDelay) Len() int

Len implements TLV.Len.

func (*RetryDelay) MarshalBinary

func (tlv *RetryDelay) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (RetryDelay) String

func (tlv RetryDelay) String() string

String implements TLV.String.

func (RetryDelay) Type

func (tlv RetryDelay) Type() Type

Type implements TLV.Type.

func (*RetryDelay) UnmarshalBinary

func (tlv *RetryDelay) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*RetryDelay) Verify

func (tlv *RetryDelay) Verify(usage Usage) error

Verify implements TLV.Verify.

type Subscribe

type Subscribe struct {
	// Domain name of RR that subscriber wants.
	//
	// DNS wildcarding is not supported, case insensitivity applies, CNAME matches
	// only a CNAME record.
	Name string
	// Type of RR that subscriber wants.
	//
	// TypeANY (255) is interepreted to mean "ALL".
	RRType uint16
	// Class of RR that subscriber wants.
	//
	// ClassANY (255) is interpreted to mean "ALL".
	Class uint16
}

Subscribe is RFC 8765, Section 6.2 Subscribe TLV.

func (*Subscribe) AppendBinary

func (tlv *Subscribe) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender by writing uncompressed wire representation.

func (*Subscribe) Clone

func (tlv *Subscribe) Clone() TLV

Clone implements TLV.Clone.

func (*Subscribe) Equal

func (tlv *Subscribe) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (*Subscribe) Len

func (tlv *Subscribe) Len() int

Len implements TLV.Len.

func (*Subscribe) MarshalBinary

func (tlv *Subscribe) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler by writing uncompressed wire representation.

func (Subscribe) String

func (tlv Subscribe) String() string

String implements TLV.String.

func (Subscribe) Type

func (tlv Subscribe) Type() Type

Type implements TLV.Type.

func (*Subscribe) UnmarshalBinary

func (tlv *Subscribe) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler for uncompressed wire representation.

func (*Subscribe) Verify

func (tlv *Subscribe) Verify(usage Usage) error

Verify implements TLV.Verify.

type TLV

type TLV interface {
	// Type returns numerical TLV type.
	Type() Type
	// Len returns upper boundary of uncompressed length. Actual wire length can be lower.
	Len() int
	// Verify checks that TLV satisfies specification in given usage context.
	Verify(usage Usage) error
	// Equal returns true if TLVs are equal.
	Equal(tlv TLV) bool
	// Clone creates deep-copy of TLV.
	Clone() TLV
	// String converts TLV to readable string.
	String() string

	encoding.BinaryAppender
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	// contains filtered or unexported methods
}

TLV is generic DSO TLV.

type TLVHeader

type TLVHeader struct {
	Type   Type
	Length uint16
}

TLVHeader is header of DSO TLV.

func (TLVHeader) AppendBinary

func (h TLVHeader) AppendBinary(b []byte) ([]byte, error)

AppendBinary implements encoding.BinaryAppender.

func (TLVHeader) MarshalBinary

func (h TLVHeader) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*TLVHeader) UnmarshalBinary

func (h *TLVHeader) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Type

type Type uint16

Type is DSO TLV type.

func (Type) String

func (t Type) String() string

type UnpackingError

type UnpackingError struct {
	Offset int // offset where unpacking halted
	// contains filtered or unexported fields
}

UnpackingError wraps dns.UnpackRR error (available via UnpackingError.Unwrap) with offset where unpacking halted.

func (*UnpackingError) Error

func (e *UnpackingError) Error() string

func (*UnpackingError) Unwrap

func (e *UnpackingError) Unwrap() error

type Unsubscribe

type Unsubscribe struct {
	// ID of the previously sent Subscribe request message.
	SubscribeID uint16
}

Unsubscribe is RFC 8765, Section 6.4 Unsubscribe TLV.

func (*Unsubscribe) AppendBinary

func (tlv *Unsubscribe) AppendBinary(b []byte) (b1 []byte, err error)

AppendBinary implements encoding.BinaryAppender.

func (*Unsubscribe) Clone

func (tlv *Unsubscribe) Clone() TLV

Clone implements TLV.Clone.

func (*Unsubscribe) Equal

func (tlv *Unsubscribe) Equal(tlv1 TLV) bool

Equal implements TLV.Equal.

func (Unsubscribe) Len

func (tlv Unsubscribe) Len() int

Len implements TLV.Len.

func (*Unsubscribe) MarshalBinary

func (tlv *Unsubscribe) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Unsubscribe) String

func (tlv Unsubscribe) String() (s string)

String implements TLV.String.

func (Unsubscribe) Type

func (tlv Unsubscribe) Type() Type

Type implements TLV.Type.

func (*Unsubscribe) UnmarshalBinary

func (tlv *Unsubscribe) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Unsubscribe) Verify

func (tlv *Unsubscribe) Verify(usage Usage) error

Verify implements TLV.Verify.

type Usage

type Usage uint16

Usage RFC 8490, Section 8.2 TLV usage contexts matrix.

const (
	UsageInvalid Usage = 0

	// UsageSP is primary TLV, sent in DSO request message, from server to client.
	UsageSP Usage = usageP
	// UsageSU is primary TLV, sent in DSO unidirectional message, from server to client.
	UsageSU Usage = usageU
	// UsageSA is additional TLV, optionally added to a DSO request message or DSO unidirectional message
	// from server to client.
	UsageSA Usage = usageA
	// UsageCRP is response primary TLV, included in response message sent back to the client
	// where the DSO-TYPE of the Response TLV matches the DSO-TYPE of the Primary TLV in the request.
	UsageCRP Usage = usageRP
	// UsageCRA is response additional TLV, included in response message sent back to the client where
	// the DSO-TYPE of the Response TLV does not match the DSO-TYPE of the Primary TLV in the request.
	UsageCRA Usage = usageRA

	// UsageCP is primary TLV, sent in DSO request message, from client to server.
	UsageCP Usage = usageP << usageClientOff
	// UsageCU is primary TLV, sent in DSO unidirectional message, from client to server.
	UsageCU Usage = usageU << usageClientOff
	// UsageCA is additional TLV, optionally added to a DSO request message or DSO unidirectional message
	// from client to server.
	UsageCA Usage = usageA << usageClientOff
	// UsageSRP is response primary TLV, included in response message sent back to the server where the DSO-TYPE
	// of the Response TLV matches the DSO-TYPE of the Primary TLV in the request.
	UsageSRP Usage = usageRP << usageClientOff
	// UsageSRA is response additional TLV, included in response message sent back to the server where the DSO-TYPE
	// of the Response TLV does not match the DSO-TYPE of the Primary TLV in the request.
	UsageSRA Usage = usageRA << usageClientOff

	// UsagePrimary is mask of primary usage contexts.
	UsagePrimary Usage = UsageCP | UsageCU | UsageCRP | UsageSP | UsageSU | UsageSRP
	// UsageAdditional is mask of additional usage contexts.
	UsageAdditional Usage = UsageCA | UsageCRA | UsageSA | UsageSRA

	// UsageFromServer is mask of usage contexts originated from server.
	UsageFromServer Usage = UsageSP | UsageSU | UsageSA | UsageCRP | UsageCRA
	// UsageFromClient is mask of usage contexts originated from client.
	UsageFromClient Usage = UsageCP | UsageCU | UsageCA | UsageSRP | UsageSRA

	// UsageKeepAlive is mask of allowed usage contexts of [KeepAlive].
	UsageKeepAlive Usage = UsageCP | UsageCRP | UsageSU
	// UsageRetryDelay is mask of allowed usage contexts of [RetryDelay].
	UsageRetryDelay Usage = UsageCRA | UsageSU | UsageSRA
	// UsageEncryptionPadding is mask of allowed usage contexts of [EncryptionPadding].
	UsageEncryptionPadding Usage = UsageCA | UsageCRA | UsageSA | UsageSRA
	// UsageSubscribe is mask of allowed usage contexts of [Subscribe].
	UsageSubscribe Usage = UsageCP
	// UsagePush is mask of allowed usage contexts of [Push].
	UsagePush Usage = UsageSU
	// UsageUnsubscribe is mask of allowed usage contexts of [Unsubscribe].
	UsageUnsubscribe Usage = UsageCU
	// UsageReconfirm is mask of allowed usage contexts of [Reconfirm].
	UsageReconfirm Usage = UsageCU
)

func (Usage) Origin

func (u Usage) Origin() Origin

Origin extracts origin from usage context.

Jump to

Keyboard shortcuts

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