1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
6 #include <bpf/bpf_helpers.h>
7 #include "bpf_tcp_helpers.h"
9 char _license[] SEC("license") = "GPL";
12 struct bpf_timer timer;
16 __uint(type, BPF_MAP_TYPE_HASH);
17 __uint(max_entries, 1024);
19 __type(value, struct hmap_elem);
20 } inner_htab SEC(".maps");
26 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
27 __uint(max_entries, 2);
28 __uint(key_size, sizeof(int));
29 __uint(value_size, sizeof(int));
30 __array(values, struct inner_map);
31 } outer_arr SEC(".maps") = {
32 .values = { [ARRAY_KEY] = &inner_htab },
39 static int timer_cb1(void *map, int *key, struct hmap_elem *val);
41 static int timer_cb2(void *map, int *key, struct hmap_elem *val)
44 bpf_timer_set_callback(&val->timer, timer_cb1);
45 if (bpf_timer_start(&val->timer, 1000, 0))
51 /* callback for inner hash map */
52 static int timer_cb1(void *map, int *key, struct hmap_elem *val)
55 bpf_timer_set_callback(&val->timer, timer_cb2);
56 if (bpf_timer_start(&val->timer, 1000, 0))
58 /* Do a lookup to make sure 'map' and 'key' pointers are correct */
59 bpf_map_lookup_elem(map, key);
64 SEC("fentry/bpf_fentry_test1")
65 int BPF_PROG(test1, int a)
67 struct hmap_elem init = {};
68 struct bpf_map *inner_map;
69 struct hmap_elem *val;
70 int array_key = ARRAY_KEY;
71 int hash_key = HASH_KEY;
73 inner_map = bpf_map_lookup_elem(&outer_arr, &array_key);
77 bpf_map_update_elem(inner_map, &hash_key, &init, 0);
78 val = bpf_map_lookup_elem(inner_map, &hash_key);
82 bpf_timer_init(&val->timer, inner_map, CLOCK_MONOTONIC);
83 if (bpf_timer_set_callback(&val->timer, timer_cb1))
85 if (bpf_timer_start(&val->timer, 0, 0))