staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / prog_tests / skb_ctx.c
blobe95baa32e2778daba75b5af14eb09f8992289df7
1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
4 void test_skb_ctx(void)
6 struct __sk_buff skb = {
7 .cb[0] = 1,
8 .cb[1] = 2,
9 .cb[2] = 3,
10 .cb[3] = 4,
11 .cb[4] = 5,
12 .priority = 6,
14 struct bpf_prog_test_run_attr tattr = {
15 .data_in = &pkt_v4,
16 .data_size_in = sizeof(pkt_v4),
17 .ctx_in = &skb,
18 .ctx_size_in = sizeof(skb),
19 .ctx_out = &skb,
20 .ctx_size_out = sizeof(skb),
22 struct bpf_object *obj;
23 int err;
24 int i;
26 err = bpf_prog_load("./test_skb_ctx.o", BPF_PROG_TYPE_SCHED_CLS, &obj,
27 &tattr.prog_fd);
28 if (CHECK_ATTR(err, "load", "err %d errno %d\n", err, errno))
29 return;
31 /* ctx_in != NULL, ctx_size_in == 0 */
33 tattr.ctx_size_in = 0;
34 err = bpf_prog_test_run_xattr(&tattr);
35 CHECK_ATTR(err == 0, "ctx_size_in", "err %d errno %d\n", err, errno);
36 tattr.ctx_size_in = sizeof(skb);
38 /* ctx_out != NULL, ctx_size_out == 0 */
40 tattr.ctx_size_out = 0;
41 err = bpf_prog_test_run_xattr(&tattr);
42 CHECK_ATTR(err == 0, "ctx_size_out", "err %d errno %d\n", err, errno);
43 tattr.ctx_size_out = sizeof(skb);
45 /* non-zero [len, tc_index] fields should be rejected*/
47 skb.len = 1;
48 err = bpf_prog_test_run_xattr(&tattr);
49 CHECK_ATTR(err == 0, "len", "err %d errno %d\n", err, errno);
50 skb.len = 0;
52 skb.tc_index = 1;
53 err = bpf_prog_test_run_xattr(&tattr);
54 CHECK_ATTR(err == 0, "tc_index", "err %d errno %d\n", err, errno);
55 skb.tc_index = 0;
57 /* non-zero [hash, sk] fields should be rejected */
59 skb.hash = 1;
60 err = bpf_prog_test_run_xattr(&tattr);
61 CHECK_ATTR(err == 0, "hash", "err %d errno %d\n", err, errno);
62 skb.hash = 0;
64 skb.sk = (struct bpf_sock *)1;
65 err = bpf_prog_test_run_xattr(&tattr);
66 CHECK_ATTR(err == 0, "sk", "err %d errno %d\n", err, errno);
67 skb.sk = 0;
69 err = bpf_prog_test_run_xattr(&tattr);
70 CHECK_ATTR(err != 0 || tattr.retval,
71 "run",
72 "err %d errno %d retval %d\n",
73 err, errno, tattr.retval);
75 CHECK_ATTR(tattr.ctx_size_out != sizeof(skb),
76 "ctx_size_out",
77 "incorrect output size, want %lu have %u\n",
78 sizeof(skb), tattr.ctx_size_out);
80 for (i = 0; i < 5; i++)
81 CHECK_ATTR(skb.cb[i] != i + 2,
82 "ctx_out_cb",
83 "skb->cb[i] == %d, expected %d\n",
84 skb.cb[i], i + 2);
85 CHECK_ATTR(skb.priority != 7,
86 "ctx_out_priority",
87 "skb->priority == %d, expected %d\n",
88 skb.priority, 7);