Skip to content

Commit 1d1cff3

Browse files
committed
feat(mgmt): strong typing for derived interface names
Linux interface names have strict rules. These rules are captured and enforced by the `InterfaceName` type. This commit switches the type of the generated interface names to indicate this to downstream consumers (including the VPC manager). To be clear, these constraints are absolutely accounted for already in the generated string. We just need the types to catch up. Signed-off-by: Daniel Noland <daniel@githedgehog.com>
1 parent 1fd3aba commit 1d1cff3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

mgmt/src/processor/confbuild.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn vpc_ipv4_import_configuration(vpc: &Vpc) -> (RouteMap, Vec<PrefixList>, Vec<S
9090
/* update route-map */
9191
let entry = RouteMapEntry::new(seq, MatchingPolicy::Permit)
9292
.add_match(RouteMapMatch::Ipv4AddressPrefixList(plist.name.clone()))
93-
.add_match(RouteMapMatch::SrcVrf(p.remote_id.vrf_name()));
93+
.add_match(RouteMapMatch::SrcVrf(p.remote_id.vrf_name().to_string()));
9494
rmap.add_entry(entry);
9595
seq += 10;
9696

@@ -104,7 +104,7 @@ fn vpc_ipv4_import_configuration(vpc: &Vpc) -> (RouteMap, Vec<PrefixList>, Vec<S
104104
fn vpc_ipv4_imports(vpc: &Vpc) -> VrfImports {
105105
let mut imports = VrfImports::new().set_routemap(&vpc.import_route_map_ipv4());
106106
for p in vpc.peerings.iter() {
107-
imports.add_vrf(&p.remote_id.vrf_name());
107+
imports.add_vrf(p.remote_id.vrf_name().as_ref());
108108
}
109109
imports
110110
}

mgmt/src/processor/namegen.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
#![allow(unused)]
77

88
use crate::models::external::overlay::vpc::{Vpc, VpcId};
9+
use net::interface::InterfaceName;
910

1011
impl VpcId {
11-
pub(crate) fn vrf_name(&self) -> String {
12-
format!("{self}-vrf")
12+
pub(crate) fn vrf_name(&self) -> InterfaceName {
13+
InterfaceName::try_from(format!("{self}-vrf")).unwrap_or_else(|_| unreachable!())
1314
}
14-
pub(crate) fn bridge_name(&self) -> String {
15-
format!("{self}-bri")
15+
pub(crate) fn bridge_name(&self) -> InterfaceName {
16+
InterfaceName::try_from(format!("{self}-bri")).unwrap_or_else(|_| unreachable!())
1617
}
17-
pub(crate) fn vtep_name(&self) -> String {
18-
format!("{self}-vtp")
18+
pub(crate) fn vtep_name(&self) -> InterfaceName {
19+
InterfaceName::try_from(format!("{self}-vtp")).unwrap_or_else(|_| unreachable!())
1920
}
2021
}
2122

2223
impl Vpc {
2324
pub(crate) fn vrf_name(&self) -> String {
24-
self.id.vrf_name()
25+
self.id.vrf_name().to_string()
2526
}
2627
pub(crate) fn import_route_map_ipv4(&self) -> String {
2728
format!("RM-IMPORT-{}", self.name.to_uppercase())

0 commit comments

Comments
 (0)