linux/tools/testing/selftests/bpf/progs/modify_return.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2
   3/*
   4 * Copyright 2020 Google LLC.
   5 */
   6
   7#include <linux/bpf.h>
   8#include <bpf/bpf_helpers.h>
   9#include <bpf/bpf_tracing.h>
  10
  11char _license[] SEC("license") = "GPL";
  12
  13static int sequence = 0;
  14__s32 input_retval = 0;
  15
  16__u64 fentry_result = 0;
  17SEC("fentry/bpf_modify_return_test")
  18int BPF_PROG(fentry_test, int a, __u64 b)
  19{
  20        sequence++;
  21        fentry_result = (sequence == 1);
  22        return 0;
  23}
  24
  25__u64 fmod_ret_result = 0;
  26SEC("fmod_ret/bpf_modify_return_test")
  27int BPF_PROG(fmod_ret_test, int a, int *b, int ret)
  28{
  29        sequence++;
  30        /* This is the first fmod_ret program, the ret passed should be 0 */
  31        fmod_ret_result = (sequence == 2 && ret == 0);
  32        return input_retval;
  33}
  34
  35__u64 fexit_result = 0;
  36SEC("fexit/bpf_modify_return_test")
  37int BPF_PROG(fexit_test, int a, __u64 b, int ret)
  38{
  39        sequence++;
  40        /* If the input_reval is non-zero a successful modification should have
  41         * occurred.
  42         */
  43        if (input_retval)
  44                fexit_result = (sequence == 3 && ret == input_retval);
  45        else
  46                fexit_result = (sequence == 3 && ret == 4);
  47
  48        return 0;
  49}
  50