github.com/cilium/cilium@v1.16.2/pkg/bpf/testdata/unreachable-tailcall.c (about) 1 #include <bpf/loader.h> 2 #include <bpf/section.h> 3 4 #include <bpf/ctx/skb.h> 5 #include <bpf/tailcall.h> 6 7 #define CILIUM_MAP_CALLS 2 8 9 volatile const int global_var = 0; 10 11 struct bpf_elf_map __section_maps cilium_calls_test = { 12 .type = BPF_MAP_TYPE_PROG_ARRAY, 13 .id = CILIUM_MAP_CALLS, 14 .size_key = sizeof(__u32), 15 .size_value = sizeof(__u32), 16 .max_elem = 5, 17 }; 18 19 #define TAIL_A 0 20 #define TAIL_B 1 21 #define TAIL_C 2 22 #define TAIL_D 3 23 #define TAIL_E 4 24 25 __section_tail(CILIUM_MAP_CALLS, TAIL_E) 26 static int e(void *ctx) { 27 return 0; 28 } 29 30 __section_tail(CILIUM_MAP_CALLS, TAIL_D) 31 static int d(void *ctx) { 32 tail_call_static(ctx, cilium_calls_test, TAIL_E); 33 return 0; 34 } 35 36 __section_tail(CILIUM_MAP_CALLS, TAIL_C) 37 static int c(void *ctx) { 38 return 0; 39 } 40 41 __section_tail(CILIUM_MAP_CALLS, TAIL_B) 42 static int b(void *ctx) { 43 tail_call_static(ctx, cilium_calls_test, TAIL_C); 44 return 0; 45 } 46 47 48 __section_tail(CILIUM_MAP_CALLS, TAIL_A) 49 static int a(void *ctx) { 50 if (global_var == 0x01) { 51 tail_call_static(ctx, cilium_calls_test, TAIL_B); 52 } else { 53 tail_call_static(ctx, cilium_calls_test, TAIL_C); 54 } 55 56 return 0; 57 } 58 59 __section("tc") 60 static int cil_entry(void *ctx) { 61 tail_call_static(ctx, cilium_calls_test, TAIL_A); 62 return 0; 63 }