From f2fc0ddcd78525dc32641d6c03483f2310399f6e Mon Sep 17 00:00:00 2001 From: Ryan Goodfellow Date: Mon, 8 Jan 2024 19:58:00 -0800 Subject: [PATCH] ensure underlay origin when originating teps --- mg-lower/src/ddm.rs | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/mg-lower/src/ddm.rs b/mg-lower/src/ddm.rs index b8afa41e..ef557761 100644 --- a/mg-lower/src/ddm.rs +++ b/mg-lower/src/ddm.rs @@ -2,11 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use ddm_admin_client::{Client, TunnelOrigin}; +use ddm_admin_client::{Client, Ipv6Prefix, TunnelOrigin}; use rdb::Route4ImportKey; use slog::{error, Logger}; use std::{collections::HashSet, net::Ipv6Addr, sync::Arc}; +const BOUNDARY_SERVICES_VNI: u32 = 99; + pub(crate) fn update_tunnel_endpoints( tep: Ipv6Addr, // tunnel endpoint address client: &Client, @@ -33,11 +35,41 @@ pub(crate) fn update_tunnel_endpoints( let to_add = target.difference(¤t); let to_remove = current.difference(&target); - add_tunnel_endpoints(client, to_add.into_iter(), &rt, log); + add_tunnel_endpoints(tep, client, to_add.into_iter(), &rt, log); remove_tunnel_endpoints(client, to_remove.into_iter(), &rt, log); } -const BOUNDARY_SERVICES_VNI: u32 = 99; +fn ensure_tep_underlay_origin( + client: &Client, + tep: Ipv6Addr, + rt: &Arc, + log: &Logger, +) { + let current: Vec = match rt + .block_on(async { client.get_originated().await }) + .map(|x| x.into_inner()) + { + Ok(x) => x, + Err(e) => { + error!(log, "get originated endpoints: {e}"); + return; + } + } + .into_iter() + .collect(); + + let target = Ipv6Prefix { addr: tep, len: 64 }; + + if current.contains(&target) { + return; + } + + if let Err(e) = + rt.block_on(async { client.advertise_prefixes(&vec![target]).await }) + { + error!(log, "get originated endpoints: {e}"); + }; +} fn route_to_tunnel(tep: Ipv6Addr, x: &Route4ImportKey) -> TunnelOrigin { TunnelOrigin { @@ -61,15 +93,17 @@ pub(crate) fn add_tunnel_routes( ) { let teps: Vec = routes.iter().map(|x| route_to_tunnel(tep, x)).collect(); - add_tunnel_endpoints(client, teps.iter(), &rt, log) + add_tunnel_endpoints(tep, client, teps.iter(), &rt, log) } pub(crate) fn add_tunnel_endpoints<'a, I: Iterator>( + tep: Ipv6Addr, // tunnel endpoint address client: &Client, routes: I, rt: &Arc, log: &Logger, ) { + ensure_tep_underlay_origin(client, tep, rt, log); let routes = routes.cloned().collect(); let resp = rt.block_on(async { client.advertise_tunnel_endpoints(&routes).await });