rpki

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package rpki implements an RPKI data cache for BGP route validation.

The Cache holds VRPs for Route Origin Validation (RFC 6811) and ASPA records for AS_PATH verification (draft-ietf-sidrops-aspa-verification). Writers stage changes in a pending set (AddVRP, AddASPA, Parse) and publish them atomically with Apply; readers validate against immutable snapshots without taking locks.

Data can be fed from an RTR client (see the rtr package), or parsed from Routinator/rpki-client JSON or CSV files (see Parse).

Index

Constants

View Source
const (
	HOP_NO_ATTESTATION = iota // CAS has no ASPA record
	HOP_PROVIDER              // PAS is listed as a provider of CAS
	HOP_NOT_PROVIDER          // CAS has an ASPA record that does not list PAS
)

Hop authorization results (draft-ietf-sidrops-aspa-verification §5)

View Source
const (
	ROV_VALID     = iota // prefix+origin covered by a valid VRP
	ROV_INVALID          // prefix+origin conflicts with a VRP
	ROV_NOT_FOUND        // no VRP covers the prefix
)

ROV validation results (RFC 6811)

View Source
const (
	ASPA_VALID   = iota // path is valley-free and fully attested
	ASPA_UNKNOWN        // insufficient attestation
	ASPA_INVALID        // proven route leak
)

ASPA path verification results (draft-ietf-sidrops-aspa-verification)

View Source
const (
	MIN_VRP_V4 = 8  // no VRPs shorter than /8 for IPv4
	MIN_VRP_V6 = 12 // no VRPs shorter than /12 for IPv6
)

minimum VRP prefix lengths checked by ValidateOrigin

Variables

This section is empty.

Functions

func Hop

func Hop(aspa ASPA, cas, pas uint32) int

Hop checks ASPA authorization for a CAS→PAS hop. NB: provider lists must be sorted (see Cache.AddASPA).

func ValidateOrigin

func ValidateOrigin(v4, v6 VRPs, p netip.Prefix, origin uint32) int

ValidateOrigin performs Route Origin Validation (RFC 6811) of prefix p announced by the origin ASN, against VRP snapshots v4 and v6 (see Cache.VRPs). Returns ROV_VALID, ROV_INVALID, or ROV_NOT_FOUND. NB: origin 0 (eg. unknown) never validates.

func VerifyPath

func VerifyPath(aspa ASPA, path []uint32, downstream bool) (result int, failCAS, failPAS uint32)

VerifyPath verifies the flat AS_PATH against ASPA records (see Cache.ASPAs).

path[0] is the most-recently-traversed AS (direct peer), path[N-1] is the origin AS. Returns ASPA_VALID, ASPA_UNKNOWN, or ASPA_INVALID. On ASPA_INVALID, failCAS and failPAS identify the hop where CAS has an ASPA record that does not list PAS as a provider. Both are 0 for other results.

downstream=true when received from a provider or RS (downstream direction). downstream=false when received from a customer, peer, or RS-client (upstream).

NB: does not check path[0] == neighbor AS (draft §5.4/5.5 step 2). The caller must do that check, skipping it for RS peers (RFC 7947).

Types

type ASPA

type ASPA = map[uint32][]uint32

ASPA maps Customer ASN to its sorted list of Provider ASNs

type Cache

type Cache struct {
	*zerolog.Logger
	// contains filtered or unexported fields
}

Cache is an RPKI data cache for ROV and ASPA validation.

Writers stage changes in a pending set and publish them with Apply. Readers obtain immutable snapshots (VRPs, ASPAs) — the published maps must never be modified, so reads are lock-free.

func NewCache

func NewCache(logger *zerolog.Logger) *Cache

NewCache returns a new, empty Cache. If logger is nil, logging is disabled.

func (*Cache) ASPAs

func (c *Cache) ASPAs() ASPA

ASPAs returns the current ASPA snapshot. The returned map is immutable and must not be modified.

func (*Cache) AddASPA

func (c *Cache) AddASPA(add bool, cas uint32, providers []uint32)

AddASPA adds (add=true) or removes (add=false) an ASPA record in the pending set. Providers are normalized: zeros removed, deduplicated, sorted.

func (*Cache) AddVRP

func (c *Cache) AddVRP(add bool, prefix netip.Prefix, maxLen uint8, asn uint32)

AddVRP adds (add=true) or removes (add=false) a VRP in the pending set. Entries with invalid maxLen are dropped with a warning.

func (*Cache) Apply

func (c *Cache) Apply()

Apply atomically publishes the pending set as the current snapshot. The next pending set starts as a lazy clone of the snapshot, so that subsequent incremental updates continue from the published state.

func (*Cache) Flush

func (c *Cache) Flush()

Flush drops all pending changes, restarting from an empty pending set. The current snapshot is not affected until the next Apply.

func (*Cache) Parse

func (c *Cache) Parse(data []byte) error

Parse parses RPKI data in JSON or CSV format (auto-detected) into the pending set. Call Flush first to start from scratch, and Apply after to publish the result.

func (*Cache) ParseCSV

func (c *Cache) ParseCSV(data []byte) error

ParseCSV parses CSV VRP data (prefix,maxLength,asn) into the pending set. The Routinator column order (asn,prefix,maxLength[,trustAnchor]) is auto-detected per line. Invalid lines are skipped with a warning.

func (*Cache) ParseJSON

func (c *Cache) ParseJSON(data []byte) error

ParseJSON parses Routinator/rpki-client JSON with VRPs and ASPA records into the pending set. Malformed JSON or unexpected field types (eg. a string customer_asid) return an error; well-typed entries with invalid values (bad prefix, out-of-range maxLength/ASN) are skipped with a warning.

func (*Cache) Ready

func (c *Cache) Ready() <-chan struct{}

Ready returns a channel that is closed after the first Apply.

func (*Cache) Sizes

func (c *Cache) Sizes() (vrps4, vrps6, aspas int)

Sizes returns the number of entries in the current snapshots.

func (*Cache) VRPs

func (c *Cache) VRPs() (v4, v6 VRPs)

VRPs returns the current IPv4 and IPv6 VRP snapshots. The returned maps are immutable and must not be modified.

func (*Cache) ValidateOrigin

func (c *Cache) ValidateOrigin(p netip.Prefix, origin uint32) int

ValidateOrigin performs ROV against the current cache snapshot. See the package-level ValidateOrigin.

func (*Cache) VerifyPath

func (c *Cache) VerifyPath(path []uint32, downstream bool) (result int, failCAS, failPAS uint32)

VerifyPath verifies path against the current cache snapshot. See the package-level VerifyPath.

func (*Cache) WaitReady

func (c *Cache) WaitReady(ctx context.Context) error

WaitReady blocks until the cache has data (first Apply), or ctx is done.

type VRP

type VRP struct {
	MaxLen uint8
	ASN    uint32
}

VRP represents a single Validated ROA Payload

type VRPs

type VRPs = map[netip.Prefix][]VRP

VRPs maps prefixes to lists of VRP entries

Jump to

Keyboard shortcuts

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