Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
fork
Configure Feed
Select the types of activity you want to include in your feed.
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_helpers.h"
7
8struct bpf_map_def SEC("maps") mim_array = {
9 .type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
10 .key_size = sizeof(int),
11 /* must be sizeof(__u32) for map in map */
12 .value_size = sizeof(__u32),
13 .max_entries = 1,
14 .map_flags = 0,
15};
16
17struct bpf_map_def SEC("maps") mim_hash = {
18 .type = BPF_MAP_TYPE_HASH_OF_MAPS,
19 .key_size = sizeof(int),
20 /* must be sizeof(__u32) for map in map */
21 .value_size = sizeof(__u32),
22 .max_entries = 1,
23 .map_flags = 0,
24};
25
26SEC("xdp_mimtest")
27int xdp_mimtest0(struct xdp_md *ctx)
28{
29 int value = 123;
30 int key = 0;
31 void *map;
32
33 map = bpf_map_lookup_elem(&mim_array, &key);
34 if (!map)
35 return XDP_DROP;
36
37 bpf_map_update_elem(map, &key, &value, 0);
38
39 map = bpf_map_lookup_elem(&mim_hash, &key);
40 if (!map)
41 return XDP_DROP;
42
43 bpf_map_update_elem(map, &key, &value, 0);
44
45 return XDP_PASS;
46}
47
48int _version SEC("version") = 1;
49char _license[] SEC("license") = "GPL";