Skip to content

Commit

Permalink
ensure underlay origin when originating teps
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Jan 9, 2024
1 parent 534c0bb commit f2fc0dd
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions mg-lower/src/ddm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,11 +35,41 @@ pub(crate) fn update_tunnel_endpoints(
let to_add = target.difference(&current);
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<tokio::runtime::Handle>,
log: &Logger,
) {
let current: Vec<Ipv6Prefix> = 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 {
Expand All @@ -61,15 +93,17 @@ pub(crate) fn add_tunnel_routes(
) {
let teps: Vec<TunnelOrigin> =
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<Item = &'a TunnelOrigin>>(
tep: Ipv6Addr, // tunnel endpoint address
client: &Client,
routes: I,
rt: &Arc<tokio::runtime::Handle>,
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 });
Expand Down

0 comments on commit f2fc0dd

Please sign in to comment.