0001
0002
0003 #include <stddef.h>
0004 #include <linux/bpf.h>
0005 #include <linux/types.h>
0006 #include <bpf/bpf_helpers.h>
0007
0008 struct {
0009 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
0010 __uint(max_entries, 1);
0011 __uint(map_flags, 0);
0012 __type(key, __u32);
0013 __type(value, __u32);
0014 } mim_array SEC(".maps");
0015
0016 struct {
0017 __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
0018 __uint(max_entries, 1);
0019 __uint(map_flags, 0);
0020 __type(key, int);
0021 __type(value, __u32);
0022 } mim_hash SEC(".maps");
0023
0024 SEC("xdp")
0025 int xdp_mimtest0(struct xdp_md *ctx)
0026 {
0027 int value = 123;
0028 int *value_p;
0029 int key = 0;
0030 void *map;
0031
0032 map = bpf_map_lookup_elem(&mim_array, &key);
0033 if (!map)
0034 return XDP_DROP;
0035
0036 bpf_map_update_elem(map, &key, &value, 0);
0037 value_p = bpf_map_lookup_elem(map, &key);
0038 if (!value_p || *value_p != 123)
0039 return XDP_DROP;
0040
0041 map = bpf_map_lookup_elem(&mim_hash, &key);
0042 if (!map)
0043 return XDP_DROP;
0044
0045 bpf_map_update_elem(map, &key, &value, 0);
0046
0047 return XDP_PASS;
0048 }
0049
0050 char _license[] SEC("license") = "GPL";