RustBond
A Rust implementation of the MetalBond route distribution protocol.
MetalBond distributes virtual network routes across hypervisors. Connections between clients and servers use TCP (typically over IPv6 for an IPv6-only fabric), while the overlay supports both IPv4 and IPv6 routes (IPv4/6-in-IPv6 tunneling).
Features
- Async client/server with Tokio
- Automatic reconnection
- VNI-based subscriptions
- Multi-server HA with ECMP support
- Standard, NAT, and LoadBalancer route types
- Interoperable with Go MetalBond
- Optional netlink integration for kernel route installation
Protocol Overview
MetalBond uses a simple message-based protocol over TCP:
- Handshake: Client and server exchange
HELLOmessages to negotiate keepalive intervals - Keepalive: Both sides send periodic
KEEPALIVEmessages to detect connection loss - Subscribe: Clients subscribe to VNIs to receive routes for specific virtual networks
- Update: Route announcements and withdrawals are distributed via
UPDATEmessages
When a client disconnects, the server automatically withdraws all routes announced by that client.
Quick Start
Server
use ;
let server = start.await?;
// ... server.shutdown().await?;
Client
use ;
;
let client = connect;
client.wait_established.await?;
client.subscribe.await?;
Multi-Server (HA)
For high availability, connect to multiple servers simultaneously:
let client = connect;
client.wait_any_established.await?;
// Routes are deduplicated across servers; ECMP supported
Examples
# Run server (default: [::1]:4711)
# Run server on custom address
# Connect client to VNI 100
# Announce a route (VNI#prefix@nexthop)
# Multi-server HA (just add more -s flags)
Route Types
Announcement format: VNI#prefix@nexthop[#type[#fromPort#toPort]]
# Standard route (default) on VNI 100
# NAT route with port range on VNI 200
# Load balancer target on VNI 100
Kernel Route Installation (Netlink)
Enable the netlink feature to install routes directly into the Linux kernel routing tables:
# Install routes from VNI 100 to kernel routing table 100
Options:
--install-routes VNI#TABLE- Map VNI to kernel routing table (can be repeated)--tun DEVICE- Tunnel device name for encapsulated traffic (default: ip6tnl0)
How it works:
- Routes received for a VNI are installed into the corresponding kernel routing table
- Each route points to the tunnel device with the next-hop as the gateway
- Routes are marked with protocol 254 (
RTPROT_METALBOND) for identification - On startup, stale routes from previous runs (same protocol marker) are automatically cleaned up
- When a route is withdrawn by the server, it's removed from the kernel table
Note: Requires root/CAP_NET_ADMIN to modify kernel routing tables.
Error Handling
The library uses a single Error type for all operations. Common errors include:
Error::NotEstablished- Operation attempted before connection is readyError::Timeout/Error::ConnectionTimeout- Connection or operation timed outError::Closed- Connection was closedError::RouteAlreadyAnnounced- Attempted to announce a duplicate routeError::RouteNotFound- Attempted to withdraw a non-existent routeError::Io(...)- Underlying I/O errorError::Protocol(...)- Protocol violation or malformed message
For multi-server setups, operations like subscribe() and announce() succeed if at least one server accepts them, logging warnings for servers that fail.
Testing