mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 03:45:04 +07:00
451d1dc886
Since, the new syntax of BTF-defined map has been introduced,
the syntax for using maps under samples directory are mixed up.
For example, some are already using the new syntax, and some are using
existing syntax by calling them as 'legacy'.
As stated at commit abd29c9314
("libbpf: allow specifying map
definitions using BTF"), the BTF-defined map has more compatablility
with extending supported map definition features.
The commit doesn't replace all of the map to new BTF-defined map,
because some of the samples still use bpf_load instead of libbpf, which
can't properly create BTF-defined map.
This will only updates the samples which uses libbpf API for loading bpf
program. (ex. bpf_prog_load_xattr)
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
31 lines
657 B
C
31 lines
657 B
C
#include <uapi/linux/bpf.h>
|
|
#include <uapi/linux/if_ether.h>
|
|
#include <uapi/linux/if_packet.h>
|
|
#include <uapi/linux/ip.h>
|
|
#include "bpf_helpers.h"
|
|
#include "bpf_legacy.h"
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_ARRAY);
|
|
__type(key, u32);
|
|
__type(value, long);
|
|
__uint(max_entries, 256);
|
|
} my_map SEC(".maps");
|
|
|
|
SEC("socket1")
|
|
int bpf_prog1(struct __sk_buff *skb)
|
|
{
|
|
int index = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
|
|
long *value;
|
|
|
|
if (skb->pkt_type != PACKET_OUTGOING)
|
|
return 0;
|
|
|
|
value = bpf_map_lookup_elem(&my_map, &index);
|
|
if (value)
|
|
__sync_fetch_and_add(value, skb->len);
|
|
|
|
return 0;
|
|
}
|
|
char _license[] SEC("license") = "GPL";
|