@@ -4,8 +4,10 @@ use netlink_packet_utils::nla::NlaBuffer;
4
4
use netlink_packet_utils:: { Emitable , Parseable } ;
5
5
6
6
use crate :: tc:: {
7
- TcActionGeneric , TcActionGenericBuffer , TcActionMirrorOption , TcActionType ,
8
- TcMirror , TcMirrorActionType , TcMirrorBuffer ,
7
+ TcAction , TcActionAttribute , TcActionGeneric , TcActionGenericBuffer ,
8
+ TcActionMirrorOption , TcActionOption , TcActionType , TcMirror ,
9
+ TcMirrorActionType , TcMirrorBuffer , TcStats2 , TcStatsBasic , TcStatsQueue ,
10
+ Tcf ,
9
11
} ;
10
12
11
13
#[ test]
@@ -64,22 +66,76 @@ fn tc_mirror_example_parse_back() {
64
66
assert_eq ! ( orig, parsed) ;
65
67
}
66
68
69
+ // > act actions add action mirred egress redirect dev veth1
70
+ // > tools/nl_dump.py dump_actions mirred
71
+ // Note: 5.15 and 6.8 kernels do NOT set NLA_F_NESTED for TCA_ACT_OPTIONS
72
+ //
67
73
#[ test]
68
- fn tc_mirror_tm_default_parse_back ( ) {
69
- let mirror_option = TcActionMirrorOption :: Tm ( vec ! [ ] ) ;
70
- let mut buffer = vec ! [ 0 ; mirror_option. buffer_len( ) ] ;
71
- mirror_option. emit ( & mut buffer) ;
72
- let nla_buf = NlaBuffer :: new_checked ( & buffer) . unwrap ( ) ;
73
- let parsed = TcActionMirrorOption :: parse ( & nla_buf) . unwrap ( ) ;
74
- assert_eq ! ( mirror_option, parsed) ;
75
- }
74
+ fn get_mirred_eggress_redirect_action ( ) {
75
+ let raw = vec ! [
76
+ 0x9C , 0x00 , 0x00 , 0x00 , 0x0B , 0x00 , 0x01 , 0x00 , 0x6D , 0x69 , 0x72 , 0x72 ,
77
+ 0x65 , 0x64 , 0x00 , 0x00 , 0x44 , 0x00 , 0x04 , 0x00 , 0x14 , 0x00 , 0x01 , 0x00 ,
78
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
79
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x14 , 0x00 , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
80
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
81
+ 0x18 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
82
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
83
+ 0x48 , 0x00 , 0x02 , 0x80 , 0x20 , 0x00 , 0x02 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 ,
84
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 ,
85
+ 0x02 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 ,
86
+ 0x24 , 0x00 , 0x01 , 0x00 , 0x68 , 0x3D , 0xB6 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 ,
87
+ 0x68 , 0x3D , 0xB6 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
88
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
89
+ ] ;
76
90
77
- #[ test]
78
- fn tc_mirror_tm_example_parse_back ( ) {
79
- let mirror_option = TcActionMirrorOption :: Tm ( vec ! [ 1 , 2 , 3 ] ) ;
80
- let mut buffer = vec ! [ 0 ; mirror_option. buffer_len( ) ] ;
81
- mirror_option. emit ( & mut buffer) ;
82
- let nla_buf = NlaBuffer :: new_checked ( & buffer) . unwrap ( ) ;
83
- let parsed = TcActionMirrorOption :: parse ( & nla_buf) . unwrap ( ) ;
84
- assert_eq ! ( mirror_option, parsed) ;
91
+ let expected = TcAction {
92
+ tab : 0 ,
93
+ attributes : vec ! [
94
+ TcActionAttribute :: Kind ( "mirred" . to_string( ) ) ,
95
+ TcActionAttribute :: Stats ( vec![
96
+ TcStats2 :: Basic ( TcStatsBasic {
97
+ bytes: 0 ,
98
+ packets: 0 ,
99
+ } ) ,
100
+ TcStats2 :: BasicHw ( TcStatsBasic {
101
+ bytes: 0 ,
102
+ packets: 0 ,
103
+ } ) ,
104
+ TcStats2 :: Queue ( TcStatsQueue {
105
+ qlen: 0 ,
106
+ backlog: 0 ,
107
+ drops: 0 ,
108
+ requeues: 0 ,
109
+ overlimits: 0 ,
110
+ } ) ,
111
+ ] ) ,
112
+ TcActionAttribute :: Options ( vec![
113
+ TcActionOption :: Mirror ( TcActionMirrorOption :: Parms ( TcMirror {
114
+ generic: TcActionGeneric {
115
+ index: 1 ,
116
+ capab: 0 ,
117
+ action: TcActionType :: Ok ,
118
+ refcnt: 2 ,
119
+ bindcnt: 2 ,
120
+ } ,
121
+ eaction: TcMirrorActionType :: EgressRedir ,
122
+ ifindex: 3 ,
123
+ } ) ) ,
124
+ TcActionOption :: Mirror ( TcActionMirrorOption :: Tm ( Tcf {
125
+ install: 45497704 ,
126
+ lastuse: 45497704 ,
127
+ expires: 0 ,
128
+ firstuse: 0 ,
129
+ } ) ) ,
130
+ ] ) ,
131
+ ] ,
132
+ } ;
133
+
134
+ assert_eq ! ( expected, TcAction :: parse( & NlaBuffer :: new( & raw) ) . unwrap( ) ) ;
135
+
136
+ let mut buf = vec ! [ 0 ; expected. buffer_len( ) ] ;
137
+
138
+ expected. emit ( & mut buf) ;
139
+
140
+ assert_eq ! ( buf, raw) ;
85
141
}
0 commit comments