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

RouteOrigin needs to compare using resolved_max_len. #195

Merged
merged 1 commit into from
Jan 21, 2022
Merged
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
52 changes: 51 additions & 1 deletion src/rtr/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//! The types are currently not very rich. They will receive more methods as
//! they become necessary. So don’t hesitate to ask for them!

use std::hash;
use std::cmp::Ordering;
use std::time::Duration;
use routecore::addr::MaxLenPrefix;
use routecore::asn::Asn;
Expand All @@ -23,7 +25,7 @@ use super::pdu::RouterKeyInfo;
///
/// The type includes authorizations for both IPv4 and IPv6 prefixes which
/// are separate payload types in RTR.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug)]
pub struct RouteOrigin {
/// The address prefix to authorize.
pub prefix: MaxLenPrefix,
Expand All @@ -40,6 +42,54 @@ impl RouteOrigin {
}


//--- PartialEq and Eq
impl PartialEq for RouteOrigin {
fn eq(&self, other: &Self) -> bool {
self.prefix.prefix() == other.prefix.prefix()
&& self.prefix.resolved_max_len() == other.prefix.resolved_max_len()
&& self.asn == other.asn
}
}

impl Eq for RouteOrigin { }


//--- PartialOrd and Ord

impl PartialOrd for RouteOrigin {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for RouteOrigin {
fn cmp(&self, other: &Self) -> Ordering {
match self.prefix.prefix().cmp(&other.prefix.prefix()) {
Ordering::Equal => { }
other => return other
}
match self.prefix.resolved_max_len().cmp(
&other.prefix.resolved_max_len()
) {
Ordering::Equal => { }
other => return other
}
self.asn.cmp(&other.asn)
}
}


//--- Hash

impl hash::Hash for RouteOrigin {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.prefix.prefix().hash(state);
self.prefix.resolved_max_len().hash(state);
self.asn.hash(state);
}
}


//------------ RouterKey -----------------------------------------------------

/// A BGPsec router key.
Expand Down