tlv

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tlv implements a parser for TLV encoded babel messages defined in rfc8966

https://datatracker.ietf.org/doc/html/rfc8966#section-4 https://datatracker.ietf.org/doc/html/draft-ietf-babel-source-specific-07#section-7

Index

Constants

View Source
const (
	TypePad1         = Type(0)
	TypePadN         = Type(1)
	TypeAckReq       = Type(2)
	TypeAck          = Type(3)
	TypeHello        = Type(4)
	TypeIHU          = Type(5)
	TypeRouterID     = Type(6)
	TypeNextHop      = Type(7)
	TypeUpdate       = Type(8)
	TypeRouteRequest = Type(9)
	TypeSeqnoRequest = Type(10)
	TypeTSPC         = Type(11)
	TypeHMAC         = Type(12)
)

Type TLV constants

View Source
const (
	SubTypePad1         = SubType(0)
	SubTypePadN         = SubType(1)
	SubTypeDiversity    = SubType(2)
	SubTypeTimestamp    = SubType(3)
	SubTypeSourcePrefix = SubType(128)
)

SubType Sub-TLV constants

View Source
const (
	AEWildcard  = AEType(0)
	AEIPv4      = AEType(1)
	AEIPv6      = AEType(2)
	AEIPv6LL    = AEType(3)
	AEIPv4oIPv6 = AEType(4)
)

AEType AE constants

Variables

View Source
var (
	ErrRouterIDZeros = errors.New("Invalid RouterID: consists of all zeros")
	ErrRouterIDOnes  = errors.New("Invalid RouterID: consists of all ones")
)

Errors specific to RouterID.

Functions

This section is empty.

Types

type AEType

type AEType uint8

AEType encodes the AE field in TLVs

func AEFromIP

func AEFromIP(p netip.Addr) AEType

AEFromIP returns the address encoding of an address.

func AEFromPrefix

func AEFromPrefix(p netip.Prefix) AEType

AEFromPrefix returns the address encoding of a prefix:

func (AEType) String

func (i AEType) String() string

type Ack

type Ack struct {
	Opaque uint16
}

Ack - Acknowledgment TLV

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

func (Ack) L

func (Ack) L() uint8

L is 4.

func (Ack) T

func (Ack) T() Type

T returns TypeAck.

type AckReq

type AckReq struct {
	Opaque   [2]byte
	Interval uint16
}

AckReq - Acknowledgment Request TLV

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

func (AckReq) L

func (a AckReq) L() uint8

L 8.

func (AckReq) T

func (AckReq) T() Type

T returns TypePadReq.

type ErrSubTLVLength

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

ErrSubTLVLength is used to inform about invalid length fields in Sub-TLVs

func (ErrSubTLVLength) Error

func (e ErrSubTLVLength) Error() string

type ErrTLVLength

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

ErrTLVLength is used to inform about invalid length fields in TLVs

func (ErrTLVLength) Error

func (e ErrTLVLength) Error() string

type ErrorIpFromBytesLength added in v0.3.0

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

func (ErrorIpFromBytesLength) Error added in v0.3.0

func (e ErrorIpFromBytesLength) Error() string

type Hello

type Hello struct {
	Flags    uint16
	Seqno    uint16
	Interval uint16
}

Hello TLV

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

func (Hello) L

func (Hello) L() uint8

L is 8.

func (Hello) T

func (Hello) T() Type

T returns TypeHello.

type IHU

type IHU struct {
	// AE uint8
	// reserved uint8
	Rxcost   uint16
	Interval uint16
	Address  netip.Addr
}

IHU - I Heard You TLV

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

func (IHU) AE

func (i IHU) AE() AEType

AE returns the address encofing

func (IHU) L

func (i IHU) L() uint8

L depends on the address enoding, but is at least 6 bytes.

func (IHU) T

func (IHU) T() Type

T returns TypeIHU.

type NextHop

type NextHop struct {
	// AE uint8
	// reserved uint8
	Address netip.Addr
}

NextHop TLV

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

func (NextHop) L

func (n NextHop) L() uint8

L depends on the address encoding, at least 2.

func (NextHop) T

func (NextHop) T() Type

T returns TypeNextHop.

type PacketDecoder

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

PacketDecoder splits a packet into TLVs and parses their content

func (*PacketDecoder) Err

func (s *PacketDecoder) Err() error

Err returns the first error that occured during parsing.

func (*PacketDecoder) Reset

func (s *PacketDecoder) Reset(b []byte, nexthop netip.Addr, ifindex int)

Reset clears the parser state and sets a new byte slice to work on.

func (*PacketDecoder) Scan

func (s *PacketDecoder) Scan() bool

Scan parses the next TLV. Returns true on success or false on error and when no more TLVs can be found.

func (*PacketDecoder) SubTLV

func (s *PacketDecoder) SubTLV() []byte

