proto

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PacketHeaderMagic   = 42
	PacketHeaderVersion = 2
	PacketHeaderLength  = 4
)
View Source
const (
	FlagUpdatePrefix   uint8 = 0x80
	FlagUpdateRouterID uint8 = 0x40
)

Flags for Update TLV https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.9 https://www.iana.org/assignments/babel/babel.xhtml#flags

View Source
const (
	FlagHelloUnicast uint16 = 0x8000
)

Flags for Hello TLV https://datatracker.ietf.org/doc/html/rfc8966#name-hello https://www.iana.org/assignments/babel/babel.xhtml#hello

View Source
const (
	ValueHeaderLength = 2
)

Variables

View Source
var (
	ErrInvalidLength                = errors.New("invalid TLV length")
	ErrInvalidHeader                = errors.New("invalid TLV header")
	ErrInvalidMagic                 = errors.New("invalid packet magic")
	ErrUnsupportedVersion           = errors.New("unsupported version")
	ErrCompressionNotAllowed        = errors.New("address encoding does not allow compression")
	ErrInvalidAddress               = errors.New("invalid address")
	ErrMissingDefaultPrefix         = errors.New("received update TLV with non-zero omitted value but no previous default prefix")
	ErrInvalidRouterID              = errors.New("invalid router-id")
	ErrInvalidValueType             = errors.New("invalid value type")
	ErrTooShort                     = errors.New("buffer is too short")
	ErrTooLong                      = errors.New("buffer is too long")
	ErrUnsupportedValue             = errors.New("value is not supported")
	ErrUnsupportedButMandatoryValue = errors.New("value is not supported but mandatory")
	ErrInvalidValueForTrailer       = errors.New("value is not supported in packet trailer")
)
View Source
var (
	RouterIDAllZeros = RouterID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
	RouterIDAllOnes  = RouterID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

	RouterIDUnspecified = RouterIDAllZeros
)

Functions

func IsBabelPacket

func IsBabelPacket(buf []byte) bool

func IsUrgent

func IsUrgent(v Value) bool

func SeqnoAbsDistance

func SeqnoAbsDistance(a, b SequenceNumber) int16

func SeqnoDistance

func SeqnoDistance(a, b SequenceNumber) int16

func SeqnoLess

func SeqnoLess(a, b SequenceNumber) bool

Types

type Acknowledgment

type Acknowledgment struct {
	Opaque uint16 // Set to the Opaque value of the Acknowledgment Request that prompted this Acknowledgment.
}

4.6.4. Acknowledgment https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.4

func (*Acknowledgment) LogValue

func (a *Acknowledgment) LogValue() slog.Value

type AcknowledgmentRequest

type AcknowledgmentRequest struct {
	Opaque   uint16        // An arbitrary value that will be echoed in the receiver's Acknowledgment TLV.
	Interval time.Duration // A time interval after which the sender will assume that this packet has been lost. This MUST NOT be 0. The receiver MUST send an Acknowledgment TLV before this time has elapsed (with a margin allowing for propagation time).
}

4.6.3. Acknowledgment Request https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.3

func (*AcknowledgmentRequest) LogValue

func (a *AcknowledgmentRequest) LogValue() slog.Value

type Address

type Address = netip.Addr

4.1.4. Address https://datatracker.ietf.org/doc/html/rfc8966#section-4.1.4

func AddressFrom

func AddressFrom(addr net.Addr) Address

type AddressEncoding

type AddressEncoding = uint8
const (
	AddressEncodingWildcard      AddressEncoding = 0 // RFC 8966: The value is 0 octets long.
	AddressEncodingIPv4          AddressEncoding = 1 // RFC 8966: Compression is allowed. 4 octets or less.
	AddressEncodingIPv6          AddressEncoding = 2 // RFC 8966: Compression is allowed. 16 octets or less.
	AddressEncodingIPv6LinkLocal AddressEncoding = 3 // RFC 8966: Compression is not allowed. The value is 8 octets long, a prefix of fe80::/64 is implied.
	AddressEncodingIPv4inIPv6    AddressEncoding = 4 // RFC 9229: IPv4 Routes with an IPv6 Next Hop
)

Babel Address Encodings https://www.iana.org/assignments/babel/babel.xhtml#ae

type AddressFamily

type AddressFamily = int
const (
	AddressFamilyUnspecified AddressFamily = iota
	AddressFamilyIPv4
	AddressFamilyIPv6
)

type Hello

type Hello struct {
	Flags    uint16         // The individual bits of this field specify special handling of this TLV (see FlagHello*).
	Seqno    SequenceNumber // If the Unicast flag is set, this is the value of the sending node's outgoing Unicast Hello seqno for this neighbour. Otherwise, it is the sending node's outgoing Multicast Hello seqno for this interface.
	Interval time.Duration  // If nonzero, this is an upper bound, on the time after which the sending node will send a new scheduled Hello TLV with the same setting of the Unicast flag. If this is 0, then this Hello represents an unscheduled Hello and doesn't carry any new information about times at which Hellos are sent.

	// Sub-TLVs
	Timestamp *TimestampHello
}

