From ef1861af7577763adbaea5c0884412ba7f6c577e Mon Sep 17 00:00:00 2001 From: moustique82 Date: Mon, 21 Sep 2026 21:25:19 +0200 Subject: [PATCH] [Changed] move Kamailio to 6.1 on Debian 13: the 5.6 bullseye image no longer builds Debian 11 left long-term support on 31 August 2026 and its security archive is being withdrawn: the apt-get install step fails with 404s, so the Kamailio image cannot be rebuilt anywhere. Moving to kamailio:6.1.4-trixie took three changes beyond the base image: - Dockerfile: pip refuses system-wide installs since Debian 12, hence --break-system-packages; upgrading pip and setuptools over the distribution's own copies is dropped for the same reason. - kamailio.cfg: the dialog module no longer has dlg_flag. It was never set anyway: dialogs are tracked by dlg_manage(). app_python3 gets threads_mode 1: with the default mode, Python 3.13 aborts every worker at start-up (_PyThreadState_Attach: non-NULL old thread state). - request_gw.py: Kamailio 6 no longer ships the legacy Router module nor the old message object. Logging goes through KSR.err, and the request is read through $mt, $ru, $rm and $hdr(From), and rewritten through $ru. The routing logic is unchanged. --- deploy/kamailio/Dockerfile | 6 ++---- deploy/kamailio/config/kamailio.cfg | 2 +- deploy/kamailio/config/request_gw.py | 31 +++++++++++++++++----------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/deploy/kamailio/Dockerfile b/deploy/kamailio/Dockerfile index 0fdab5c7..8c36e5a7 100644 --- a/deploy/kamailio/Dockerfile +++ b/deploy/kamailio/Dockerfile @@ -1,13 +1,11 @@ -FROM ghcr.io/kamailio/kamailio:5.6.3-bullseye +FROM ghcr.io/kamailio/kamailio:6.1.4-trixie RUN apt-get update && apt-get install -y --no-install-recommends \ python3 python3-dev python3-pip cron \ && apt autoremove -y \ && apt autoclean -y -RUN pip3 install --upgrade pip -RUN pip3 install --upgrade setuptools -RUN pip3 install requests httplib2 mysql-connector-python +RUN pip3 install --break-system-packages requests httplib2 mysql-connector-python WORKDIR /etc/kamailio/ diff --git a/deploy/kamailio/config/kamailio.cfg b/deploy/kamailio/config/kamailio.cfg index 86e1c98e..8660cf00 100644 --- a/deploy/kamailio/config/kamailio.cfg +++ b/deploy/kamailio/config/kamailio.cfg @@ -340,7 +340,6 @@ loadmodule "siptrace.so" # ------ dialog ------- modparam("dialog", "enable_stats", 1) -modparam("dialog", "dlg_flag", 4) modparam("dialog", "hash_size", 4096) modparam("dialog", "db_url", DBURL) modparam("dialog", "db_mode", 1) @@ -349,6 +348,7 @@ modparam("dialog", "db_mode", 1) modparam("app_python3", "load", "/etc/kamailio/request_gw.py") modparam("app_python3", "mod_init_function", "mod_init") modparam("app_python3", "child_init_method", "child_init") +modparam("app_python3", "threads_mode", 1) # ------ ssl ------- #modparam("tls", "tls_force_run", 1) diff --git a/deploy/kamailio/config/request_gw.py b/deploy/kamailio/config/request_gw.py index d03771d4..ae0621cf 100755 --- a/deploy/kamailio/config/request_gw.py +++ b/deploy/kamailio/config/request_gw.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import sys -import Router.Logger as Logger import KSR as KSR import httplib2 import json @@ -12,6 +11,14 @@ from contextlib import closing from configparser import ConfigParser + +class Logger: + """Kamailio 6 dropped the legacy Router module: log through KSR.""" + @staticmethod + def LM_ERR(text): + KSR.err(text) + + parser = ConfigParser() parser.optionxform = str with open("/etc/kamailio/kamctlrc") as stream: @@ -100,27 +107,27 @@ def lockGw (self): def handler(self, msg, args): Logger.LM_ERR("Loggers.py: LM_ERR: msg: %s" % str(args)) - Logger.LM_ERR('RequestGw.handler(%s, %s)\n' % (msg.Type, str(args))) - if (msg.Type == 'SIP_REQUEST' and - (any((msg.RURI).find(d) != -1 for d in self.sipDomains) or - (msg.RURI).find(self.publicIP) != -1)): - if msg.Method == 'INVITE' and (msg.RURI).find(self.gwNamePart) == -1: - Logger.LM_ERR('SIP request, method = %s, RURI = %s, From = %s\n' % (msg.Method, msg.RURI, msg.getHeader('from'))) - uri = msg.RURI + Logger.LM_ERR('RequestGw.handler(%s, %s)\n' % (KSR.pv.get("$mt"), str(args))) + if (KSR.pv.get("$mt") == 1 and + (any(KSR.pv.get("$ru").find(d) != -1 for d in self.sipDomains) or + KSR.pv.get("$ru").find(self.publicIP) != -1)): + if KSR.pv.get("$rm") == 'INVITE' and KSR.pv.get("$ru").find(self.gwNamePart) == -1: + Logger.LM_ERR('SIP request, method = %s, RURI = %s, From = %s\n' % (KSR.pv.get("$rm"), KSR.pv.get("$ru"), KSR.pv.get("$hdr(From)"))) + uri = KSR.pv.get("$ru") room = (uri.split(":", 1)[1]).split('@')[0] displayName = "" - if "<" in msg.getHeader('from'): - displayName = (msg.getHeader('from').split('<')[0]) + if "<" in KSR.pv.get("$hdr(From)"): + displayName = (KSR.pv.get("$hdr(From)").split('<')[0]) Logger.LM_ERR('Room Name %s\n' % room ) gwRes = self.lockGw() if gwRes: gwUri = gwRes['username'] gwSocket = gwRes['socket'].split(':')[1] Logger.LM_ERR('Returned Gateway: %s\n' % gwUri) - msg.rewrite_ruri("sip:%s@%s" % (gwUri, gwSocket)) + KSR.pv.sets("$ru", "sip:%s@%s" % (gwUri, gwSocket)) displayNameWRoom = '"%s-%s%s"' % (str(len(room)), room, displayName.replace('"','')) KSR.uac.uac_replace_from(displayNameWRoom, "") - Logger.LM_ERR('########## SIP request, method = %s, RURI = %s, From = %s\n' % (msg.Method, msg.RURI, msg.getHeader('from'))) + Logger.LM_ERR('########## SIP request, method = %s, RURI = %s, From = %s\n' % (KSR.pv.get("$rm"), KSR.pv.get("$ru"), KSR.pv.get("$hdr(From)"))) return 1