Wednesday, January 15, 2014

Disable Asterisk call loop detection: SIP 482 check

Asterisk does not allow to loop sip calls. This is in fact the correct behavior as specified in the SIP RFC. However, in some cases this might be very well the behavior that someone wants.

What loop detection prevents is essentially that an Asterisk instance does not accept an incoming call that was triggered by himself.

This might happen, if the Asterisk:

  1. Tries to call himself (I had a good reason to do this**)
  2. Asterisk tries to make a SIP call to another SIP peer, but the call is routed back to the Asterisk.
    This might happen if Asterisk registers with two or more accounts at an external SIP provider and one of account tries to call the other.
How to disable loop detection
There is no default option provided to deactivate this feature (as this should only be done, if you know what you are doing).

Loop detection is done in channel/chan_sip.c in function handle_request_invite(...). On line 22325 (Asterisk 1.8) a check is done, if loop detection should be done. You can also search for "482 Loop Detected". If this if-statement is disabled (add 0 == 1 &&) or removed, no loop detection will be done.

Re-compile and install as I described here.

** I am using Asterisk for Transcoding twice in the same instance. Basically Asterisk fowards an incoming SIP-call to himself (setting SIP_CODEC_OUTBOUND to whatever I needed) and then relays the call to the callee:
Caller Client --(slin)-> Asterisk --(whatever) -> Asterisk --(slin)-> Callee Client

Patch a asterisk module without breaking package management on Ubuntu


I needed to modify one module (chan_sip) of Asterisk, but was to lazy to download and install Asterisk manually.
  1. Install build-tools
    apt-get install build-essential
  2. Get the source and build dependencies
    apt-get source asterisk
    apt-get build-dep asterisk
  3. Patch or do whatever you wanted.
    ....
  4. Re-compile Asterisk
    ./configure && make
  5. Install the Asterisk module
    cp channels/chan_sip.so /usr/lib/asterisk/modules/
PS: Was done on Ubuntu 13.10.