1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2018 Facebook */ 3 #include <stddef.h> 4 #include <linux/bpf.h> 5 #include <linux/types.h> 6 #include <bpf/bpf_helpers.h> 7 8 struct { 9 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); 10 __uint(max_entries, 1); 11 __uint(map_flags, 0); 12 __type(key, __u32); 13 __type(value, __u32); 14 } mim_array SEC(".maps"); 15 16 struct { 17 __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS); 18 __uint(max_entries, 1); 19 __uint(map_flags, 0); 20 __type(key, int); 21 __type(value, __u32); 22 } mim_hash SEC(".maps"); 23 24 SEC("xdp") 25 int xdp_mimtest0(struct xdp_md *ctx) 26 { 27 int value = 123; 28 int *value_p; 29 int key = 0; 30 void *map; 31 32 map = bpf_map_lookup_elem(&mim_array, &key); 33 if (!map) 34 return XDP_DROP; 35 36 bpf_map_update_elem(map, &key, &value, 0); 37 value_p = bpf_map_lookup_elem(map, &key); 38 if (!value_p || *value_p != 123) 39 return XDP_DROP; 40 41 map = bpf_map_lookup_elem(&mim_hash, &key); 42 if (!map) 43 return XDP_DROP; 44 45 bpf_map_update_elem(map, &key, &value, 0); 46 47 return XDP_PASS; 48 } 49 50 char _license[] SEC("license") = "GPL"; 51