@@ -7,7 +7,8 @@ use std::{
7
7
8
8
use netlink_packet_route:: {
9
9
route:: {
10
- RouteAddress , RouteAttribute , RouteFlags , RouteHeader , RouteMessage ,
10
+ MplsLabel , RouteAddress , RouteAttribute , RouteFlags , RouteHeader ,
11
+ RouteLwEnCapType , RouteLwTunnelEncap , RouteMessage , RouteMplsIpTunnel ,
11
12
RouteProtocol , RouteScope , RouteType ,
12
13
} ,
13
14
AddressFamily ,
@@ -52,6 +53,29 @@ impl<T> RouteMessageBuilder<T> {
52
53
self
53
54
}
54
55
56
+ /// Sets the output MPLS encapsulation labels.
57
+ pub fn output_mpls ( mut self , labels : Vec < MplsLabel > ) -> Self {
58
+ if labels. is_empty ( ) {
59
+ return self ;
60
+ }
61
+ if self . message . header . address_family == AddressFamily :: Mpls {
62
+ self . message
63
+ . attributes
64
+ . push ( RouteAttribute :: NewDestination ( labels) ) ;
65
+ } else {
66
+ self . message
67
+ . attributes
68
+ . push ( RouteAttribute :: EncapType ( RouteLwEnCapType :: Mpls ) ) ;
69
+ let encap = RouteLwTunnelEncap :: Mpls (
70
+ RouteMplsIpTunnel :: Destination ( labels) ,
71
+ ) ;
72
+ self . message
73
+ . attributes
74
+ . push ( RouteAttribute :: Encap ( vec ! [ encap] ) ) ;
75
+ }
76
+ self
77
+ }
78
+
55
79
/// Sets the route priority (metric)
56
80
pub fn priority ( mut self , priority : u32 ) -> Self {
57
81
self . message
@@ -402,3 +426,44 @@ impl Default for RouteMessageBuilder<IpAddr> {
402
426
Self :: new ( )
403
427
}
404
428
}
429
+
430
+ impl RouteMessageBuilder < MplsLabel > {
431
+ /// Create default RouteMessage with header set to:
432
+ /// * route: [RouteHeader::RT_TABLE_MAIN]
433
+ /// * protocol: [RouteProtocol::Static]
434
+ /// * scope: [RouteScope::Universe]
435
+ /// * kind: [RouteType::Unicast]
436
+ /// * address_family: [AddressFamily::Mpls]
437
+ ///
438
+ /// For using this message in querying routes, these settings
439
+ /// are ignored unless `NETLINK_GET_STRICT_CHK` been enabled.
440
+ pub fn new ( ) -> Self {
441
+ let mut builder = Self :: new_no_address_family ( ) ;
442
+ builder. get_mut ( ) . header . address_family = AddressFamily :: Mpls ;
443
+ builder
444
+ }
445
+
446
+ /// Sets the destination MPLS label.
447
+ pub fn label ( mut self , label : MplsLabel ) -> Self {
448
+ self . message . header . address_family = AddressFamily :: Mpls ;
449
+ self . message . header . destination_prefix_length = 20 ;
450
+ self . message
451
+ . attributes
452
+ . push ( RouteAttribute :: Destination ( RouteAddress :: Mpls ( label) ) ) ;
453
+ self
454
+ }
455
+
456
+ /// Sets the gateway (via) address.
457
+ pub fn via ( mut self , addr : IpAddr ) -> Self {
458
+ self . message
459
+ . attributes
460
+ . push ( RouteAttribute :: Via ( addr. into ( ) ) ) ;
461
+ self
462
+ }
463
+ }
464
+
465
+ impl Default for RouteMessageBuilder < MplsLabel > {
466
+ fn default ( ) -> Self {
467
+ Self :: new ( )
468
+ }
469
+ }
0 commit comments