4.6.5. Hello https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.5

func (*Hello) LogValue

func (h *Hello) LogValue() slog.Value

type IHU

type IHU struct {
	RxCost   uint16        // The rxcost according to the sending node of the interface whose address is specified in the Address field. The value FFFF hexadecimal (infinity) indicates that this interface is unreachable.
	Interval time.Duration // An upper bound, on the time after which the sending node will send a new IHU; this MUST NOT be 0. The receiving node will use this value in order to compute a hold time for this symmetric association.
	Address  netip.Addr    // The address of the destination node, in the format specified by the AE field. Address compression is not allowed.

	// Sub-TLVs
	Timestamp *TimestampIHU
}

4.6.6. IHU https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.6

func (*IHU) LogValue

func (i *IHU) LogValue() slog.Value

type Metric

type Metric = uint16
const (
	Retraction Metric = 0xffff
)

type NextHop

type NextHop struct {
	NextHop netip.Addr // The next-hop address advertised by subsequent Update TLVs for this address family.
}

4.6.8. Next Hop https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.8

func (*NextHop) LogValue

func (n *NextHop) LogValue() slog.Value

type Packet

type Packet struct {
	Body    []Value
	Trailer []Value
}

4.2. Packet Format https://datatracker.ietf.org/doc/html/rfc8966#section-4.2

func (*Packet) LogValue

func (p *Packet) LogValue() slog.Value

type PadN

type PadN struct {
	N int
}

4.6.2. PadN https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.2

func (*PadN) LogValue

func (p *PadN) LogValue() slog.Value

type Parser

type Parser struct {
	CurrentDefaultPrefix map[AddressEncoding]Address
	CurrentNextHop       map[AddressFamily]Address
	CurrentRouterID      RouterID
}

Parser implements the protocol en/decoding of Babel packets It keeps internal state which is required for compressing prefixes and other details for Update TLVs.

See also: 4.5. Parser State and Encoding of Updates https://datatracker.ietf.org/doc/html/rfc8966#section-4.5

func NewParser

func NewParser() *Parser

func (*Parser) AppendPacket

func (p *Parser) AppendPacket(b []byte, pkt *Packet) []byte

AppendPacket encodes a packet by appending it to the provided buffer. Ideally the buffer should be pre-allocated with a capacity determined by PacketLength()

func (*Parser) AppendValue

func (p *Parser) AppendValue(b []byte, v Value) []byte

func (*Parser) AppendValues

func (p *Parser) AppendValues(b []byte, vs []Value) []byte

func (*Parser) FinalizePacket

func (p *Parser) FinalizePacket(b []byte)

func (*Parser) Packet

func (p *Parser) Packet(b []byte) ([]byte, *Packet, error)

Packet attempts to decode a packet from the provided buffer. It returns a advanced buffer slice starting at the end of the parsed packet.

func (*Parser) PacketLength

func (p *Parser) PacketLength(pkt *Packet) uint16

PacketLength calculates the length of the required buffer to encode the packet without actually encoding it. This should be used for pre-allocate an appropriately sized buffer.

func (*Parser) Reset

func (p *Parser) Reset()

Reset resets the internal parser state

func (*Parser) StartPacket

func (p *Parser) StartPacket(b []byte) []byte

func (*Parser) ValueLength

func (p *Parser) ValueLength(v Value) (l int)

ValueLength returns the number of octets of an TLV including the type / length fields.

func (*Parser) Values

func (p *Parser) Values(b []byte, trailer bool) ([]byte, []Value, error)

func (*Parser) ValuesLength

func (p *Parser) ValuesLength(vs []Value) uint16

type RouteRequest

type RouteRequest struct {
	Prefix netip.Prefix // The prefix being requested. This field's size is Plen/8 rounded upwards.

	// Sub-TLVs
	SourcePrefix *Prefix
}

4.6.10. Route Request https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.10

func (*RouteRequest) LogValue

func (r *RouteRequest) LogValue() slog.Value

type RouterID

type RouterID = [8]byte

4.1.3. Router-Id https://datatracker.ietf.org/doc/html/rfc8966#section-4.1.3

func GenerateRouterID

func GenerateRouterID() (RouterID, error)

GenerateRouterID generates a random router ID

func RouterIDFromAddr

func RouterIDFromAddr(addr netip.Addr) RouterID

type RouterIDValue

type RouterIDValue struct {
	RouterID RouterID // The router-id for routes advertised in subsequent Update TLVs. This MUST NOT consist of all zeroes or all ones.
}

4.6.7. Router-Id https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.7

func (*RouterIDValue) LogValue

func (r *RouterIDValue) LogValue() slog.Value

type SeqnoRequest

type SeqnoRequest struct {
	Seqno    SequenceNumber // The sequence number that is being requested.
	HopCount uint8          // The maximum number of times that this TLV may be forwarded, plus 1. This MUST NOT be 0.
	RouterID RouterID       // The Router-Id that is being requested. This MUST NOT consist of all zeroes or all ones.
	Prefix   netip.Prefix   // The prefix being requested. This field's size is Plen/8 rounded upwards.

	// Sub-TLVs
	SourcePrefix *Prefix
}

