File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -351,27 +351,36 @@ async fn get_default_interface(
351351 ) )
352352 . await ?;
353353
354- let mut default_index = 0 ;
354+ let mut best_index = 0 ;
355+ let mut best_metric = u32:: MAX ;
355356
356357 recv_until_done ! ( sock, msg: Rtmsg => {
357358 if msg. rtm_type != Rtn :: Unicast {
358359 continue ;
359360 }
361+ // Only check default routes (rtm_dst_len == 0)
362+ if msg. rtm_dst_len != 0 {
363+ continue ;
364+ }
365+
360366 let mut index = None ;
361- let mut is_default = false ;
367+ let mut metric = 0u32 ;
362368 for attr in msg. rtattrs. iter( ) {
363369 match attr. rta_type {
364370 Rta :: Oif => index = Some ( attr. get_payload_as:: <i32 >( ) ?) ,
365- Rta :: Gateway => is_default = true ,
371+ Rta :: Priority => metric = attr . get_payload_as :: < u32 > ( ) ? ,
366372 _ => ( ) ,
367373 }
368374 }
369- if is_default && default_index == 0 {
370- default_index = index. unwrap( ) ;
375+ if let Some ( i) = index {
376+ if metric < best_metric {
377+ best_metric = metric;
378+ best_index = i;
379+ }
371380 }
372381 } ) ;
373382
374- Ok ( default_index )
383+ Ok ( best_index )
375384}
376385
377386async fn ip_payload < const BYTES : usize > (
You can’t perform that action at this time.
0 commit comments