Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #include <linux/bpf.h>
0004 #include <bpf/bpf_helpers.h>
0005 
0006 char _license[] SEC("license") = "GPL";
0007 
0008 struct {
0009     __uint(type, BPF_MAP_TYPE_HASH);
0010     __uint(max_entries, 2);
0011     __type(key, struct bigelement);
0012     __type(value, __u32);
0013 } hash_map SEC(".maps");
0014 
0015 struct {
0016     __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
0017     __uint(max_entries, 1);
0018     __type(key, __u32);
0019     __type(value, struct bigelement);
0020 } key_map SEC(".maps");
0021 
0022 struct bigelement {
0023     int a;
0024     char b[4096];
0025     long long c;
0026 };
0027 
0028 SEC("raw_tracepoint/sys_enter")
0029 int bpf_hash_large_key_test(void *ctx)
0030 {
0031     int zero = 0, err = 1, value = 42;
0032     struct bigelement *key;
0033 
0034     key = bpf_map_lookup_elem(&key_map, &zero);
0035     if (!key)
0036         return 0;
0037 
0038     key->c = 1;
0039     if (bpf_map_update_elem(&hash_map, key, &value, BPF_ANY))
0040         return 0;
0041 
0042     return 0;
0043 }
0044