3e689141e6
Fix all selftests to include libbpf header files with the bpf/ prefix, to be consistent with external users of the library. Also ensure that all includes of exported libbpf header files (those that are exported on 'make install' of the library) use bracketed includes instead of quoted. To not break the build, keep the old include path until everything has been changed to the new one; a subsequent patch will remove that. Fixes: 6910d7d3867a ("selftests/bpf: Ensure bpf_helper_defs.h are taken from selftests dir") Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/157952560568.1683545.9649335788846513446.stgit@toke.dk
60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
// Copyright (c) 2018 Politecnico di Torino
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <linux/bpf.h>
|
|
#include <linux/if_ether.h>
|
|
#include <linux/ip.h>
|
|
#include <linux/pkt_cls.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
int _version SEC("version") = 1;
|
|
|
|
struct {
|
|
__uint(type, MAP_TYPE);
|
|
__uint(max_entries, 32);
|
|
__uint(map_flags, 0);
|
|
__uint(key_size, 0);
|
|
__uint(value_size, sizeof(__u32));
|
|
} map_in SEC(".maps");
|
|
|
|
struct {
|
|
__uint(type, MAP_TYPE);
|
|
__uint(max_entries, 32);
|
|
__uint(map_flags, 0);
|
|
__uint(key_size, 0);
|
|
__uint(value_size, sizeof(__u32));
|
|
} map_out SEC(".maps");
|
|
|
|
SEC("test")
|
|
int _test(struct __sk_buff *skb)
|
|
{
|
|
void *data_end = (void *)(long)skb->data_end;
|
|
void *data = (void *)(long)skb->data;
|
|
struct ethhdr *eth = (struct ethhdr *)(data);
|
|
__u32 value;
|
|
int err;
|
|
|
|
if (eth + 1 > data_end)
|
|
return TC_ACT_SHOT;
|
|
|
|
struct iphdr *iph = (struct iphdr *)(eth + 1);
|
|
|
|
if (iph + 1 > data_end)
|
|
return TC_ACT_SHOT;
|
|
|
|
err = bpf_map_pop_elem(&map_in, &value);
|
|
if (err)
|
|
return TC_ACT_SHOT;
|
|
|
|
iph->daddr = value;
|
|
|
|
err = bpf_map_push_elem(&map_out, &iph->saddr, 0);
|
|
if (err)
|
|
return TC_ACT_SHOT;
|
|
|
|
return TC_ACT_OK;
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|