lizrice / learning-ebpf

Learning eBPF, published by O'Reilly - out now! Here's where you'll find a VM config for the examples, and more

Home Page:https://www.amazon.com/Learning-eBPF-Programming-Observability-Networking/dp/1098135121

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make File Error Chapter 8

laikas123 opened this issue · comments

clang
-target bpf
-D BPF_TRACING
-I/usr/include/x86_64-linux-gnu
-Wall
-O2 -g -o hello.bpf.o -c hello.bpf.c
bpftool net detach xdp dev lo
rm -f /sys/fs/bpf/hello
bpftool prog load hello.bpf.o /sys/fs/bpf/hello
libbpf: prog 'ping': BPF program load failed: Invalid argument
libbpf: prog 'ping': -- BEGIN PROG LOAD LOG --
0: R1=ctx(off=0,imm=0) R10=fp0
; void *data_end = (void *)(long)ctx->data_end;
0: (61) r2 = *(u32 *)(r1 +4) ; R1=ctx(off=0,imm=0) R2_w=pkt_end(off=0,imm=0)
; void *data = (void *)(long)ctx->data;
1: (61) r3 = *(u32 *)(r1 +0) ; R1=ctx(off=0,imm=0) R3_w=pkt(off=0,r=0,imm=0)
; if (data + sizeof(struct ethhdr) > data_end)
2: (bf) r1 = r3 ; R1_w=pkt(off=0,r=0,imm=0) R3_w=pkt(off=0,r=0,imm=0)
3: (07) r1 += 14 ; R1_w=pkt(off=14,r=0,imm=0)
; if (data + sizeof(struct ethhdr) > data_end)
4: (2d) if r1 > r2 goto pc+10 ; R1_w=pkt(off=14,r=14,imm=0) R2_w=pkt_end(off=0,imm=0)
; if (bpf_ntohs(eth->h_proto) == ETH_P_IP)
5: (69) r4 = *(u16 *)(r3 +12) ; R3_w=pkt(off=0,r=14,imm=0) R4_w=scalar(umax=65535,var_off=(0x0; 0xffff))
; if (bpf_ntohs(eth->h_proto) == ETH_P_IP)
6: (55) if r4 != 0x8 goto pc+8 ; R4_w=8
7: (07) r3 += 34 ; R3=pkt(off=34,r=14,imm=0)
8: (2d) if r3 > r2 goto pc+6 ; R2=pkt_end(off=0,imm=0) R3=pkt(off=34,r=34,imm=0)
; protocol = iph->protocol;
9: (71) r1 = *(u8 *)(r1 +9) ; R1_w=scalar(umax=255,var_off=(0x0; 0xff))
; if (protocol == 1) // ICMP
10: (55) if r1 != 0x1 goto pc+4 ; R1_w=1
; bpf_printk("Hello ping");
11: (18) r1 = 0xffff9b35a233c710 ; R1_w=map_value(off=0,ks=4,vs=11,imm=0)
13: (b7) r2 = 11 ; R2_w=11
14: (85) call bpf_trace_printk#6
cannot call GPL-restricted function from non-GPL compatible program
processed 14 insns (limit 1000000) max_states_per_insn 0 total_states 1 peak_states 1 mark_read 1
-- END PROG LOAD LOG --
libbpf: prog 'ping': failed to load: -22
libbpf: failed to load object 'hello.bpf.o'
Error: failed to load object file
make: *** [Makefile:13: hello] Error 255

The second bolded line above is what is confusing me. I even added the -g flag but that didn't make it go away..

I also tried to manually load into the kernel but same issue..

Solution:

Add the following line to the bottom of hello.bpf.c:

char LICENSE[] SEC("license") = "Dual BSD/GPL";