Skip to content

Commit 1a6dc2f

Browse files
author
Tim Bruijnzeels
authored
Give clear error for ASPA with duplicate providers #1061 (#1062)
1 parent a03cedc commit 1a6dc2f

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/cli/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,8 @@ impl Options {
19771977
let aspa = AspaDefinition::from_str(aspa_config_str)?;
19781978
if aspa.customer_used_as_provider() {
19791979
Err(Error::general("Customer AS may not be used as provider."))
1980+
} else if aspa.contains_duplicate_providers() {
1981+
Err(Error::general("ASPA may not have duplicate providers."))
19801982
} else if !aspa.providers_has_both_afis() {
19811983
Err(Error::general("Definition has providers for one address family only. Please include an explicit AS0 provider for the missing address family if this is intentional."))
19821984
} else if aspa.providers().is_empty() {

src/commons/api/aspa.rs

+14
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ impl AspaDefinition {
100100
self.providers.iter().any(|p| p.provider() == self.customer)
101101
}
102102

103+
/// Returns true if there are duplicate provider ASNs. This
104+
/// is not allowed by spec and these definitions should be
105+
/// rejected by Krill.
106+
pub fn contains_duplicate_providers(&self) -> bool {
107+
let mut providers: Vec<Asn> = self.providers.iter().map(|p| p.provider()).collect();
108+
109+
let len_before_duplicates = providers.len();
110+
111+
providers.sort();
112+
providers.dedup();
113+
114+
len_before_duplicates > providers.len()
115+
}
116+
103117
/// Returns true if this contains both IPv4 and IPv6 providers.
104118
///
105119
/// Technically,it is allowed to omit one address family entirely,

src/commons/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub enum Error {
274274
AspaCustomerAlreadyPresent(CaHandle, AspaCustomer),
275275
AspaCustomerUnknown(CaHandle, AspaCustomer),
276276
AspaCustomerAsProvider(CaHandle, AspaCustomer),
277+
AspaProvidersDuplicates(CaHandle, AspaCustomer),
277278
AspaProvidersEmpty(CaHandle, AspaCustomer),
278279
AspaProvidersSingleAfi(CaHandle, AspaCustomer),
279280

@@ -464,6 +465,7 @@ impl fmt::Display for Error {
464465
Error::AspaCustomerAlreadyPresent(_ca, asn) => write!(f, "ASPA already exists for customer AS '{}'", asn),
465466
Error::AspaProvidersEmpty(_ca, asn) => write!(f, "ASPA for customer AS '{}' requires at least one provider", asn),
466467
Error::AspaCustomerAsProvider(_ca, asn) => write!(f, "ASPA for customer AS '{}' cannot have that AS as provider", asn),
468+
Error::AspaProvidersDuplicates(_ca, asn) => write!(f, "ASPA for customer AS '{}' cannot have duplicate providers", asn),
467469
Error::AspaCustomerUnknown(_ca, asn) => write!(f, "No current ASPA exists for customer AS '{}'", asn),
468470
Error::AspaProvidersSingleAfi(_ca, asn) => write!(f, "ASPA for customer AS '{}' only has providers for one address family. Please include an explicit AS0 provider for the missing address family if this is intentional.", asn),
469471

@@ -882,6 +884,9 @@ impl Error {
882884
Error::AspaCustomerAsProvider(ca, asn) => ErrorResponse::new("ca-aspa-customer-as-provider", self)
883885
.with_ca(ca)
884886
.with_asn(*asn),
887+
Error::AspaProvidersDuplicates(ca, asn) => ErrorResponse::new("ca-aspa-provider-duplicates", self)
888+
.with_ca(ca)
889+
.with_asn(*asn),
885890
Error::AspaCustomerUnknown(ca, asn) => ErrorResponse::new("ca-aspa-unknown-customer-as", self)
886891
.with_ca(ca)
887892
.with_asn(*asn),

src/daemon/ca/certauth.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,10 @@ impl CertAuth {
17441744
return Err(Error::AspaProvidersSingleAfi(self.handle.clone(), customer));
17451745
}
17461746

1747+
if aspa_config.contains_duplicate_providers() {
1748+
return Err(Error::AspaProvidersDuplicates(self.handle.clone(), customer));
1749+
}
1750+
17471751
if !self.all_resources().contains_asn(customer) {
17481752
return Err(Error::AspaCustomerAsNotEntitled(self.handle().clone(), customer));
17491753
}

0 commit comments

Comments
 (0)