@@ -211,6 +211,14 @@ impl RouteMessageBuilder<Ipv4Addr> {
211
211
. push ( RouteAttribute :: Gateway ( RouteAddress :: Inet ( addr) ) ) ;
212
212
self
213
213
}
214
+
215
+ /// Sets the IPv6 gateway (via) address.
216
+ pub fn via ( mut self , addr : Ipv6Addr ) -> Self {
217
+ self . message
218
+ . attributes
219
+ . push ( RouteAttribute :: Via ( RouteVia :: Inet6 ( addr) ) ) ;
220
+ self
221
+ }
214
222
}
215
223
216
224
impl Default for RouteMessageBuilder < Ipv4Addr > {
@@ -403,25 +411,17 @@ impl RouteMessageBuilder<IpAddr> {
403
411
mut self ,
404
412
addr : IpAddr ,
405
413
) -> Result < Self , InvalidRouteMessage > {
406
- self . set_address_family_from_ip_addr ( addr) ;
407
- match self . message . header . address_family {
408
- AddressFamily :: Inet => {
409
- if addr. is_ipv6 ( ) {
410
- return Err ( InvalidRouteMessage :: Gateway ( addr) ) ;
411
- } ;
412
- }
413
- AddressFamily :: Inet6 => {
414
- if addr. is_ipv4 ( ) {
415
- return Err ( InvalidRouteMessage :: Gateway ( addr) ) ;
416
- } ;
414
+ let attr = match ( self . message . header . address_family , addr) {
415
+ ( AddressFamily :: Inet , addr @ IpAddr :: V4 ( _) )
416
+ | ( AddressFamily :: Inet6 , addr @ IpAddr :: V6 ( _) ) => {
417
+ RouteAttribute :: Gateway ( addr. into ( ) )
417
418
}
418
- af => {
419
- return Err ( InvalidRouteMessage :: AddressFamily ( af ) ) ;
419
+ ( AddressFamily :: Inet , IpAddr :: V6 ( v6 ) ) => {
420
+ RouteAttribute :: Via ( RouteVia :: Inet6 ( v6 ) )
420
421
}
421
- }
422
- self . message
423
- . attributes
424
- . push ( RouteAttribute :: Gateway ( addr. into ( ) ) ) ;
422
+ ( af, _) => return Err ( InvalidRouteMessage :: AddressFamily ( af) ) ,
423
+ } ;
424
+ self . message . attributes . push ( attr) ;
425
425
Ok ( self )
426
426
}
427
427
0 commit comments