netfilter: xt_bpf: support ebpf
Subsystems (3)
PATCH v2 1/1 netfilter: xt_bpf: support ebpf
From: Willem de Bruijn <[email protected]>
Add support for attaching an eBPF object by file descriptor.
The iptables binary can be called with a path to an elf object or a pinned bpf object. Also pass the mode and path to the kernel to be able to return it later for iptables dump and save.
---
Changes
v1 -> v2
- define XT_BPF_PATH_MAX (== 512: does not grow structure size)
--- include/uapi/linux/netfilter/xt_bpf.h | 21 ++++++++ net/netfilter/xt_bpf.c | 96 +++++++++++++++++++++++++++++------ 2 files changed, 101 insertions(+), 16 deletions(-)
include/uapi/linux/netfilter/xt_bpf.h +21 -0
@@ -2,9 +2,11 @@#define _XT_BPF_H#include <linux/filter.h> +#include <linux/limits.h> #include <linux/types.h> #define XT_BPF_MAX_NUM_INSTR 64 +#define XT_BPF_PATH_MAX (XT_BPF_MAX_NUM_INSTR * sizeof(struct sock_filter))struct bpf_prog ;
@@ -16,4 +18,23 @@ struct xt_bpf_info { struct bpf_prog *filter __attribute__((aligned(8))); }; +enum xt_bpf_modes { +XT_BPF_MODE_BYTECODE , +XT_BPF_MODE_FD_PINNED , +XT_BPF_MODE_FD_ELF , +}; + +struct xt_bpf_info_v1 { +__u16 mode; +__u16 bpf_program_num_elem; +__s32 fd; +union { +struct sock_filter bpf_program[XT_BPF_MAX_NUM_INSTR ]; +char path[XT_BPF_PATH_MAX ]; + }; + +/* only used in the kernel */ +struct bpf_prog *filter __attribute__((aligned (8 ))); +}; +#endif /*_XT_BPF_H */
net/netfilter/xt_bpf.c +80 -16
138 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
Quoted 7 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add support for attaching an eBPF object by file descriptor.
The iptables binary can be called with a path to an elf object or a pinned bpf object. Also pass the mode and path to the kernel to be able to return it later for iptables dump and save.
Applied, thanks Willem.