linux/tools/testing/selftests/bpf/progs/recursion.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright (c) 2021 Facebook */
   3
   4#include "vmlinux.h"
   5#include <bpf/bpf_helpers.h>
   6#include <bpf/bpf_tracing.h>
   7
   8char _license[] SEC("license") = "GPL";
   9
  10struct {
  11        __uint(type, BPF_MAP_TYPE_HASH);
  12        __uint(max_entries, 1);
  13        __type(key, int);
  14        __type(value, long);
  15} hash1 SEC(".maps");
  16
  17struct {
  18        __uint(type, BPF_MAP_TYPE_HASH);
  19        __uint(max_entries, 1);
  20        __type(key, int);
  21        __type(value, long);
  22} hash2 SEC(".maps");
  23
  24int pass1 = 0;
  25int pass2 = 0;
  26
  27SEC("fentry/__htab_map_lookup_elem")
  28int BPF_PROG(on_lookup, struct bpf_map *map)
  29{
  30        int key = 0;
  31
  32        if (map == (void *)&hash1) {
  33                pass1++;
  34                return 0;
  35        }
  36        if (map == (void *)&hash2) {
  37                pass2++;
  38                /* htab_map_gen_lookup() will inline below call
  39                 * into direct call to __htab_map_lookup_elem()
  40                 */
  41                bpf_map_lookup_elem(&hash2, &key);
  42                return 0;
  43        }
  44
  45        return 0;
  46}
  47