Add iproute2_compat.h to get iproute2 map support

This is needed for pinning maps later.

Cannot use the binary compatible top-part of struct, due to the
need for pinning later.

Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
This commit is contained in:
Jesper Dangaard Brouer
2020-11-08 13:53:04 +01:00
parent 30e9f04cf3
commit 30e9bddd8b
2 changed files with 36 additions and 0 deletions

View File

@@ -1,9 +1,21 @@
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <xdp/parsing_helpers.h>
#include "iproute2_compat.h"
char _license[] SEC("license") = "GPL";
/* The tc tool (iproute2) use another ELF map layout than libbpf (struct
* bpf_map_def), see struct bpf_elf_map from iproute2.
*/
struct bpf_elf_map SEC("maps") cnt_map = {
.type = BPF_MAP_TYPE_ARRAY,
.size_key = sizeof(__u32),
.size_value = sizeof(__u64),
.max_elem = 1,
//.pinning = PIN_GLOBAL_NS,
};
SEC("classifier") int tc_dummy(struct __sk_buff *skb)
{
volatile void *data, *data_end;

View File

@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __IPROUTE2_COMPAT_H
#define __IPROUTE2_COMPAT_H
/* The tc tool (iproute2) use another ELF map layout than libbpf, see struct
* bpf_elf_map from iproute2, but struct bpf_map_def from libbpf have same
* binary layout until "flags". Thus, BPF-progs can use both if careful.
*/
/* ELF map definition (copied from iproute2 source code) */
struct bpf_elf_map {
__u32 type;
__u32 size_key;
__u32 size_value;
__u32 max_elem;
__u32 flags;
__u32 id;
__u32 pinning;
__u32 inner_id;
__u32 inner_idx;
};
#endif /* __IPROUTE2_COMPAT_H */