Я использую Ubuntu 24.04 с ядром Linux версии 6.8 . Это моя программа:
Код: Выделить всё
#include
#include
#include
#include
SEC("netfilter") /* hint to BPF loader that this is an netfilter BPF program */
int filter(const struct bpf_nf_ctx *ctx) {
const struct nf_hook_state *state = ctx->state;
unsigned int routing_decision = state->hook;
if (routing_decision == NF_INET_LOCAL_IN ||
routing_decision == NF_INET_LOCAL_OUT)
return NF_DROP;
return NF_ACCEPT;
}
char LICENSE[] SEC("license") = "GPL";
Код: Выделить всё
clang --target=bpf -O2 -Wall -I/usr/include/x86_64-linux-gnu -c filter.c -o filter.bpf.o
filter.c:8:27: warning: declaration of 'struct bpf_nf_ctx' will not be visible outside of this function [-Wvisibility]
8 | int filter(const struct bpf_nf_ctx *ctx) {
| ^
filter.c:9:42: error: incomplete definition of type 'struct bpf_nf_ctx'
9 | const struct nf_hook_state *state = ctx->state;
| ~~~^
filter.c:8:27: note: forward declaration of 'struct bpf_nf_ctx'
8 | int filter(const struct bpf_nf_ctx *ctx) {
| ^
filter.c:10:29: error: incomplete definition of type 'struct bpf_nf_ctx'
10 | int routing_decision = ctx->state->hook;
| ~~~^
filter.c:8:27: note: forward declaration of 'struct bpf_nf_ctx'
8 | int filter(const struct bpf_nf_ctx *ctx) {
| ^
1 warning and 2 errors generated.
Код: Выделить всё
#include Код: Выделить всё
clang --target=bpf -O2 -Wall -I/usr/include/x86_64-linux-gnu -I/usr/src/linux-headers-6.8.0-48/include -c filter.c -o filter.bpf.o
In file included from filter.c:1:
In file included from /usr/src/linux-headers-6.8.0-48/include/linux/bpf.h:8:
In file included from /usr/src/linux-headers-6.8.0-48/include/uapi/linux/filter.h:9:
/usr/src/linux-headers-6.8.0-48/include/linux/compiler.h:251:10: fatal error: 'asm/rwonce.h' file not found
251 | #include
| ^~~~~~~~~~~~~~
1 error generated.
make: *** [Makefile:7: all] Error 1
Подробнее здесь: https://stackoverflow.com/questions/791 ... nvironment
Мобильная версия