Commit a1f93c8f authored by Daniel T. Lee's avatar Daniel T. Lee Committed by Alexei Starovoitov

samples/bpf: replace legacy map with the BTF-defined map

With libbpf 1.0 release, support for legacy BPF map declaration syntax
had been dropped. If you run a program using legacy BPF in the latest
libbpf, the following error will be output.

    libbpf: map 'lwt_len_hist_map' (legacy): legacy map definitions are deprecated, use BTF-defined maps instead
    libbpf: Use of BPF_ANNOTATE_KV_PAIR is deprecated, use BTF-defined maps in .maps section instead

This commit replaces legacy map with the BTF-defined map.
Signed-off-by: default avatarDaniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230115071613.125791-7-danieltimlee@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 58e975d0
...@@ -16,23 +16,13 @@ ...@@ -16,23 +16,13 @@
#include <uapi/linux/in.h> #include <uapi/linux/in.h>
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
struct bpf_elf_map { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_HASH);
__u32 size_key; __type(key, u64);
__u32 size_value; __type(value, u64);
__u32 max_elem; __uint(pinning, LIBBPF_PIN_BY_NAME);
__u32 flags; __uint(max_entries, 1024);
__u32 id; } lwt_len_hist_map SEC(".maps");
__u32 pinning;
};
struct bpf_elf_map SEC("maps") lwt_len_hist_map = {
.type = BPF_MAP_TYPE_PERCPU_HASH,
.size_key = sizeof(__u64),
.size_value = sizeof(__u64),
.pinning = 2,
.max_elem = 1024,
};
static unsigned int log2(unsigned int v) static unsigned int log2(unsigned int v)
{ {
......
...@@ -19,24 +19,13 @@ struct eth_hdr { ...@@ -19,24 +19,13 @@ struct eth_hdr {
unsigned short h_proto; unsigned short h_proto;
}; };
#define PIN_GLOBAL_NS 2 struct {
struct bpf_elf_map { __uint(type, BPF_MAP_TYPE_CGROUP_ARRAY);
__u32 type; __type(key, u32);
__u32 size_key; __type(value, u32);
__u32 size_value; __uint(pinning, LIBBPF_PIN_BY_NAME);
__u32 max_elem; __uint(max_entries, 1);
__u32 flags; } test_cgrp2_array_pin SEC(".maps");
__u32 id;
__u32 pinning;
};
struct bpf_elf_map SEC("maps") test_cgrp2_array_pin = {
.type = BPF_MAP_TYPE_CGROUP_ARRAY,
.size_key = sizeof(uint32_t),
.size_value = sizeof(uint32_t),
.pinning = PIN_GLOBAL_NS,
.max_elem = 1,
};
SEC("filter") SEC("filter")
int handle_egress(struct __sk_buff *skb) int handle_egress(struct __sk_buff *skb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment