Skip to content

Commit 6b46043

Browse files
committed
feat(routing): Prefix convertter as test-only
It was annotated initially as such, but the annotation was droppped. Add the annotation back again and use the Prefix associated method try_from_tuple() in gRPC as this was causing a panic when feeding bad prefixes. Signed-off-by: Fredi Raspall <[email protected]>
1 parent e098333 commit 6b46043

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mgmt/src/grpc/converter.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,17 @@ pub fn convert_expose_from_grpc(expose: &gateway_config::Expose) -> Result<VpcEx
492492
// Parse CIDR into IP and netmask
493493
let (ip_str, netmask) = parse_cidr(cidr)?;
494494
// Add as an include rule
495-
vpc_expose = vpc_expose.ip(Prefix::from((ip_str.as_str(), netmask)));
495+
vpc_expose = vpc_expose.ip(Prefix::try_from_tuple((ip_str.as_str(), netmask))
496+
.map_err(|e| e.to_string())?);
496497
}
497498
gateway_config::config::peering_i_ps::Rule::Not(not) => {
498499
// Parse CIDR into IP and netmask for exclude rule
499500
let (ip_str, netmask) = parse_cidr(not)?;
500501
// Add as an exclude rule
501-
vpc_expose = vpc_expose.not(Prefix::from((ip_str.as_str(), netmask)));
502+
vpc_expose = vpc_expose.not(
503+
Prefix::try_from_tuple((ip_str.as_str(), netmask))
504+
.map_err(|e| e.to_string())?,
505+
);
502506
}
503507
}
504508
} else {
@@ -514,13 +518,19 @@ pub fn convert_expose_from_grpc(expose: &gateway_config::Expose) -> Result<VpcEx
514518
// Parse CIDR into IP and netmask
515519
let (ip_str, netmask) = parse_cidr(cidr)?;
516520
// Add as an include rule for AS
517-
vpc_expose = vpc_expose.as_range(Prefix::from((ip_str.as_str(), netmask)));
521+
vpc_expose = vpc_expose.as_range(
522+
Prefix::try_from_tuple((ip_str.as_str(), netmask))
523+
.map_err(|e| e.to_string())?,
524+
);
518525
}
519526
gateway_config::config::peering_as::Rule::Not(ip_exclude) => {
520527
// Parse CIDR into IP and netmask for exclude rule
521528
let (ip_str, netmask) = parse_cidr(ip_exclude)?;
522529
// Add as an exclude rule for AS
523-
vpc_expose = vpc_expose.not_as(Prefix::from((ip_str.as_str(), netmask)));
530+
vpc_expose = vpc_expose.not_as(
531+
Prefix::try_from_tuple((ip_str.as_str(), netmask))
532+
.map_err(|e| e.to_string())?,
533+
);
524534
}
525535
}
526536
} else {

routing/src/prefix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl From<Ipv6Prefix> for Prefix {
171171
}
172172

173173
/// Only for testing. Will panic with badly formed address strings
174+
#[cfg(test)]
174175
impl From<(&str, u8)> for Prefix {
175176
fn from(tuple: (&str, u8)) -> Self {
176177
let a = IpAddr::from_str(tuple.0).expect("Bad address");

0 commit comments

Comments
 (0)