Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v5.13 47 lines 970 B view raw
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2021 Facebook */ 3#include <linux/bpf.h> 4#include <bpf/bpf_helpers.h> 5#include "bpf_tcp_helpers.h" 6 7extern int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym; 8extern __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b, 9 __u32 c, __u64 d) __ksym; 10 11SEC("classifier") 12int kfunc_call_test2(struct __sk_buff *skb) 13{ 14 struct bpf_sock *sk = skb->sk; 15 16 if (!sk) 17 return -1; 18 19 sk = bpf_sk_fullsock(sk); 20 if (!sk) 21 return -1; 22 23 return bpf_kfunc_call_test2((struct sock *)sk, 1, 2); 24} 25 26SEC("classifier") 27int kfunc_call_test1(struct __sk_buff *skb) 28{ 29 struct bpf_sock *sk = skb->sk; 30 __u64 a = 1ULL << 32; 31 __u32 ret; 32 33 if (!sk) 34 return -1; 35 36 sk = bpf_sk_fullsock(sk); 37 if (!sk) 38 return -1; 39 40 a = bpf_kfunc_call_test1((struct sock *)sk, 1, a | 2, 3, a | 4); 41 ret = a >> 32; /* ret should be 2 */ 42 ret += (__u32)a; /* ret should be 12 */ 43 44 return ret; 45} 46 47char _license[] SEC("license") = "GPL";