summaryrefslogtreecommitdiffstats
path: root/testsuite/tests/tc/pedit.t
blob: 8d531a054367d934c30d24a62323db327e9e6c47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/sh

. lib/generic.sh

DEV="$(rand_dev)"
ts_ip "$0" "Add $DEV dummy interface" link add dev $DEV type dummy
ts_ip "$0" "Enable $DEV" link set $DEV up
ts_tc "pedit" "Add ingress qdisc" qdisc add dev $DEV ingress


do_pedit() {
	ts_tc "pedit" "Drop ingress qdisc" \
		qdisc del dev $DEV ingress
	ts_tc "pedit" "Add ingress qdisc" \
		qdisc add dev $DEV ingress
	ts_tc "pedit" "Add pedit action $*" \
		filter add dev $DEV parent ffff: \
		u32 match u32 0 0 \
		action pedit munge $@
	ts_tc "pedit" "Show ingress filters" \
		filter show dev $DEV parent ffff:
}

do_pedit offset 12 u32 set 0x12345678
test_on "key #0  at 12: val 12345678 mask 00000000"
do_pedit offset 12 u16 set 0x1234
test_on "key #0  at 12: val 12340000 mask 0000ffff"
do_pedit offset 14 u16 set 0x1234
test_on "key #0  at 12: val 00001234 mask ffff0000"
do_pedit offset 12 u8 set 0x23
test_on "key #0  at 12: val 23000000 mask 00ffffff"
do_pedit offset 13 u8 set 0x23
test_on "key #0  at 12: val 00230000 mask ff00ffff"
do_pedit offset 14 u8 set 0x23
test_on "key #0  at 12: val 00002300 mask ffff00ff"
do_pedit offset 15 u8 set 0x23
test_on "key #0  at 12: val 00000023 mask ffffff00"

do_pedit offset 13 u8 invert
test_on "key #0  at 12: val 00ff0000 mask ffffffff"
do_pedit offset 13 u8 clear
test_on "key #0  at 12: val 00000000 mask ff00ffff"
do_pedit offset 13 u8 preserve
test_on "key #0  at 12: val 00000000 mask ffffffff"

# the following set of tests has been auto-generated by running this little
# shell script:
#
# do_it() {
#	echo "do_pedit $@"
#	tc qd del dev veth0 ingress >/dev/null 2>&1
#	tc qd add dev veth0 ingress >/dev/null 2>&1
#	tc filter add dev veth0 parent ffff: u32 \
#		match u32 0 0 \
#		action pedit munge $@ >/dev/null 2>&1
#	tc filter show dev veth0 parent ffff: | \
#		sed -n 's/^[\t ]*\(key #0.*\)/test_on "\1"/p'
# }
#
# do_it_all() { # (field, val1 [, val2, ...])
#	local field=$1
#	shift
#	for val in $@; do
#		do_it ip $field set $val
#	done
#	for i in preserve invert clear; do
#		do_it ip $field $i
#	done
# }
#
# do_it_all ihl 0x04 0x40
# do_it_all src 1.2.3.4
# do_it_all dst 1.2.3.4
# do_it_all tos 0x1 0x10
# do_it_all protocol 0x23
# do_it_all nofrag 0x23 0xf4
# do_it_all firstfrag 0x03 0xfa
# do_it_all ce 0x23 0x04 0xf3
# do_it_all df 0x23 0x04 0xf3
# do_it_all mf 0x23 0x04 0xf3
# do_it_all dport 0x1234
# do_it_all sport 0x1234
# do_it_all icmp_type 0x23
# do_it_all icmp_code 0x23

