1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Isovalent, Inc.
5 #include <linux/pkt_cls.h>
8 #include <bpf/bpf_helpers.h>
11 __uint(type, BPF_MAP_TYPE_ARRAY);
12 __uint(max_entries, 11);
15 } result_number SEC(".maps");
18 __uint(type, BPF_MAP_TYPE_ARRAY);
19 __uint(max_entries, 5);
21 const char (*value)[32];
22 } result_string SEC(".maps");
31 __uint(type, BPF_MAP_TYPE_ARRAY);
32 __uint(max_entries, 5);
34 __type(value, struct foo);
35 } result_struct SEC(".maps");
37 /* Relocation tests for __u64s. */
39 static __u64 num1 = 42;
40 static const __u64 num2 = 24;
41 static __u64 num3 = 0;
42 static __u64 num4 = 0xffeeff;
43 static const __u64 num5 = 0xabab;
44 static const __u64 num6 = 0xab;
46 /* Relocation tests for strings. */
47 static const char str0[32] = "abcdefghijklmnopqrstuvwxyz";
48 static char str1[32] = "abcdefghijklmnopqrstuvwxyz";
51 /* Relocation tests for structs. */
52 static const struct foo struct0 = {
55 .c = 0x1111111111111111ULL,
57 static struct foo struct1;
58 static const struct foo struct2;
59 static struct foo struct3 = {
62 .c = 0x2111111111111111ULL,
65 #define test_reloc(map, num, var) \
68 bpf_map_update_elem(&result_##map, &key, var, 0); \
72 int load_static_data(struct __sk_buff *skb)
74 static const __u64 bar = ~0;
76 test_reloc(number, 0, &num0);
77 test_reloc(number, 1, &num1);
78 test_reloc(number, 2, &num2);
79 test_reloc(number, 3, &num3);
80 test_reloc(number, 4, &num4);
81 test_reloc(number, 5, &num5);
83 test_reloc(number, 6, &num4);
84 test_reloc(number, 7, &num0);
85 test_reloc(number, 8, &num6);
87 test_reloc(string, 0, str0);
88 test_reloc(string, 1, str1);
89 test_reloc(string, 2, str2);
91 test_reloc(string, 3, str1);
92 __builtin_memcpy(&str2[2], "hello", sizeof("hello"));
93 test_reloc(string, 4, str2);
95 test_reloc(struct, 0, &struct0);
96 test_reloc(struct, 1, &struct1);
97 test_reloc(struct, 2, &struct2);
98 test_reloc(struct, 3, &struct3);
100 test_reloc(number, 9, &struct0.c);
101 test_reloc(number, 10, &bar);
106 char _license[] SEC("license") = "GPL";