Architecture
Component diagram
Section titled “Component diagram”Wi-Fi Client ──> Access Point (hostapd) ──> Catsplash │ │ │ ┌────┴────┐ │ │ Firewall│ │ │(iptables)│ │ └─────────┘ │ │ │ ┌────┴────┐ │ │ SQLite │ │ │ (WAL) │ │ └─────────┘ │ │ │ ┌────┴────┐ │ │ Web │ │ │ Portal │ │ └─────────┘Main components
Section titled “Main components”main.go (Entry point)
Section titled “main.go (Entry point)”- Loads configuration (TOML + CLI flags).
- Opens SQLite database with WAL.
- Initializes firewall (iptables).
- Sets up DNAT redirection.
- Starts the Reaper (session expiration manager).
- Starts the traffic monitor.
- Launches the portal web server.
- Waits for termination signal to clean up resources.
config/ (Configuration)
Section titled “config/ (Configuration)”Loads and validates configuration from a TOML file. Supports CLI flag overrides (--iface, --wan, --port, --db).
firewall/ (Firewall)
Section titled “firewall/ (Firewall)”iptables management module:
- Init(): Creates custom
CATS_PREROUTINGchain, NAT Masquerade, FORWARD rules. - SetupRedirect(): Adds DNAT rule to redirect HTTP traffic to the portal.
- AllowClient(): Inserts 2 FORWARD rules (upload/download) + 1 NAT rule (bypass).
- BlockClient(): Removes the above rules.
- Teardown(): Complete cleanup on exit.
state/ (State)
Section titled “state/ (State)”SQLite session management:
- DB: Opens SQLite connection with WAL, automatic migrations.
- Reaper: Goroutine that checks every 10 seconds for expired sessions and closes them.
- Client: Struct with MAC, IP, state, timestamps, traffic, and limits.
server/ (Web server)
Section titled “server/ (Web server)”Serves the captive portal:
/portal- Welcome page with authentication form./auth- Processes authentication and releases the client./admin- Admin panel with basic auth./(catch-all) - Intercepts any HTTP request and redirects to the portal.
catsctl/ (CLI)
Section titled “catsctl/ (CLI)”Terminal administration tool with commands: status, list, auth, kick, extend, limit, band.
Authentication flow
Section titled “Authentication flow”- Client connects to WiFi and gets an IP via DHCP.
- Client tries to browse (e.g.
http://example.com). - iptables redirects port 80 to the Catsplash portal (DNAT).
- Catsplash shows the welcome portal.
- User accepts terms → POST to
/auth. - Catsplash inserts firewall rules to release the client.
- Client has Internet access until their session expires.
- On expiration, the Reaper blocks the client and cleans up rules.
Testing with network namespaces
Section titled “Testing with network namespaces”The test suite creates isolated namespaces:
ns_router: Runs Catsplash.ns_wan: Simulates public Internet.ns_client [1..100]: Simulated clients with unique IP and MAC addresses.