bgpkit-commons
Overview
bgpkit-commons is a library for common BGP-related data and functions with a lazy-loading
architecture. Each module can be independently enabled via feature flags, allowing for minimal builds.
Quick Start
Add bgpkit-commons to your Cargo.toml:
[]
= "0.10"
All modules follow the same pattern: create a [BgpkitCommons] instance, call a load_xxx()
method to fetch data, then use xxx_yyy() methods to access it.
use BgpkitCommons;
let mut commons = new;
commons.load_bogons.unwrap;
if let Ok = commons.bogons_match
Modules
[asinfo] — Autonomous System Information
Feature: asinfo | Sources: RIPE NCC, CAIDA as2org, APNIC population, IIJ IHR hegemony, PeeringDB
- Load:
load_asinfo(as2org, population, hegemony, peeringdb),load_asinfo_cached(),load_asinfo_with(builder) - Access:
asinfo_get(asn),asinfo_all(),asinfo_are_siblings(asn1, asn2) - AS name resolution, country mapping, organization data, population statistics, hegemony scores
[as2rel] — AS Relationship Data
Feature: as2rel | Source: BGPKIT AS relationship inference
- Load:
load_as2rel() - Access:
as2rel_lookup(asn1, asn2) - Provider-customer, peer-to-peer, and sibling relationships between ASes
[bogons] — Bogon Detection
Feature: bogons | Source: IANA special registries (IPv4, IPv6, ASN)
- Load:
load_bogons() - Access:
bogons_match(input),bogons_match_prefix(prefix),bogons_match_asn(asn),get_bogon_prefixes(),get_bogon_asns() - Detect invalid/reserved IP prefixes and ASNs that shouldn't appear in routing
[countries] — Country Information
Feature: countries | Source: GeoNames geographical database
- Load:
load_countries() - Access:
country_by_code(code),country_by_code3(code),country_by_name(name),country_all() - ISO country code to name mapping and geographical information
[mrt_collectors] — MRT Collector Metadata
Feature: mrt_collectors | Sources: RouteViews and RIPE RIS official APIs
- Load:
load_mrt_collectors(),load_mrt_collector_peers() - Access:
mrt_collectors_all(),mrt_collectors_by_name(name),mrt_collectors_by_country(country),mrt_collector_peers_all(),mrt_collector_peers_full_feed() - BGP collector information, peer details, full-feed vs partial-feed classification
[peeringdb] — PeeringDB Data
Feature: peeringdb | Source: PeeringDB API
- Load:
Peeringdb::new()(all tables),Peeringdb::new_networks_only()(lightweight) - Access:
get_network(asn),get_ixp(ix_id),get_ixp_memberships(asn),lookup_ixp_prefix(prefix),get_facility(fac_id) - Typed structs mirroring all 12 PeeringDB API endpoints: networks, internet exchanges, IXP prefixes, IXP membership, facilities, organizations, carriers, and more
PeeringdbDatais a type alias for the fullNetworkstruct (backward compatible)
[rpki] — RPKI Validation
Feature: rpki | Sources: Cloudflare (real-time), RIPE NCC historical, RPKIviews historical, RPKISPOOL historical
- Load:
load_rpki(optional_date),load_rpki_historical(date, source),load_rpki_from_files(urls, source, date) - Poll:
RpkiTrie::from_cloudflare_conditional(etag, last_modified)returnsOk(None)on304 Not Modified - Access:
rpki_validate(asn, prefix),rpki_validate_check_expiry(asn, prefix, timestamp),rpki_lookup_by_prefix(prefix),rpki_lookup_aspa(customer_asn) - Route Origin Authorization (ROA) and ASPA validation, supports real-time and historical sources
- Poll current Cloudflare data with
RpkiTrie::from_cloudflare_conditional, retaining the returned [rpki::RpkiLoad] validators and keeping the existing trie when the result isOk(None). BgpkitCommons::reload()performs a full reload; it does not use validators or provide an atomic poll-and-swap operation.
Examples
Loading multiple modules
use BgpkitCommons;
let mut commons = new;
commons.load_asinfo.unwrap;
commons.load_countries.unwrap;
if let Ok = commons.asinfo_get
Using AsInfoBuilder
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
Loading historical RPKI data
use BgpkitCommons;
use ;
use NaiveDate;
let mut commons = new;
let date = from_ymd_opt.unwrap;
// Load from RIPE NCC historical archives
commons.load_rpki_historical.unwrap;
// Or load from RPKIviews collectors
let source = RpkiViews;
commons.load_rpki_historical.unwrap;
// List available files for a date
let files = commons.list_rpki_files.unwrap;
Direct module access
Modules can also be used directly without BgpkitCommons:
use Bogons;
let bogons = new.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 |
peeringdb |
PeeringDB API data (networks, IXPs, facilities, organizations) |
rpki |
RPKI validation (ROA and ASPA) |
all (default) |
Enables all modules |
For a minimal build:
[]
= { = "0.10", = false, = ["bogons", "countries"] }
License: MIT