1 // SPDX-License-Identifier: GPL-2.0-only 2 3 /* 4 * Copyright 2021 Google LLC. 5 */ 6 7 #include <errno.h> 8 #include <linux/bpf.h> 9 #include <bpf/bpf_helpers.h> 10 11 __u32 invocations = 0; 12 __u32 assertion_error = 0; 13 __u32 retval_value = 0; 14 __u32 ctx_retval_value = 0; 15 16 SEC("cgroup/getsockopt") get_retval(struct bpf_sockopt * ctx)17int get_retval(struct bpf_sockopt *ctx) 18 { 19 retval_value = bpf_get_retval(); 20 ctx_retval_value = ctx->retval; 21 __sync_fetch_and_add(&invocations, 1); 22 23 return 1; 24 } 25 26 SEC("cgroup/getsockopt") set_eisconn(struct bpf_sockopt * ctx)27int set_eisconn(struct bpf_sockopt *ctx) 28 { 29 __sync_fetch_and_add(&invocations, 1); 30 31 if (bpf_set_retval(-EISCONN)) 32 assertion_error = 1; 33 34 return 1; 35 } 36 37 SEC("cgroup/getsockopt") clear_retval(struct bpf_sockopt * ctx)38int clear_retval(struct bpf_sockopt *ctx) 39 { 40 __sync_fetch_and_add(&invocations, 1); 41 42 ctx->retval = 0; 43 44 return 1; 45 } 46