Skip to content

Commit

Permalink
update cf rpki processing
Browse files Browse the repository at this point in the history
  • Loading branch information
digizeph committed Oct 11, 2024
1 parent d7e34f5 commit ba2872d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 21 deletions.
9 changes: 9 additions & 0 deletions examples/list_aspas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use serde_json::json;

fn main() {
let cf_data = bgpkit_commons::rpki::CfData::new().unwrap();
println!(
"{}",
serde_json::to_string_pretty(&json!(cf_data.aspas)).unwrap()
);
}
97 changes: 80 additions & 17 deletions src/rpki/cloudflare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,91 @@
use anyhow::Result;
use ipnet::IpNet;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

use super::{Rir, RoaEntry, RpkiTrie};

#[derive(Clone, Debug, Deserialize)]
struct CfData {
roas: Vec<CfRoaEntry>,
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfData {
pub metadata: CfMetaData,
pub roas: Vec<CfRoaEntry>,
pub aspas: Vec<CfAspaEntry>,
pub bgpsec_keys: Vec<CfBgpsecKeysEntry>,
}

#[derive(Clone, Debug, Deserialize)]
struct CfRoaEntry {
prefix: String,
impl CfData {
pub fn new() -> Result<Self> {
let data: CfData =
oneio::read_json_struct::<CfData>("https://rpki.cloudflare.com/rpki.json")?;
Ok(data)
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfMetaData {
pub buildmachine: Option<String>,
pub buildtime: Option<String>,
pub elapsedtime: Option<u32>,
pub usertime: Option<u32>,
pub systemtime: Option<u32>,
pub roas: Option<u32>,
pub failedroas: Option<u32>,
pub invalidroas: Option<u32>,
pub spls: Option<u32>,
pub failedspls: Option<u32>,
pub invalidspls: Option<u32>,
pub aspas: Option<u32>,
pub failedaspas: Option<u32>,
pub invalidaspas: Option<u32>,
pub bgpsec_pubkeys: Option<u32>,
pub certificates: Option<u32>,
pub invalidcertificates: Option<u32>,
pub taks: Option<u32>,
pub tals: Option<u32>,
pub invalidtals: Option<u32>,
pub talfiles: Option<Vec<String>>,
pub manifests: Option<u32>,
pub failedmanifests: Option<u32>,
pub crls: Option<u32>,
pub gbrs: Option<u32>,
pub repositories: Option<u32>,
pub vrps: Option<u32>,
pub uniquevrps: Option<u32>,
pub vsps: Option<u32>,
pub uniquevsps: Option<u32>,
pub vaps: Option<u32>,
pub uniquevaps: Option<u32>,
pub cachedir_new_files: Option<u32>,
pub cachedir_del_files: Option<u32>,
pub cachedir_del_dirs: Option<u32>,
pub cachedir_superfluous_files: Option<u32>,
pub cachedir_del_superfluous_files: Option<u32>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfAspaEntry {
pub customer_asid: u32,
pub expires: i64,
pub providers: Vec<u32>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfBgpsecKeysEntry {
pub asn: u32,
pub ski: String,
pub pubkey: String,
pub ta: String,
pub expires: i64,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfRoaEntry {
pub prefix: String,
#[serde(rename = "maxLength")]
max_length: u8,
asn: String,
ta: String,
pub max_length: u8,
pub asn: u32,
pub ta: String,
}

impl RpkiTrie {
Expand All @@ -27,23 +95,18 @@ impl RpkiTrie {
oneio::read_json_struct::<CfData>("https://rpki.cloudflare.com/rpki.json")?;

let mut trie = RpkiTrie::default();
trie.aspas = data.aspas;

for roa in data.roas {
let prefix = roa.prefix.parse::<IpNet>()?;
let asn = roa
.asn
.to_lowercase()
.strip_prefix("as")
.unwrap()
.parse::<u32>()?;
let max_length = roa.max_length;
let rir = match Rir::from_str(roa.ta.as_str()) {
Ok(rir) => Some(rir),
Err(_) => None,
};
let roa_entry = RoaEntry {
prefix,
asn,
asn: roa.asn,
max_length,
rir,
not_before: None,
Expand Down
8 changes: 4 additions & 4 deletions src/rpki/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ use ipnet_trie::IpnetTrie;

use crate::BgpkitCommons;
use anyhow::{anyhow, Result};
pub use cloudflare::*;
use std::fmt::Display;
use std::str::FromStr;

pub struct RpkiTrie {
pub trie: IpnetTrie<RoaEntry>,
pub aspas: Vec<CfAspaEntry>,
date: Option<NaiveDate>,
}

impl Default for RpkiTrie {
fn default() -> Self {
Self {
trie: IpnetTrie::new(),
aspas: vec![],
date: None,
}
}
Expand Down Expand Up @@ -115,10 +118,7 @@ impl Display for RpkiValidation {

impl RpkiTrie {
pub fn new(date: Option<NaiveDate>) -> Self {
Self {
trie: IpnetTrie::new(),
date,
}
Self::default()
}

/// insert an [RoaEntry]. If old value exists, it is returned.
Expand Down

0 comments on commit ba2872d

Please sign in to comment.