Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ASPA payload in RTR. #250

Merged
merged 6 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rpki"
version = "0.15.11-dev"
version = "0.16.0-dev"
edition = "2018"
authors = ["The NLnet Labs RPKI Team <[email protected]>"]
description = "A library for validating and creating RPKI data."
Expand Down
77 changes: 76 additions & 1 deletion src/rtr/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::time::Duration;
use routecore::addr::MaxLenPrefix;
use routecore::asn::Asn;
use routecore::bgpsec::KeyIdentifier;
use super::pdu::RouterKeyInfo;
use super::pdu::{RouterKeyInfo, ProviderAsns};


//------------ RouteOrigin ---------------------------------------------------
Expand Down Expand Up @@ -115,6 +115,30 @@ impl RouterKey {
}


//------------ Aspa ----------------------------------------------------------

/// An ASPA ... unit.
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Aspa {
/// The customer ASN.
pub customer: Asn,

/// The address family this ASPA pertains to.
pub afi: Afi,

/// The provider ASNs.
pub providers: ProviderAsns,
}

impl Aspa {
/// Creates a new ASPA unit from its components.
pub fn new(
customer: Asn, afi: Afi, providers: ProviderAsns,
) -> Self {
Self { customer, afi, providers }
}
}


//------------ Payload -------------------------------------------------------

Expand All @@ -126,6 +150,9 @@ pub enum Payload {

/// A BGPsec router key.
RouterKey(RouterKey),

/// An ASPA unit.
Aspa(Aspa),
}

impl Payload {
Expand All @@ -141,6 +168,13 @@ impl Payload {
Payload::RouterKey(RouterKey::new(key_identifier, asn, key_info))
}

/// Creates a new ASPA unit.
pub fn aspa(
customer: Asn, afi: Afi, providers: ProviderAsns,
) -> Self {
Payload::Aspa(Aspa::new(customer, afi, providers))
}

/// Returns the origin prefix if the value is of the origin variant.
pub fn to_origin(&self) -> Option<RouteOrigin> {
match *self {
Expand All @@ -156,6 +190,14 @@ impl Payload {
_ => None
}
}

/// Returns the ASPA unit if the value is of the ASPA variant.
pub fn as_aspa(&self) -> Option<&Aspa> {
match *self {
Payload::Aspa(ref aspa) => Some(aspa),
_ => None
}
}
}


Expand Down Expand Up @@ -220,6 +262,39 @@ impl Action {
}


//------------ Afi -----------------------------------------------------------

/// The RTR representation of an address family.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Afi(u8);

impl Afi {
pub fn ipv4() -> Self {
Self(0)
}

pub fn ipv6() -> Self {
Self(1)
}

pub fn is_ipv4(self) -> bool {
self.0 & 0x01 == 0
}

pub fn is_ipv6(self) -> bool {
self.0 & 0x01 == 1
}

pub fn into_u8(self) -> u8 {
self.0
}

pub fn from_u8(src: u8) -> Self {
Self(src)
}
}


//------------ Timing --------------------------------------------------------

/// The timing parameters of a data exchange.
Expand Down
Loading