Foundry is a purpose-built, educational container runtime and software-defined networking (SDN) implementation. It is designed to deconstruct and rebuild the core primitives of modern cloud infrastructure: OCI-compliant container execution, CNI networking orchestration, and high-performance packet processing using eBPF/XDP.
This repository contains two distinct subsystems:
- Foundry Runtime (Rust): A client/server architecture for managing container lifecycles (namespaces, cgroups, chroot).
- Foundry Data Plane (Go/C): A high-performance forwarding plane leveraging XDP (eXpress Data Path) to handle container traffic in the kernel.
The project follows a split-binary architecture to separate user interaction from state management, further extended by a dedicated programmable data plane.
-
foundry(Client): A stateless "thin client" CLI. It parses user arguments and transmits them via JSON-RPC over a Unix Domain Socket. -
foundryd(Daemon): A long-running background service managed bysystemd. It creates and holds the state of all containers. It is responsible for: -
Parsing OCI Bundles (
config.json). -
Setting up Linux Namespaces (PID, UTS, MNT, NET).
-
Configuring Control Groups (cgroups v2) for resource limiting.
-
Invoking CNI plugins to configure network interfaces.
-
XDP Forwarder (Data Plane): An eBPF program attached to the host-side
vethinterfaces. It currently functions as a transparent Layer 2 bridge, bypassing the host kernel's TCP/IP stack to forward packets between isolated namespaces.
.
├── src/
│ ├── bin/
│ │ └── foundry.rs # CLI Client entry point
│ └── main.rs # Daemon (foundryd) entry point & core logic
├── xdp-forwarder/ # [Active] eBPF Data Plane implementation
│ ├── forwarder.c # XDP C source code (Kernel Land)
│ ├── main.go # Go Loader & Lifecycle Manager (User Land)
│ ├── gen.go # bpf2go generation directive
│ └── setup-lab.sh # Network namespace topology setup script
├── Cargo.toml # Rust project definition
├── foundryd.service # systemd unit file
└── README.md # Documentation
To build and run the full stack, the following toolchains are required:
System Dependencies:
- Linux Kernel 5.10+ (Required for modern BPF features)
- Clang & LLVM: For compiling C to eBPF bytecode.
- libbpf-dev: Development headers for BPF.
Languages:
- Rust (Latest Stable): For the runtime engine.
- Go (1.20+): For the BPF loader and future SDN agent.
- Build the binaries:
cargo build --release
- Install to system path:
sudo install ./target/release/foundryd /usr/local/bin/
sudo install ./target/release/foundry /usr/local/bin/
- Start the Daemon via systemd:
sudo cp foundryd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now foundryd
- Interaction:
# Create a container from an OCI bundle
foundry create --bundle-path /path/to/bundle --container-id test-1
# Start the container
foundry start --container-id test-1
Currently, the data plane acts as a standalone L2 forwarder for verification purposes.
- Navigate to the module:
cd xdp-forwarder
- Generate BPF Artifacts:
This step uses
bpf2goto compileforwarder.cagainst the host headers.
go generate
- Setup the Verification Lab:
Creates two network namespaces (
netns1,netns2) connected via veth pairs to the host.
sudo ./setup-lab.sh
- Run the Loader: Loads the XDP program into the kernel and attaches it to the host-side veth interfaces.
go build -o loader
sudo ./loader
- Verify Forwarding: Open a separate terminal to monitor traffic while the loader is running:
# Ping from netns1 to netns2 (simulating container-to-container traffic)
sudo ip netns exec netns1 ping 10.0.0.2
The project is currently in Phase 3: The Data Plane. Below is the immediate implementation schedule.
- Objective: Implement transparent L2 forwarding in eBPF.
- Status: Functional.
- Capabilities:
- Parses Ethernet frames in kernel space.
- Performs MAC address rewriting (Source/Dest swapping).
- Redirects packets between interfaces using
bpf_redirect(Egress).
- Objective: Evolve the forwarder into a Virtual Tunnel Endpoint (VTEP).
- Technical Implementation:
- Implement
bpf_xdp_adjust_headto resize packet buffers. - Encapsulation: Wrap inner Ethernet frames with outer IP/UDP/VXLAN headers.
- Decapsulation: Parse incoming VXLAN packets, validate VNI, and strip headers.
- Support for RFC 7348 VXLAN packet structure.
- Objective: Remove hardcoded logic and implement a Forwarding Database (FDB).
- Technical Implementation:
- FDB Map:
BPF_MAP_TYPE_HASHstoring[VNI, MAC] -> [Type, RemoteIP/IfIndex]. - Lookups: Logic to distinguish between LOCAL (direct redirect) and REMOTE (VXLAN encap) traffic.
- Control Plane: Go loader acts as the initial map population tool.
- Objective: Create a long-running daemon to manage the data plane lifecycle.
- Technical Implementation:
- gRPC API: Define
agent.protofor adding/removing forwarding entries. - Lifecycle Management: Handle loading XDP programs and pinning BPF maps (
/sys/fs/bpf/). - Persistence: Ensure map state survives process restarts via BPF filesystem pinning.