do_pedit ip ihl set 0x04
test_on "key #0  at 0: val 04000000 mask f0ffffff"
do_pedit ip ihl set 0x40
test_on "key #0  at 0: val 00000000 mask f0ffffff"
do_pedit ip ihl preserve
test_on "key #0  at 0: val 00000000 mask ffffffff"
do_pedit ip ihl invert
test_on "key #0  at 0: val 0f000000 mask ffffffff"
do_pedit ip ihl clear
test_on "key #0  at 0: val 00000000 mask f0ffffff"
do_pedit ip src set 1.2.3.4
test_on "key #0  at 12: val 01020304 mask 00000000"
do_pedit ip src preserve
test_on "key #0  at 12: val 00000000 mask ffffffff"
do_pedit ip src invert
test_on "key #0  at 12: val ffffffff mask ffffffff"
do_pedit ip src clear
test_on "key #0  at 12: val 00000000 mask 00000000"
do_pedit ip dst set 1.2.3.4
test_on "key #0  at 16: val 01020304 mask 00000000"
do_pedit ip dst preserve
test_on "key #0  at 16: val 00000000 mask ffffffff"
do_pedit ip dst invert
test_on "key #0  at 16: val ffffffff mask ffffffff"
do_pedit ip dst clear
test_on "key #0  at 16: val 00000000 mask 00000000"
do_pedit ip tos set 0x1
test_on "key #0  at 0: val 00010000 mask ff00ffff"
do_pedit ip tos set 0x10
test_on "key #0  at 0: val 00100000 mask ff00ffff"
do_pedit ip tos preserve
test_on "key #0  at 0: val 00000000 mask ffffffff"
do_pedit ip tos invert
test_on "key #0  at 0: val 00ff0000 mask ffffffff"
do_pedit ip tos clear
test_on "key #0  at 0: val 00000000 mask ff00ffff"
do_pedit ip protocol set 0x23
test_on "key #0  at 8: val 00230000 mask ff00ffff"
do_pedit ip protocol preserve
test_on "key #0  at 8: val 00000000 mask ffffffff"
do_pedit ip protocol invert
test_on "key #0  at 8: val 00ff0000 mask ffffffff"
do_pedit ip protocol clear
test_on "key #0  at 8: val 00000000 mask ff00ffff"
do_pedit ip nofrag set 0x23
test_on "key #0  at 4: val 00002300 mask ffffc0ff"
do_pedit ip nofrag set 0xf4
test_on "key #0  at 4: val 00003400 mask ffffc0ff"
do_pedit ip nofrag preserve
test_on "key #0  at 4: val 00000000 mask ffffffff"
do_pedit ip nofrag invert
test_on "key #0  at 4: val 00003f00 mask ffffffff"
do_pedit ip nofrag clear
test_on "key #0  at 4: val 00000000 mask ffffc0ff"
do_pedit ip firstfrag set 0x03
test_on "key #0  at 4: val 00000300 mask ffffe0ff"
do_pedit ip firstfrag set 0xfa
test_on "key #0  at 4: val 00001a00 mask ffffe0ff"
do_pedit ip firstfrag preserve
test_on "key #0  at 4: val 00000000 mask ffffffff"
do_pedit ip firstfrag invert
test_on "key #0  at 4: val 00001f00 mask ffffffff"
do_pedit ip firstfrag clear
test_on "key #0  at 4: val 00000000 mask ffffe0ff"
do_pedit ip ce set 0x23
test_on "key #0  at 4: val 00000000 mask ffff7fff"
do_pedit ip ce set 0x04
test_on "key #0  at 4: val 00000000 mask ffff7fff"
do_pedit ip ce set 0xf3
test_on "key #0  at 4: val 00008000 mask ffff7fff"
do_pedit ip ce preserve
test_on "key #0  at 4: val 00000000 mask ffffffff"
do_pedit ip ce invert
test_on "key #0  at 4: val 00008000 mask ffffffff"
do_pedit ip ce clear
test_on "key #0  at 4: val 00000000 mask ffff7fff"
do_pedit ip df set 0x23
test_on "key #0  at 4: val 00000000 mask ffffbfff"
do_pedit ip df set 0x04
test_on "key #0  at 4: val 00000000 mask ffffbfff"
do_pedit ip df set 0xf3
test_on "key #0  at 4: val 00004000 mask ffffbfff"
do_pedit ip df preserve
test_on "key #0  at 4: val 00000000 mask ffffffff"
do_pedit ip df invert
test_on "key #0  at 4: val 00004000 mask ffffffff"
do_pedit ip df clear
test_on "key #0  at 4: val 00000000 mask ffffbfff"
do_pedit ip mf set 0x23
test_on "key #0  at 4: val 00002000 mask ffffdfff"
do_pedit ip mf set 0x04
test_on "key #0  at 4: val 00000000 mask ffffdfff"
do_pedit ip mf set 0xf3
test_on "key #0  at 4: val 00002000 mask ffffdfff"
do_pedit ip mf preserve
test_on "key #0  at 4: val 00000000 mask ffffffff"
do_pedit ip mf invert
test_on "key #0  at 4: val 00002000 mask ffffffff"
do_pedit ip mf clear
test_on "key #0  at 4: val 00000000 mask ffffdfff"
do_pedit ip dport set 0x1234
test_on "key #0  at 20: val 00001234 mask ffff0000"
do_pedit ip dport preserve
test_on "key #0  at 20: val 00000000 mask ffffffff"
do_pedit ip dport invert
test_on "key #0  at 20: val 0000ffff mask ffffffff"
do_pedit ip dport clear
test_on "key #0  at 20: val 00000000 mask ffff0000"
do_pedit ip sport set 0x1234
test_on "key #0  at 20: val 12340000 mask 0000ffff"
do_pedit ip sport preserve
test_on "key #0  at 20: val 00000000 mask ffffffff"
do_pedit ip sport invert
test_on "key #0  at 20: val ffff0000 mask ffffffff"
do_pedit ip sport clear
test_on "key #0  at 20: val 00000000 mask 0000ffff"
do_pedit ip icmp_type set 0x23
test_on "key #0  at 20: val 23000000 mask 00ffffff"
do_pedit ip icmp_type preserve
test_on "key #0  at 20: val 00000000 mask ffffffff"
do_pedit ip icmp_type invert
test_on "key #0  at 20: val ff000000 mask ffffffff"
do_pedit ip icmp_type clear
test_on "key #0  at 20: val 00000000 mask 00ffffff"
do_pedit ip icmp_code set 0x23
test_on "key #0  at 20: val 23000000 mask 00ffffff"
do_pedit ip icmp_code preserve
test_on "key #0  at 20: val 00000000 mask ffffffff"
do_pedit ip icmp_code invert
test_on "key #0  at 20: val ff000000 mask ffffffff"
do_pedit ip icmp_code clear
test_on "key #0  at 20: val 00000000 mask 00ffffff"