SubTLV returns the last successfully parsed Sub-TLV

func (*PacketDecoder) TLV

func (s *PacketDecoder) TLV() TLV

TLV returns the last successfully parsed TLV

type Pad1

type Pad1 struct{}

Pad1 TLV

1 byte padding that is silently ignored. https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.1

func (Pad1) L

func (Pad1) L() uint8

L returns 0 message body length.

func (Pad1) T

func (Pad1) T() Type

T returns TypePad1.

type PadN

type PadN uint8

PadN TLV

Multi byte padding that is silently ignored. https://datatracker.ietf.org/doc/html/rfc8966#section-4.6.2

func (PadN) L

func (p PadN) L() uint8

L returns the length of the padding.

func (PadN) T

func (PadN) T() Type

T returns TypePadN.

type Raw

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

Raw holds an unparsed TLV

func (Raw) L

func (t Raw) L() uint8

L returns the value of the length field in a TLV

func (Raw) T

func (t Raw) T() Type

T returns the Type of a Raw TLV

func (Raw) V

func (t Raw) V() []byte

V returns the message body of a TLV

type RouteRequest

type RouteRequest struct {
	// AE     uint8
	// plen   uint8
	Prefix netip.Prefix
}

RouteRequest TLV

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

func (RouteRequest) AE

func (r RouteRequest) AE() AEType

AE returns the address encoding of the requested prefix

func (RouteRequest) L

func (r RouteRequest) L() uint8

L depends on the requested prefix, at least 4.

func (RouteRequest) T

func (RouteRequest) T() Type

T returns TypeRouteRequest.

type RouterID

type RouterID [8]byte

RouterID TLV

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

func (RouterID) L

func (RouterID) L() uint8

L is 8.

func (RouterID) String

func (r RouterID) String() string

String formats a Routerid in EUI-64

func (RouterID) T

func (RouterID) T() Type

T returns TypeRouterID.

type Scanner

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

Scanner splits bytes into TLV tokens.

func (*Scanner) Err

func (ts *Scanner) Err() error

Err returns the first error that occured during scanning.

func (*Scanner) Raw

func (ts *Scanner) Raw() Raw

Raw returns an unparsed TLV

func (*Scanner) Reset

func (ts *Scanner) Reset(buf []byte)

Reset resets a scanner state and sets a new byte slice to work on.

func (*Scanner) Scan

func (ts *Scanner) Scan() bool

Scan scans for the next TLV

Returns true if a TLV is found, or false on error or no more TLVs are found.

type SeqnoRequest

type SeqnoRequest struct {
	// AE    uint8
	// Plen  uint8
	Seqno    uint16
	HopCount uint8
	RouterID RouterID
	Prefix   netip.Prefix
}

SeqnoRequest TLV

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

func (SeqnoRequest) L

func (r SeqnoRequest) L() uint8

L depends on the requested prefix, at least 14.

func (SeqnoRequest) T

func (SeqnoRequest) T() Type

T returns TypeSeqnoRequest.

type SourcePrefix

type SourcePrefix struct {
	netip.Prefix
}

SourcePrefix Sub-TLV

https://datatracker.ietf.org/doc/html/draft-ietf-babel-source-specific-07#section-7.1

func SourcePrefixFromBytes

func SourcePrefixFromBytes(b []byte) (SourcePrefix, []byte, error)

SourcePrefixFromBytes parses a SourcePrefix SubTLV

func (SourcePrefix) L

func (s SourcePrefix) L() uint8

L depends on the encoded prefix

func (SourcePrefix) T

func (SourcePrefix) T() SubType

T returns SubTypeSourcePrefix.

type SubTLV

type SubTLV interface {
	T() SubType
	L() uint8
}

SubTLV holds a single Sub-TLV

type SubType

type SubType uint8

SubType encodes the type of Sub-TLV

func (SubType) IsMandatory

func (s SubType) IsMandatory() bool

IsMandatory checks if a Sub-TLV is mandatory

func (SubType) String

func (i SubType) String() string

type TLV

type TLV interface {
	T() Type
	L() uint8
}

TLV holds a single TLV

type Type

type Type uint8

Type encodes the type of TLV

func (Type) String

func (i Type) String() string

type Update

type Update struct {
	// AE       uint8
	Flags uint8
	// Plen     uint8
	Omitted  uint8
	Interval uint16
	Seqno    uint16
	Metric   uint16
	RouterID RouterID
	Prefix   netip.Prefix
	NextHop  netip.Addr
}

Update TLV

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

func (Update) FormatHeader

func (u Update) FormatHeader() string

FormatHeader returns a string of the most important fields except the prefix

func (Update) L

func (u Update) L() uint8

L depends on the anounced prefix, at least 10.

func (Update) T

func (Update) T() Type

T returns TypeUpdate.

Jump to

Keyboard shortcuts

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