diff options
-rw-r--r-- | src/blocking.rs | 2 | ||||
-rw-r--r-- | src/route.rs | 92 |
2 files changed, 94 insertions, 0 deletions
diff --git a/src/blocking.rs b/src/blocking.rs index 04b15c8..066ffe0 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -105,6 +105,8 @@ pub mod route { blockify!(route_flush, link: String); blockify!(route_add4, r: Route4); blockify!(route_add6, r: Route6); + blockify!(route_del4, r: Route4); + blockify!(route_del6, r: Route6); } } diff --git a/src/route.rs b/src/route.rs index b1728cd..72fa177 100644 --- a/src/route.rs +++ b/src/route.rs @@ -228,4 +228,96 @@ impl Connection { add.execute().await?; Ok(()) } + + /// Deletes a simple IPv4 route with an optional gateway. + pub async fn route_del4(&self, r: Route4) -> Result<()> { + let link = self + .handle() + .link() + .get() + .match_name(r.link.clone()) + .execute() + .try_next() + .await? + .ok_or(Error::LinkNotFound(r.link))?; + + let id = link.header.index; + + let mut add = self + .handle() + .route() + .add() + .v4() + .destination_prefix(r.dst, r.prefix_len) + .output_interface(id); + + if let Some(rtr) = r.rtr { + add = add.gateway(rtr); + } + + if r.on_link { + add = add.scope(RouteScope::Link); + } + + if let Some(table) = r.table { + add = add.table_id(table); + } + + if let Some(metric) = r.metric { + add = add.priority(metric); + } + + self.handle() + .route() + .del(add.message_mut().clone()) + .execute() + .await?; + Ok(()) + } + + /// Deletes a simple IPv6 route with an optional gateway. + pub async fn route_del6(&self, r: Route6) -> Result<()> { + let link = self + .handle() + .link() + .get() + .match_name(r.link.clone()) + .execute() + .try_next() + .await? + .ok_or(Error::LinkNotFound(r.link))?; + + let id = link.header.index; + + let mut add = self + .handle() + .route() + .add() + .v6() + .destination_prefix(r.dst, r.prefix_len) + .output_interface(id); + + if let Some(rtr) = r.rtr { + add = add.gateway(rtr); + } + + if r.on_link { + add = add.scope(RouteScope::Link); + } + + if let Some(table) = r.table { + add = add.table_id(table); + } + + if let Some(metric) = r.metric { + add = add.priority(metric); + } + + self.handle() + .route() + .del(add.message_mut().clone()) + .execute() + .await?; + Ok(()) + } } |