How hnimminh/libresbc works
1. What this repo is
LibreSBC is a Session Border Controller built around a split between a real-time SIP/media engine and a management/control layer. The repo contains the runtime logic, deployment automation, UI, and config generation needed to run the SBC on a host or in containers.
2. Core data plane: FreeSWITCH
The SBC’s call processing and media handling are centered on FreeSWITCH. The liberator/fscfg tree shows generated FreeSWITCH configuration, and prebuild/Dockerfile.freeswitch indicates a packaged FreeSWITCH image. This is the boundary where SIP signaling and RTP/SRTP media are actually terminated and relayed.
3. Call-routing logic inside FreeSWITCH: callng/
The callng directory is a Lua-based call-control layer that appears to run inside the FreeSWITCH runtime. Its files are organized by event:
- startup and initialization
- call initiation
- capacity checks
- unauthorized-call handling
- CDR emission
- redirection and utilities
This is the main policy/routing engine for live call decisions, sitting directly on the call path.
4. Control plane / management service: liberator/
liberator is the administrative backend. It includes API modules (api.py, libreapi.py, cfgapi.py), configuration management, CDR handling, and utility code. It likely generates or updates FreeSWITCH and related system configuration, exposes management endpoints, and coordinates runtime behavior.
5. Configuration generation boundary
The liberator/fscfg/xml/*.j2.xml templates show that FreeSWITCH XML config is rendered from templates rather than hand-edited. That makes configuration a first-class output of the control plane. Related templates also exist for nftables, systemd units, and env files, so the backend owns the authoritative runtime config.
6. UI layer: webui/
The webui directory is a separate Go module that serves the operator-facing UI. It is not the SBC itself; it is the presentation layer for administration and monitoring. The presence of static assets and a standalone main.go suggests it serves compiled/static content and likely talks to the Liberator API.
7. Deployment automation: Ansible
The ansible/ tree is the host provisioning and deployment system. It installs and configures:
- Docker
- nftables firewalling
- platform/kernel/sysctl tuning
- SSH and sudo hardening
- the LibreSBC container stack
- the LibreUI service
- a “shield” service
This is the infrastructure layer that turns a machine into a SBC node.
8. Containerized runtime
ansible/roles/libresbc-container plus docker-compose.yml.j2, libre.env.j2, and redis.conf indicate the primary runtime can be deployed as a composed container stack. That stack likely includes FreeSWITCH, Liberator, and supporting services such as Redis for shared state/caching in the SBC runtime.
9. Network and security boundary
ansible/roles/nftables and liberator/nft/nftables.j2.conf show firewall rules are part of the design, not an afterthought. The repo also includes a shield service and platform sysctl tuning, which means traffic filtering, attack mitigation, and kernel/network tuning are treated as core SBC concerns.
10. Operational hooks and external integrations
The project explicitly supports HTTP-based integration for routing and CDR export. The examples/ directory includes sample HTTP route and CDR servers, showing external systems can influence routing decisions and receive call records. This is an important architecture boundary: LibreSBC can delegate policy or observability to third-party services over HTTP.
11. Runtime packaging and service management
Besides containers, the repo also contains systemd units and logrotate/rsyslog configs under liberator/system, plus a systemd service for liberator. That suggests the project supports both containerized and host-managed service modes, with logging and startup handled at the OS service layer.
12. How the main flow fits together
Traffic enters the SBC at the network edge, passes through firewall rules, reaches FreeSWITCH for SIP/media handling, and is governed by Lua call logic in callng. The Liberator control plane supplies config, manages policies and APIs, and emits/collects operational data such as CDRs. The web UI sits on top for operators, while Ansible and Docker handle repeatable deployment of the whole stack.
Main entry points: main.py Liberator API · main.lua Call logic · deployment.yml Host deploy · main.yml Container stack
Components 22
Runtime
Live call handling and SIP/media termination
- FreeSWITCH · Core SIP signaling and media termination runtime
liberator/fscfg/xml/freeswitch.xml - Call logic · Event-driven call control executed inside FreeSWITCH
callng/main.lua - Startup · Bootstraps callng runtime and initialization flow
callng/event.startup.lua - Initiation · Handles new call setup and routing decisions
callng/event.initiation.lua - Capacity · Checks capacity and admission constraints
callng/event.capacity.lua - Unauthorized · Rejects or handles unauthorized call attempts
callng/event.unauth.lua - CDR event · Emits call detail records from the call path
callng/event.cdr.lua - Redirection · Redirect and manipulation helpers for call flow
callng/redirection.lua - Utilities · Common Lua helpers used by callng modules
callng/utilities.lua
Control plane
Management APIs, config generation, and CDR handling
- Liberator API · Administrative backend exposing control and config APIs
liberator/main.py - API modules · Primary API surface for management operations
liberator/api.py - Config API · Configuration management and generation endpoints
liberator/cfgapi.py - CDR service · Call detail record processing and export support
liberator/cdr.py - Config core · Shared configuration and runtime settings model
liberator/configuration.py - FreeSWITCH cfg · Generated FreeSWITCH XML configuration templates
liberator/fscfg/xml/directory.j2.xml - Firewall cfg · Generated nftables policy for network boundary control
liberator/nft/nftables.j2.conf
Operations
Deployment, provisioning, and host/runtime management
- Host deploy · Provisioning and deployment entrypoint
ansible/playbooks/deployment.yml - Container stack · Builds and runs the LibreSBC containerized runtime
ansible/roles/libresbc-container/tasks/main.yml - Host hardening · System tuning, SSH, sudo, and platform configuration
ansible/roles/platform/tasks/main.yml - Nftables role · Installs and configures firewall service and rules
ansible/roles/nftables/tasks/main.yml
UI
Operator-facing web interface
- LibreUI · Standalone operator interface for administration and monitoring
webui/main.go
External integrations
Example HTTP services and exported operational hooks
- HTTP examples · Example route and CDR HTTP endpoints for integration
examples/httproute-server.py
Connections 25
- Call logic → Startup: loads · callng initializes through its startup handler
- Call logic → Initiation: routes · call initiation drives per-call policy
- Call logic → Capacity: checks · capacity enforcement during live call handling
- Call logic → Unauthorized: blocks · unauthorized calls are rejected by policy
- Call logic → CDR event: emits · CDR generation is part of the call path
- Call logic → Redirection: uses · routing helpers support call manipulation
- Call logic → Utilities: shares · common utilities support the event modules
- Liberator API → API modules: exposes · main backend service exposes API modules
- Liberator API → Config API: manages · configuration endpoints are part of the backend
- Liberator API → CDR service: handles · backend processes and exports call records
- Liberator API → Config core: loads · shared configuration model feeds backend behavior
- Liberator API → FreeSWITCH cfg: renders · backend generates FreeSWITCH XML config
- Liberator API → Firewall cfg: renders · backend generates firewall policy templates
- FreeSWITCH cfg → FreeSWITCH: configures · generated XML config feeds the FreeSWITCH runtime
- Firewall cfg → Nftables role: applies · nftables configuration is deployed through the firewall role
- Host deploy → Container stack: deploys · playbook provisions the containerized SBC stack
- Host deploy → Host hardening: configures · playbook applies platform hardening and tuning
- Host deploy → Nftables role: configures · playbook installs and enables firewalling
- Host deploy → LibreUI: installs · playbook can deploy the LibreUI service
- Container stack → FreeSWITCH: runs · container stack includes the media engine runtime
- Container stack → Liberator API: hosts · container stack includes the Liberator control plane
- Container stack → LibreUI: pairs with · UI is deployed alongside the SBC stack
- LibreUI → Liberator API: calls · UI uses backend APIs for administration
- HTTP examples → Liberator API: integrates · example HTTP services show external routing/CDR hooks
- HTTP examples → CDR service: receives · example CDR server consumes exported call records