Skip to content

Kamailio Handbook — English

How Kamailio is built on the inside.

Kamailio Lang Switch to Ukrainian


[!IMPORTANT] This handbook is deliberately not a re-telling of the official docs. It assumes you already know what Kamailio is at a surface level and instead drills into the runtime, the message lifecycle, the script engine, KEMI, and the architectural tricks that make Kamailio behave the way it does. There is no module-by-module reference here.

Sources used:

How a SIP request flows through Kamailio

flowchart LR
    In([SIP IN]) --> Parser[Parser]
    Parser --> Sanity[Sanity checks]
    Sanity --> RR[request_route]
    RR --> Mods[[Module functions<br/>tm · rr · auth · dispatcher · …]]
    Mods --> Decision{Stateful?}
    Decision -- yes --> TM[tm: create transaction]
    Decision -- no --> SL[sl: stateless forward]
    TM --> Out([SIP OUT])
    SL --> Out

    classDef io fill:#238636,stroke:#238636,color:#fff
    classDef core fill:#1f6feb,stroke:#1f6feb,color:#fff
    classDef mod fill:#bf8700,stroke:#bf8700,color:#fff
    classDef branch fill:#6e7681,stroke:#6e7681,color:#fff

    class In,Out io
    class Parser,Sanity,RR core
    class Mods,TM,SL mod
    class Decision branch

A single received SIP message walks through this pipeline. Most of what looks like "magic" in a Kamailio config is just deciding which way it branches — and the handbook unpacks every box above.

Table of contents

1. Preface

2. The Runtime

3. SIP Message Lifecycle

4. The Script Engine

  • 4. Script engine — pointer chapter — thin map of where the script-engine machinery is documented across other chapters, plus the few internals (AST shape, pseudo-variable dispatch, return-value convention) that didn't fit elsewhere ✅

5. KEMI — embedded scripting

6. State, Transactions, Dialogs

7. Control Plane

  • 7.1 RPC architecture — BINRPC vs JSON-RPC, the command registry, auth posture ✅
  • 7.2 kamcmd — the operator's lever, the five commands you'll run constantly ✅
  • 7.3 Event routes — programmable hooks into runtime lifecycle ✅

8. Cool architectural tricks

  • 8.1 Topology hiding (topos) — rewriting calls so the topology vanishes ✅
  • 8.2 Async transactionst_suspend / t_continue for non-blocking flows ✅
  • 8.3 htable — shared-memory hash tables as a poor man's Redis ✅
  • 8.4 dispatcher — hash-based stickiness, gateway sets, failover algorithms ✅
  • 8.5 dmq — distributed state sync between Kamailio instances ✅
  • 8.6 Media — rtpengine — anchoring RTP, controlling the daemon from the config, RTP-bleed defence, SRTP/DTLS↔RTP, ICE/STUN, kernel-mode forwarding ✅
  • 8.7 Capturing SIP over TLS — why wire capture fails on TLS/WSS, tapping decrypted SIP with siptrace, HEP, and live sngrep

9. Security & Hardening

10. Kamailio in IMS

11. Reference


🇺🇦 Українська