i'm trying to install XDP program on my network driver but i get the error ELF contains non-{map,call} related relo data in entry 0 pointing to section 4! Compiler bug?! Error fetching program/map!
the code i'm trying to run :
#define KBUILD_MODNAME "filter"
#include <arpa/inet.h>
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <linux/udp.h>
static int (*bpf_trace_printk)(const char *fmt,...) = (void *)BPF_FUNC_trace_printk;
int udpfilter(struct xdp_md *ctx) {
bpf_trace_printk("got a packet\n");
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct ethhdr *eth = data;
if ((void*)eth + sizeof(*eth) <= data_end) {
struct iphdr *ip = data + sizeof(*eth);
if ((void*)ip + sizeof(*ip) <= data_end) {
if (ip->protocol == IPPROTO_UDP) {
struct udphdr *udp = (void*)ip + sizeof(*ip);
if ((void*)udp + sizeof(*udp) <= data_end) {
if (udp->dest == ntohs(7999)) {
bpf_trace_printk("udp port 7999\n");
udp->dest = ntohs(7998);
}
}
}
}
}
return XDP_PASS;
}
compiling command : clang -O2 -g -Wall -target bpf -c filter.c -o filter.o and it's ok!
and the command i use to install : ip link set enp0s3 xdpgeneric obj filter.o then i get the above error.
i'm not sure what it should means this message, did i miss something?