4.6.11. Seqno Request https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.11

func (*SeqnoRequest) LogValue

func (s *SeqnoRequest) LogValue() slog.Value

type SequenceNumber

type SequenceNumber = uint16

type SubValue

type SubValue any

SubValue represents a sub-TLV See also: 4.4. Sub-TLV Format https://datatracker.ietf.org/doc/html/rfc8966#section-4.4

type Timestamp

type Timestamp = uint32 // in microseconds

Timestamp for Babel RTT extension https://datatracker.ietf.org/doc/html/draft-ietf-babel-rtt-extension-00#section-3

type TimestampHello

type TimestampHello struct {
	Transmit Timestamp
}

3.1. Timestamp sub-TLV in Hello TLVs https://datatracker.ietf.org/doc/html/draft-ietf-babel-rtt-extension-00#section-3.1

func (*TimestampHello) LogValue

func (t *TimestampHello) LogValue() slog.Value

type TimestampIHU

type TimestampIHU struct {
	Origin  Timestamp
	Receive Timestamp
}

3.2. Timestamp sub-TLV in IHU TLVs https://datatracker.ietf.org/doc/html/draft-ietf-babel-rtt-extension-00#section-3.2

func (*TimestampIHU) LogValue

func (t *TimestampIHU) LogValue() slog.Value

type Update

type Update struct {
	Flags    uint8          // The individual bits of this field specify special handling of this TLV (see FlagUpdate*).
	Interval Interval       // An upper bound, expressed in centiseconds, on the time after which the sending node will send a new update for this prefix. This MUST NOT be 0. The receiving node will use this value to compute a hold time for the route table entry. The value FFFF hexadecimal (infinity) expresses that this announcement will not be repeated unless a request is received (Section 3.8.2.3).
	Seqno    SequenceNumber // The originator's sequence number for this update.
	Metric   Metric         // The sender's metric for this route. The value FFFF hexadecimal (infinity) means that this is a route retraction.
	Prefix   netip.Prefix   // The prefix being advertised. This field's size is (Plen/8 - Omitted) rounded upwards.

	// The following fields are not actually encoded in an update TLV.
	// Instead are derived from the parser state / preceding TLVs.
	RouterID RouterID // Taken from a previous RouterID TLV
	NextHop  Address  // Taken from a previous NextHop TLV

	// Sub-TLVs
	SourcePrefix *Prefix
}

4.6.9. Update https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.9

func (*Update) Less

func (a *Update) Less(b *Update) bool

Less compares two update values and returns true if the passed update is larger. The comparison is implemented in a way such it reduces the size of the route update packets when compressed as defined in: https://www.rfc-editor.org/rfc/rfc8966.html#section-4.6.9

func (*Update) LogValue

func (u *Update) LogValue() slog.Value

type Value

type Value any

Value represents a Type-Length-Value (TLV) See also: 4.3. TLV Format https://datatracker.ietf.org/doc/html/rfc8966#section-4.3

type ValueType

type ValueType uint8
const (
	TypePad1                  ValueType = iota // RFC 8966
	TypePadN                                   // RFC 8966
	TypeAcknowledgmentRequest                  // RFC 8966
	TypeAcknowledgment                         // RFC 8966
	TypeHello                                  // RFC 8966
	TypeIHU                                    // RFC 8966
	TypeRouterID                               // RFC 8966
	TypeNextHop                                // RFC 8966
	TypeUpdate                                 // RFC 8966
	TypeRouteRequest                           // RFC 8966
	TypeSeqnoRequest                           // RFC 8966
	TypeTSPC                                   // RFC 7298
	TypeHMAC                                   // RFC 7298

	TypeMAC              // RFC 8967
	TypePC               // RFC 8967
	TypeChallengeRequest // RFC 8967
	TypeChallengeReply   // RFC 8967

	// TypeInvalid is specified by any RFC and just used internal to
	// represent an invalid type
	TypeInvalid ValueType = math.MaxUint8
)

Babel TLV Types https://www.iana.org/assignments/babel/babel.xhtml#tlv-types

const (
	SubTypePad1      ValueType = iota // RFC 8966
	SubTypePadN                       // RFC 8966
	SubTypeDiversity                  // draft-chroboczek-babel-diversity-routing
	SubTypeTimestamp                  // draft-jonglez-babel-rtt-extension

	SubTypeSourcePrefix ValueType = 128 //	RFC 9079
)

Babel Sub-TLV Types https://www.iana.org/assignments/babel/babel.xhtml#sub-tlv-types

func ValuesType

func ValuesType(v Value) ValueType

func (ValueType) IsMandatory

func (t ValueType) IsMandatory() bool

IsMandatory checks whether the sub-TLV type is mandatory

func (ValueType) IsSubType

func (t ValueType) IsSubType() bool

func (ValueType) IsTrailerType

func (t ValueType) IsTrailerType() bool

func (ValueType) String

func (t ValueType) String() string

Jump to

Keyboard shortcuts

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