BGPKIT Commons
bgpkit-commons is a library for common BGP-related data and functions. It provides a unified
interface to multiple BGP data sources through a lazy-loading architecture — modules are
independently enabled via feature flags and data is only fetched when explicitly requested.
Architecture
graph TD
B[BgpkitCommons]
B -->|load_asinfo| M1[asinfo]
B -->|load_as2rel| M2[as2rel]
B -->|load_bogons| M3[bogons]
B -->|load_countries| M4[countries]
B -->|load_mrt_collectors| M5[mrt_collectors]
B -->|load_rpki| M6[rpki]
M1 -->|asinfo_get, asinfo_all| A1[RIPE NCC / CAIDA / APNIC / PeeringDB]
M2 -->|as2rel_lookup| A2[BGPKIT inference]
M3 -->|bogons_match| A3[IANA registries]
M4 -->|country_by_code| A4[GeoNames]
M5 -->|mrt_collectors_all| A5[RouteViews / RIPE RIS]
M6 -->|rpki_validate| A6[Cloudflare / RIPE NCC / RPKIviews / RPKISPOOL]
Each module is gated by a feature flag. The all feature (default) enables everything.
Data is fetched on the first load_xxx() call and kept in memory until reload() is called.
The Cloudflare RPKI module also exposes a validator-aware polling API for avoiding full
re-downloads when the source has not changed; see Conditional RPKI loading.
Modules
| Module | Feature | Data Sources | Key Functions |
|---|---|---|---|
[asinfo] |
asinfo |
RIPE NCC, CAIDA as2org, APNIC, IIJ IHR, PeeringDB | asinfo_get, asinfo_all, asinfo_are_siblings |
[as2rel] |
as2rel |
BGPKIT AS relationship inference | as2rel_lookup |
[bogons] |
bogons |
IANA special registries | bogons_match, bogons_match_prefix, bogons_match_asn |
[countries] |
countries |
GeoNames | country_by_code, country_by_code3, country_by_name |
[mrt_collectors] |
mrt_collectors |
RouteViews, RIPE RIS | mrt_collectors_all, mrt_collector_peers_all |
[rpki] |
rpki |
Cloudflare, RIPE NCC, RPKIviews, RPKISPOOL | rpki_validate, rpki_validate_check_expiry, rpki_lookup_by_prefix |
RPKI data sources
| Source | Data and scope | Wire/file compression | Main entry points |
|---|---|---|---|
| Cloudflare | Current aggregate ROA, ASPA, and BGPsec data | HTTP Content-Encoding: gzip |
RpkiTrie::from_cloudflare, RpkiTrie::from_cloudflare_conditional |
| RIPE NCC | Historical data from all five RIRs | output.json.xz |
RpkiTrie::from_ripe_historical, list_ripe_files |
| RPKIviews | Historical collector-specific snapshots | .tgz (gzip-compressed tar) |
RpkiTrie::from_rpkiviews, list_rpkiviews_files |
| RPKISPOOL | Historical CCR snapshots from a collector | .tar.zst |
RpkiTrie::from_rpkispools, parse_rpkispools_archive |
Collector-specific sources represent the selected collector's vantage point and snapshot; they should not be interpreted as a complete global view by themselves.
Quick Start
[]
= "0.10"
use BgpkitCommons;
let mut commons = new;
// Load the modules you need
commons.load_bogons.unwrap;
commons.load_asinfo.unwrap;
// Access the data
if let Ok = commons.bogons_match
if let Ok = commons.asinfo_get
Examples
RPKI Validation
use BgpkitCommons;
let mut commons = new;
commons.load_rpki.unwrap; // None = real-time from Cloudflare
let result = commons.rpki_validate.unwrap;
println!;
Conditional RPKI loading
For a long-running service that polls Cloudflare repeatedly, retain the validators from the
previous successful load. A matching validator produces Ok(None) from the next request, so
the large JSON payload is not downloaded or parsed again:
use RpkiTrie;
let mut etag = None;
let mut last_modified = None;
if let Some = from_cloudflare_conditional? // `None` means HTTP 304: keep the currently served trie.
# Ok::
BgpkitCommons::reload() is not validator-aware: it performs a regular full reload. Use the
direct RpkiTrie conditional API when polling needs ETag/Last-Modified reuse.
Historical RPKI Data
use BgpkitCommons;
use ;
use NaiveDate;
let mut commons = new;
let date = from_ymd_opt.unwrap;
// From RIPE NCC historical archives
commons.load_rpki_historical.unwrap;
// Or from an RPKIviews collector
let source = RpkiViews;
commons.load_rpki_historical.unwrap;
// Or from RPKISPOOL (CCR format, parses faster)
use RpkiSpoolsCollector;
let source = RpkiSpools;
commons.load_rpki_historical.unwrap;
Available RPKIviews collectors: SobornostNet (default), MassarsNet, AttnJp, KerfuffleNet.
Available RPKISPOOL collectors: SobornostNet (default), AttnJp, KerfuffleNet.
AS Information with Builder
use BgpkitCommons;
let mut commons = new;
let builder = commons.asinfo_builder
.with_as2org
.with_peeringdb;
commons.load_asinfo_with.unwrap;
if let Ok = commons.asinfo_are_siblings
Direct Module Access
All modules can be used directly without BgpkitCommons:
use Bogons;
use RpkiTrie;
let bogons = new.unwrap;
let trie = from_cloudflare.unwrap;
Feature Flags
| Feature | Description |
|---|---|
asinfo |
AS information: names, countries, organizations, population, hegemony |
as2rel |
AS relationship data |
bogons |
Bogon prefix and ASN detection |
countries |
Country information lookup |
mrt_collectors |
MRT collector metadata |
rpki |
RPKI validation (ROA and ASPA) |
all (default) |
Enables all modules |
For a minimal build:
[]
= { = "0.10", = false, = ["bogons", "rpki"] }
Examples requiring a particular module are feature-gated in Cargo.toml. For example:
Operational notes
- Loading data requires network access; sources are fetched lazily when their load method is called.
- The Cloudflare RPKI payload is large in memory even when HTTP gzip substantially reduces transfer size.
.gz,.xz, and.bz2URL suffixes are decompressed by oneio. RPKIviews.tgzarchives are streamed and require thegunzipexecutable to be available inPATH.- PeeringDB loading can use
PEERINGDB_API_KEY; when unset, the client sends no empty API-key header. reload()replaces already-loaded module data by fetching it again. It does not provide an atomic swap or conditional HTTP polling for the RPKI module.
License
MIT