WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_skmsg_load_helpers.c
blob45e8fc75a7397a0e68e5329893b21be4a63c8099
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Isovalent, Inc.
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
6 struct {
7 __uint(type, BPF_MAP_TYPE_SOCKMAP);
8 __uint(max_entries, 2);
9 __type(key, __u32);
10 __type(value, __u64);
11 } sock_map SEC(".maps");
13 struct {
14 __uint(type, BPF_MAP_TYPE_SOCKHASH);
15 __uint(max_entries, 2);
16 __type(key, __u32);
17 __type(value, __u64);
18 } sock_hash SEC(".maps");
20 struct {
21 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
22 __uint(map_flags, BPF_F_NO_PREALLOC);
23 __type(key, __u32);
24 __type(value, __u64);
25 } socket_storage SEC(".maps");
27 SEC("sk_msg")
28 int prog_msg_verdict(struct sk_msg_md *msg)
30 struct task_struct *task = (struct task_struct *)bpf_get_current_task();
31 int verdict = SK_PASS;
32 __u32 pid, tpid;
33 __u64 *sk_stg;
35 pid = bpf_get_current_pid_tgid() >> 32;
36 sk_stg = bpf_sk_storage_get(&socket_storage, msg->sk, 0, BPF_SK_STORAGE_GET_F_CREATE);
37 if (!sk_stg)
38 return SK_DROP;
39 *sk_stg = pid;
40 bpf_probe_read_kernel(&tpid , sizeof(tpid), &task->tgid);
41 if (pid != tpid)
42 verdict = SK_DROP;
43 bpf_sk_storage_delete(&socket_storage, (void *)msg->sk);
44 return verdict;
47 char _license[] SEC("license") = "GPL";