Documentation ¶
Index ¶
- Constants
- Variables
- func IsBabelPacket(buf []byte) bool
- func IsUrgent(v Value) bool
- func SeqnoAbsDistance(a, b SequenceNumber) int16
- func SeqnoDistance(a, b SequenceNumber) int16
- func SeqnoLess(a, b SequenceNumber) bool
- type Acknowledgment
- type AcknowledgmentRequest
- type Address
- type AddressEncoding
- type AddressFamily
- type Hello
- type IHU
- type Interval
- type Metric
- type NextHop
- type Packet
- type Pad1
- type PadN
- type Parser
- func (p *Parser) AppendPacket(b []byte, pkt *Packet) []byte
- func (p *Parser) AppendValue(b []byte, v Value) []byte
- func (p *Parser) AppendValues(b []byte, vs []Value) []byte
- func (p *Parser) FinalizePacket(b []byte)
- func (p *Parser) Packet(b []byte) ([]byte, *Packet, error)
- func (p *Parser) PacketLength(pkt *Packet) uint16
- func (p *Parser) Reset()
- func (p *Parser) StartPacket(b []byte) []byte
- func (p *Parser) ValueLength(v Value) (l int)
- func (p *Parser) Values(b []byte, trailer bool) ([]byte, []Value, error)
- func (p *Parser) ValuesLength(vs []Value) uint16
- type Prefix
- type RouteRequest
- type RouterID
- type RouterIDValue
- type SeqnoRequest
- type SequenceNumber
- type SubValue
- type Timestamp
- type TimestampHello
- type TimestampIHU
- type Update
- type Value
- type ValueType
Constants ¶
const ( PacketHeaderMagic = 42 PacketHeaderVersion = 2 PacketHeaderLength = 4 )
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
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
const (
ValueHeaderLength = 2
)
Variables ¶
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") )
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 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 ¶
4.1.4. Address https://datatracker.ietf.org/doc/html/rfc8966#section-4.1.4
func AddressFrom ¶
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
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
type Interval ¶
4.1.2. Interval https://datatracker.ietf.org/doc/html/rfc8966#section-4.1.2
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
type Packet ¶
4.2. Packet Format https://datatracker.ietf.org/doc/html/rfc8966#section-4.2
type Pad1 ¶
type Pad1 struct{}
4.6.1. Pad1 https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.1
type PadN ¶
type PadN struct {
N int
}
4.6.2. PadN https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.2
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 (*Parser) AppendPacket ¶
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) FinalizePacket ¶
func (*Parser) Packet ¶
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 ¶
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) StartPacket ¶
func (*Parser) ValueLength ¶
ValueLength returns the number of octets of an TLV including the type / length fields.
func (*Parser) ValuesLength ¶
type Prefix ¶
4.1.5. Prefixes https://datatracker.ietf.org/doc/html/rfc8966#section-4.1.5
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 ¶
GenerateRouterID generates a random router ID
func RouterIDFromAddr ¶
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 ¶
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 ¶
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
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 (ValueType) IsMandatory ¶
IsMandatory checks whether the sub-TLV type is mandatory