rtrlib

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PROTOCOL_VERSION_0 = 0
	PROTOCOL_VERSION_1 = 1
	PROTOCOL_VERSION_2 = 2

	PDU_ID_SERIAL_NOTIFY  = 0
	PDU_ID_SERIAL_QUERY   = 1
	PDU_ID_RESET_QUERY    = 2
	PDU_ID_CACHE_RESPONSE = 3
	PDU_ID_IPV4_PREFIX    = 4
	PDU_ID_IPV6_PREFIX    = 6
	PDU_ID_END_OF_DATA    = 7
	PDU_ID_CACHE_RESET    = 8
	PDU_ID_ROUTER_KEY     = 9
	PDU_ID_ERROR_REPORT   = 10
	PDU_ID_ASPA           = 11

	FLAG_ADDED   = 1
	FLAG_REMOVED = 0

	PDU_ERROR_CORRUPTDATA     = 0
	PDU_ERROR_INTERNALERR     = 1
	PDU_ERROR_NODATA          = 2
	PDU_ERROR_INVALIDREQUEST  = 3
	PDU_ERROR_BADPROTOVERSION = 4
	PDU_ERROR_BADPDUTYPE      = 5
	PDU_ERROR_WITHDRAWUNKNOWN = 6
	PDU_ERROR_DUPANNOUNCE     = 7

	AFI_IPv4 = uint8(0)
	AFI_IPv6 = uint8(1)

	TYPE_UNKNOWN = iota
	TYPE_PLAIN
	TYPE_TLS
	TYPE_SSH
)

Variables

View Source
var DisableASPA = flag.Bool("disable.aspa", false, "Disable sending out ASPA objects")
View Source
var DisableBGPSec = flag.Bool("disable.bgpsec", false, "Disable sending out BGPSEC Router Keys")

Functions

func ConvertSDListToMap added in v0.5.0

func ConvertSDListToMap(SDs []SendableData) map[string]SendableData

func GenerateSessionId

func GenerateSessionId() uint16

func IsCorrectPDUVersion

func IsCorrectPDUVersion(pdu PDU, version uint8) bool

func TypeToString

func TypeToString(t uint8) string

Types

type BgpsecKey added in v0.5.0

type BgpsecKey struct {
	ASN    uint32
	Pubkey []byte
	Ski    []byte
	Flags  uint8
}

func (*BgpsecKey) Copy added in v0.5.0

func (brk *BgpsecKey) Copy() SendableData

func (*BgpsecKey) Equals added in v0.5.0

func (r1 *BgpsecKey) Equals(r2 SendableData) bool

func (*BgpsecKey) GetFlag added in v0.5.0

func (brk *BgpsecKey) GetFlag() uint8

func (*BgpsecKey) HashKey added in v0.5.0

func (brk *BgpsecKey) HashKey() string

func (*BgpsecKey) SetFlag added in v0.5.0

func (brk *BgpsecKey) SetFlag(f uint8)

func (*BgpsecKey) String added in v0.5.0

func (brk *BgpsecKey) String() string

func (*BgpsecKey) Type added in v0.5.0

func (brk *BgpsecKey) Type() string

type Client

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

func ClientFromConn

func ClientFromConn(tcpconn net.Conn, handler RTRServerEventHandler, simpleHandler RTREventHandler) *Client

func ClientFromConnSSH

func ClientFromConnSSH(tcpconn net.Conn, channel ssh.Channel, handler RTRServerEventHandler, simpleHandler RTREventHandler) *Client

func (*Client) DisableASPA added in v0.5.0

func (c *Client) DisableASPA()

func (*Client) DisableBGPsec added in v0.5.0

func (c *Client) DisableBGPsec()

func (*Client) Disconnect

func (c *Client) Disconnect()

func (*Client) GetLocalAddress

func (c *Client) GetLocalAddress() net.Addr

func (*Client) GetRemoteAddress

