Connection from FreePBX to Kamailio

Hi Guys,

i have Kamailio as a front end to my Freepbx, all the phones register to it and fwd invites to to my PBX, the calls are making it to my PBX but it refuses to use the outbound Dialplan that points back to Kamailio, im thinking its the context its driving me mad lol any suggestions would be appreciated

Logs

Providing Great Debug - Support Services - Sangoma Documentation (atlassian.net)

here is a log of one of the calls
19623[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [1234@from-sip-external:1] NoOp(“PJSIP/anonymous-00000032”, “Received incoming SIP connection from unknown peer to 1234”) in new stack

19624[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [1234@from-sip-external:2] Set(“PJSIP/anonymous-00000032”, “DID=1234”) in new stack

19625[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [1234@from-sip-external:3] Goto(“PJSIP/anonymous-00000032”, “s,1”) in new stack

19626[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx_builtins.c: Goto (from-sip-external,s,1)

19627[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-sip-external:1] GotoIf(“PJSIP/anonymous-00000032”, “1?setlanguage:checkanon”) in new stack

19628[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx_builtins.c: Goto (from-sip-external,s,2)

19629[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-sip-external:2] Set(“PJSIP/anonymous-00000032”, “CHANNEL(language)=en”) in new stack

19630[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-sip-external:3] GotoIf(“PJSIP/anonymous-00000032”, “0?noanonymous”) in new stack

19631[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-sip-external:4] Goto(“PJSIP/anonymous-00000032”, “from-trunk,1234,1”) in new stack

19632[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx_builtins.c: Goto (from-trunk,1234,1)

19633[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [1234@from-trunk:1] Set(“PJSIP/anonymous-00000032”, “__FROM_DID=1234”) in new stack

19634[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [1234@from-trunk:2] NoOp(“PJSIP/anonymous-00000032”, “Received an unknown call with DID set to 1234”) in new stack

19635[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [1234@from-trunk:3] Goto(“PJSIP/anonymous-00000032”, “s,a2”) in new stack

19636[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx_builtins.c: Goto (from-trunk,s,2)

19637[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-trunk:2] Answer(“PJSIP/anonymous-00000032”, “”) in new stack

19638[2024-07-15 20:59:32] WARNING[7996][C-00000033] chan_sip.c: This function can only be used on SIP channels.

19639[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-trunk:3] Log(“PJSIP/anonymous-00000032”, "WARNING,Friendly Scanner from ") in new stack

19640[2024-07-15 20:59:32] WARNING[7996][C-00000033] Ext. s: Friendly Scanner from

19641[2024-07-15 20:59:32] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-trunk:4] Wait(“PJSIP/anonymous-00000032”, “2”) in new stack

19642[2024-07-15 20:59:34] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-trunk:5] Playback(“PJSIP/anonymous-00000032”, “ss-noservice”) in new stack

19643[2024-07-15 20:59:34] VERBOSE[7996][C-00000033] file.c: <PJSIP/anonymous-00000032> Playing ‘ss-noservice.ulaw’ (language ‘en’)

19644[2024-07-15 20:59:39] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-trunk:6] SayAlpha(“PJSIP/anonymous-00000032”, “1234”) in new stack

19645[2024-07-15 20:59:39] VERBOSE[7996][C-00000033] file.c: <PJSIP/anonymous-00000032> Playing ‘digits/1.ulaw’ (language ‘en’)

19646[2024-07-15 20:59:40] VERBOSE[7996][C-00000033] file.c: <PJSIP/anonymous-00000032> Playing ‘digits/2.ulaw’ (language ‘en’)

19647[2024-07-15 20:59:41] VERBOSE[7996][C-00000033] file.c: <PJSIP/anonymous-00000032> Playing ‘digits/3.ulaw’ (language ‘en’)

19648[2024-07-15 20:59:42] VERBOSE[7996][C-00000033] file.c: <PJSIP/anonymous-00000032> Playing ‘digits/4.ulaw’ (language ‘en’)

19649[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Executing [s@from-trunk:7] Hangup(“PJSIP/anonymous-00000032”, “”) in new stack

19650[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Spawn extension (from-trunk, s, 7) exited non-zero on ‘PJSIP/anonymous-00000032’

19651[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Executing [h@from-trunk:1] Macro(“PJSIP/anonymous-00000032”, “hangupcall,”) in new stack

19652[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Executing [s@macro-hangupcall:1] GotoIf(“PJSIP/anonymous-00000032”, “1?theend”) in new stack

19653[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx_builtins.c: Goto (macro-hangupcall,s,3)

19654[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Executing [s@macro-hangupcall:3] ExecIf(“PJSIP/anonymous-00000032”, “0?Set(CDR(recordingfile)=)”) in new stack

19655[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Executing [s@macro-hangupcall:4] Hangup(“PJSIP/anonymous-00000032”, “”) in new stack

19656[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] app_macro.c: Spawn extension (macro-hangupcall, s, 4) exited non-zero on ‘PJSIP/anonymous-00000032’ in macro ‘hangupcall’

19657[2024-07-15 20:59:43] VERBOSE[7996][C-00000033] pbx.c: Spawn extension (from-trunk, h, 1) exited non-zero on ‘PJSIP/anonymous-00000032’

all 1xxx ext are trunked up to the kamailio

Do you allow anonymous calling? Is that the issue?

The log shows that Asterisk did not recognize the call as coming from the Kamailio trunk.
You should have a pjsip trunk with:
Registration None
Authentication None
SIP Server (IP address from which Kamailio sends calls to Asterisk)
Context: from-internal

i do allow anonymous calling, but when the call comes in, it doesnt route out the trunk, the trunk is up. just get the message number you have dialed is not in services…

Is that a separate trunk just for outgoing calls to Kamailio? Or should it be also hit for incoming calls from Kamailio?

ok let me try that

so currently this trunk is only servicing phones external to kamalio pbx1—kamailio–phones, it also running rtpengine nat etc which is working as i can hit voicemail etc. external isp calls will eventually flow over this trunk… incoming calls seem to bypass and it comes in as anonymous, trunk in now setup as

Registration None
Authentication None
SIP Server (IP address from which Kamailio sends calls to Asterisk)
Context: from-internal

and the trunk is up but its just the same.

At the Asterisk command prompt type
pjsip set logger on
Make a test call, paste the Asterisk log for the call at pastebin.com and post the link here.

What is the ‘context’ of the tie-line trunk with Kamailio?

Please explain the network topology. The first lines look really weird. It shows a call apparently from extension 1234 to extension 1234. Is that what you dialed? If so, it might be handled differently from a normal call between extensions.

Also, the request apparently came in from 192.168.129.118 but was sent to 192.168.129.118. Is that the address of Kamailio, Asterisk, or something else. Is the port 1555 a configured value, or is it an ephemeral port?

Later on, we see Kamailio at 172.16.21.118 and Asterisk at 172.16.21.10, with mostly normal communication.

If Kamailio has its ‘user’ interface at 192.168.129.118 and ‘server’ interface at 172.16.21.118, then it is somehow misconfigured (sorry, I know almost nothing about Kamailio), because the source address should have been rewritten to 172.16.21.118.

so i dialed 1234 from ext 1324 the the pbx is on an isolated network, and all the the phones are on the outside of the kamailio.

call flow is

PBX-172.16.21.10-------172.16.21.118-kamalio-192.168.129.118------>phones could be on any ip address.they mostly on 10.10.10.x/24 and 192.168.x.x/16 for testing.

Hi Dicko, ive tried a few, this is one of the question i have, what should it be ?

I suggest you use [from-internal] to access extensions and other endpoints only locally available.

The fact that the call is hitting the anonymous endpoint is the clue. The trunk for the Kamailio server needs to have the Kamailio IP in the Match (Permit) setting of the trunk. Kamailio is sending a request to the PBX and none of the endpoints configured are matching the source IP of the requests and thus ends up on the anonymous endpoint which sends calls to a specific context.

i suppose it worth mentioning no phones are registered on the PBX i basically just want to use it for call routing, all the phones will be registered on the kamailio boxes i did try Match (Permit) along with from-internal, ill try it again tho

ok thanks guys, Ive moved fwd, so setting the match and using internal seems to have it, using sngrep i can now see the call hitting coming in to the pxb and going back out to the kamailio.