11use crate :: tc:: filters:: cls_flower:: TCA_FLOWER_KEY_MPLS_OPTS ;
2- use anyhow:: Error ;
32use netlink_packet_utils:: nla:: {
43 DefaultNla , Nla , NlaBuffer , NlasIterator , NLA_F_NESTED ,
54} ;
65use netlink_packet_utils:: parsers:: { parse_u32, parse_u8} ;
76use netlink_packet_utils:: { DecodeError , Emitable , Parseable } ;
87
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;
819
8210#[ derive( Debug , PartialEq , Eq , Clone ) ]
8311#[ non_exhaustive]
@@ -90,9 +18,9 @@ pub enum Options {
9018#[ non_exhaustive]
9119pub enum LseOptions {
9220 Depth ( u8 ) ,
93- Label ( Label ) ,
21+ Label ( mpls :: Label ) ,
9422 TrafficClass ( u8 ) ,
95- BottomOfStack ( BottomOfStack ) ,
23+ BottomOfStack ( mpls :: BottomOfStack ) ,
9624 Ttl ( u8 ) ,
9725}
9826
@@ -200,13 +128,13 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for LseOptions {
200128 }
201129 TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL => Self :: Ttl ( parse_u8 ( payload) ?) ,
202130 TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS => {
203- Self :: BottomOfStack ( BottomOfStack :: from ( parse_u8 ( payload) ?) )
131+ Self :: BottomOfStack ( mpls :: BottomOfStack :: from ( parse_u8 ( payload) ?) )
204132 }
205133 TCA_FLOWER_KEY_MPLS_OPT_LSE_TC => {
206134 Self :: TrafficClass ( parse_u8 ( payload) ?)
207135 }
208136 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) ?) ?)
210138 }
211139 _ => Err ( DecodeError :: from ( "invalid mpls option kind" ) ) ?,
212140 } )
0 commit comments