func (c *Client) GetRemoteAddress() net.Addr

func (*Client) GetVersion

func (c *Client) GetVersion() uint8

func (*Client) Notify

func (c *Client) Notify(sessionId uint16, serialNumber uint32)

func (*Client) SendCacheReset

func (c *Client) SendCacheReset()

func (*Client) SendCorruptData added in v0.5.0

func (c *Client) SendCorruptData()

func (*Client) SendData added in v0.5.0

func (c *Client) SendData(sd SendableData)

Converts a SendableData to a PDU and sends it to the client

func (*Client) SendInternalError

func (c *Client) SendInternalError()

func (*Client) SendNoDataError

func (c *Client) SendNoDataError()

func (*Client) SendPDU

func (c *Client) SendPDU(pdu PDU)

func (*Client) SendRawPDU

func (c *Client) SendRawPDU(pdu PDU)

func (*Client) SendSDs added in v0.5.0

func (c *Client) SendSDs(sessionId uint16, serialNumber uint32, data []SendableData)

func (*Client) SendWrongVersionError

func (c *Client) SendWrongVersionError()

func (*Client) SetDisableVersionCheck

func (c *Client) SetDisableVersionCheck(disableCheck bool)

func (*Client) SetIntervals

func (c *Client) SetIntervals(refreshInterval uint32, retryInterval uint32, expireInterval uint32)

func (*Client) SetVersion

func (c *Client) SetVersion(newversion uint8)

func (*Client) Start

func (c *Client) Start()

func (*Client) String

func (c *Client) String() string

type ClientCallback

type ClientCallback func(net.Conn) error

type ClientConfiguration

type ClientConfiguration struct {
	ProtocolVersion uint8

	RefreshInterval uint32
	RetryInterval   uint32
	ExpireInterval  uint32

	Log Logger
}

type ClientSession

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

func NewClientSession

func NewClientSession(configuration ClientConfiguration, handler RTRClientSessionEventHandler) *ClientSession

func (*ClientSession) Disconnect

func (c *ClientSession) Disconnect()

func (*ClientSession) SendPDU

func (c *ClientSession) SendPDU(pdu PDU)

func (*ClientSession) SendRawPDU

func (c *ClientSession) SendRawPDU(pdu PDU)

func (*ClientSession) SendResetQuery

func (c *ClientSession) SendResetQuery()

func (*ClientSession) SendSerialQuery

func (c *ClientSession) SendSerialQuery(sessionid uint16, serial uint32)

func (*ClientSession) Start

func (c *ClientSession) Start(addr string, connType int, configTLS *tls.Config, configSSH *ssh.ClientConfig) error

func (*ClientSession) StartPlain

func (c *ClientSession) StartPlain(addr string) error

func (*ClientSession) StartRW

func (c *ClientSession) StartRW(rd io.Reader, wr io.Writer) error

func (*ClientSession) StartSSH

func (c *ClientSession) StartSSH(addr string, config *ssh.ClientConfig) error

func (*ClientSession) StartTLS

func (c *ClientSession) StartTLS(addr string, config *tls.Config) error

func (*ClientSession) StartWithConn

func (c *ClientSession) StartWithConn(tcpconn net.Conn) error

func (*ClientSession) StartWithSSH

func (c *ClientSession) StartWithSSH(tcpconn *net.TCPConn, session *ssh.Session) error

type DefaultRTREventHandler

type DefaultRTREventHandler struct {
	Log Logger
	// contains filtered or unexported fields
}

func (*DefaultRTREventHandler) RequestCache

func (e *DefaultRTREventHandler) RequestCache(c *Client)

func (*DefaultRTREventHandler) RequestNewVersion

func (e *DefaultRTREventHandler) RequestNewVersion(c *Client, sessionId uint16, serialNumber uint32)

func (*DefaultRTREventHandler) SetSDManager added in v0.5.0

func (e *DefaultRTREventHandler) SetSDManager(m SendableDataManager)

