netxfw supports dynamic loading of third-party plugins via the eBPF Tail Call mechanism. This allows developers to extend custom packet processing logic without modifying or recompiling the core firewall code.
After extracting basic packet information, the main XDP program of netxfw attempts to jump to a BPF_MAP_TYPE_PROG_ARRAY named jmp_table.
2 to 15 in the jmp_table.bpf_tail_call to return to the main program’s protocol handler, or directly return XDP_PASS/XDP_DROP.clang and llvm.netxfw BPF headers.Create a .c file (e.g., my_filter.bpf.c):
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "include/plugin.h"
SEC("xdp")
int my_custom_filter(struct xdp_md *ctx) {
// Your logic here
// e.g., Drop specific packets
// To continue to netxfw core logic
return XDP_PASS;
}
char _license[] SEC("license") = "GPL";
Use the Makefile provided by netxfw:
make plugins
The compiled object file will be located in bpf/plugins/out/.
Use the netxfw CLI to manage plugins dynamically:
Load the compiled .o file to a specific jump table index (e.g., index 2):
sudo netxfw plugin load bpf/plugins/out/my_filter.o 2
sudo netxfw plugin remove 2