blob: f8d2b2a13131f48eaab6e300fa7876bd035ddab1 [file] [log] [blame]
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001/*
2 * Testsuite for BPF interpreter and BPF JIT compiler
3 *
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/filter.h>
21#include <linux/skbuff.h>
22#include <linux/netdevice.h>
23#include <linux/if_vlan.h>
24
Daniel Borkmann10f18e02014-05-23 18:44:00 +020025/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070026#define MAX_SUBTESTS 3
Daniel Borkmann10f18e02014-05-23 18:44:00 +020027#define MAX_TESTRUNS 10000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070028#define MAX_DATA 128
29#define MAX_INSNS 512
30#define MAX_K 0xffffFFFF
31
Daniel Borkmann10f18e02014-05-23 18:44:00 +020032/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070033#define SKB_TYPE 3
34#define SKB_MARK 0x1234aaaa
35#define SKB_HASH 0x1234aaab
36#define SKB_QUEUE_MAP 123
37#define SKB_VLAN_TCI 0xffff
38#define SKB_DEV_IFINDEX 577
39#define SKB_DEV_TYPE 588
40
Daniel Borkmann10f18e02014-05-23 18:44:00 +020041/* Redefine REGs to make tests less verbose */
42#define R0 BPF_REG_0
43#define R1 BPF_REG_1
44#define R2 BPF_REG_2
45#define R3 BPF_REG_3
46#define R4 BPF_REG_4
47#define R5 BPF_REG_5
48#define R6 BPF_REG_6
49#define R7 BPF_REG_7
50#define R8 BPF_REG_8
51#define R9 BPF_REG_9
52#define R10 BPF_REG_10
53
54/* Flags that can be passed to test cases */
55#define FLAG_NO_DATA BIT(0)
56#define FLAG_EXPECTED_FAIL BIT(1)
57
58enum {
59 CLASSIC = BIT(6), /* Old BPF instructions only. */
60 INTERNAL = BIT(7), /* Extended instruction set. */
61};
62
63#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070064
65struct bpf_test {
66 const char *descr;
67 union {
68 struct sock_filter insns[MAX_INSNS];
69 struct sock_filter_int insns_int[MAX_INSNS];
Andrew Mortonece80492014-05-22 10:16:46 -070070 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020071 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070072 __u8 data[MAX_DATA];
73 struct {
74 int data_size;
75 __u32 result;
76 } test[MAX_SUBTESTS];
77};
78
79static struct bpf_test tests[] = {
80 {
81 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -070082 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -070083 BPF_STMT(BPF_LD | BPF_IMM, 1),
84 BPF_STMT(BPF_MISC | BPF_TAX, 0),
85 BPF_STMT(BPF_LD | BPF_IMM, 2),
86 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
87 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
88 BPF_STMT(BPF_MISC | BPF_TAX, 0),
89 BPF_STMT(BPF_LD | BPF_LEN, 0),
90 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
91 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
92 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
93 BPF_STMT(BPF_RET | BPF_A, 0)
94 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +020095 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -070096 { 10, 20, 30, 40, 50 },
97 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
98 },
99 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700100 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700101 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700102 BPF_STMT(BPF_LDX | BPF_LEN, 0),
103 BPF_STMT(BPF_MISC | BPF_TXA, 0),
104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
105 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
106 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200107 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700108 { 10, 20, 30, 40, 50 },
109 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
110 },
111 {
112 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700113 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700114 BPF_STMT(BPF_LD | BPF_IMM, 1),
115 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
116 BPF_STMT(BPF_LDX | BPF_IMM, 3),
117 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
118 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
119 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
120 BPF_STMT(BPF_RET | BPF_A, 0)
121 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200122 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700123 { },
124 { { 0, 0xfffffffd } }
125 },
126 {
127 "DIV_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700128 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700129 BPF_STMT(BPF_LD | BPF_IMM, 8),
130 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
131 BPF_STMT(BPF_MISC | BPF_TAX, 0),
132 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
133 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
134 BPF_STMT(BPF_MISC | BPF_TAX, 0),
135 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
136 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
137 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
138 BPF_STMT(BPF_RET | BPF_A, 0)
139 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200140 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700141 { },
142 { { 0, 0x40000001 } }
143 },
144 {
145 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700146 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700147 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
148 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
149 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
150 BPF_STMT(BPF_MISC | BPF_TAX, 0),
151 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
152 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
153 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
154 BPF_STMT(BPF_RET | BPF_A, 0)
155 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200156 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700157 { },
158 { { 0, 0x800000ff }, { 1, 0x800000ff } },
159 },
160 {
161 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700162 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700163 BPF_STMT(BPF_LDX | BPF_LEN, 0),
164 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
165 BPF_STMT(BPF_RET | BPF_K, 1)
166 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200167 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700168 { },
169 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
170 },
171 {
172 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700173 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700174 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
175 BPF_STMT(BPF_RET | BPF_K, 1)
176 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200177 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700178 { },
179 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
180 },
181 {
182 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700183 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700184 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
185 BPF_STMT(BPF_MISC | BPF_TAX, 0),
186 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
187 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
188 BPF_STMT(BPF_RET | BPF_A, 0)
189 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200190 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700191 { 1, 2, 3 },
192 { { 1, 0 }, { 2, 3 } },
193 },
194 {
195 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700196 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700197 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
198 BPF_STMT(BPF_LDX | BPF_LEN, 0),
199 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
200 BPF_STMT(BPF_MISC | BPF_TAX, 0),
201 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
202 BPF_STMT(BPF_RET | BPF_A, 0)
203 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200204 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700205 { 1, 2, 3, 0xff },
206 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
207 },
208 {
209 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700210 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700211 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
212 BPF_STMT(BPF_MISC | BPF_TAX, 0),
213 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
214 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
215 BPF_STMT(BPF_RET | BPF_A, 0)
216 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200217 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700218 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
219 { { 15, 0 }, { 16, 3 } },
220 },
221 {
222 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700223 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700224 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
225 BPF_STMT(BPF_LDX | BPF_LEN, 0),
226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
227 BPF_STMT(BPF_MISC | BPF_TAX, 0),
228 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
229 BPF_STMT(BPF_RET | BPF_A, 0)
230 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200231 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700232 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
233 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
234 },
235 {
236 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700237 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700238 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
239 SKF_AD_OFF + SKF_AD_PKTTYPE),
240 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
241 BPF_STMT(BPF_RET | BPF_K, 1),
242 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
243 SKF_AD_OFF + SKF_AD_PKTTYPE),
244 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
245 BPF_STMT(BPF_RET | BPF_K, 1),
246 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
247 SKF_AD_OFF + SKF_AD_PKTTYPE),
248 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
249 BPF_STMT(BPF_RET | BPF_K, 1),
250 BPF_STMT(BPF_RET | BPF_A, 0)
251 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200252 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700253 { },
254 { { 1, 3 }, { 10, 3 } },
255 },
256 {
257 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700258 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700259 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
260 SKF_AD_OFF + SKF_AD_MARK),
261 BPF_STMT(BPF_RET | BPF_A, 0)
262 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200263 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700264 { },
265 { { 1, SKB_MARK}, { 10, SKB_MARK} },
266 },
267 {
268 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700269 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700270 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
271 SKF_AD_OFF + SKF_AD_RXHASH),
272 BPF_STMT(BPF_RET | BPF_A, 0)
273 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200274 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700275 { },
276 { { 1, SKB_HASH}, { 10, SKB_HASH} },
277 },
278 {
279 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700280 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700281 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
282 SKF_AD_OFF + SKF_AD_QUEUE),
283 BPF_STMT(BPF_RET | BPF_A, 0)
284 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200285 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700286 { },
287 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
288 },
289 {
290 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700291 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700292 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
293 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
294 BPF_STMT(BPF_RET | BPF_K, 0),
295 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
296 SKF_AD_OFF + SKF_AD_PROTOCOL),
297 BPF_STMT(BPF_MISC | BPF_TAX, 0),
298 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
299 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
300 BPF_STMT(BPF_RET | BPF_K, 0),
301 BPF_STMT(BPF_MISC | BPF_TXA, 0),
302 BPF_STMT(BPF_RET | BPF_A, 0)
303 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200304 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700305 { 10, 20, 30 },
306 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
307 },
308 {
309 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700310 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700311 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
312 SKF_AD_OFF + SKF_AD_VLAN_TAG),
313 BPF_STMT(BPF_RET | BPF_A, 0)
314 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200315 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700316 { },
317 {
318 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
319 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
320 },
321 },
322 {
323 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700324 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700325 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
326 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
327 BPF_STMT(BPF_RET | BPF_A, 0)
328 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200329 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700330 { },
331 {
332 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
333 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
334 },
335 },
336 {
337 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700338 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700339 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
340 SKF_AD_OFF + SKF_AD_IFINDEX),
341 BPF_STMT(BPF_RET | BPF_A, 0)
342 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200343 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700344 { },
345 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
346 },
347 {
348 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700349 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700350 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
351 SKF_AD_OFF + SKF_AD_HATYPE),
352 BPF_STMT(BPF_RET | BPF_A, 0)
353 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200354 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700355 { },
356 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
357 },
358 {
359 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700360 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700361 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
362 SKF_AD_OFF + SKF_AD_CPU),
363 BPF_STMT(BPF_MISC | BPF_TAX, 0),
364 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
365 SKF_AD_OFF + SKF_AD_CPU),
366 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
367 BPF_STMT(BPF_RET | BPF_A, 0)
368 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200369 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700370 { },
371 { { 1, 0 }, { 10, 0 } },
372 },
373 {
374 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700375 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700376 BPF_STMT(BPF_LDX | BPF_IMM, 1),
377 BPF_STMT(BPF_MISC | BPF_TXA, 0),
378 BPF_STMT(BPF_LDX | BPF_IMM, 3),
379 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
380 SKF_AD_OFF + SKF_AD_NLATTR),
381 BPF_STMT(BPF_RET | BPF_A, 0)
382 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200383 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700384 { 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
385 { { 4, 0 }, { 20, 5 } },
386 },
387 {
388 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700389 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700390 BPF_STMT(BPF_LD | BPF_IMM, 1),
391 BPF_STMT(BPF_LDX | BPF_IMM, 3),
392 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
393 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
394 BPF_STMT(BPF_LD | BPF_IMM, 1),
395 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
396 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
397 BPF_STMT(BPF_LD | BPF_IMM, 1),
398 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
399 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
400 BPF_STMT(BPF_LD | BPF_IMM, 1),
401 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
402 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
403 BPF_STMT(BPF_LD | BPF_IMM, 1),
404 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
405 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
406 BPF_STMT(BPF_LD | BPF_IMM, 1),
407 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
408 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
409 BPF_STMT(BPF_LD | BPF_IMM, 1),
410 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
411 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
412 BPF_STMT(BPF_LD | BPF_IMM, 1),
413 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
414 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
415 BPF_STMT(BPF_RET | BPF_A, 0)
416 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200417 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700418 { 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
419 { { 4, 0 }, { 20, 9 } },
420 },
421 {
422 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700423 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700424 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
425 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
426 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
427 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
428 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
429 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
430 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
431 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
432 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
433 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
434 BPF_STMT(BPF_RET | BPF_A, 0)
435 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200436 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700437 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
438 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
439 * id 9737, seq 1, length 64
440 */
441 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
443 0x08, 0x00,
444 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
445 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
446 { { 30, 0 }, { 100, 42 } },
447 },
448 {
449 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700450 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700451 BPF_STMT(BPF_LD | BPF_IMM, 10),
452 BPF_STMT(BPF_LDX | BPF_IMM, 300),
453 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
454 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
455 BPF_STMT(BPF_RET | BPF_A, 0)
456 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200457 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700458 { },
459 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
460 },
461 {
462 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700463 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700464 BPF_STMT(BPF_LDX | BPF_LEN, 0),
465 BPF_STMT(BPF_LD | BPF_IMM, 2),
466 BPF_STMT(BPF_ALU | BPF_RSH, 1),
467 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
468 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
469 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
470 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
471 BPF_STMT(BPF_STX, 15), /* M3 = len */
472 BPF_STMT(BPF_LDX | BPF_MEM, 1),
473 BPF_STMT(BPF_LD | BPF_MEM, 2),
474 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
475 BPF_STMT(BPF_LDX | BPF_MEM, 15),
476 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
477 BPF_STMT(BPF_RET | BPF_A, 0)
478 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200479 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700480 { },
481 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
482 },
483 {
484 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700485 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700486 BPF_STMT(BPF_LDX | BPF_LEN, 0),
487 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
488 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
489 BPF_STMT(BPF_RET | BPF_K, 1),
490 BPF_STMT(BPF_RET | BPF_K, MAX_K)
491 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200492 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700493 { 3, 3, 3, 3, 3 },
494 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
495 },
496 {
497 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700498 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700499 BPF_STMT(BPF_LDX | BPF_LEN, 0),
500 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
501 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
502 BPF_STMT(BPF_RET | BPF_K, 1),
503 BPF_STMT(BPF_RET | BPF_K, MAX_K)
504 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200505 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700506 { 4, 4, 4, 3, 3 },
507 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
508 },
509 {
510 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700511 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700512 BPF_STMT(BPF_LDX | BPF_LEN, 0),
513 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
514 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
515 BPF_STMT(BPF_RET | BPF_K, 10),
516 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
517 BPF_STMT(BPF_RET | BPF_K, 20),
518 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
519 BPF_STMT(BPF_RET | BPF_K, 30),
520 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
521 BPF_STMT(BPF_RET | BPF_K, 40),
522 BPF_STMT(BPF_RET | BPF_K, MAX_K)
523 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200524 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700525 { 1, 2, 3, 4, 5 },
526 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
527 },
528 {
529 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700530 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700531 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
532 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
533 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
534 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
535 BPF_STMT(BPF_LDX | BPF_LEN, 0),
536 BPF_STMT(BPF_MISC | BPF_TXA, 0),
537 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
538 BPF_STMT(BPF_MISC | BPF_TAX, 0),
539 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
540 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
541 BPF_STMT(BPF_RET | BPF_K, 10),
542 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
543 BPF_STMT(BPF_RET | BPF_K, 20),
544 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
545 BPF_STMT(BPF_RET | BPF_K, 30),
546 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
547 BPF_STMT(BPF_RET | BPF_K, 30),
548 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
549 BPF_STMT(BPF_RET | BPF_K, 30),
550 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
551 BPF_STMT(BPF_RET | BPF_K, 30),
552 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
553 BPF_STMT(BPF_RET | BPF_K, 30),
554 BPF_STMT(BPF_RET | BPF_K, MAX_K)
555 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200556 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700557 { 0, 0xAA, 0x55, 1 },
558 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
559 },
560 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700561 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -0700562 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +0200563 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
564 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
565 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
566 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
567 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
568 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
569 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
570 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
571 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
572 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
573 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
574 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
575 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
576 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
577 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
578 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
579 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
580 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
581 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
582 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
583 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
584 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
585 BPF_STMT(BPF_RET | BPF_K, 0xffff),
586 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700587 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200588 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700589 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
590 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
591 * seq 1305692979:1305693027, ack 3650467037, win 65535,
592 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
593 */
594 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
595 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
596 0x08, 0x00,
597 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
598 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
599 0x0a, 0x01, 0x01, 0x95, /* ip src */
600 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
601 0xc2, 0x24,
602 0x00, 0x16 /* dst port */ },
603 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
604 },
605 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700606 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -0700607 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700608 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
609 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
610 * (len > 115 or len < 30000000000)' -d
611 */
Daniel Borkmannce25b682014-05-26 20:17:35 +0200612 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
613 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
614 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
615 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
616 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
617 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
618 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
619 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
620 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
621 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
622 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
623 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
624 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
625 BPF_STMT(BPF_ST, 1),
626 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
627 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
628 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
629 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
630 BPF_STMT(BPF_LD | BPF_MEM, 1),
631 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
632 BPF_STMT(BPF_ST, 5),
633 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
634 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
635 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
636 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
637 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
638 BPF_STMT(BPF_LD | BPF_MEM, 5),
639 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
640 BPF_STMT(BPF_LD | BPF_LEN, 0),
641 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
642 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
643 BPF_STMT(BPF_RET | BPF_K, 0xffff),
644 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700645 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200646 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700647 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
648 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
649 0x08, 0x00,
650 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
651 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
652 0x0a, 0x01, 0x01, 0x95, /* ip src */
653 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
654 0xc2, 0x24,
655 0x00, 0x16 /* dst port */ },
656 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
657 },
658 {
659 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -0700660 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700661 /* check that unitialized X and A contain zeros */
662 BPF_STMT(BPF_MISC | BPF_TXA, 0),
663 BPF_STMT(BPF_RET | BPF_A, 0)
664 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200665 CLASSIC,
666 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700667 { {1, 0}, {2, 0} },
668 },
669 {
670 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -0700671 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700672 BPF_ALU64_IMM(BPF_MOV, R1, 1),
673 BPF_ALU64_IMM(BPF_ADD, R1, 2),
674 BPF_ALU64_IMM(BPF_MOV, R2, 3),
675 BPF_ALU64_REG(BPF_SUB, R1, R2),
676 BPF_ALU64_IMM(BPF_ADD, R1, -1),
677 BPF_ALU64_IMM(BPF_MUL, R1, 3),
678 BPF_ALU64_REG(BPF_MOV, R0, R1),
679 BPF_EXIT_INSN(),
680 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200681 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700682 { },
683 { { 0, 0xfffffffd } }
684 },
685 {
686 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -0700687 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700688 BPF_ALU64_IMM(BPF_MOV, R0, -1),
689 BPF_ALU64_IMM(BPF_MOV, R1, -1),
690 BPF_ALU64_IMM(BPF_MOV, R2, 3),
691 BPF_ALU64_REG(BPF_MUL, R1, R2),
692 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
693 BPF_EXIT_INSN(),
694 BPF_ALU64_IMM(BPF_MOV, R0, 1),
695 BPF_EXIT_INSN(),
696 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200697 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700698 { },
699 { { 0, 1 } }
700 },
701 {
702 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -0700703 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700704 BPF_ALU32_IMM(BPF_MOV, R0, -1),
705 BPF_ALU32_IMM(BPF_MOV, R1, -1),
706 BPF_ALU32_IMM(BPF_MOV, R2, 3),
707 BPF_ALU64_REG(BPF_MUL, R1, R2),
708 BPF_ALU64_IMM(BPF_RSH, R1, 8),
709 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
710 BPF_EXIT_INSN(),
711 BPF_ALU32_IMM(BPF_MOV, R0, 1),
712 BPF_EXIT_INSN(),
713 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200714 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700715 { },
716 { { 0, 1 } }
717 },
718 {
719 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -0700720 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700721 BPF_ALU32_IMM(BPF_MOV, R0, -1),
722 BPF_ALU64_IMM(BPF_MOV, R1, -1),
723 BPF_ALU32_IMM(BPF_MOV, R2, 3),
724 BPF_ALU32_REG(BPF_MUL, R1, R2),
725 BPF_ALU64_IMM(BPF_RSH, R1, 8),
726 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
727 BPF_EXIT_INSN(),
728 BPF_ALU32_IMM(BPF_MOV, R0, 1),
729 BPF_EXIT_INSN(),
730 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200731 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700732 { },
733 { { 0, 1 } }
734 },
735 {
736 /* Have to test all register combinations, since
737 * JITing of different registers will produce
738 * different asm code.
739 */
740 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -0700741 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700742 BPF_ALU64_IMM(BPF_MOV, R0, 0),
743 BPF_ALU64_IMM(BPF_MOV, R1, 1),
744 BPF_ALU64_IMM(BPF_MOV, R2, 2),
745 BPF_ALU64_IMM(BPF_MOV, R3, 3),
746 BPF_ALU64_IMM(BPF_MOV, R4, 4),
747 BPF_ALU64_IMM(BPF_MOV, R5, 5),
748 BPF_ALU64_IMM(BPF_MOV, R6, 6),
749 BPF_ALU64_IMM(BPF_MOV, R7, 7),
750 BPF_ALU64_IMM(BPF_MOV, R8, 8),
751 BPF_ALU64_IMM(BPF_MOV, R9, 9),
752 BPF_ALU64_IMM(BPF_ADD, R0, 20),
753 BPF_ALU64_IMM(BPF_ADD, R1, 20),
754 BPF_ALU64_IMM(BPF_ADD, R2, 20),
755 BPF_ALU64_IMM(BPF_ADD, R3, 20),
756 BPF_ALU64_IMM(BPF_ADD, R4, 20),
757 BPF_ALU64_IMM(BPF_ADD, R5, 20),
758 BPF_ALU64_IMM(BPF_ADD, R6, 20),
759 BPF_ALU64_IMM(BPF_ADD, R7, 20),
760 BPF_ALU64_IMM(BPF_ADD, R8, 20),
761 BPF_ALU64_IMM(BPF_ADD, R9, 20),
762 BPF_ALU64_IMM(BPF_SUB, R0, 10),
763 BPF_ALU64_IMM(BPF_SUB, R1, 10),
764 BPF_ALU64_IMM(BPF_SUB, R2, 10),
765 BPF_ALU64_IMM(BPF_SUB, R3, 10),
766 BPF_ALU64_IMM(BPF_SUB, R4, 10),
767 BPF_ALU64_IMM(BPF_SUB, R5, 10),
768 BPF_ALU64_IMM(BPF_SUB, R6, 10),
769 BPF_ALU64_IMM(BPF_SUB, R7, 10),
770 BPF_ALU64_IMM(BPF_SUB, R8, 10),
771 BPF_ALU64_IMM(BPF_SUB, R9, 10),
772 BPF_ALU64_REG(BPF_ADD, R0, R0),
773 BPF_ALU64_REG(BPF_ADD, R0, R1),
774 BPF_ALU64_REG(BPF_ADD, R0, R2),
775 BPF_ALU64_REG(BPF_ADD, R0, R3),
776 BPF_ALU64_REG(BPF_ADD, R0, R4),
777 BPF_ALU64_REG(BPF_ADD, R0, R5),
778 BPF_ALU64_REG(BPF_ADD, R0, R6),
779 BPF_ALU64_REG(BPF_ADD, R0, R7),
780 BPF_ALU64_REG(BPF_ADD, R0, R8),
781 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
782 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
783 BPF_EXIT_INSN(),
784 BPF_ALU64_REG(BPF_ADD, R1, R0),
785 BPF_ALU64_REG(BPF_ADD, R1, R1),
786 BPF_ALU64_REG(BPF_ADD, R1, R2),
787 BPF_ALU64_REG(BPF_ADD, R1, R3),
788 BPF_ALU64_REG(BPF_ADD, R1, R4),
789 BPF_ALU64_REG(BPF_ADD, R1, R5),
790 BPF_ALU64_REG(BPF_ADD, R1, R6),
791 BPF_ALU64_REG(BPF_ADD, R1, R7),
792 BPF_ALU64_REG(BPF_ADD, R1, R8),
793 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
794 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
795 BPF_EXIT_INSN(),
796 BPF_ALU64_REG(BPF_ADD, R2, R0),
797 BPF_ALU64_REG(BPF_ADD, R2, R1),
798 BPF_ALU64_REG(BPF_ADD, R2, R2),
799 BPF_ALU64_REG(BPF_ADD, R2, R3),
800 BPF_ALU64_REG(BPF_ADD, R2, R4),
801 BPF_ALU64_REG(BPF_ADD, R2, R5),
802 BPF_ALU64_REG(BPF_ADD, R2, R6),
803 BPF_ALU64_REG(BPF_ADD, R2, R7),
804 BPF_ALU64_REG(BPF_ADD, R2, R8),
805 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
806 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
807 BPF_EXIT_INSN(),
808 BPF_ALU64_REG(BPF_ADD, R3, R0),
809 BPF_ALU64_REG(BPF_ADD, R3, R1),
810 BPF_ALU64_REG(BPF_ADD, R3, R2),
811 BPF_ALU64_REG(BPF_ADD, R3, R3),
812 BPF_ALU64_REG(BPF_ADD, R3, R4),
813 BPF_ALU64_REG(BPF_ADD, R3, R5),
814 BPF_ALU64_REG(BPF_ADD, R3, R6),
815 BPF_ALU64_REG(BPF_ADD, R3, R7),
816 BPF_ALU64_REG(BPF_ADD, R3, R8),
817 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
818 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
819 BPF_EXIT_INSN(),
820 BPF_ALU64_REG(BPF_ADD, R4, R0),
821 BPF_ALU64_REG(BPF_ADD, R4, R1),
822 BPF_ALU64_REG(BPF_ADD, R4, R2),
823 BPF_ALU64_REG(BPF_ADD, R4, R3),
824 BPF_ALU64_REG(BPF_ADD, R4, R4),
825 BPF_ALU64_REG(BPF_ADD, R4, R5),
826 BPF_ALU64_REG(BPF_ADD, R4, R6),
827 BPF_ALU64_REG(BPF_ADD, R4, R7),
828 BPF_ALU64_REG(BPF_ADD, R4, R8),
829 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
830 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
831 BPF_EXIT_INSN(),
832 BPF_ALU64_REG(BPF_ADD, R5, R0),
833 BPF_ALU64_REG(BPF_ADD, R5, R1),
834 BPF_ALU64_REG(BPF_ADD, R5, R2),
835 BPF_ALU64_REG(BPF_ADD, R5, R3),
836 BPF_ALU64_REG(BPF_ADD, R5, R4),
837 BPF_ALU64_REG(BPF_ADD, R5, R5),
838 BPF_ALU64_REG(BPF_ADD, R5, R6),
839 BPF_ALU64_REG(BPF_ADD, R5, R7),
840 BPF_ALU64_REG(BPF_ADD, R5, R8),
841 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
842 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
843 BPF_EXIT_INSN(),
844 BPF_ALU64_REG(BPF_ADD, R6, R0),
845 BPF_ALU64_REG(BPF_ADD, R6, R1),
846 BPF_ALU64_REG(BPF_ADD, R6, R2),
847 BPF_ALU64_REG(BPF_ADD, R6, R3),
848 BPF_ALU64_REG(BPF_ADD, R6, R4),
849 BPF_ALU64_REG(BPF_ADD, R6, R5),
850 BPF_ALU64_REG(BPF_ADD, R6, R6),
851 BPF_ALU64_REG(BPF_ADD, R6, R7),
852 BPF_ALU64_REG(BPF_ADD, R6, R8),
853 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
854 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
855 BPF_EXIT_INSN(),
856 BPF_ALU64_REG(BPF_ADD, R7, R0),
857 BPF_ALU64_REG(BPF_ADD, R7, R1),
858 BPF_ALU64_REG(BPF_ADD, R7, R2),
859 BPF_ALU64_REG(BPF_ADD, R7, R3),
860 BPF_ALU64_REG(BPF_ADD, R7, R4),
861 BPF_ALU64_REG(BPF_ADD, R7, R5),
862 BPF_ALU64_REG(BPF_ADD, R7, R6),
863 BPF_ALU64_REG(BPF_ADD, R7, R7),
864 BPF_ALU64_REG(BPF_ADD, R7, R8),
865 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
866 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
867 BPF_EXIT_INSN(),
868 BPF_ALU64_REG(BPF_ADD, R8, R0),
869 BPF_ALU64_REG(BPF_ADD, R8, R1),
870 BPF_ALU64_REG(BPF_ADD, R8, R2),
871 BPF_ALU64_REG(BPF_ADD, R8, R3),
872 BPF_ALU64_REG(BPF_ADD, R8, R4),
873 BPF_ALU64_REG(BPF_ADD, R8, R5),
874 BPF_ALU64_REG(BPF_ADD, R8, R6),
875 BPF_ALU64_REG(BPF_ADD, R8, R7),
876 BPF_ALU64_REG(BPF_ADD, R8, R8),
877 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
878 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
879 BPF_EXIT_INSN(),
880 BPF_ALU64_REG(BPF_ADD, R9, R0),
881 BPF_ALU64_REG(BPF_ADD, R9, R1),
882 BPF_ALU64_REG(BPF_ADD, R9, R2),
883 BPF_ALU64_REG(BPF_ADD, R9, R3),
884 BPF_ALU64_REG(BPF_ADD, R9, R4),
885 BPF_ALU64_REG(BPF_ADD, R9, R5),
886 BPF_ALU64_REG(BPF_ADD, R9, R6),
887 BPF_ALU64_REG(BPF_ADD, R9, R7),
888 BPF_ALU64_REG(BPF_ADD, R9, R8),
889 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
890 BPF_ALU64_REG(BPF_MOV, R0, R9),
891 BPF_EXIT_INSN(),
892 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200893 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700894 { },
895 { { 0, 2957380 } }
896 },
897 {
898 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -0700899 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700900 BPF_ALU32_IMM(BPF_MOV, R0, 20),
901 BPF_ALU32_IMM(BPF_MOV, R1, 1),
902 BPF_ALU32_IMM(BPF_MOV, R2, 2),
903 BPF_ALU32_IMM(BPF_MOV, R3, 3),
904 BPF_ALU32_IMM(BPF_MOV, R4, 4),
905 BPF_ALU32_IMM(BPF_MOV, R5, 5),
906 BPF_ALU32_IMM(BPF_MOV, R6, 6),
907 BPF_ALU32_IMM(BPF_MOV, R7, 7),
908 BPF_ALU32_IMM(BPF_MOV, R8, 8),
909 BPF_ALU32_IMM(BPF_MOV, R9, 9),
910 BPF_ALU64_IMM(BPF_ADD, R1, 10),
911 BPF_ALU64_IMM(BPF_ADD, R2, 10),
912 BPF_ALU64_IMM(BPF_ADD, R3, 10),
913 BPF_ALU64_IMM(BPF_ADD, R4, 10),
914 BPF_ALU64_IMM(BPF_ADD, R5, 10),
915 BPF_ALU64_IMM(BPF_ADD, R6, 10),
916 BPF_ALU64_IMM(BPF_ADD, R7, 10),
917 BPF_ALU64_IMM(BPF_ADD, R8, 10),
918 BPF_ALU64_IMM(BPF_ADD, R9, 10),
919 BPF_ALU32_REG(BPF_ADD, R0, R1),
920 BPF_ALU32_REG(BPF_ADD, R0, R2),
921 BPF_ALU32_REG(BPF_ADD, R0, R3),
922 BPF_ALU32_REG(BPF_ADD, R0, R4),
923 BPF_ALU32_REG(BPF_ADD, R0, R5),
924 BPF_ALU32_REG(BPF_ADD, R0, R6),
925 BPF_ALU32_REG(BPF_ADD, R0, R7),
926 BPF_ALU32_REG(BPF_ADD, R0, R8),
927 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
928 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
929 BPF_EXIT_INSN(),
930 BPF_ALU32_REG(BPF_ADD, R1, R0),
931 BPF_ALU32_REG(BPF_ADD, R1, R1),
932 BPF_ALU32_REG(BPF_ADD, R1, R2),
933 BPF_ALU32_REG(BPF_ADD, R1, R3),
934 BPF_ALU32_REG(BPF_ADD, R1, R4),
935 BPF_ALU32_REG(BPF_ADD, R1, R5),
936 BPF_ALU32_REG(BPF_ADD, R1, R6),
937 BPF_ALU32_REG(BPF_ADD, R1, R7),
938 BPF_ALU32_REG(BPF_ADD, R1, R8),
939 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
940 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
941 BPF_EXIT_INSN(),
942 BPF_ALU32_REG(BPF_ADD, R2, R0),
943 BPF_ALU32_REG(BPF_ADD, R2, R1),
944 BPF_ALU32_REG(BPF_ADD, R2, R2),
945 BPF_ALU32_REG(BPF_ADD, R2, R3),
946 BPF_ALU32_REG(BPF_ADD, R2, R4),
947 BPF_ALU32_REG(BPF_ADD, R2, R5),
948 BPF_ALU32_REG(BPF_ADD, R2, R6),
949 BPF_ALU32_REG(BPF_ADD, R2, R7),
950 BPF_ALU32_REG(BPF_ADD, R2, R8),
951 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
952 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
953 BPF_EXIT_INSN(),
954 BPF_ALU32_REG(BPF_ADD, R3, R0),
955 BPF_ALU32_REG(BPF_ADD, R3, R1),
956 BPF_ALU32_REG(BPF_ADD, R3, R2),
957 BPF_ALU32_REG(BPF_ADD, R3, R3),
958 BPF_ALU32_REG(BPF_ADD, R3, R4),
959 BPF_ALU32_REG(BPF_ADD, R3, R5),
960 BPF_ALU32_REG(BPF_ADD, R3, R6),
961 BPF_ALU32_REG(BPF_ADD, R3, R7),
962 BPF_ALU32_REG(BPF_ADD, R3, R8),
963 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
964 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
965 BPF_EXIT_INSN(),
966 BPF_ALU32_REG(BPF_ADD, R4, R0),
967 BPF_ALU32_REG(BPF_ADD, R4, R1),
968 BPF_ALU32_REG(BPF_ADD, R4, R2),
969 BPF_ALU32_REG(BPF_ADD, R4, R3),
970 BPF_ALU32_REG(BPF_ADD, R4, R4),
971 BPF_ALU32_REG(BPF_ADD, R4, R5),
972 BPF_ALU32_REG(BPF_ADD, R4, R6),
973 BPF_ALU32_REG(BPF_ADD, R4, R7),
974 BPF_ALU32_REG(BPF_ADD, R4, R8),
975 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
976 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
977 BPF_EXIT_INSN(),
978 BPF_ALU32_REG(BPF_ADD, R5, R0),
979 BPF_ALU32_REG(BPF_ADD, R5, R1),
980 BPF_ALU32_REG(BPF_ADD, R5, R2),
981 BPF_ALU32_REG(BPF_ADD, R5, R3),
982 BPF_ALU32_REG(BPF_ADD, R5, R4),
983 BPF_ALU32_REG(BPF_ADD, R5, R5),
984 BPF_ALU32_REG(BPF_ADD, R5, R6),
985 BPF_ALU32_REG(BPF_ADD, R5, R7),
986 BPF_ALU32_REG(BPF_ADD, R5, R8),
987 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
988 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
989 BPF_EXIT_INSN(),
990 BPF_ALU32_REG(BPF_ADD, R6, R0),
991 BPF_ALU32_REG(BPF_ADD, R6, R1),
992 BPF_ALU32_REG(BPF_ADD, R6, R2),
993 BPF_ALU32_REG(BPF_ADD, R6, R3),
994 BPF_ALU32_REG(BPF_ADD, R6, R4),
995 BPF_ALU32_REG(BPF_ADD, R6, R5),
996 BPF_ALU32_REG(BPF_ADD, R6, R6),
997 BPF_ALU32_REG(BPF_ADD, R6, R7),
998 BPF_ALU32_REG(BPF_ADD, R6, R8),
999 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1000 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1001 BPF_EXIT_INSN(),
1002 BPF_ALU32_REG(BPF_ADD, R7, R0),
1003 BPF_ALU32_REG(BPF_ADD, R7, R1),
1004 BPF_ALU32_REG(BPF_ADD, R7, R2),
1005 BPF_ALU32_REG(BPF_ADD, R7, R3),
1006 BPF_ALU32_REG(BPF_ADD, R7, R4),
1007 BPF_ALU32_REG(BPF_ADD, R7, R5),
1008 BPF_ALU32_REG(BPF_ADD, R7, R6),
1009 BPF_ALU32_REG(BPF_ADD, R7, R7),
1010 BPF_ALU32_REG(BPF_ADD, R7, R8),
1011 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1012 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1013 BPF_EXIT_INSN(),
1014 BPF_ALU32_REG(BPF_ADD, R8, R0),
1015 BPF_ALU32_REG(BPF_ADD, R8, R1),
1016 BPF_ALU32_REG(BPF_ADD, R8, R2),
1017 BPF_ALU32_REG(BPF_ADD, R8, R3),
1018 BPF_ALU32_REG(BPF_ADD, R8, R4),
1019 BPF_ALU32_REG(BPF_ADD, R8, R5),
1020 BPF_ALU32_REG(BPF_ADD, R8, R6),
1021 BPF_ALU32_REG(BPF_ADD, R8, R7),
1022 BPF_ALU32_REG(BPF_ADD, R8, R8),
1023 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1024 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1025 BPF_EXIT_INSN(),
1026 BPF_ALU32_REG(BPF_ADD, R9, R0),
1027 BPF_ALU32_REG(BPF_ADD, R9, R1),
1028 BPF_ALU32_REG(BPF_ADD, R9, R2),
1029 BPF_ALU32_REG(BPF_ADD, R9, R3),
1030 BPF_ALU32_REG(BPF_ADD, R9, R4),
1031 BPF_ALU32_REG(BPF_ADD, R9, R5),
1032 BPF_ALU32_REG(BPF_ADD, R9, R6),
1033 BPF_ALU32_REG(BPF_ADD, R9, R7),
1034 BPF_ALU32_REG(BPF_ADD, R9, R8),
1035 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1036 BPF_ALU32_REG(BPF_MOV, R0, R9),
1037 BPF_EXIT_INSN(),
1038 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001039 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001040 { },
1041 { { 0, 2957380 } }
1042 },
1043 { /* Mainly checking JIT here. */
1044 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001045 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001046 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1047 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1048 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1049 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1050 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1051 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1052 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1053 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1054 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1055 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1056 BPF_ALU64_REG(BPF_SUB, R0, R0),
1057 BPF_ALU64_REG(BPF_SUB, R0, R1),
1058 BPF_ALU64_REG(BPF_SUB, R0, R2),
1059 BPF_ALU64_REG(BPF_SUB, R0, R3),
1060 BPF_ALU64_REG(BPF_SUB, R0, R4),
1061 BPF_ALU64_REG(BPF_SUB, R0, R5),
1062 BPF_ALU64_REG(BPF_SUB, R0, R6),
1063 BPF_ALU64_REG(BPF_SUB, R0, R7),
1064 BPF_ALU64_REG(BPF_SUB, R0, R8),
1065 BPF_ALU64_REG(BPF_SUB, R0, R9),
1066 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1067 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1068 BPF_EXIT_INSN(),
1069 BPF_ALU64_REG(BPF_SUB, R1, R0),
1070 BPF_ALU64_REG(BPF_SUB, R1, R2),
1071 BPF_ALU64_REG(BPF_SUB, R1, R3),
1072 BPF_ALU64_REG(BPF_SUB, R1, R4),
1073 BPF_ALU64_REG(BPF_SUB, R1, R5),
1074 BPF_ALU64_REG(BPF_SUB, R1, R6),
1075 BPF_ALU64_REG(BPF_SUB, R1, R7),
1076 BPF_ALU64_REG(BPF_SUB, R1, R8),
1077 BPF_ALU64_REG(BPF_SUB, R1, R9),
1078 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1079 BPF_ALU64_REG(BPF_SUB, R2, R0),
1080 BPF_ALU64_REG(BPF_SUB, R2, R1),
1081 BPF_ALU64_REG(BPF_SUB, R2, R3),
1082 BPF_ALU64_REG(BPF_SUB, R2, R4),
1083 BPF_ALU64_REG(BPF_SUB, R2, R5),
1084 BPF_ALU64_REG(BPF_SUB, R2, R6),
1085 BPF_ALU64_REG(BPF_SUB, R2, R7),
1086 BPF_ALU64_REG(BPF_SUB, R2, R8),
1087 BPF_ALU64_REG(BPF_SUB, R2, R9),
1088 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1089 BPF_ALU64_REG(BPF_SUB, R3, R0),
1090 BPF_ALU64_REG(BPF_SUB, R3, R1),
1091 BPF_ALU64_REG(BPF_SUB, R3, R2),
1092 BPF_ALU64_REG(BPF_SUB, R3, R4),
1093 BPF_ALU64_REG(BPF_SUB, R3, R5),
1094 BPF_ALU64_REG(BPF_SUB, R3, R6),
1095 BPF_ALU64_REG(BPF_SUB, R3, R7),
1096 BPF_ALU64_REG(BPF_SUB, R3, R8),
1097 BPF_ALU64_REG(BPF_SUB, R3, R9),
1098 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1099 BPF_ALU64_REG(BPF_SUB, R4, R0),
1100 BPF_ALU64_REG(BPF_SUB, R4, R1),
1101 BPF_ALU64_REG(BPF_SUB, R4, R2),
1102 BPF_ALU64_REG(BPF_SUB, R4, R3),
1103 BPF_ALU64_REG(BPF_SUB, R4, R5),
1104 BPF_ALU64_REG(BPF_SUB, R4, R6),
1105 BPF_ALU64_REG(BPF_SUB, R4, R7),
1106 BPF_ALU64_REG(BPF_SUB, R4, R8),
1107 BPF_ALU64_REG(BPF_SUB, R4, R9),
1108 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1109 BPF_ALU64_REG(BPF_SUB, R5, R0),
1110 BPF_ALU64_REG(BPF_SUB, R5, R1),
1111 BPF_ALU64_REG(BPF_SUB, R5, R2),
1112 BPF_ALU64_REG(BPF_SUB, R5, R3),
1113 BPF_ALU64_REG(BPF_SUB, R5, R4),
1114 BPF_ALU64_REG(BPF_SUB, R5, R6),
1115 BPF_ALU64_REG(BPF_SUB, R5, R7),
1116 BPF_ALU64_REG(BPF_SUB, R5, R8),
1117 BPF_ALU64_REG(BPF_SUB, R5, R9),
1118 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1119 BPF_ALU64_REG(BPF_SUB, R6, R0),
1120 BPF_ALU64_REG(BPF_SUB, R6, R1),
1121 BPF_ALU64_REG(BPF_SUB, R6, R2),
1122 BPF_ALU64_REG(BPF_SUB, R6, R3),
1123 BPF_ALU64_REG(BPF_SUB, R6, R4),
1124 BPF_ALU64_REG(BPF_SUB, R6, R5),
1125 BPF_ALU64_REG(BPF_SUB, R6, R7),
1126 BPF_ALU64_REG(BPF_SUB, R6, R8),
1127 BPF_ALU64_REG(BPF_SUB, R6, R9),
1128 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1129 BPF_ALU64_REG(BPF_SUB, R7, R0),
1130 BPF_ALU64_REG(BPF_SUB, R7, R1),
1131 BPF_ALU64_REG(BPF_SUB, R7, R2),
1132 BPF_ALU64_REG(BPF_SUB, R7, R3),
1133 BPF_ALU64_REG(BPF_SUB, R7, R4),
1134 BPF_ALU64_REG(BPF_SUB, R7, R5),
1135 BPF_ALU64_REG(BPF_SUB, R7, R6),
1136 BPF_ALU64_REG(BPF_SUB, R7, R8),
1137 BPF_ALU64_REG(BPF_SUB, R7, R9),
1138 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1139 BPF_ALU64_REG(BPF_SUB, R8, R0),
1140 BPF_ALU64_REG(BPF_SUB, R8, R1),
1141 BPF_ALU64_REG(BPF_SUB, R8, R2),
1142 BPF_ALU64_REG(BPF_SUB, R8, R3),
1143 BPF_ALU64_REG(BPF_SUB, R8, R4),
1144 BPF_ALU64_REG(BPF_SUB, R8, R5),
1145 BPF_ALU64_REG(BPF_SUB, R8, R6),
1146 BPF_ALU64_REG(BPF_SUB, R8, R7),
1147 BPF_ALU64_REG(BPF_SUB, R8, R9),
1148 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1149 BPF_ALU64_REG(BPF_SUB, R9, R0),
1150 BPF_ALU64_REG(BPF_SUB, R9, R1),
1151 BPF_ALU64_REG(BPF_SUB, R9, R2),
1152 BPF_ALU64_REG(BPF_SUB, R9, R3),
1153 BPF_ALU64_REG(BPF_SUB, R9, R4),
1154 BPF_ALU64_REG(BPF_SUB, R9, R5),
1155 BPF_ALU64_REG(BPF_SUB, R9, R6),
1156 BPF_ALU64_REG(BPF_SUB, R9, R7),
1157 BPF_ALU64_REG(BPF_SUB, R9, R8),
1158 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1159 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1160 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1161 BPF_ALU64_REG(BPF_SUB, R0, R1),
1162 BPF_ALU64_REG(BPF_SUB, R0, R2),
1163 BPF_ALU64_REG(BPF_SUB, R0, R3),
1164 BPF_ALU64_REG(BPF_SUB, R0, R4),
1165 BPF_ALU64_REG(BPF_SUB, R0, R5),
1166 BPF_ALU64_REG(BPF_SUB, R0, R6),
1167 BPF_ALU64_REG(BPF_SUB, R0, R7),
1168 BPF_ALU64_REG(BPF_SUB, R0, R8),
1169 BPF_ALU64_REG(BPF_SUB, R0, R9),
1170 BPF_EXIT_INSN(),
1171 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001172 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001173 { },
1174 { { 0, 11 } }
1175 },
1176 { /* Mainly checking JIT here. */
1177 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001178 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001179 BPF_ALU64_REG(BPF_SUB, R0, R0),
1180 BPF_ALU64_REG(BPF_XOR, R1, R1),
1181 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1182 BPF_EXIT_INSN(),
1183 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1184 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1185 BPF_ALU64_REG(BPF_SUB, R1, R1),
1186 BPF_ALU64_REG(BPF_XOR, R2, R2),
1187 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1188 BPF_EXIT_INSN(),
1189 BPF_ALU64_REG(BPF_SUB, R2, R2),
1190 BPF_ALU64_REG(BPF_XOR, R3, R3),
1191 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1192 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1193 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1194 BPF_EXIT_INSN(),
1195 BPF_ALU64_REG(BPF_SUB, R3, R3),
1196 BPF_ALU64_REG(BPF_XOR, R4, R4),
1197 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1198 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1199 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1200 BPF_EXIT_INSN(),
1201 BPF_ALU64_REG(BPF_SUB, R4, R4),
1202 BPF_ALU64_REG(BPF_XOR, R5, R5),
1203 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1204 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1205 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1206 BPF_EXIT_INSN(),
1207 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1208 BPF_ALU64_REG(BPF_SUB, R5, R5),
1209 BPF_ALU64_REG(BPF_XOR, R6, R6),
1210 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1211 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1212 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1213 BPF_EXIT_INSN(),
1214 BPF_ALU64_REG(BPF_SUB, R6, R6),
1215 BPF_ALU64_REG(BPF_XOR, R7, R7),
1216 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1217 BPF_EXIT_INSN(),
1218 BPF_ALU64_REG(BPF_SUB, R7, R7),
1219 BPF_ALU64_REG(BPF_XOR, R8, R8),
1220 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1221 BPF_EXIT_INSN(),
1222 BPF_ALU64_REG(BPF_SUB, R8, R8),
1223 BPF_ALU64_REG(BPF_XOR, R9, R9),
1224 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1225 BPF_EXIT_INSN(),
1226 BPF_ALU64_REG(BPF_SUB, R9, R9),
1227 BPF_ALU64_REG(BPF_XOR, R0, R0),
1228 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1229 BPF_EXIT_INSN(),
1230 BPF_ALU64_REG(BPF_SUB, R1, R1),
1231 BPF_ALU64_REG(BPF_XOR, R0, R0),
1232 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1233 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1234 BPF_EXIT_INSN(),
1235 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1236 BPF_EXIT_INSN(),
1237 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001238 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001239 { },
1240 { { 0, 1 } }
1241 },
1242 { /* Mainly checking JIT here. */
1243 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001244 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001245 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1246 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1247 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1248 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1249 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1250 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1251 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1252 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1253 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1254 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1255 BPF_ALU64_REG(BPF_MUL, R0, R0),
1256 BPF_ALU64_REG(BPF_MUL, R0, R1),
1257 BPF_ALU64_REG(BPF_MUL, R0, R2),
1258 BPF_ALU64_REG(BPF_MUL, R0, R3),
1259 BPF_ALU64_REG(BPF_MUL, R0, R4),
1260 BPF_ALU64_REG(BPF_MUL, R0, R5),
1261 BPF_ALU64_REG(BPF_MUL, R0, R6),
1262 BPF_ALU64_REG(BPF_MUL, R0, R7),
1263 BPF_ALU64_REG(BPF_MUL, R0, R8),
1264 BPF_ALU64_REG(BPF_MUL, R0, R9),
1265 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1266 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1267 BPF_EXIT_INSN(),
1268 BPF_ALU64_REG(BPF_MUL, R1, R0),
1269 BPF_ALU64_REG(BPF_MUL, R1, R2),
1270 BPF_ALU64_REG(BPF_MUL, R1, R3),
1271 BPF_ALU64_REG(BPF_MUL, R1, R4),
1272 BPF_ALU64_REG(BPF_MUL, R1, R5),
1273 BPF_ALU64_REG(BPF_MUL, R1, R6),
1274 BPF_ALU64_REG(BPF_MUL, R1, R7),
1275 BPF_ALU64_REG(BPF_MUL, R1, R8),
1276 BPF_ALU64_REG(BPF_MUL, R1, R9),
1277 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1278 BPF_ALU64_REG(BPF_MOV, R2, R1),
1279 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1280 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1281 BPF_EXIT_INSN(),
1282 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1283 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1284 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1285 BPF_EXIT_INSN(),
1286 BPF_ALU64_REG(BPF_MUL, R2, R0),
1287 BPF_ALU64_REG(BPF_MUL, R2, R1),
1288 BPF_ALU64_REG(BPF_MUL, R2, R3),
1289 BPF_ALU64_REG(BPF_MUL, R2, R4),
1290 BPF_ALU64_REG(BPF_MUL, R2, R5),
1291 BPF_ALU64_REG(BPF_MUL, R2, R6),
1292 BPF_ALU64_REG(BPF_MUL, R2, R7),
1293 BPF_ALU64_REG(BPF_MUL, R2, R8),
1294 BPF_ALU64_REG(BPF_MUL, R2, R9),
1295 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1296 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1297 BPF_ALU64_REG(BPF_MOV, R0, R2),
1298 BPF_EXIT_INSN(),
1299 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001300 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001301 { },
1302 { { 0, 0x35d97ef2 } }
1303 },
1304 {
1305 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001306 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001307 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1308 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1309 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1310 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1311 BPF_ALU64_REG(BPF_DIV, R0, R2),
1312 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1313 BPF_EXIT_INSN(),
1314 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1315 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1316 BPF_EXIT_INSN(),
1317 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1318 BPF_EXIT_INSN(),
1319 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001320 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001321 { },
1322 { { 0, -1 } }
1323 },
1324 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001325 "INT: DIV + ABS",
Andrew Mortonece80492014-05-22 10:16:46 -07001326 .u.insns_int = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001327 BPF_ALU64_REG(BPF_MOV, R6, R1),
1328 BPF_LD_ABS(BPF_B, 3),
1329 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1330 BPF_ALU32_REG(BPF_DIV, R0, R2),
1331 BPF_ALU64_REG(BPF_MOV, R8, R0),
1332 BPF_LD_ABS(BPF_B, 4),
1333 BPF_ALU64_REG(BPF_ADD, R8, R0),
1334 BPF_LD_IND(BPF_B, R8, -70),
1335 BPF_EXIT_INSN(),
1336 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001337 INTERNAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001338 { 10, 20, 30, 40, 50 },
1339 { { 4, 0 }, { 5, 10 } }
1340 },
1341 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001342 "INT: DIV by zero",
Andrew Mortonece80492014-05-22 10:16:46 -07001343 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001344 BPF_ALU64_REG(BPF_MOV, R6, R1),
1345 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1346 BPF_LD_ABS(BPF_B, 3),
1347 BPF_ALU32_REG(BPF_DIV, R0, R7),
1348 BPF_EXIT_INSN(),
1349 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001350 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001351 { 10, 20, 30, 40, 50 },
1352 { { 3, 0 }, { 4, 0 } }
1353 },
1354 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001355 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07001356 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001357 BPF_STMT(BPF_LD | BPF_IMM, 1),
1358 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001359 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001360 { },
1361 { }
1362 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001363 {
1364 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07001365 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001366 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1367 BPF_STMT(BPF_RET | BPF_K, 0)
1368 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001369 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001370 { },
1371 { }
1372 },
1373 {
1374 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07001375 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001376 /* seccomp insn, rejected in socket filter */
1377 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1378 BPF_STMT(BPF_RET | BPF_K, 0)
1379 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001380 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001381 { },
1382 { }
1383 },
1384 {
1385 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07001386 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001387 BPF_STMT(BPF_STX, 16),
1388 BPF_STMT(BPF_RET | BPF_K, 0)
1389 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001390 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001391 { },
1392 { }
1393 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001394 {
1395 "JUMPS + HOLES",
1396 .u.insns = {
1397 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1398 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1399 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1400 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1401 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1402 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1403 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1404 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1405 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1406 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1407 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1408 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1409 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1410 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1411 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1412 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1413 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1414 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1415 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1416 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1417 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1418 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1419 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1420 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1421 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1422 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1423 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1424 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1425 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1426 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1427 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1428 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1429 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1430 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1431 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1432 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1433 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1434 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1435 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1436 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1437 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1438 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1439 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1440 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1441 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1442 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1443 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1444 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1445 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1446 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1447 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1448 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1449 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1450 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1451 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1452 BPF_STMT(BPF_RET | BPF_A, 0),
1453 BPF_STMT(BPF_RET | BPF_A, 0),
1454 },
1455 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02001456 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1457 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1458 0x08, 0x00,
1459 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1460 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1461 0xc0, 0xa8, 0x33, 0x01,
1462 0xc0, 0xa8, 0x33, 0x02,
1463 0xbb, 0xb6,
1464 0xa9, 0xfa,
1465 0x00, 0x14, 0x00, 0x00,
1466 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1467 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1468 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1469 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1470 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1471 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1472 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1473 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001474 { { 88, 0x001b } }
1475 },
1476 {
1477 "check: RET X",
1478 .u.insns = {
1479 BPF_STMT(BPF_RET | BPF_X, 0),
1480 },
1481 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1482 { },
1483 { },
1484 },
1485 {
1486 "check: LDX + RET X",
1487 .u.insns = {
1488 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1489 BPF_STMT(BPF_RET | BPF_X, 0),
1490 },
1491 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1492 { },
1493 { },
1494 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02001495 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02001496 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02001497 .u.insns = {
1498 BPF_STMT(BPF_LDX | BPF_IMM, 100),
1499 BPF_STMT(BPF_STX, 0),
1500 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1501 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1502 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1503 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1504 BPF_STMT(BPF_STX, 1),
1505 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1506 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1507 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1508 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1509 BPF_STMT(BPF_STX, 2),
1510 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1511 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1512 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1513 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1514 BPF_STMT(BPF_STX, 3),
1515 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1516 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1517 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1518 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1519 BPF_STMT(BPF_STX, 4),
1520 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1521 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1522 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1523 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1524 BPF_STMT(BPF_STX, 5),
1525 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1526 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1527 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1528 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1529 BPF_STMT(BPF_STX, 6),
1530 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1531 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1532 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1533 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1534 BPF_STMT(BPF_STX, 7),
1535 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1536 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1537 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1538 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1539 BPF_STMT(BPF_STX, 8),
1540 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1541 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1542 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1543 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1544 BPF_STMT(BPF_STX, 9),
1545 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1546 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1547 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1548 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1549 BPF_STMT(BPF_STX, 10),
1550 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1551 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1552 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1553 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1554 BPF_STMT(BPF_STX, 11),
1555 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1556 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1557 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1558 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1559 BPF_STMT(BPF_STX, 12),
1560 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1561 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1562 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1563 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1564 BPF_STMT(BPF_STX, 13),
1565 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1566 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1567 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1568 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1569 BPF_STMT(BPF_STX, 14),
1570 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1571 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1572 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1573 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1574 BPF_STMT(BPF_STX, 15),
1575 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1576 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1577 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1578 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1579 BPF_STMT(BPF_RET | BPF_A, 0),
1580 },
1581 CLASSIC | FLAG_NO_DATA,
1582 { },
1583 { { 0, 116 } },
1584 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02001585 { /* Mainly checking JIT here. */
1586 "M[]: full STX + full LDX",
1587 .u.insns = {
1588 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
1589 BPF_STMT(BPF_STX, 0),
1590 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
1591 BPF_STMT(BPF_STX, 1),
1592 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
1593 BPF_STMT(BPF_STX, 2),
1594 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
1595 BPF_STMT(BPF_STX, 3),
1596 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
1597 BPF_STMT(BPF_STX, 4),
1598 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
1599 BPF_STMT(BPF_STX, 5),
1600 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
1601 BPF_STMT(BPF_STX, 6),
1602 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
1603 BPF_STMT(BPF_STX, 7),
1604 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
1605 BPF_STMT(BPF_STX, 8),
1606 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
1607 BPF_STMT(BPF_STX, 9),
1608 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
1609 BPF_STMT(BPF_STX, 10),
1610 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
1611 BPF_STMT(BPF_STX, 11),
1612 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
1613 BPF_STMT(BPF_STX, 12),
1614 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
1615 BPF_STMT(BPF_STX, 13),
1616 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
1617 BPF_STMT(BPF_STX, 14),
1618 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
1619 BPF_STMT(BPF_STX, 15),
1620 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1621 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1622 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1623 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1624 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1625 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1626 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1627 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1628 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1629 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1630 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1631 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1632 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1633 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1634 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1635 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1636 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1637 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1638 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1639 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1640 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1641 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1642 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1643 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1644 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1645 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1646 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1647 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1648 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1649 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1650 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1651 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1652 BPF_STMT(BPF_RET | BPF_A, 0),
1653 },
1654 CLASSIC | FLAG_NO_DATA,
1655 { },
1656 { { 0, 0x2a5a5e5 } },
1657 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02001658 {
1659 "check: SKF_AD_MAX",
1660 .u.insns = {
1661 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
1662 SKF_AD_OFF + SKF_AD_MAX),
1663 BPF_STMT(BPF_RET | BPF_A, 0),
1664 },
1665 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1666 { },
1667 { },
1668 },
1669 { /* Passes checker but fails during runtime. */
1670 "LD [SKF_AD_OFF-1]",
1671 .u.insns = {
1672 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
1673 SKF_AD_OFF - 1),
1674 BPF_STMT(BPF_RET | BPF_K, 1),
1675 },
1676 CLASSIC,
1677 { },
1678 { { 1, 0 } },
1679 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001680};
1681
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001682static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001683
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001684static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001685{
1686 struct sk_buff *skb;
1687
1688 if (size >= MAX_DATA)
1689 return NULL;
1690
1691 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
1692 if (!skb)
1693 return NULL;
1694
1695 memcpy(__skb_put(skb, size), buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001696
1697 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001698 skb_reset_mac_header(skb);
1699 skb->protocol = htons(ETH_P_IP);
1700 skb->pkt_type = SKB_TYPE;
1701 skb->mark = SKB_MARK;
1702 skb->hash = SKB_HASH;
1703 skb->queue_mapping = SKB_QUEUE_MAP;
1704 skb->vlan_tci = SKB_VLAN_TCI;
1705 skb->dev = &dev;
1706 skb->dev->ifindex = SKB_DEV_IFINDEX;
1707 skb->dev->type = SKB_DEV_TYPE;
1708 skb_set_network_header(skb, min(size, ETH_HLEN));
1709
1710 return skb;
1711}
1712
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001713static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001714{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001715 if (test->aux & FLAG_NO_DATA)
1716 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001717
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001718 /* Test case expects an skb, so populate one. Various
1719 * subtests generate skbs of different sizes based on
1720 * the same data.
1721 */
1722 return populate_skb(test->data, test->test[sub].data_size);
1723}
1724
1725static void release_test_data(const struct bpf_test *test, void *data)
1726{
1727 if (test->aux & FLAG_NO_DATA)
1728 return;
1729
1730 kfree_skb(data);
1731}
1732
1733static int probe_filter_length(struct sock_filter *fp)
1734{
1735 int len = 0;
1736
1737 while (fp->code != 0 || fp->k != 0) {
1738 fp++;
1739 len++;
1740 }
1741
1742 return len;
1743}
1744
1745static struct sk_filter *generate_filter(int which, int *err)
1746{
1747 struct sk_filter *fp;
1748 struct sock_fprog_kern fprog;
1749 unsigned int flen = probe_filter_length(tests[which].u.insns);
1750 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
1751
1752 switch (test_type) {
1753 case CLASSIC:
1754 fprog.filter = tests[which].u.insns;
1755 fprog.len = flen;
1756
1757 *err = sk_unattached_filter_create(&fp, &fprog);
1758 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
1759 if (*err == -EINVAL) {
1760 pr_cont("PASS\n");
1761 /* Verifier rejected filter as expected. */
1762 *err = 0;
1763 return NULL;
1764 } else {
1765 pr_cont("UNEXPECTED_PASS\n");
1766 /* Verifier didn't reject the test that's
1767 * bad enough, just return!
1768 */
1769 *err = -EINVAL;
1770 return NULL;
1771 }
1772 }
1773 /* We don't expect to fail. */
1774 if (*err) {
1775 pr_cont("FAIL to attach err=%d len=%d\n",
1776 *err, fprog.len);
1777 return NULL;
1778 }
1779 break;
1780
1781 case INTERNAL:
1782 fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
1783 if (fp == NULL) {
1784 pr_cont("UNEXPECTED_FAIL no memory left\n");
1785 *err = -ENOMEM;
1786 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001787 }
1788
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001789 fp->len = flen;
1790 memcpy(fp->insnsi, tests[which].u.insns_int,
1791 fp->len * sizeof(struct sock_filter_int));
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001792
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001793 sk_filter_select_runtime(fp);
1794 break;
1795 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001796
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001797 *err = 0;
1798 return fp;
1799}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001800
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001801static void release_filter(struct sk_filter *fp, int which)
1802{
1803 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001804
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001805 switch (test_type) {
1806 case CLASSIC:
1807 sk_unattached_filter_destroy(fp);
1808 break;
1809 case INTERNAL:
1810 sk_filter_free(fp);
1811 break;
1812 }
1813}
1814
1815static int __run_one(const struct sk_filter *fp, const void *data,
1816 int runs, u64 *duration)
1817{
1818 u64 start, finish;
1819 int ret, i;
1820
1821 start = ktime_to_us(ktime_get());
1822
1823 for (i = 0; i < runs; i++)
1824 ret = SK_RUN_FILTER(fp, data);
1825
1826 finish = ktime_to_us(ktime_get());
1827
1828 *duration = (finish - start) * 1000ULL;
1829 do_div(*duration, runs);
1830
1831 return ret;
1832}
1833
1834static int run_one(const struct sk_filter *fp, struct bpf_test *test)
1835{
1836 int err_cnt = 0, i, runs = MAX_TESTRUNS;
1837
1838 for (i = 0; i < MAX_SUBTESTS; i++) {
1839 void *data;
1840 u64 duration;
1841 u32 ret;
1842
1843 if (test->test[i].data_size == 0 &&
1844 test->test[i].result == 0)
1845 break;
1846
1847 data = generate_test_data(test, i);
1848 ret = __run_one(fp, data, runs, &duration);
1849 release_test_data(test, data);
1850
1851 if (ret == test->test[i].result) {
1852 pr_cont("%lld ", duration);
1853 } else {
1854 pr_cont("ret %d != %d ", ret,
1855 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001856 err_cnt++;
1857 }
1858 }
1859
1860 return err_cnt;
1861}
1862
1863static __init int test_bpf(void)
1864{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001865 int i, err_cnt = 0, pass_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001866
1867 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001868 struct sk_filter *fp;
1869 int err;
1870
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001871 pr_info("#%d %s ", i, tests[i].descr);
1872
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001873 fp = generate_filter(i, &err);
1874 if (fp == NULL) {
1875 if (err == 0) {
1876 pass_cnt++;
1877 continue;
1878 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001879
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001880 return err;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001881 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001882 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001883 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001884
1885 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001886 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001887 err_cnt++;
1888 } else {
1889 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001890 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001891 }
1892 }
1893
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001894 pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
1895 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001896}
1897
1898static int __init test_bpf_init(void)
1899{
1900 return test_bpf();
1901}
1902
1903static void __exit test_bpf_exit(void)
1904{
1905}
1906
1907module_init(test_bpf_init);
1908module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001909
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001910MODULE_LICENSE("GPL");