type Logger

type Logger interface {
	Debugf(string, ...interface{})
	Printf(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	Infof(string, ...interface{})
}

type PDU

type PDU interface {
	Bytes() []byte
	Write(io.Writer)
	String() string
	SetVersion(uint8)
	GetVersion() uint8
	GetType() uint8
}

func Decode

func Decode(rdr io.Reader) (PDU, error)

func DecodeBytes

func DecodeBytes(b []byte) (PDU, error)

type PDUASPA added in v0.5.0

type PDUASPA struct {
	Version           uint8
	Flags             uint8
	AFIFlags          uint8
	ProviderASCount   uint16
	CustomerASNumber  uint32
	ProviderASNumbers []uint32
}

func (*PDUASPA) Bytes added in v0.5.0

func (pdu *PDUASPA) Bytes() []byte

func (*PDUASPA) GetType added in v0.5.0

func (pdu *PDUASPA) GetType() uint8

func (*PDUASPA) GetVersion added in v0.5.0

func (pdu *PDUASPA) GetVersion() uint8

func (*PDUASPA) SetVersion added in v0.5.0

func (pdu *PDUASPA) SetVersion(version uint8)

func (*PDUASPA) String added in v0.5.0

func (pdu *PDUASPA) String() string

func (*PDUASPA) Write added in v0.5.0

func (pdu *PDUASPA) Write(wr io.Writer)

type PDUCacheReset

type PDUCacheReset struct {
	Version uint8
}

func (*PDUCacheReset) Bytes

func (pdu *PDUCacheReset) Bytes() []byte

func (*PDUCacheReset) GetType

func (pdu *PDUCacheReset) GetType() uint8

func (*PDUCacheReset) GetVersion

func (pdu *PDUCacheReset) GetVersion() uint8

func (*PDUCacheReset) SetVersion

func (pdu *PDUCacheReset) SetVersion(version uint8)

func (*PDUCacheReset) String

func (pdu *PDUCacheReset) String() string

func (*PDUCacheReset) Write

func (pdu *PDUCacheReset) Write(wr io.Writer)

type PDUCacheResponse

type PDUCacheResponse struct {
	Version   uint8
	SessionId uint16
}

func (*PDUCacheResponse) Bytes

func (pdu *PDUCacheResponse) Bytes() []byte

func (*PDUCacheResponse) GetType

func (pdu *PDUCacheResponse) GetType() uint8

func (*PDUCacheResponse) GetVersion

func (pdu *PDUCacheResponse) GetVersion() uint8

func (*PDUCacheResponse) SetVersion

func (pdu *PDUCacheResponse) SetVersion(version uint8)

func (*PDUCacheResponse) String

func (pdu *PDUCacheResponse) String() string

func (*PDUCacheResponse) Write

func (pdu *PDUCacheResponse) Write(wr io.Writer)

type PDUEndOfData

type PDUEndOfData struct {
	Version      uint8
	SessionId    uint16
	SerialNumber uint32

	RefreshInterval uint32
	RetryInterval   uint32
	ExpireInterval  uint32
}

func (*PDUEndOfData) Bytes

func (pdu *PDUEndOfData) Bytes() []byte

func (*PDUEndOfData) GetType

func (pdu *PDUEndOfData) GetType() uint8

func (*PDUEndOfData) GetVersion

func (pdu *PDUEndOfData) GetVersion() uint8

func (*PDUEndOfData) SetVersion

func (pdu *PDUEndOfData) SetVersion(version uint8)

func (*PDUEndOfData) String

func (pdu *PDUEndOfData) String() string

func (*PDUEndOfData) Write

func (pdu *PDUEndOfData) Write(wr io.Writer)

type PDUErrorReport

type PDUErrorReport struct {
	Version   uint8
	ErrorCode uint16
	PDUCopy   []byte
	ErrorMsg  string
}

func (*PDUErrorReport) Bytes

func (pdu *PDUErrorReport) Bytes() []byte

func (*PDUErrorReport) GetType

func (pdu *PDUErrorReport) GetType() uint8

func (*PDUErrorReport) GetVersion

func (pdu *PDUErrorReport) GetVersion() uint8

func (*PDUErrorReport) SetVersion

func (pdu *PDUErrorReport) SetVersion(version uint8)

func (*PDUErrorReport) String

func (pdu *PDUErrorReport) String() string

func (*PDUErrorReport) Write

func (pdu *PDUErrorReport) Write(wr io.Writer)

type PDUIPv4Prefix

type PDUIPv4Prefix struct {
	Version uint8
	Prefix  net.IPNet
	MaxLen  uint8
	ASN     uint32
	Flags   uint8
}

func (*PDUIPv4Prefix) Bytes

func (pdu *PDUIPv4Prefix) Bytes() []byte

func (*PDUIPv4Prefix) GetType

func (pdu *PDUIPv4Prefix) GetType() uint8

func (*PDUIPv4Prefix) GetVersion

func (pdu *PDUIPv4Prefix) GetVersion() uint8

func (*PDUIPv4Prefix) SetVersion

func (pdu *PDUIPv4Prefix) SetVersion(version uint8)

func (*PDUIPv4Prefix) String

func (pdu *PDUIPv4Prefix) String() string

func (*PDUIPv4Prefix) Write

func (pdu *PDUIPv4Prefix) Write(wr io.Writer)

type PDUIPv6Prefix

type PDUIPv6Prefix struct {
	Version uint8
	Prefix  net.IPNet
	MaxLen  uint8
	ASN     uint32
	Flags   uint8
}

func (*PDUIPv6Prefix) Bytes

func (pdu *PDUIPv6Prefix) Bytes() []byte

func (*PDUIPv6Prefix) GetType

func (pdu *PDUIPv6Prefix) GetType() uint8

func (*PDUIPv6Prefix) GetVersion

func (pdu *PDUIPv6Prefix) GetVersion() uint8

func (*PDUIPv6Prefix) SetVersion

func (pdu *PDUIPv6Prefix) SetVersion(version uint8)

func (*PDUIPv6Prefix) String

func (pdu *PDUIPv6Prefix) String() string

func (*PDUIPv6Prefix) Write

func (pdu *PDUIPv6Prefix) Write(wr io.Writer)

type PDUResetQuery

type PDUResetQuery struct {
	Version uint8
}

func (*PDUResetQuery) Bytes

func (pdu *PDUResetQuery) Bytes() []byte

func (*PDUResetQuery) GetType

func (pdu *PDUResetQuery) GetType() uint8

func (*PDUResetQuery) GetVersion

func (pdu *PDUResetQuery) GetVersion() uint8

func (*PDUResetQuery) SetVersion

func (pdu *PDUResetQuery) SetVersion(version uint8)

func (*PDUResetQuery) String

func (pdu *PDUResetQuery) String() string

func (*PDUResetQuery) Write

func (pdu *PDUResetQuery) Write(wr io.Writer)

type PDURouterKey

type PDURouterKey struct {
	Version              uint8
	Flags                uint8
	SubjectKeyIdentifier []byte
	ASN                  uint32
	SubjectPublicKeyInfo []byte
}

func (*PDURouterKey) Bytes

func (pdu *PDURouterKey) Bytes() []byte

func (*PDURouterKey) GetType

func (pdu *PDURouterKey) GetType() uint8

func (*PDURouterKey) GetVersion

func (pdu *PDURouterKey) GetVersion() uint8

func (*PDURouterKey) SetVersion

func (pdu *PDURouterKey) SetVersion(version uint8)

func (*PDURouterKey) String

func (pdu *PDURouterKey) String() string

func (*PDURouterKey) Write

func (pdu *PDURouterKey) Write(wr io.Writer)

type PDUSerialNotify

type PDUSerialNotify struct {
	Version      uint8
	SessionId    uint16
	SerialNumber uint32
}

func (*PDUSerialNotify) Bytes

func (pdu *PDUSerialNotify) Bytes() []byte

func (*PDUSerialNotify) GetType

func (pdu *PDUSerialNotify) GetType() uint8

func (*PDUSerialNotify) GetVersion

func (pdu *PDUSerialNotify) GetVersion() uint8

func (*PDUSerialNotify) SetVersion

func (pdu *PDUSerialNotify) SetVersion(version uint8)

func (*PDUSerialNotify) String

func (pdu *PDUSerialNotify) String() string

func (*PDUSerialNotify) Write

func (pdu *PDUSerialNotify) Write(wr io.Writer)

type PDUSerialQuery

type PDUSerialQuery struct {
	Version      uint8
	SessionId    uint16
	SerialNumber uint32
}

func (*PDUSerialQuery) Bytes

func (pdu *PDUSerialQuery) Bytes() []byte

func (*PDUSerialQuery) GetType

func (pdu *PDUSerialQuery) GetType() uint8

func (*PDUSerialQuery) GetVersion

func (pdu *PDUSerialQuery) GetVersion() uint8

func (*PDUSerialQuery) SetVersion

func (pdu *PDUSerialQuery) SetVersion(version uint8)

func (*PDUSerialQuery) String

func (pdu *PDUSerialQuery) String() string

func (*PDUSerialQuery) Write

func (pdu *PDUSerialQuery) Write(wr io.Writer)

type RTRClientSessionEventHandler

type RTRClientSessionEventHandler interface {
	//RequestCache(*ClientSession)
	HandlePDU(*ClientSession, PDU)
	ClientConnected(*ClientSession)
	ClientDisconnected(*ClientSession)
}

type RTREventHandler

type RTREventHandler interface {
	RequestCache(*Client)
	RequestNewVersion(*Client, uint16, uint32)
}

type RTRServerEventHandler

type RTRServerEventHandler interface {
	ClientConnected(*Client)
	ClientDisconnected(*Client)
	HandlePDU(*Client, PDU)
}

type SendableData added in v0.5.0

type SendableData interface {
	Copy() SendableData
	Equals(SendableData) bool
	HashKey() string
	String() string
	Type() string
	SetFlag(uint8)
	GetFlag() uint8
}

This is a general interface for things like a VRP, BGPsec Router key or ASPA object Be sure to have all of these as pointers, or SetFlag() cannot work!

func ApplyDiff

func ApplyDiff(diff, prevSDs []SendableData) []SendableData

func ComputeDiff

func ComputeDiff(newSDs, prevSDs []SendableData) (added, removed, unchanged []SendableData)

type SendableDataManager added in v0.5.0

type SendableDataManager interface {
	GetCurrentSerial(uint16) (uint32, bool)
	GetSessionId() uint16
	GetCurrentSDs() ([]SendableData, bool)
	GetSDsSerialDiff(uint32) ([]SendableData, bool)
}

This handles things like ROAs, BGPsec Router keys, ASPA info etc

type Server

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

func NewServer

func NewServer(configuration ServerConfiguration, handler RTRServerEventHandler, simpleHandler RTREventHandler) *Server

func (*Server) AddData added in v0.5.0

func (s *Server) AddData(vrps []SendableData)

func (*Server) AddSDsDiff added in v0.5.0

func (s *Server) AddSDsDiff(diff []SendableData)

func (*Server) ClientConnected

func (s *Server) ClientConnected(c *Client)

func (*Server) ClientDisconnected

func (s *Server) ClientDisconnected(c *Client)

func (*Server) CountVRPs added in v0.4.0

func (s *Server) CountVRPs() int

func (*Server) GenerateSerial

func (s *Server) GenerateSerial() uint32

func (*Server) GetClientList

func (s *Server) GetClientList() []*Client

func (*Server) GetCurrentSDs added in v0.5.0

func (s *Server) GetCurrentSDs() ([]SendableData, bool)

func (*Server) GetCurrentSerial

func (s *Server) GetCurrentSerial(sessId uint16) (uint32, bool)

func (*Server) GetMaxConnections

func (s *Server) GetMaxConnections() int

func (*Server) GetSDsSerialDiff added in v0.5.0

func (s *Server) GetSDsSerialDiff(serial uint32) ([]SendableData, bool)

func (*Server) GetSessionId

func (s *Server) GetSessionId() uint16

func (*Server) HandlePDU

func (s *Server) HandlePDU(c *Client, pdu PDU)

func (*Server) NotifyClients

func (s *Server) NotifyClients(serialNumber uint32)

func (*Server) NotifyClientsLatest

func (s *Server) NotifyClientsLatest()

func (*Server) RequestCache

func (s *Server) RequestCache(c *Client)

func (*Server) RequestNewVersion

func (s *Server) RequestNewVersion(c *Client, sessionId uint16, serial uint32)

func (*Server) SendPDU

func (s *Server) SendPDU(pdu PDU)

func (*Server) SetBaseVersion

func (s *Server) SetBaseVersion(version uint8)

func (*Server) SetManualSerial

func (s *Server) SetManualSerial(v bool)

func (*Server) SetMaxConnections

func (s *Server) SetMaxConnections(maxconn int)

func (*Server) SetSerial

func (s *Server) SetSerial(serial uint32)

This function sets the serial. Function must be called before the VRPs data is added.

func (*Server) SetSessionId

func (s *Server) SetSessionId(sessId uint16)

func (*Server) SetVersionEnforced

func (s *Server) SetVersionEnforced(adapt bool)

func (*Server) Start

func (s *Server) Start(bind string) error

func (*Server) StartSSH

func (s *Server) StartSSH(bind string, config *ssh.ServerConfig) error

func (*Server) StartTLS

func (s *Server) StartTLS(bind string, config *tls.Config) error

type ServerConfiguration

type ServerConfiguration struct {
	MaxConn         int
	ProtocolVersion uint8
	EnforceVersion  bool
	KeepDifference  int

	SessId int

	RefreshInterval uint32
	RetryInterval   uint32
	ExpireInterval  uint32

	Log        Logger
	LogVerbose bool
}

type VAP added in v0.5.0

type VAP struct {
	Flags       uint8
	AFI         uint8
	CustomerASN uint32
	Providers   []uint32
}

func (*VAP) Copy added in v0.5.0

func (vap *VAP) Copy() SendableData

func (*VAP) Equals added in v0.5.0

func (r1 *VAP) Equals(r2 SendableData) bool

func (*VAP) GetFlag added in v0.5.0

func (vap *VAP) GetFlag() uint8

func (*VAP) HashKey added in v0.5.0

func (vap *VAP) HashKey() string

func (*VAP) SetFlag added in v0.5.0

func (vap *VAP) SetFlag(f uint8)

func (*VAP) String added in v0.5.0

func (vap *VAP) String() string

func (*VAP) Type added in v0.5.0

func (vap *VAP) Type() string

type VRP

type VRP struct {
	Prefix net.IPNet
	MaxLen uint8
	ASN    uint32
	Flags  uint8
}

func (*VRP) Copy

func (r1 *VRP) Copy() SendableData

func (*VRP) Equals

func (r1 *VRP) Equals(r2 SendableData) bool

func (*VRP) GetFlag added in v0.5.0

func (r1 *VRP) GetFlag() uint8

func (*VRP) HashKey

func (vrp *VRP) HashKey() string

func (*VRP) SetFlag added in v0.5.0

func (r1 *VRP) SetFlag(f uint8)

func (*VRP) String

func (r *VRP) String() string

func (*VRP) Type added in v0.5.0

func (r *VRP) Type() string

Jump to

Keyboard shortcuts

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