netxfw

netxfw Architecture Design

Overview

netxfw is a high-performance, programmable firewall built on eBPF (Extended Berkeley Packet Filter) and XDP (eXpress Data Path). It operates at the earliest possible point in the Linux networking stack (the driver hook), allowing it to drop or redirect packets with minimal CPU overhead before they reach the kernel’s networking stack (sk_buff allocation).

Core Components

1. Data Plane (eBPF/XDP)

The data plane is written in C and compiled into BPF bytecode. It runs directly in the kernel.

2. Control Plane (Go Agent)

The control plane is written in Go and runs in user space. It manages the lifecycle of the BPF programs and interacts with BPF maps.

Unified Dual-Stack Architecture

To simplify maintenance and reduce memory usage, netxfw uses a unified Map strategy:

Directory Structure

Data Flow

  1. Packet Arrival: NIC receives packet -> XDP driver hook.
  2. Parsing: filter.bpf.c parses Ethernet -> IP (v4/v6) -> L4 headers.
  3. Lookup:
    • Check whitelist (Allow).
    • Check lock_list (Block).
    • Check ip_port_rules (Fine-grained).
  4. Decision:
    • If Match Deny -> XDP_DROP + Increment drop counter.
    • If No Match -> XDP_PASS (Continue to kernel stack).

Persistence Model