...

Text file src/github.com/cilium/ebpf/testdata/subprog_reloc.c

Documentation: github.com/cilium/ebpf/testdata

     1/* This file excercises the ELF loader.
     2 */
     3
     4#include "common.h"
     5
     6char __license[] __section("license") = "MIT";
     7
     8struct bpf_map_def hash_map __section("maps") = {
     9	.type        = BPF_MAP_TYPE_HASH,
    10	.key_size    = sizeof(uint32_t),
    11	.value_size  = sizeof(uint64_t),
    12	.max_entries = 1,
    13};
    14
    15static int sub_prog() {
    16	uint32_t key = 0;
    17	uint64_t val = 42;
    18
    19	map_update_elem(&hash_map, &key, &val, /* BPF_ANY */ 0);
    20
    21	return 0;
    22}
    23
    24__section("xdp") int fp_relocation() {
    25	uint32_t key = 0;
    26	uint64_t val = 1;
    27
    28	map_update_elem(&hash_map, &key, &val, /* BPF_ANY */ 0);
    29
    30	for_each_map_elem(&hash_map, sub_prog, (void *)0, 0);
    31
    32	uint64_t *new_val = map_lookup_elem(&hash_map, &key);
    33	if (!new_val) {
    34		return -1;
    35	}
    36
    37	return *new_val;
    38}

View as plain text