Documentation
¶
Overview ¶
Package rtr implements a minimal RPKI-to-Router (RTR) protocol client. It supports protocol versions 0 (draft-ietf-sidr-rpki-rtr), 1 (RFC 8210), and 2 (draft-ietf-sidrops-8210bis, which adds ASPA).
Usage:
c := rtr.NewClient(&rtr.Options{
OnROA: func(...) { /* handle ROA */ },
OnASPA: func(...) { /* handle ASPA */ },
OnEndOfData: func(...) { /* cache consistent */ },
})
err := c.Run(ctx, conn) // blocks; call from reconnection loop
Index ¶
Constants ¶
const ( PDUSerialNotify byte = 0 // S: new data available since serial PDUSerialQuery byte = 1 // C: request incremental update since serial PDUResetQuery byte = 2 // C: request full cache PDUCacheResponse byte = 3 // S: begin data stream PDUIPv4Prefix byte = 4 // S: IPv4 ROA entry PDUIPv6Prefix byte = 6 // S: IPv6 ROA entry PDUEndOfData byte = 7 // S: end of data batch; cache is now consistent PDUCacheReset byte = 8 // S: full refresh required; send Reset Query PDURouterKey byte = 9 // S: BGPsec Router Key (not used by this client) PDUErrorReport byte = 10 // S: error notification PDUAspa byte = 11 // S: ASPA entry (RTR v2 only) )
PDU type codes. Direction: S=Server->Client, C=Client->Server.
const ( FlagAnnounce byte = 1 // record is being added FlagWithdraw byte = 0 // record is being removed )
Flags for announcement/withdrawal PDUs (IPv4 Prefix, IPv6 Prefix, ASPA).
const ( VersionV0 byte = 0 // original (draft-ietf-sidr-rpki-rtr) VersionV1 byte = 1 // RFC 8210 VersionV2 byte = 2 // draft-ietf-sidrops-8210bis (adds ASPA) VersionAuto byte = 255 // auto-negotiate: try v2, fall back to v1, then v0 )
RTR protocol version numbers.
const ( ErrCorruptData uint16 = 0 // corrupt data received ErrInternal uint16 = 1 // internal error ErrNoData uint16 = 2 // no data available (non-fatal, server still initializing) ErrInvalidReq uint16 = 3 // invalid request ErrUnsupVersion uint16 = 4 // unsupported protocol version (non-fatal, triggers downgrade) ErrUnsupPDUType uint16 = 5 // unsupported PDU type ErrWithdrawUnk uint16 = 6 // withdrawal of unknown record ErrDupAnnounce uint16 = 7 // duplicate announcement ErrUnexpVersion uint16 = 8 // unexpected protocol version ErrASPAProvList uint16 = 9 // ASPA provider list error )
Error codes from Error Report PDUs.
Variables ¶
var DefaultOptions = Options{ Logger: &log.Logger, Version: VersionAuto, }
DefaultOptions are the default RTR client options.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a single-endpoint RTR protocol client. It can be reused across multiple connections (reconnections). All fields except Options must not be modified after the first call to Run.
func NewClient ¶
NewClient returns a new Client with the given options. If opts is nil, DefaultOptions is used (VersionAuto + default logger). When opts is non-nil, all fields are used as-is, including Version:
- VersionAuto (255): auto-negotiate v2 → v1 → v0 on ErrUnsupVersion
- VersionV0/V1/V2: use that version with no fallback
func (*Client) Run ¶
Run starts an RTR session over conn, processing PDUs until conn closes or ctx is done. It sends a Reset Query immediately on connect. Run always closes conn before returning. On receiving ErrUnsupVersion with VersionAuto, it downgrades version (v2→v1→v0) and retries. Returns ctx.Err() if ctx is cancelled, otherwise the connection error. The caller is responsible for reconnection.
NB: Run starts one internal goroutine that exits when Run returns.
func (*Client) SendSerial ¶
SendSerial sends a Serial Query to request incremental updates since the last serial. Returns false if not connected, no full cache has been received yet, or the write fails. Safe to call concurrently with Run from a different goroutine.
type Options ¶
type Options struct {
Logger *zerolog.Logger // if nil, logging is disabled
Version byte // preferred RTR protocol version (VersionAuto = negotiate v2 → v1 → v0)
// OnROA is called for each ROA announcement or withdrawal.
// add=true means announcement; false means withdrawal.
OnROA func(add bool, prefix netip.Prefix, maxLen uint8, asn uint32)
// OnASPA is called for each ASPA announcement or withdrawal (RTR v2 only).
// For withdrawals, providers is nil.
OnASPA func(add bool, cas uint32, providers []uint32)
// OnEndOfData is called after each complete batch of PDUs.
// sessid and serial reflect the server's current cache state.
OnEndOfData func(sessid uint16, serial uint32)
// OnCacheReset is called when the server requests a full cache reload.
// The client sends a new Reset Query automatically after this callback.
OnCacheReset func()
// OnError is called when the server sends an Error Report PDU.
// code is one of the Err* constants; text may be empty.
OnError func(code uint16, text string)
}
Options configures the RTR client behavior and callbacks. All callbacks are called serially from the Run goroutine.