WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_sockmap_update.c
blob9d0c9f28cab2ed6cc0587f8eca4ad1ba1d31ee53
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Cloudflare
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
6 struct {
7 __uint(type, BPF_MAP_TYPE_SOCKMAP);
8 __uint(max_entries, 1);
9 __type(key, __u32);
10 __type(value, __u64);
11 } src SEC(".maps");
13 struct {
14 __uint(type, BPF_MAP_TYPE_SOCKMAP);
15 __uint(max_entries, 1);
16 __type(key, __u32);
17 __type(value, __u64);
18 } dst_sock_map SEC(".maps");
20 struct {
21 __uint(type, BPF_MAP_TYPE_SOCKHASH);
22 __uint(max_entries, 1);
23 __type(key, __u32);
24 __type(value, __u64);
25 } dst_sock_hash SEC(".maps");
27 SEC("classifier/copy_sock_map")
28 int copy_sock_map(void *ctx)
30 struct bpf_sock *sk;
31 bool failed = false;
32 __u32 key = 0;
34 sk = bpf_map_lookup_elem(&src, &key);
35 if (!sk)
36 return SK_DROP;
38 if (bpf_map_update_elem(&dst_sock_map, &key, sk, 0))
39 failed = true;
41 if (bpf_map_update_elem(&dst_sock_hash, &key, sk, 0))
42 failed = true;
44 bpf_sk_release(sk);
45 return failed ? SK_DROP : SK_PASS;
48 char _license[] SEC("license") = "GPL";