@@ -8,14 +8,13 @@ use std::{
8
8
sync:: LazyLock ,
9
9
} ;
10
10
11
- use nested_enum_utils:: common_fields;
12
- use snafu:: { Backtrace , IntoError , OptionExt , Snafu } ;
13
-
14
11
use libc:: { c_int, uintptr_t, AF_INET , AF_INET6 , AF_LINK , AF_ROUTE , AF_UNSPEC , CTL_NET } ;
15
12
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
16
13
use libc:: {
17
14
NET_RT_DUMP , RTAX_BRD , RTAX_DST , RTAX_GATEWAY , RTAX_MAX , RTAX_NETMASK , RTA_IFP , RTF_GATEWAY ,
18
15
} ;
16
+ use nested_enum_utils:: common_fields;
17
+ use snafu:: { Backtrace , IntoError , OptionExt , Snafu } ;
19
18
use tracing:: warn;
20
19
21
20
use super :: DefaultRouteDetails ;
@@ -409,7 +408,7 @@ impl WireFormat {
409
408
continue ;
410
409
}
411
410
name = std:: str:: from_utf8 ( & data[ 6 ..6 + i] )
412
- . map_err ( |_| RouteError :: InvalidAddress ) ?
411
+ . map_err ( |_| InvalidAddressSnafu . build ( ) ) ?
413
412
. to_string ( ) ;
414
413
break ;
415
414
}
@@ -447,9 +446,7 @@ struct RoutingStack {
447
446
448
447
/// Parses b as a routing information base and returns a list of routing messages.
449
448
pub fn parse_rib ( typ : RIBType , data : & [ u8 ] ) -> Result < Vec < WireMessage > , RouteError > {
450
- if !is_valid_rib_type ( typ) {
451
- return Err ( RouteError :: InvalidRibType ( typ) ) ;
452
- }
449
+ snafu:: ensure!( is_valid_rib_type( typ) , InvalidRibTypeSnafu ( typ) ) ;
453
450
454
451
let mut msgs = Vec :: new ( ) ;
455
452
let mut nmsgs = 0 ;
@@ -796,9 +793,7 @@ where
796
793
let a = parse_default_addr ( b) ?;
797
794
addrs. push ( a) ;
798
795
let l = roundup ( b[ 0 ] as usize ) ;
799
- if b. len ( ) < l {
800
- return Err ( RouteError :: MessageTooShort ) ;
801
- }
796
+ snafu:: ensure!( b. len( ) >= l, MessageTooShortSnafu ) ;
802
797
b = & b[ l..] ;
803
798
}
804
799
}
@@ -850,7 +845,7 @@ fn parse_inet_addr(af: i32, b: &[u8]) -> Result<Addr, RouteError> {
850
845
zone,
851
846
} )
852
847
}
853
- _ => Err ( RouteError :: InvalidAddress ) ,
848
+ _ => Err ( InvalidAddressSnafu . build ( ) ) ,
854
849
}
855
850
}
856
851
0 commit comments