char _license[] __section("license") = "GPL";
root@ubuntu1804hwe:~# clang -target bpf -I/usr/include/x86_64-linux-gnu/ -O2 -o test.o -c test.c
root@ubuntu1804hwe:~# ip link add name dummy1 type dummy
root@ubuntu1804hwe:~# ip link set dummy1 up
root@ubuntu1804hwe:~# tc qdisc add dev dummy1 clsact
root@ubuntu1804hwe:~# tc filter add dev dummy1 egress matchall action bpf obj ./test.o sec test
Here is an example:
root@ubuntu1804 hwe:~# uname -a hwe:~# cat test.c
Linux ubuntu1804hwe 5.4.0-47-generic #51~18.04.1-Ubuntu SMP Sat Sep 5 14:35:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu1804
#include <linux/pkt_cls.h>
#include <linux/bpf.h>
#ifndef __section _((section( NAME), used))
# define __section(NAME) __attribute_
#endif
static int (*bpf_skb_ change_ head)(void *ctx, int headroom, int flags) = skb_change_ head;
(void *) BPF_FUNC_
__section("test")
bpf_skb_ change_ head(skb, 14, 0);
int _test(struct __sk_buff *skb)
{
return TC_ACT_OK;
}
char _license[] __section( "license" ) = "GPL"; hwe:~# clang -target bpf -I/usr/ include/ x86_64- linux-gnu/ -O2 -o test.o -c test.c hwe:~# ip link add name dummy1 type dummy hwe:~# ip link set dummy1 up hwe:~# tc qdisc add dev dummy1 clsact hwe:~# tc filter add dev dummy1 egress matchall action bpf obj ./test.o sec test
root@ubuntu1804
root@ubuntu1804
root@ubuntu1804
root@ubuntu1804
root@ubuntu1804
Prog section 'test' rejected: Invalid argument (22)!
- Type: 4
- Instructions: 5 (0 over limit)
- License: GPL
Verifier analysis:
0: (b7) r2 = 14 change_ head#43 change_ head#43
1: (b7) r3 = 0
2: (85) call bpf_skb_
unknown func bpf_skb_
processed 3 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
Error fetching program/map! hwe:~#
bad action parsing
parse_action: bad value (5:bpf)!
Illegal "action"
root@ubuntu1804