45 lines · c
1// SPDX-License-Identifier: GPL-2.02 3#include <linux/bpf.h>4#include <bpf/bpf_helpers.h>5 6char _license[] SEC("license") = "GPL";7 8struct {9 __uint(type, BPF_MAP_TYPE_HASH);10 __uint(max_entries, 2);11 __type(key, struct bigelement);12 __type(value, __u32);13} hash_map SEC(".maps");14 15struct {16 __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);17 __uint(max_entries, 1);18 __type(key, __u32);19 __type(value, struct bigelement);20} key_map SEC(".maps");21 22struct bigelement {23 int a;24 char b[4096];25 long long c;26};27 28SEC("raw_tracepoint/sys_enter")29int bpf_hash_large_key_test(void *ctx)30{31 int zero = 0, value = 42;32 struct bigelement *key;33 34 key = bpf_map_lookup_elem(&key_map, &zero);35 if (!key)36 return 0;37 38 key->c = 1;39 if (bpf_map_update_elem(&hash_map, key, &value, BPF_ANY))40 return 0;41 42 return 0;43}44 45