This is my simple ebpf program
#include <linux/bpf.h>
#include <linux/version.h>
#include <linux/ip.h>
#include <linux/if_ether.h>
#include <bpf_helpers.h>
#include <bpf_endian.h>// iproute specifically looks for this ELF section
//#include <net/sock.h>
#include <linux/bpf.h>
#include <linux/version.h>
#include <bpf_helpers.h>
#define bpf_printk(fmt, ...) \
({ \
char ____fmt[] = fmt; \
bpf_trace_printk(____fmt, sizeof(____fmt), \
##__VA_ARGS__); \
})
SEC("kprobe/tcp_connect")
int connect(struct pt_regs *ctx)
{
bpf_printk("connect called -- Hello from [fawad] \n");
return 0;
}
char _license[] SEC("license") = "GPL";
compiling above program with this command
clang -O2 -Wall -target bpf -c -o xdp.o -I /build/root/usr/include/bpf -I /usr/src/linux-headers-5.11.0-41/arch/alpha/include/ -I /usr/src/linux-headers-5.11.0-41/arch/alpha/include/ xdp.c
and this is a loader program
#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>
#include <bpf/libbpf.h>
#include <bpf_load.h>
int main() { // raise the rlimit or see
// failed to create a map: 1 Operation not permitted
// when load_bpf_file is run
if (load_bpf_file("xdp.o"))
{
printf("%s\n", bpf_log_buf);
return 1;
}
while(1){
sleep(1);
}
} return 0;
}
compiling my ebpf loader program like this
clang -O2 -Wall -target bpf -c -o user.o -I /build/root/usr/include/bpf -I /home/ubuntu/Desktop/linux/test/linux-5.14.1/samples/bpf/ -I /usr/src/linux-headers-5.11.0-41/arch/alpha/include/ -I /usr/src/linux-headers-5.11.0-41/arch/alpha/include/ user.c
When I run the loader program like #./user.o
it gives error
bash: ./user.o: Permission denied
running with sudo does not even recognized the file
root@this:/home/ubuntu/Desktop/ebpf# sudo ./user.o
sudo: ./user.o: command not found
root@this:/home/ubuntu/Desktop/ebpf#