Skip to content

Commit

Permalink
SpecImportFromCustomers for #70
Browse files Browse the repository at this point in the history
  • Loading branch information
SichangHe committed Oct 30, 2023
1 parent 2b87fc2 commit b0efa3f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
1 change: 0 additions & 1 deletion route_verification/bgp/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::net::{Ipv4Addr, Ipv6Addr};

use as_path_regex::interpreter::{InterpretErr::*, Interpreter};
use ipnet::*;
use parse::*;

use super::*;

Expand Down
46 changes: 44 additions & 2 deletions route_verification/bgp/src/cmp/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ impl<'a> CheckFilter<'a> {
if match_ips(&self.cmp.prefix, routes, op) {
return None;
}
if self.maybe_filter_customers(num, op) {
if self.is_filter_export_customer(num, op) {
self.special_any_report(|| SpecExportCustomers)
} else if self.is_filter_import_from_customer(num, op) {
self.special_any_report(|| SpecImportFromCustomers)
} else if self.maybe_filter_as_is_origin(num, op) {
self.special_any_report(|| SpecAsIsOriginButNoRoute(num))
} else {
Expand All @@ -80,7 +82,8 @@ impl<'a> CheckFilter<'a> {
/// Check for this case:
/// - The AS number itself is the `<filter>`.
/// - Exporting customers routes.
pub fn maybe_filter_customers(&self, num: u32, op: RangeOperator) -> bool {
#[inline]
pub fn is_filter_export_customer(&self, num: u32, op: RangeOperator) -> bool {
if self.export && self.cmp.verbosity.check_customer && num == self.self_num {
self.filter_as_set(
&customer_set(num),
Expand All @@ -94,6 +97,45 @@ impl<'a> CheckFilter<'a> {
}
}

/// Check for this case:
/// - Importing.
/// - The customer AS is the `<filter>`.
/// - The `<peering>` is just the customer AS.
/// - The prefix length matches the range operator, if any.
#[inline]
pub fn is_filter_import_from_customer(&self, num: u32, op: RangeOperator) -> bool {
if let (
false,
true,
1,
Some(PeeringAction {
mp_peering:
Peering {
remote_as: AsExpr::Single(AsName::Num(peering_num)),
remote_router: _,
local_router: _,
},
actions: _,
}),
) = (
self.export,
self.cmp.verbosity.check_customer,
self.mp_peerings.len(),
self.mp_peerings.first(),
) {
num == *peering_num && {
let prefix_len = self.cmp.prefix.prefix_len();
match op {
RangeOperator::NoOp | RangeOperator::Minus | RangeOperator::Plus => true,
RangeOperator::Num(n) => n == prefix_len,
RangeOperator::Range(n, m) => (n..=m).contains(&prefix_len),
}
}
} else {
false
}
}

/// The last AS number on the AS path.
/// `None` if it is a set.
pub fn last_on_path(&self) -> Option<u32> {
Expand Down
3 changes: 2 additions & 1 deletion route_verification/bgp/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ops::{BitAnd, BitOr, BitOrAssign};

use ::lex::Call;
use parse::*;

use super::*;

Expand Down Expand Up @@ -152,6 +151,8 @@ pub enum ReportItem {
// Can be repetitive for each import/export.
/// Export customer routes while specifying the AS itself as `<filter>`.
SpecExportCustomers,
/// Import from neighbor customer while specifying them as `<filter>`.
SpecImportFromCustomers,
/// AS in `<filter>` is the origin on the path, but the route mismatches.
SpecAsIsOriginButNoRoute(u32),

Expand Down

0 comments on commit b0efa3f

Please sign in to comment.