proxy-wasm-rust-sdk icon indicating copy to clipboard operation
proxy-wasm-rust-sdk copied to clipboard

Add Envoy TCP Routing example demonstrating source-based dynamic cluster selection

Open SiiiTschiii opened this issue 3 weeks ago • 5 comments

Introduce a new Proxy-Wasm TCP filter example that demonstrates dynamic routing of TCP connections based on source IP addresses at the TCP stream context (L4). This example showcases application-layer routing decisions without HTTP processing, filling a gap in the existing HTTP-focused examples.

Inspired by the wasmerang project, this example demonstrates advanced TCP routing patterns in Envoy/Istio/K8s environments using WASM filters.

Key Features

  • Source-based routing: Dynamic cluster selection based on source IP last octet (even → egress-router1, odd → egress-router2)
  • TCP stream context: Operates at L4 rather than HTTP layer for protocol-agnostic routing
  • Envoy filter state API: Uses set_envoy_filter_state foreign function with protobuf encoding
  • Complete Docker setup: Includes Docker Compose environment for testing with httpbin.org
  • Comprehensive documentation: Usage examples, expected output, and technical context

Implementation Details

  • Protobuf definitions for Envoy's filter state API with build-time code generation
  • MSRV-compatible dependencies (Rust 1.65) with explicit pinning for CI compatibility
  • Envoy v1.34.1 configuration with dual upstream clusters

Documentation Highlights

  • Links to Proxy-Wasm spec for TCP stream context
  • Explanation of TCP vs HTTP layer routing trade-offs
  • Future enhancement ideas: PROXY protocol support for source-based egress routing in managed K8s environments

This example is useful for scenarios requiring performance-critical or protocol-agnostic routing decisions where application-layer processing should be avoided.

SiiiTschiii avatar Nov 20 '25 03:11 SiiiTschiii