Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 
0003 /*
0004  * Copyright 2021 Google LLC.
0005  */
0006 
0007 #include <errno.h>
0008 #include <linux/bpf.h>
0009 #include <bpf/bpf_helpers.h>
0010 
0011 __u32 invocations = 0;
0012 __u32 assertion_error = 0;
0013 __u32 retval_value = 0;
0014 
0015 SEC("cgroup/setsockopt")
0016 int get_retval(struct bpf_sockopt *ctx)
0017 {
0018     retval_value = bpf_get_retval();
0019     __sync_fetch_and_add(&invocations, 1);
0020 
0021     return 1;
0022 }
0023 
0024 SEC("cgroup/setsockopt")
0025 int set_eunatch(struct bpf_sockopt *ctx)
0026 {
0027     __sync_fetch_and_add(&invocations, 1);
0028 
0029     if (bpf_set_retval(-EUNATCH))
0030         assertion_error = 1;
0031 
0032     return 0;
0033 }
0034 
0035 SEC("cgroup/setsockopt")
0036 int set_eisconn(struct bpf_sockopt *ctx)
0037 {
0038     __sync_fetch_and_add(&invocations, 1);
0039 
0040     if (bpf_set_retval(-EISCONN))
0041         assertion_error = 1;
0042 
0043     return 0;
0044 }
0045 
0046 SEC("cgroup/setsockopt")
0047 int legacy_eperm(struct bpf_sockopt *ctx)
0048 {
0049     __sync_fetch_and_add(&invocations, 1);
0050 
0051     return 0;
0052 }