@@ -8,7 +8,7 @@ use std::{
8
8
use netlink_packet_route:: {
9
9
route:: {
10
10
RouteAddress , RouteAttribute , RouteHeader , RouteMessage , RouteProtocol ,
11
- RouteScope , RouteType ,
11
+ RouteScope , RouteType , RouteVia ,
12
12
} ,
13
13
AddressFamily ,
14
14
} ;
@@ -159,6 +159,13 @@ impl RouteMessageBuilder<Ipv4Addr> {
159
159
. push ( RouteAttribute :: Gateway ( RouteAddress :: Inet ( addr) ) ) ;
160
160
self
161
161
}
162
+
163
+ pub fn gateway6 ( mut self , addr : Ipv6Addr ) -> Self {
164
+ self . message
165
+ . attributes
166
+ . push ( RouteAttribute :: Via ( RouteVia :: Inet6 ( addr) ) ) ;
167
+ self
168
+ }
162
169
}
163
170
164
171
impl Default for RouteMessageBuilder < Ipv4Addr > {
@@ -351,25 +358,15 @@ impl RouteMessageBuilder<IpAddr> {
351
358
mut self ,
352
359
addr : IpAddr ,
353
360
) -> Result < Self , InvalidRouteMessage > {
354
- self . set_address_family_from_ip_addr ( addr) ;
355
- match self . message . header . address_family {
356
- AddressFamily :: Inet => {
357
- if addr. is_ipv6 ( ) {
358
- return Err ( InvalidRouteMessage :: Gateway ( addr) ) ;
359
- } ;
361
+ use AddressFamily :: * ;
362
+ let attr = match ( self . message . header . address_family , addr) {
363
+ ( Inet , addr @ IpAddr :: V4 ( _) ) | ( Inet6 , addr @ IpAddr :: V6 ( _) ) => {
364
+ RouteAttribute :: Gateway ( addr. into ( ) )
360
365
}
361
- AddressFamily :: Inet6 => {
362
- if addr. is_ipv4 ( ) {
363
- return Err ( InvalidRouteMessage :: Gateway ( addr) ) ;
364
- } ;
365
- }
366
- af => {
367
- return Err ( InvalidRouteMessage :: AddressFamily ( af) ) ;
368
- }
369
- }
370
- self . message
371
- . attributes
372
- . push ( RouteAttribute :: Gateway ( addr. into ( ) ) ) ;
366
+ ( Inet , IpAddr :: V6 ( v6) ) => RouteAttribute :: Via ( RouteVia :: Inet6 ( v6) ) ,
367
+ ( af, _) => return Err ( InvalidRouteMessage :: AddressFamily ( af) ) ,
368
+ } ;
369
+ self . message . attributes . push ( attr) ;
373
370
Ok ( self )
374
371
}
375
372
0 commit comments