calricon.
VoIP & Telecom

Fixing Kamailio Pike False-Positive Bans on Carrier SIP Trunks

Nov 15, 2026/5 min read/Verified Production Playbook

calricon / field note

When Kamailio's pike module runs before carrier and dispatcher

Nov 15, 2026/VoIP & Telecom
358
Advertisement

Fixing Kamailio Pike False-Positive Bans on Carrier SIP Trunks

In production Kamailio Session Border Controllers (SBCs) and SIP proxies protected by the pike flood-detection module, operators frequently encounter sudden, unexplained call drops from upstream PSTN carriers or internal Asterisk/FreeSWITCH media servers. Inbound INVITEs, OPTIONS keepalives, and BYE messages from a primary trunk vanish silently—or receive 403 Forbidden—right during peak traffic bursts or carrier failover waves, while the carrier's SIP trace shows zero response from Kamailio.

The root cause is executing pike_check_req() unconditionally in REQINIT before exempting trusted infrastructure IPs, combined with misunderstanding how pike's radix IP tree (ip_tree) and remove_latency memory retention accelerate false-positive RED states.



Problem Diagnosis & Root Cause Architecture

The pike module tracks incoming SIP request density per source IP in a shared-memory byte tree:



  • Unconditional REQINIT Inspection: Standard Kamailio templates (WITH_ANTIFLOOD) invoke pike_check_req() at the top of route[REQINIT]. If a carrier trunk or high-volume NAT gateway exceeds reqs_density_per_unit (default 30 requests per 2-second sampling_time_unit), Kamailio flags that IP as a flood source.

  • Cached Leaf Acceleration (remove_latency): By default, remove_latency is 120 seconds. Once a carrier IP's full 4-byte path is expanded into a leaf in ip_tree, it remains cached in memory for two minutes after the last packet—meaning any subsequent burst hits the leaf threshold (1x reqs_density_per_unit) immediately rather than the initial 3x expansion threshold.

  • In-Dialog and Keepalive Amplification: Carrier trunks multiplex hundreds of concurrent calls over a single signaling IP. A burst of 200 OK retransmissions, ACKs, BYEs, and OPTIONS pings easily crosses 15 requests per second from one IP.

  • Sticky htable Lockouts: When paired with an htable ban cache ($sht(ipban=>$si)), a single 2-second carrier microburst locks out the entire trunk for 5 minutes or longer.


Production Rule: Never pass trusted carrier trunks, dispatcher media nodes, or loopback interfaces through pike_check_req(). Exempt verified peers via permissions or dispatcher lookups before flood evaluation.


Why Standard Implementations Fail

1. Raising reqs_density_per_unit Globally

Bumping reqs_density_per_unit from 30 to 500 to stop carrier false positives defeats the purpose of flood protection. Unverified internet scanners can now send hundreds of SIP packets per second per IP before pike trips, exposing INVITE and REGISTER workers to CPU exhaustion.


2. Relying on src_ip == myself Alone

Checking only if (src_ip == myself) exempts Kamailio's own local interfaces, but it does nothing for external PSTN carrier IPs, SBC peers, or downstream Asterisk/FreeSWITCH farms that sit on separate hosts or VPC subnets.


3. Blocking Without Logging or Bypassing Health Checks

Dropping packets silently when !pike_check_req() triggers without logging $si and $rm (or without excluding OPTIONS keepalives from trusted peers) makes carrier outages look like upstream network blackholes rather than local Kamailio rate-limiting.



Validated Step-by-Step Resolution Playbook

Step 1: Inspect Active and Blocked IPs in the Pike Tree

Connect via kamcmd during an incident to inspect HOT and ALL nodes currently tracked by pike, and check your htable ban entries and syslog warnings:


kamcmd pike.top HOT
kamcmd pike.top ALL
kamcmd htable.dump ipban
grep -i "pike" /var/log/kamailio.log | tail -n 30

If your carrier signaling IP or internal media server appears in pike.top HOT or htable.dump ipban, you have confirmed a false-positive flood ban.



Step 2: Configure Carrier and Media Server Allowlists Before Pike

Use the permissions module (allow_source_address()) and dispatcher (ds_is_from_list()) in /etc/kamailio/kamailio.cfg to bypass pike_check_req() for all trusted infrastructure:


loadmodule "pike.so"
loadmodule "htable.so"
loadmodule "permissions.so"

modparam("pike", "sampling_time_unit", 2)
modparam("pike", "reqs_density_per_unit", 30)
modparam("pike", "remove_latency", 120)

modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
modparam("permissions", "address_table", "address")

Next, place the allowlist guard inside route[REQINIT] above the htable and pike_check_req() checks:


route[REQINIT] {
# Bypass flood detection for local host, dispatcher gateways, and trusted carrier IPs
if (src_ip == myself || ds_is_from_list() || allow_source_address("1")) {
return;
}

if ($sht(ipban=>$si) != $null) {
xlog("L_DBG", "Dropped packet from banned IP $si ($rm)
");
exit;
}

if (!pike_check_req()) {
xlog("L_ALERT", "ALERT: pike blocking $rm from $fu (IP:$si:$sp)
");
$sht(ipban=>$si) = 1;
exit;
}
}


Step 3: Populate Trusted Carrier IPs and Reload Without Restart

Insert your PSTN carrier signaling IPs and SBC peers into Kamailio's address table (group 1) and reload the permissions table dynamically:


kamctl address add 1 203.0.113.10 32 0 "Primary Carrier Trunk"
kamctl address add 1 198.51.100.0 24 0 "Carrier Media Subnet"
kamcmd permissions.addressReload
kamcmd permissions.addressDump


Step 4: Clear Any Active False-Positive htable Bans

If a carrier IP is currently stuck in the ipban hash table, delete that entry immediately so traffic resumes without waiting for autoexpire:


kamcmd htable.delete ipban 203.0.113.10
kamcmd htable.dump ipban


Step 5: Verify Carrier Traffic Bypasses Pike Under Burst Load

Simulate or observe peak carrier CPS and verify that trusted trunk IPs never appear in pike.top while untrusted scanners are still caught:


kamcmd pike.top HOT
kamcmd stats.get_statistics all | grep -E "rcv_requests|drop_requests"

Confirm that pike.top HOT contains zero carrier or media server IPs and that kamailio.log logs zero ALERT: pike blocking events for allowlisted trunks.

Advertisement
Engineering Advisory 48-Hour Audit Turnaround

Experiencing this issue in your production systems?

Calricon conducts senior-level VoIP, SIP trunking, Asterisk, and cloud infrastructure audits. We review your live configs, identify packet drops or contention bottlenecks, and provide exact remediation runbooks.