[asterisk-dev] Call Forwarding Detail Needed

Leif Madsen leif.madsen at asteriskdocs.org
Sun Apr 1 05:17:58 MST 2007

On Sunday 01 April 2007 03:34:53 Arpit Mehta wrote:
> I just want to know if Asterisk handles a looping case and where does it
> handle that .
> A--> B --> C--> D --> B
> If A calls  B ,
>   B call fwds to C ,
>   C call fwds to D ,
>   D call fwds to B . Now there is a loop .
> How does asterisk prevent this loop? I just to know where (as in which
> module in the Asterisk source code) and how is this prevented (that is if a
> data structure of all the numbers that it has call fwded to is passed on to
> B,C,D so that it can detect a loop)?
> Thanks. I hope you understand my scenario. Any suggestions are welcome.

As far I might understand it, Asterisk would basically parse the Via: headers 
to determine where the call was coming from, and if it detected a loop, 
*should* handle that (this does seem like a loop, and not a spiral).

I'll have to defer this to the SIP experts and C experts, but basically here 
is the code that chan_sip.c (at line 13185 of my chan_sip.c file) that checks 
for the loop:

        /* Check if this is a loop */
        if (ast_test_flag(&p->flags[0], SIP_OUTGOING) && p->owner && 
(p->owner->_state != AST_STATE_UP)) {
                /* This is a call to ourself.  Send ourselves an error code 
and stop
                processing immediately, as SIP really has no good mechanism 
                being able to call yourself */
                /* If pedantic is on, we need to check the tags. If they're 
different, this is
                in fact a forked call through a SIP proxy somewhere. */
                transmit_response(p, "482 Loop Detected", req);
                p->invitestate = INV_COMPLETED;
                sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
                return 0;

Leif Madsen.

More information about the asterisk-dev mailing list