netxfw

Plugin Development Guide

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.

1. Core Principle

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. Quick Start

Prerequisites

Writing a Plugin

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";

Compiling

Use the Makefile provided by netxfw:

make plugins

The compiled object file will be located in bpf/plugins/out/.

3. Loading and Management

Use the netxfw CLI to manage plugins dynamically:

Load Plugin

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

Remove Plugin

sudo netxfw plugin remove 2