Просмотр исходного кода

iface/route: use own error type.

Dario Nieuwenhuis 2 лет назад
Родитель
Сommit
e782ada6a0
2 измененных файлов с 15 добавлено и 6 удалено
  1. 1 1
      src/iface/mod.rs
  2. 14 5
      src/iface/route.rs

+ 1 - 1
src/iface/mod.rs

@@ -19,7 +19,7 @@ pub(crate) use self::neighbor::Answer as NeighborAnswer;
 pub use self::neighbor::Cache as NeighborCache;
 #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
 pub use self::neighbor::Neighbor;
-pub use self::route::{Route, Routes};
+pub use self::route::{Route, RouteTableFull, Routes};
 pub use socket_set::{SocketHandle, SocketSet, SocketStorage};
 
 #[cfg(any(feature = "proto-ipv4", feature = "proto-sixlowpan"))]

+ 14 - 5
src/iface/route.rs

@@ -6,10 +6,13 @@ use crate::wire::{IpAddress, IpCidr};
 use crate::wire::{Ipv4Address, Ipv4Cidr};
 #[cfg(feature = "proto-ipv6")]
 use crate::wire::{Ipv6Address, Ipv6Cidr};
-use crate::{Error, Result};
 
 pub const MAX_ROUTE_COUNT: usize = 4;
 
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+pub struct RouteTableFull;
+
 /// A prefix of addresses that should be routed via a router
 #[derive(Debug, Clone, Copy)]
 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -75,11 +78,14 @@ impl Routes {
     ///
     /// On success, returns the previous default route, if any.
     #[cfg(feature = "proto-ipv4")]
-    pub fn add_default_ipv4_route(&mut self, gateway: Ipv4Address) -> Result<Option<Route>> {
+    pub fn add_default_ipv4_route(
+        &mut self,
+        gateway: Ipv4Address,
+    ) -> Result<Option<Route>, RouteTableFull> {
         let old = self.remove_default_ipv4_route();
         self.storage
             .push(Route::new_ipv4_gateway(gateway))
-            .map_err(|_| Error::Exhausted)?;
+            .map_err(|_| RouteTableFull)?;
         Ok(old)
     }
 
@@ -87,11 +93,14 @@ impl Routes {
     ///
     /// On success, returns the previous default route, if any.
     #[cfg(feature = "proto-ipv6")]
-    pub fn add_default_ipv6_route(&mut self, gateway: Ipv6Address) -> Result<Option<Route>> {
+    pub fn add_default_ipv6_route(
+        &mut self,
+        gateway: Ipv6Address,
+    ) -> Result<Option<Route>, RouteTableFull> {
         let old = self.remove_default_ipv6_route();
         self.storage
             .push(Route::new_ipv6_gateway(gateway))
-            .map_err(|_| Error::Exhausted)?;
+            .map_err(|_| RouteTableFull)?;
         Ok(old)
     }