Skip to content

Commit c606b75

Browse files
committed
feat(mgmt): switch to RouteTableId
We need to unify some basic types between vpc/interface manager and the mgmt crate in order to integrate them properly. This commit switches the unchecked `u32` into a `RouteTableId` in order to make that process easier. Signed-off-by: Daniel Noland <daniel@githedgehog.com>
1 parent e77cfc9 commit c606b75

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mgmt/src/models/internal/routing/vrf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
//! Dataplane configuration model: VRFs
55
6-
use std::collections::BTreeSet;
7-
86
use crate::models::internal::{InterfaceConfig, InterfaceConfigTable};
7+
use net::route::RouteTableId;
98
use net::vxlan::Vni;
109
use routing::prefix::Prefix;
10+
use std::collections::BTreeSet;
1111

1212
use super::bgp::BgpConfig;
1313
use super::ospf::Ospf;
@@ -18,7 +18,7 @@ use super::statics::StaticRoute;
1818
pub struct VrfConfig {
1919
pub name: String,
2020
pub default: bool,
21-
pub tableid: Option<u32>,
21+
pub tableid: Option<RouteTableId>,
2222
pub vni: Option<Vni>,
2323
pub subnets: BTreeSet<Prefix>,
2424
pub static_routes: BTreeSet<StaticRoute>,
@@ -53,7 +53,7 @@ impl VrfConfig {
5353
..Default::default()
5454
}
5555
}
56-
pub fn set_table_id(mut self, tableid: u32) -> Self {
56+
pub fn set_table_id(mut self, tableid: RouteTableId) -> Self {
5757
if self.default {
5858
panic!("Can't set table id for default vrf");
5959
}

mgmt/src/processor/confbuild.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#[allow(unused)]
55
use tracing::{debug, error, warn};
66

7+
use net::route::RouteTableId;
78
use routing::prefix::Prefix;
89
use std::net::Ipv4Addr;
910

@@ -156,7 +157,8 @@ fn vpc_vrf_config(vpc: &Vpc, asn: u32, router_id: Option<Ipv4Addr>) -> VrfConfig
156157
/* set table-id: table ids should be unique per VRF. We should track them and pick unused ones.
157158
Setting this to the VNI is not too bad atm, except that we should avoid picking reserved values
158159
which may cause internal failures. FIXME: fredi */
159-
vrf_cfg = vrf_cfg.set_table_id(vpc.vni.as_u32());
160+
// TODO: we can't just unwrap here
161+
vrf_cfg = vrf_cfg.set_table_id(RouteTableId::try_from(vpc.vni.as_u32()).unwrap());
160162

161163
/* build BGP config for vrf */
162164
vrf_cfg.set_bgp(vpc_vrf_bgp_config(vpc, asn, router_id));

0 commit comments

Comments
 (0)