Skip to main content

Crate bgpkit_commons

Crate bgpkit_commons 

Source
Expand description

§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:

[dependencies]
bgpkit-commons = "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 bgpkit_commons::BgpkitCommons;

let mut commons = BgpkitCommons::new();
commons.load_bogons().unwrap();

if let Ok(is_bogon) = commons.bogons_match("23456") {
    println!("ASN 23456 is a bogon: {}", is_bogon);
}

§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

§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)
  • 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

§Examples

§Loading multiple modules

use bgpkit_commons::BgpkitCommons;

let mut commons = BgpkitCommons::new();
commons.load_asinfo(false, false, false, false).unwrap();
commons.load_countries().unwrap();

if let Ok(Some(asinfo)) = commons.asinfo_get(13335) {
    println!("AS13335: {} ({})", asinfo.name, asinfo.country);
}

§Using AsInfoBuilder

use bgpkit_commons::BgpkitCommons;

let mut commons = BgpkitCommons::new();
let builder = commons.asinfo_builder()
    .with_as2org()
    .with_peeringdb();
commons.load_asinfo_with(builder).unwrap();

if let Ok(are_siblings) = commons.asinfo_are_siblings(13335, 132892) {
    println!("AS13335 and AS132892 are siblings: {}", are_siblings);
}

§Loading historical RPKI data

use bgpkit_commons::BgpkitCommons;
use bgpkit_commons::rpki::{HistoricalRpkiSource, RpkiViewsCollector};
use chrono::NaiveDate;

let mut commons = BgpkitCommons::new();
let date = NaiveDate::from_ymd_opt(2024, 1, 4).unwrap();

// Load from RIPE NCC historical archives
commons.load_rpki_historical(date, HistoricalRpkiSource::Ripe).unwrap();

// Or load from RPKIviews collectors
let source = HistoricalRpkiSource::RpkiViews(RpkiViewsCollector::KerfuffleNet);
commons.load_rpki_historical(date, source).unwrap();

// List available files for a date
let files = commons.list_rpki_files(date, HistoricalRpkiSource::Ripe).unwrap();

§Direct module access

Modules can also be used directly without BgpkitCommons:

use bgpkit_commons::bogons::Bogons;
let bogons = Bogons::new().unwrap();

§Feature Flags

FeatureDescription
asinfoAS information: names, countries, organizations, population, hegemony
as2relAS relationship data
bogonsBogon prefix and ASN detection
countriesCountry information lookup
mrt_collectorsMRT collector metadata
rpkiRPKI validation (ROA and ASPA)
all (default)Enables all modules

For a minimal build:

[dependencies]
bgpkit-commons = { version = "0.10", default-features = false, features = ["bogons", "countries"] }

Re-exports§

pub use errors::BgpkitCommonsError;
pub use errors::Result;

Modules§

as2rel
AS-level relationship generated by BGPKIT
asinfo
asinfo is a module for simple Autonomous System (AS) names and country lookup
bogons
Module: bogons
countries
Module: countries
errors
Error types for bgpkit-commons
mrt_collectors
Module for getting meta information for the public MRT mrt_collectors.
rpki
RPKI (Resource Public Key Infrastructure) validation and data structures.

Structs§

BgpkitCommons

Traits§

LazyLoadable
Trait for modules that support lazy loading and reloading of data