Bläddra i källkod

route: add remove_default_ipvX_route

Dario Nieuwenhuis 4 år sedan
förälder
incheckning
22e4c65f58
1 ändrade filer med 18 tillägg och 0 borttagningar
  1. 18 0
      src/iface/route.rs

+ 18 - 0
src/iface/route.rs

@@ -106,6 +106,24 @@ impl<'a> Routes<'a> {
         }
     }
 
+    /// Remove the default ipv4 gateway
+    ///
+    /// On success, returns the previous default route, if any.
+    #[cfg(feature = "proto-ipv4")]
+    pub fn remove_default_ipv4_route(&mut self) -> Option<Route> {
+        let cidr = IpCidr::new(IpAddress::v4(0, 0, 0, 0), 0);
+        self.storage.remove(&cidr)
+    }
+
+    /// Remove the default ipv6 gateway
+    ///
+    /// On success, returns the previous default route, if any.
+    #[cfg(feature = "proto-ipv6")]
+    pub fn remove_default_ipv6_route(&mut self) -> Option<Route> {
+        let cidr = IpCidr::new(IpAddress::v6(0, 0, 0, 0, 0, 0, 0, 0), 0);
+        self.storage.remove(&cidr)
+    }
+
     pub(crate) fn lookup(&self, addr: &IpAddress, timestamp: Instant) ->
             Option<IpAddress> {
         assert!(addr.is_unicast());