Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/* Converted from tools/testing/selftests/bpf/verifier/xdp.c */
3
4#include <linux/bpf.h>
5#include <bpf/bpf_helpers.h>
6#include "bpf_misc.h"
7
8struct {
9 __uint(type, BPF_MAP_TYPE_ARRAY);
10 __uint(max_entries, 1);
11 __type(key, int);
12 __type(value, __u64);
13 __uint(map_flags, BPF_F_RDONLY_PROG);
14} map_array_ro SEC(".maps");
15
16SEC("xdp")
17__description("XDP, using ifindex from netdev")
18__success __retval(1)
19__naked void xdp_using_ifindex_from_netdev(void)
20{
21 asm volatile (" \
22 r0 = 0; \
23 r2 = *(u32*)(r1 + %[xdp_md_ingress_ifindex]); \
24 if r2 < 1 goto l0_%=; \
25 r0 = 1; \
26l0_%=: exit; \
27" :
28 : __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex))
29 : __clobber_all);
30}
31
32SEC("xdp")
33__description("XDP, using xdp_store_bytes from RO map")
34__success __retval(0)
35__naked void xdp_store_bytes_from_ro_map(void)
36{
37 asm volatile (" \
38 r6 = r1; \
39 r1 = 0; \
40 *(u64*)(r10 - 8) = r1; \
41 r2 = r10; \
42 r2 += -8; \
43 r1 = %[map_array_ro] ll; \
44 call %[bpf_map_lookup_elem]; \
45 if r0 == 0 goto l0_%=; \
46 r1 = r6; \
47 r2 = 0; \
48 r3 = r0; \
49 r4 = 8; \
50 call %[bpf_xdp_store_bytes]; \
51l0_%=: exit; \
52" :
53 : __imm(bpf_map_lookup_elem),
54 __imm(bpf_xdp_store_bytes),
55 __imm_addr(map_array_ro)
56 : __clobber_all);
57}
58
59char _license[] SEC("license") = "GPL";