1
1
use crate :: tc:: filters:: cls_flower:: TCA_FLOWER_KEY_MPLS_OPTS ;
2
- use anyhow:: Error ;
3
2
use netlink_packet_utils:: nla:: {
4
3
DefaultNla , Nla , NlaBuffer , NlasIterator , NLA_F_NESTED ,
5
4
} ;
6
5
use netlink_packet_utils:: parsers:: { parse_u32, parse_u8} ;
7
6
use netlink_packet_utils:: { DecodeError , Emitable , Parseable } ;
8
7
9
- // The "bottom of stack" flag is only a single bit wide.
10
- // For this reason, we can get away without marking this as non-exhaustive.
11
- // It is represented as `u8` in the netlink message.
12
- // I take this to mean that it functions like a c boolean and that any non-zero
13
- // value is `Set`. I
14
- /// Bottom of stack flag.
15
- ///
16
- /// The "bottom of stack" flag is only a single bit wide.
17
- /// For this reason, we can get away without marking this as non-exhaustive.
18
- /// It is represented as `u8` in the netlink message.
19
- /// I take this to mean that it functions like a c boolean and that any non-zero
20
- /// value is `Set`.
21
- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Ord , PartialOrd , Hash ) ]
22
- #[ repr( u8 ) ]
23
- pub enum BottomOfStack {
24
- Unset = 0 ,
25
- Set = 1 ,
26
- }
27
-
28
- impl From < u8 > for BottomOfStack {
29
- fn from ( bos : u8 ) -> Self {
30
- match bos {
31
- 0 => BottomOfStack :: Unset ,
32
- 1 => BottomOfStack :: Set ,
33
- _ => {
34
- log:: warn!(
35
- "Invalid BottomOfStack value: {}, interpreting as Set" ,
36
- bos
37
- ) ;
38
- BottomOfStack :: Set
39
- }
40
- }
41
- }
42
- }
43
-
44
- impl From < BottomOfStack > for u8 {
45
- fn from ( value : BottomOfStack ) -> Self {
46
- value as u8
47
- }
48
- }
49
-
50
-
51
- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Ord , PartialOrd , Hash ) ]
52
- #[ repr( transparent) ]
53
- pub struct Label ( u32 ) ;
54
-
55
- /// TODO: should we add handling for reserved labels as per [RFC 3032][1] (see
56
- /// page 4)?
57
- ///
58
- /// [1]: https://www.iana.org/assignments/mpls-label-values/mpls-label-values.xhtml
59
- impl Label {
60
- pub fn try_new ( label : u32 ) -> Result < Self , Error > {
61
- if label > 0xFFFFF {
62
- Err ( Error :: msg ( "MPLS label must be less than 0xFFFFF" ) ) ?
63
- }
64
- Ok ( Self ( label) )
65
- }
66
- }
67
-
68
- impl TryFrom < u32 > for Label {
69
- type Error = Error ;
70
-
71
- fn try_from ( label : u32 ) -> Result < Self , Self :: Error > {
72
- Self :: try_new ( label)
73
- }
74
- }
75
-
76
- impl From < Label > for u32 {
77
- fn from ( label : Label ) -> u32 {
78
- label. 0
79
- }
80
- }
8
+ use crate :: net:: mpls;
81
9
82
10
#[ derive( Debug , PartialEq , Eq , Clone ) ]
83
11
#[ non_exhaustive]
@@ -90,9 +18,9 @@ pub enum Options {
90
18
#[ non_exhaustive]
91
19
pub enum LseOptions {
92
20
Depth ( u8 ) ,
93
- Label ( Label ) ,
21
+ Label ( mpls :: Label ) ,
94
22
TrafficClass ( u8 ) ,
95
- BottomOfStack ( BottomOfStack ) ,
23
+ BottomOfStack ( mpls :: BottomOfStack ) ,
96
24
Ttl ( u8 ) ,
97
25
}
98
26
@@ -200,13 +128,13 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for LseOptions {
200
128
}
201
129
TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL => Self :: Ttl ( parse_u8 ( payload) ?) ,
202
130
TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS => {
203
- Self :: BottomOfStack ( BottomOfStack :: from ( parse_u8 ( payload) ?) )
131
+ Self :: BottomOfStack ( mpls :: BottomOfStack :: from ( parse_u8 ( payload) ?) )
204
132
}
205
133
TCA_FLOWER_KEY_MPLS_OPT_LSE_TC => {
206
134
Self :: TrafficClass ( parse_u8 ( payload) ?)
207
135
}
208
136
TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL => {
209
- Self :: Label ( Label :: try_from ( parse_u32 ( payload) ?) ?)
137
+ Self :: Label ( mpls :: Label :: try_from ( parse_u32 ( payload) ?) ?)
210
138
}
211
139
_ => Err ( DecodeError :: from ( "invalid mpls option kind" ) ) ?,
212
140
} )
0 commit comments