On 08/13/2013 03:32 PM, Roberto Fichera wrote: > On 08/13/2013 03:25 PM, Daniel-Constantin Mierla wrote: >> Can you get a ngrep trace for a registration as well (for the phone using >> tcp)? > Ok! I'll use pjsua from my local machine connecting in the same way as the > TCP client was doing. The TCP client it's an iPhone using the same pjlib > library.
I can confirm that the default cfg for TCP client doesn't work for me. My cfg file is attached. The TCP client doesn't receive any package at INVITE. Finally in /var/log/message I get this log below: Aug 13 14:05:37 proxy /usr/sbin/kamailio[8401]: ERROR: <core> [tcp_main.c:4247]: handle_tcpconn_ev(): connect 94.94.X.X:1274 failed Contact:: <sip:528@94.94.X.X:1274;transport=TCP;ob>;q=;expires=38;flags=0x0;cflags=0x0;state=0;socket=<tcp:178.79.X.X:5060>;methods=0x1FDF;user_agent=<PJSUA v2.1-svn Linux-3.10.5.201/x86_64/glibc-2.17>;reg-id=0 [root@proxy ~]# kamctl ul show 512 Contact:: <sip:512@94.94.X.X:5060>;q=;expires=61;flags=0x0;cflags=0x40;state=0;socket=<udp:178.79.X.X:5060>;methods=0xFFFFFFFF;received=<sip:94.94.X.X:1025> user_agent=<DICE 1.8.20.1>;reg-id=0 [root@proxy ~]# ngrep -W byline -d eth0 port 5060 interface: eth0 (178.79.X.X/255.255.255.0) filter: (ip or ip6) and ( port 5060 ) # T 94.94.X.X:49519 -> 178.79.x.x:5060 [AP] REGISTER sip:test.domain;transport=tcp;hide SIP/2.0. Via: SIP/2.0/TCP 94.94.X.X:49519;rport;branch=z9hG4bKPje03c11fd-d742-4502-98d8-69ca456ddd56;alias. Max-Forwards: 70. From: <sip:528@test.domain;hide>;tag=64c9e9b9-cb23-4a79-bb0d-2497135e449b. To: <sip:528@test.domain;hide>. Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1. CSeq: 30034 REGISTER. User-Agent: PJSUA v2.1-svn Linux-3.10.5.201/x86_64/glibc-2.17. Contact: <sip:528@94.94.X.X:1274;transport=TCP;ob>. Expires: 300. Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS. Content-Length: 0. . # T 178.79.x.x:5060 -> 94.94.X.X:49519 [AP] SIP/2.0 401 Unauthorized. Via: SIP/2.0/TCP 94.94.X.X:49519;rport=49519;branch=z9hG4bKPje03c11fd-d742-4502-98d8-69ca456ddd56;alias. From: <sip:528@test.domain;hide>;tag=64c9e9b9-cb23-4a79-bb0d-2497135e449b. To: <sip:528@test.domain;hide>;tag=333a0370df4a40d5d5a0c21bb156e2a6.9167. Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1. CSeq: 30034 REGISTER. WWW-Authenticate: Digest realm="test.domain", nonce="Ugo+VFIKPSgVy8fh9fSy9SDLvT0wO4QV". Server: kamailio (4.0.2 (x86_64/linux)). Content-Length: 0. . # U 178.79.x.x:5060 -> 94.94.X.X:1025 .... ## T 94.94.X.X:49519 -> 178.79.x.x:5060 [AP] REGISTER sip:test.domain;transport=tcp;hide SIP/2.0. Via: SIP/2.0/TCP 94.94.X.X:49519;rport;branch=z9hG4bKPj68a9c487-ae8c-428a-8c50-dd195a46a6bf;alias. Max-Forwards: 70. From: <sip:528@test.domain;hide>;tag=64c9e9b9-cb23-4a79-bb0d-2497135e449b. To: <sip:528@test.domain;hide>. Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1. CSeq: 30035 REGISTER. User-Agent: PJSUA v2.1-svn Linux-3.10.5.201/x86_64/glibc-2.17. Contact: <sip:528@94.94.X.X:1274;transport=TCP;ob>. Expires: 300. Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS. Authorization: Digest username="528", realm="test.domain", nonce="Ugo+VFIKPSgVy8fh9fSy9SDLvT0wO4QV", uri="sip:test.domain;transport=tcp;hide", response="ac1c7311ccb887fc8fb494d8ebf1bd36". Content-Length: 0. . # T 178.79.x.x:5060 -> 94.94.X.X:49519 [AP] SIP/2.0 200 OK. Via: SIP/2.0/TCP 94.94.X.X:49519;rport=49519;branch=z9hG4bKPj68a9c487-ae8c-428a-8c50-dd195a46a6bf;alias. From: <sip:528@test.domain;hide>;tag=64c9e9b9-cb23-4a79-bb0d-2497135e449b. To: <sip:528@test.domain;hide>;tag=333a0370df4a40d5d5a0c21bb156e2a6.5440. Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1. CSeq: 30035 REGISTER. Contact: <sip:528@94.94.X.X:1274;transport=TCP;ob>;expires=300. Server: kamailio (4.0.2 (x86_64/linux)). Content-Length: 0. . ## U 94.94.X.X:1025 -> 178.79.x.x:5060 INVITE sip:528@test.domain:5060 SIP/2.0. Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK69275d13;rport. Max-Forwards: 70. From: "asterisk" <sip:512@test.domain>;tag=as4531a4ee. To: <sip:528@test.domain:5060>. Contact: <sip:512@94.94.X.X:5060>. Call-ID: 2ea7e0f3173949d40b69385b62b79d6a@test.domain. CSeq: 102 INVITE. User-Agent: DICE 1.8.20.1. Date: Tue, 13 Aug 2013 14:04:11 GMT. Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH. Supported: replaces, timer. Content-Type: application/sdp. Content-Length: 262. . v=0. o=root 883039875 883039875 IN IP4 94.94.X.X. s=Asterisk PBX 11.3.0. c=IN IP4 94.94.X.X. t=0 0. m=audio 18120 RTP/AVP 0 110 101. a=rtpmap:0 PCMU/8000. a=rtpmap:110 speex/8000. a=rtpmap:101 telephone-event/8000. a=fmtp:101 0-16. a=ptime:20. a=sendrecv. # U 178.79.x.x:5060 -> 94.94.X.X:1025 SIP/2.0 407 Proxy Authentication Required. Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK69275d13;rport=1025. From: "asterisk" <sip:512@test.domain>;tag=as4531a4ee. To: <sip:528@test.domain:5060>;tag=333a0370df4a40d5d5a0c21bb156e2a6.038f. Call-ID: 2ea7e0f3173949d40b69385b62b79d6a@test.domain. CSeq: 102 INVITE. Proxy-Authenticate: Digest realm="test.domain", nonce="Ugo+XVIKPTFBd9tXC0QemfR9bHiZXO6x". Server: kamailio (4.0.2 (x86_64/linux)). Content-Length: 0. . # U 94.94.X.X:1025 -> 178.79.x.x:5060 INVITE sip:528@test.domain:5060 SIP/2.0. Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK69275d13;rport. Max-Forwards: 70. From: "asterisk" <sip:512@test.domain>;tag=as4531a4ee. To: <sip:528@test.domain:5060>. Contact: <sip:512@94.94.X.X:5060>. Call-ID: 2ea7e0f3173949d40b69385b62b79d6a@test.domain. CSeq: 102 INVITE. User-Agent: DICE 1.8.20.1. Date: Tue, 13 Aug 2013 14:04:11 GMT. Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH. Supported: replaces, timer. Content-Type: application/sdp. Content-Length: 262. . v=0. o=root 883039875 883039875 IN IP4 94.94.X.X. s=Asterisk PBX 11.3.0. c=IN IP4 94.94.X.X. t=0 0. m=audio 18120 RTP/AVP 0 110 101. a=rtpmap:0 PCMU/8000. a=rtpmap:110 speex/8000. a=rtpmap:101 telephone-event/8000. a=fmtp:101 0-16. a=ptime:20. a=sendrecv. # U 178.79.x.x:5060 -> 94.94.X.X:1025 SIP/2.0 407 Proxy Authentication Required. Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK69275d13;rport=1025. From: "asterisk" <sip:512@test.domain>;tag=as4531a4ee. To: <sip:528@test.domain:5060>;tag=333a0370df4a40d5d5a0c21bb156e2a6.038f. Call-ID: 2ea7e0f3173949d40b69385b62b79d6a@test.domain. CSeq: 102 INVITE. Proxy-Authenticate: Digest realm="test.domain", nonce="Ugo+XVIKPTFBd9tXC0QemfR9bHiZXO6x". Server: kamailio (4.0.2 (x86_64/linux)). Content-Length: 0. . # U 94.94.X.X:1025 -> 178.79.x.x:5060 ACK sip:528@test.domain:5060 SIP/2.0. Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK69275d13;rport. Max-Forwards: 70. From: "asterisk" <sip:512@test.domain>;tag=as4531a4ee. To: <sip:528@test.domain:5060>;tag=333a0370df4a40d5d5a0c21bb156e2a6.038f. Contact: <sip:512@94.94.X.X:5060>. Call-ID: 2ea7e0f3173949d40b69385b62b79d6a@test.domain. CSeq: 102 ACK. User-Agent: DICE 1.8.20.1. Content-Length: 0. . # U 94.94.X.X:1025 -> 178.79.x.x:5060 ACK sip:528@test.domain:5060 SIP/2.0. Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK69275d13;rport. Max-Forwards: 70. From: "asterisk" <sip:512@test.domain>;tag=as4531a4ee. To: <sip:528@test.domain:5060>. Contact: <sip:512@94.94.X.X:5060>. Call-ID: 2ea7e0f3173949d40b69385b62b79d6a@test.domain. CSeq: 102 ACK. User-Agent: DICE 1.8.20.1. Content-Length: 0. . ------------------ This is the client behind NAT --------------------------- REGISTER sip:test.domain;transport=tcp;hide SIP/2.0 Via: SIP/2.0/TCP 192.168.2.90:49519;rport;branch=z9hG4bKPj92d04d45-bd84-45b3-9439-563ebfaebf00;alias Max-Forwards: 70 From: <sip:528@test.domain;hide>;tag=ab763476-0fdb-4d85-9064-1deabcaa23e4 To: <sip:528@test.domain;hide> Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1 CSeq: 30028 REGISTER User-Agent: PJSUA v2.1-svn Linux-3.10.5.201/x86_64/glibc-2.17 Contact: <sip:528@192.168.2.90:5060;transport=TCP;ob> Expires: 300 Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Content-Length: 0 --end msg-- 15:54:02.580 pjsua_acc.c .Acc 0: Registration sent >>> 15:54:02.681 tcpc0x1515a08 !TCP transport 192.168.2.90:49519 is connected >>> to 178.79.x.x:5060 15:54:02.681 pjsua_app.c SIP TCP transport is connected to [178.79.x.x:5060] 15:54:02.785 pjsua_core.c .RX 538 bytes Response msg 401/REGISTER/cseq=30028 (rdata0x1515cf8) from TCP 178.79.x.x:5060: SIP/2.0 401 Unauthorized Via: SIP/2.0/TCP 192.168.2.90:49519;rport=49519;branch=z9hG4bKPj92d04d45-bd84-45b3-9439-563ebfaebf00;alias From: <sip:528@test.domain;hide>;tag=ab763476-0fdb-4d85-9064-1deabcaa23e4 To: <sip:528@test.domain;hide>;tag=333a0370df4a40d5d5a0c21bb156e2a6.9663 Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1 CSeq: 30028 REGISTER WWW-Authenticate: Digest realm="test.domain", nonce="Ugo7/FIKOtBneWAQzD/VoJuucFT3cNuF" Server: kamailio (4.0.2 (x86_64/linux)) Content-Length: 0 --end msg-- 15:54:02.785 pjsua_core.c ....TX 849 bytes Request msg REGISTER/cseq=30029 (tdta0x1513000) to TCP 178.79.x.x:5060: REGISTER sip:test.domain;transport=tcp;hide SIP/2.0 Via: SIP/2.0/TCP 192.168.2.90:49519;rport;branch=z9hG4bKPj03a4a7eb-d086-4add-b84c-ca5c6cf4d05d;alias Max-Forwards: 70 From: <sip:528@test.domain;hide>;tag=ab763476-0fdb-4d85-9064-1deabcaa23e4 To: <sip:528@test.domain;hide> Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1 CSeq: 30029 REGISTER User-Agent: PJSUA v2.1-svn Linux-3.10.5.201/x86_64/glibc-2.17 Contact: <sip:528@192.168.2.90:5060;transport=TCP;ob> Expires: 300 Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Authorization: Digest username="528", realm="test.domain", nonce="Ugo7/FIKOtBneWAQzD/VoJuucFT3cNuF", uri="sip:test.domain;transport=tcp;hide", response="c3dd687602ec35b2403b3eb142b496f5" Content-Length: 0 --end msg-- 15:54:02.890 pjsua_core.c .RX 495 bytes Response msg 200/REGISTER/cseq=30029 (rdata0x1515cf8) from TCP 178.79.x.x:5060: SIP/2.0 200 OK Via: SIP/2.0/TCP 192.168.2.90:49519;rport=49519;branch=z9hG4bKPj03a4a7eb-d086-4add-b84c-ca5c6cf4d05d;alias From: <sip:528@test.domain;hide>;tag=ab763476-0fdb-4d85-9064-1deabcaa23e4 To: <sip:528@test.domain;hide>;tag=333a0370df4a40d5d5a0c21bb156e2a6.189b Call-ID: 3ebadaeb-e6d6-42e3-9362-5ca4b5ddd8e1 CSeq: 30029 REGISTER Contact: <sip:528@192.168.2.90:5060;transport=TCP;ob>;expires=300 Server: kamailio (4.0.2 (x86_64/linux)) Content-Length: 0 --end msg-- 15:54:02.890 pjsua_acc.c ....SIP outbound status for acc 0 is not active 15:54:02.890 pjsua_acc.c ....sip:528@test.domain;transport=tcp;hide: registration success, status=200 (OK), will re-register in 300 seconds --------------------------------------------------- > >> Daniel >> >> On 8/13/13 3:23 PM, Roberto Fichera wrote: >>> On 08/13/2013 03:15 PM, Roberto Fichera wrote: >>>> On 08/13/2013 02:33 PM, Daniel-Constantin Mierla wrote: >>>>> Hello, >>>>> >>>>> On 8/13/13 1:10 PM, Roberto Fichera wrote: >>>>>> On 08/13/2013 12:03 PM, Daniel-Constantin Mierla wrote: >>>>>>> Hello, >>>>>>> >>>>>>> you should grab the ngrep for such call to understand better what >>>>>>> happens. Also, dumping the location records >>>>>>> will be >>>>>>> useful (kamctl ul show). >>>>>>> >>>>>>> Also, be sure that tcp connection lifetime is long enough to survive >>>>>>> re-registration. To avoid trying to open >>>>>>> connections behind nat, use set_forward_no_connect() for calls >>>>>>> involving nat traversal. >>>>>> I'm using the default conf coming from fedora rpm. So, mainly the >>>>>> problem seems related to kamailio >>>>>> which doesn't reuse the TCP port used by NATed clients. I've also notice >>>>>> that the received >>>>>> field isn't set at all, so this means that the contact will not get >>>>>> aliased at all. >>>>>> >>>>>> I would really like to have a look to a working cfg file for TCP NATed >>>>>> clients that reuse the TCP port. >>>>>> Even better if the configuration is based on the fedora default rpm. >>>>> if received is not set, then means the register was not detected as >>>>> coming from behind nat. Is the phone using stun? >>>> I'm testing with a normal rtpproxy configuration. BTW udp -> udp work >>>> perfectly. >>>> >>>>> Again, put here the ngrep for registration and a call to see if something >>>>> is wrong with signaling. There is no help >>>>> that we can provide otherwise. The default config works fine for tcp and >>>>> natted clients, I use it everywhere for this >>>>> case without issues. >>>> I tried the default cfg enabling both NAT and RTPproxy, but seems that >>>> kamailio doesn't reuse TCP ports. >>>> Anyway, this is a call from UDP (512) -> TCP (526) both behind the same >>>> NAT, from kamailio point of view >>> I forgot to say that the received field is now present because I've changed >>> the >>> route[NATDETECT] in the default configuration as >>> >>> route[NATDETECT] { >>> #!ifdef WITH_NAT >>> force_rport(); >>> >>> -->>> if (nat_uac_test("19") || proto != UDP) { >>> if (is_method("REGISTER")) { >>> fix_nated_register(); >>> } else { >>> fix_nated_contact(); >>> } >>> setflag(FLT_NATS); >>> } >>> #!endif >>> return; >>> } >>> >>> >>>> [root@proxy ~]# kamctl ul show 526 >>>> Contact:: >>>> <sip:526@94.94.X.X:1238;transport=TCP;ob>;q=;expires=537;flags=0x0;cflags=0x40;state=0;socket=<tcp:178.79.x.x:5060>;methods=0x1FDF;received=<sip:94.94.X.X:61922;transport=TCP>;user_agent=<DICE >>>> >>>> Smartphone 1.0/iPhone>;reg-id=0 >>>> [root@proxy ~]# kamctl ul show 512 >>>> Contact:: >>>> <sip:512@94.94.X.X:5060>;q=;expires=32;flags=0x0;cflags=0x40;state=0;socket=<udp:178.79.x.x:5060>;methods=0xFFFFFFFF;received=<sip:94.94.X.X:1025>;user_agent=<DICE >>>> >>>> 1.8.20.1>;reg-id=0 >>>> [root@proxy ~]# >>>> >>>> >>>> U 94.94.X.X:1025 -> 178.79.x.x:5060 >>>> INVITE sip:526@test.domain:5060 SIP/2.0. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport. >>>> Max-Forwards: 70. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>. >>>> Contact: <sip:512@94.94.X.X:5060>. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 INVITE. >>>> User-Agent: DICE 1.8.20.1. >>>> Date: Tue, 13 Aug 2013 13:04:30 GMT. >>>> Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, >>>> PUBLISH. >>>> Supported: replaces, timer. >>>> Content-Type: application/sdp. >>>> Content-Length: 264. >>>> . >>>> v=0. >>>> o=root 1263161426 1263161426 IN IP4 94.94.X.X. >>>> s=Asterisk PBX 11.3.0. >>>> c=IN IP4 94.94.X.X. >>>> t=0 0. >>>> m=audio 10782 RTP/AVP 0 110 101. >>>> a=rtpmap:0 PCMU/8000. >>>> a=rtpmap:110 speex/8000. >>>> a=rtpmap:101 telephone-event/8000. >>>> a=fmtp:101 0-16. >>>> a=ptime:20. >>>> a=sendrecv. >>>> >>>> # >>>> U 178.79.x.x:5060 -> 94.94.X.X:1025 >>>> SIP/2.0 407 Proxy Authentication Required. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport=1025. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>;tag=333a0370df4a40d5d5a0c21bb156e2a6.4a00. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 INVITE. >>>> Proxy-Authenticate: Digest realm="test.domain", >>>> nonce="UgowYFIKLzQXDSUWUpy4xlhdXZ7WNjPt". >>>> Server: kamailio (4.0.2 (x86_64/linux)). >>>> Content-Length: 0. >>>> . >>>> >>>> # >>>> U 94.94.X.X:1025 -> 178.79.x.x:5060 >>>> INVITE sip:526@test.domain:5060 SIP/2.0. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport. >>>> Max-Forwards: 70. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>. >>>> Contact: <sip:512@94.94.X.X:5060>. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 INVITE. >>>> User-Agent: DICE 1.8.20.1. >>>> Date: Tue, 13 Aug 2013 13:04:30 GMT. >>>> Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, >>>> PUBLISH. >>>> Supported: replaces, timer. >>>> Content-Type: application/sdp. >>>> Content-Length: 264. >>>> . >>>> v=0. >>>> o=root 1263161426 1263161426 IN IP4 94.94.X.X. >>>> s=Asterisk PBX 11.3.0. >>>> c=IN IP4 94.94.X.X. >>>> t=0 0. >>>> m=audio 10782 RTP/AVP 0 110 101. >>>> a=rtpmap:0 PCMU/8000. >>>> a=rtpmap:110 speex/8000. >>>> a=rtpmap:101 telephone-event/8000. >>>> a=fmtp:101 0-16. >>>> a=ptime:20. >>>> a=sendrecv. >>>> >>>> # >>>> U 178.79.x.x:5060 -> 94.94.X.X:1025 >>>> SIP/2.0 407 Proxy Authentication Required. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport=1025. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>;tag=333a0370df4a40d5d5a0c21bb156e2a6.4a00. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 INVITE. >>>> Proxy-Authenticate: Digest realm="test.domain", >>>> nonce="UgowYFIKLzQXDSUWUpy4xlhdXZ7WNjPt". >>>> Server: kamailio (4.0.2 (x86_64/linux)). >>>> Content-Length: 0. >>>> . >>>> >>>> # >>>> U 94.94.X.X:1025 -> 178.79.x.x:5060 >>>> ACK sip:526@test.domain:5060 SIP/2.0. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport. >>>> Max-Forwards: 70. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>;tag=333a0370df4a40d5d5a0c21bb156e2a6.4a00. >>>> Contact: <sip:512@94.94.X.X:5060>. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 ACK. >>>> User-Agent: DICE 1.8.20.1. >>>> Content-Length: 0. >>>> . >>>> >>>> # >>>> U 94.94.X.X:1025 -> 178.79.x.x:5060 >>>> ACK sip:526@test.domain:5060 SIP/2.0. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport. >>>> Max-Forwards: 70. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>. >>>> Contact: <sip:512@94.94.X.X:5060>. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 ACK. >>>> User-Agent: DICE 1.8.20.1. >>>> Content-Length: 0. >>>> . >>>> >>>> # >>>> T 178.79.x.x:5060 -> 94.94.X.X:61922 [AP] >>>> ACK sip:526@94.94.X.X:1238;transport=TCP;ob SIP/2.0. >>>> Via: SIP/2.0/TCP 178.79.x.x;branch=z9hG4bKcydzigwkX. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport=1025. >>>> Max-Forwards: 16. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>. >>>> Contact: <sip:512@94.94.X.X:1025>. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 ACK. >>>> User-Agent: DICE 1.8.20.1. >>>> Content-Length: 0. >>>> . >>>> >>>> # >>>> T 178.79.x.x:5060 -> 94.94.X.X:61922 [AP] >>>> ACK sip:526@94.94.X.X:1238;transport=TCP;ob SIP/2.0. >>>> Via: SIP/2.0/TCP 178.79.x.x;branch=z9hG4bKcydzigwkX. >>>> Via: SIP/2.0/UDP 94.94.X.X:5060;branch=z9hG4bK4a420cee;rport=1025. >>>> Max-Forwards: 16. >>>> From: "asterisk" <sip:512@test.domain>;tag=as76007db0. >>>> To: <sip:526@test.domain:5060>. >>>> Contact: <sip:512@94.94.X.X:1025>. >>>> Call-ID: 068a5a23639785a7583d952d6f9bca84@test.domain. >>>> CSeq: 102 ACK. >>>> User-Agent: DICE 1.8.20.1. >>>> Content-Length: 0. >>>> . >>>> >>>> >>>>> Cheers, >>>>> Daniel >>>>>> Cheers, >>>>>> Roberto Fichera. >>>>>> >>>>>>> Cheers, >>>>>>> Daniel >>>>>>> >>>>>>> On 7/30/13 6:44 PM, Roberto Fichera wrote: >>>>>>>> Hi All, >>>>>>>> >>>>>>>> Sorry for cross-posting this email to PJLIB, but maybe there are some >>>>>>>> things related. >>>>>>>> Anyhow! I'm having problems on kamailio v4.0.2 under Fedora 18 64bit >>>>>>>> and TCP client like iPhone using PJSIP as SIP >>>>>>>> library. >>>>>>>> Basically once the iPhone side in close the call (TCP->UDP) I'm >>>>>>>> getting the error below. Kamailio is running under >>>>>>>> a VPS >>>>>>>> without >>>>>>>> NATed network so it uses a real public address. Furthermore, note that >>>>>>>> tcp_main is answering to a 192.168.2.98 ip >>>>>>>> address >>>>>>>> which is the iPhone client. This looks really strange to me since it >>>>>>>> should answer directly to the public/port used >>>>>>>> for >>>>>>>> the registration >>>>>>>> and not to a such kind of reserved address. The kamilio configuration >>>>>>>> is basically the default with a very few >>>>>>>> changes >>>>>>>> like NAT, rtpproxy and postgresql backend. >>>>>>>> >>>>>>>> This problems doesn't happen at all when using UDP->UDP calls. But I >>>>>>>> cannot use it because as you certain know UDP >>>>>>>> connection under iPhone will not work when the application run in >>>>>>>> background mode. >>>>>>>> >>>>>>>> Can someone suggest how to solve this issue or maybe suggest a TCP >>>>>>>> working solution for iPhone? >>>>>>>> >>>>>>>> Thanks in advance. >>>>>>>> Roberto Fichera. >>>>>>>> >>>>>>>> Jul 30 16:21:53 proxy /usr/sbin/kamailio[9502]: ERROR: <core> >>>>>>>> [tcp_main.c:4432]: tcpconn_main_timeout(): connect >>>>>>>> 192.168.2.98:5060 failed (timeout) >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: DBUG:get_command: received >>>>>>>> command "9483_9 D >>>>>>>> 12d1d19926c4ff742a52f0c855b1bb83@94.94.x.x:5060 as74e0c388 >>>>>>>> GROahimCK6KTrl5CkYEg7nuoPIIXZ8cj" >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: INFO:handle_delete: forcefully >>>>>>>> deleting session 1 on ports 15604/17354 >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: INFO:remove_session: RTP stats: >>>>>>>> 354 in from callee, 603 in from caller, 957 >>>>>>>> relayed, 0 dropped >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: INFO:remove_session: RTCP stats: >>>>>>>> 5 in from callee, 2 in from caller, 7 >>>>>>>> relayed, 0 >>>>>>>> dropped >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: INFO:remove_session: session on >>>>>>>> ports 15604/17354 is cleaned up >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: DBUG:doreply: sending reply >>>>>>>> "9483_9 0 >>>>>>>> Jul 30 16:21:55 proxy rtpproxy[2262]: " >>>>>>>> Jul 30 16:22:04 proxy /usr/sbin/kamailio[9502]: ERROR: <core> >>>>>>>> [tcp_main.c:4432]: tcpconn_main_timeout(): connect >>>>>>>> 192.168.2.98:5060 failed (timeout) >>>>>>>> Jul 30 16:22:14 proxy rtpproxy[2262]: DBUG:get_command: received >>>>>>>> command "9496_16 D >>>>>>>> 12d1d19926c4ff742a52f0c855b1bb83@94.94.x.x:5060 >>>>>>>> GROahimCK6KTrl5CkYEg7nuoPIIXZ8cj as74e0c388" >>>>>>>> Jul 30 16:22:14 proxy rtpproxy[2262]: INFO:handle_command: delete >>>>>>>> request failed: session >>>>>>>> 12d1d19926c4ff742a52f0c855b1bb83@94.94.x.x:5060, tags >>>>>>>> GROahimCK6KTrl5CkYEg7nuoPIIXZ8cj/as74e0c388 not found >>>>>>>> Jul 30 16:22:14 proxy rtpproxy[2262]: DBUG:doreply: sending reply >>>>>>>> "9496_16 E8 >>>>>>>> Jul 30 16:22:14 proxy rtpproxy[2262]: " >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >>>>>>>> sr-users@lists.sip-router.org >>>>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>> _______________________________________________ >>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >>>> sr-users@lists.sip-router.org >>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>> > > _______________________________________________ > SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list > sr-users@lists.sip-router.org > http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >
#!KAMAILIO # # Kamailio (OpenSER) SIP Server v4.0 - default configuration script # - web: http://www.kamailio.org # - git: http://sip-router.org # # Direct your questions about this file to: <sr-users@lists.sip-router.org> # # Refer to the Core CookBook at http://www.kamailio.org/wiki/ # for an explanation of possible statements, functions and parameters. # # Several features can be enabled using '#!define WITH_FEATURE' directives: # # *** To run in debug mode: # - define WITH_DEBUG # # *** To enable mysql: # - define WITH_MYSQL # # *** To enable authentication execute: # - enable mysql # - define WITH_AUTH # - add users using 'kamctl' # # *** To enable IP authentication execute: # - enable mysql # - enable authentication # - define WITH_IPAUTH # - add IP addresses with group id '1' to 'address' table # # *** To enable persistent user location execute: # - enable mysql # - define WITH_USRLOCDB # # *** To enable presence server execute: # - enable mysql # - define WITH_PRESENCE # # *** To enable nat traversal execute: # - define WITH_NAT # - install RTPProxy: http://www.rtpproxy.org # - start RTPProxy: # rtpproxy -l _your_public_ip_ -s udp:localhost:7722 # # *** To enable PSTN gateway routing execute: # - define WITH_PSTN # - set the value of pstn.gw_ip # - check route[PSTN] for regexp routing condition # # *** To enable database aliases lookup execute: # - enable mysql # - define WITH_ALIASDB # # *** To enable speed dial lookup execute: # - enable mysql # - define WITH_SPEEDDIAL # # *** To enable multi-domain support execute: # - enable mysql # - define WITH_MULTIDOMAIN # # *** To enable TLS support execute: # - adjust CFGDIR/tls.cfg as needed # - define WITH_TLS # # *** To enable XMLRPC support execute: # - define WITH_XMLRPC # - adjust route[XMLRPC] for access policy # # *** To enable anti-flood detection execute: # - adjust pike and htable=>ipban settings as needed (default is # block if more than 16 requests in 2 seconds and ban for 300 seconds) # - define WITH_ANTIFLOOD # # *** To block 3XX redirect replies execute: # - define WITH_BLOCK3XX # # *** To enable VoiceMail routing execute: # - define WITH_VOICEMAIL # - set the value of voicemail.srv_ip # - adjust the value of voicemail.srv_port # # *** To enhance accounting execute: # - enable mysql # - define WITH_ACCDB # - add following columns to database #!ifdef ACCDB_COMMENT ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default ''; ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default ''; ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; #!endif ####### Include Local Config If Exists ######### import_file "kamailio-local.cfg" #!define WITH_PGSQL #!define WITH_AUTH #!define WITH_NAT ## #!define WITH_TLS #!define WITH_ANTIFLOOD #!define WITH_ACCDB #!define WITH_DIALPLAN #!ifdef WITH_PGSQL # - database URL - used to connect to database server by modules such # as: auth_db, acc, usrloc, a.s.o. #!define DBURL "postgres://test:testpw@localhost/test" #!endif auto_aliases=yes /* add local domain aliases */ alias="test.domain" /* add local domain aliases */ #alias="sip.mydomain.com" /* uncomment and configure the following line if you want Kamailio to bind on a specific interface/port/proto (default bind on all available) */ listen=udp:178.79.X.X:5060 listen=tcp:178.79.X.X:5060 #!ifdef WITH_TLS listen=tls:178.79.X.X:5061 #!endif ####### Defined Values ######### # *** Value defines - IDs used later in config #!ifdef WITH_MYSQL # - database URL - used to connect to database server by modules such # as: auth_db, acc, usrloc, a.s.o. #!ifndef DBURL #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio" #!endif #!endif #!ifdef WITH_MULTIDOMAIN # - the value for 'use_domain' parameters #!define MULTIDOMAIN 1 #!else #!define MULTIDOMAIN 0 #!endif # - flags # FLT_ - per transaction (message) flags # FLB_ - per branch flags #!define FLT_ACC 1 #!define FLT_ACCMISSED 2 #!define FLT_ACCFAILED 3 #!define FLT_NATS 5 #!define FLB_NATB 6 #!define FLB_NATSIPPING 7 ####### Global Parameters ######### ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR #!ifdef WITH_DEBUG debug=4 log_stderror=yes #!else debug=2 log_stderror=no #!endif memdbg=5 memlog=5 log_facility=LOG_LOCAL0 fork=yes children=4 /* uncomment the next line to disable TCP (default on) */ #disable_tcp=yes /* uncomment the next line to disable the auto discovery of local aliases based on reverse DNS on IPs (default on) */ #auto_aliases=no /* add local domain aliases */ #alias="sip.mydomain.com" /* uncomment and configure the following line if you want Kamailio to bind on a specific interface/port/proto (default bind on all available) */ #listen=udp:10.0.0.10:5060 /* port to listen to * - can be specified more than once if needed to listen on many ports */ port=5060 #!ifdef WITH_TLS enable_tls=yes #!endif # life time of TCP connection when there is no traffic # - a bit higher than registration expires to cope with UA behind NAT tcp_connection_lifetime=3605 ####### Custom Parameters ######### # These parameters can be modified runtime via RPC interface # - see the documentation of 'cfg_rpc' module. # # Format: group.id = value 'desc' description # Access: $sel(cfg_get.group.id) or @cfg_get.group.id # #!ifdef WITH_PSTN # PSTN GW Routing # # - pstn.gw_ip: valid IP or hostname as string value, example: # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address" # # - by default is empty to avoid misrouting pstn.gw_ip = "" desc "PSTN GW Address" pstn.gw_port = "" desc "PSTN GW Port" #!endif #!ifdef WITH_VOICEMAIL # VoiceMail Routing on offline, busy or no answer # # - by default Voicemail server IP is empty to avoid misrouting voicemail.srv_ip = "" desc "VoiceMail IP Address" voicemail.srv_port = "5060" desc "VoiceMail Port" #!endif ####### Modules Section ######## # set paths to location of modules (to sources or installation folders) #!ifdef WITH_SRCPATH mpath="modules_k:modules" #!else mpath="/usr/local/lib/kamailio/modules_k/:/usr/lib64/kamailio/modules/" #!endif #!ifdef WITH_MYSQL loadmodule "db_mysql.so" #!endif #!ifdef WITH_PGSQL loadmodule "db_postgres.so" #!endif loadmodule "mi_fifo.so" loadmodule "kex.so" loadmodule "corex.so" loadmodule "tm.so" loadmodule "tmx.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "pv.so" loadmodule "maxfwd.so" loadmodule "usrloc.so" loadmodule "registrar.so" loadmodule "textops.so" loadmodule "siputils.so" loadmodule "xlog.so" loadmodule "sanity.so" loadmodule "ctl.so" loadmodule "cfg_rpc.so" loadmodule "mi_rpc.so" loadmodule "acc.so" #!ifdef WITH_AUTH loadmodule "auth.so" loadmodule "auth_db.so" #!ifdef WITH_IPAUTH loadmodule "permissions.so" #!endif #!endif #!ifdef WITH_ALIASDB loadmodule "alias_db.so" #!endif #!ifdef WITH_SPEEDDIAL loadmodule "speeddial.so" #!endif #!ifdef WITH_DIALPLAN loadmodule "dialplan.so" #!endif #!ifdef WITH_MULTIDOMAIN loadmodule "domain.so" #!endif #!ifdef WITH_PRESENCE loadmodule "presence.so" loadmodule "presence_xml.so" #!endif #!ifdef WITH_NAT loadmodule "nathelper.so" loadmodule "rtpproxy.so" #!endif #!ifdef WITH_TLS loadmodule "tls.so" #!endif #!ifdef WITH_ANTIFLOOD loadmodule "htable.so" loadmodule "pike.so" #!endif #!ifdef WITH_XMLRPC loadmodule "xmlrpc.so" #!endif #!ifdef WITH_DEBUG loadmodule "debugger.so" #!endif # ----------------- setting module-specific parameters --------------- # ----- mi_fifo params ----- modparam("mi_fifo", "fifo_name", "/var/run/kamailio/kamailio_fifo") # ----- tm params ----- # auto-discard branches from previous serial forking leg modparam("tm", "failure_reply_mode", 3) # default retransmission timeout: 30sec modparam("tm", "fr_timer", 30000) # default invite retransmission timeout after 1xx: 120sec modparam("tm", "fr_inv_timer", 120000) # ----- rr params ----- # add value to ;lr param to cope with most of the UAs modparam("rr", "enable_full_lr", 1) # do not append from tag to the RR (no need for this script) modparam("rr", "append_fromtag", 1) #add a Username to RR-Header modparam("rr", "add_username", 1) # ----- registrar params ----- modparam("registrar", "method_filtering", 1) /* uncomment the next line to disable parallel forking via location */ # modparam("registrar", "append_branches", 0) /* uncomment the next line not to allow more than 10 contacts per AOR */ #modparam("registrar", "max_contacts", 10) # max value for expires of registrations modparam("registrar", "max_expires", 600) # set it to 1 to enable GRUU modparam("registrar", "gruu_enabled", 0) # ----- acc params ----- /* what special events should be accounted ? */ modparam("acc", "early_media", 0) modparam("acc", "report_ack", 0) modparam("acc", "report_cancels", 0) /* by default ww do not adjust the direct of the sequential requests. if you enable this parameter, be sure the enable "append_fromtag" in "rr" module */ modparam("acc", "detect_direction", 0) /* account triggers (flags) */ modparam("acc", "log_flag", FLT_ACC) modparam("acc", "log_missed_flag", FLT_ACCMISSED) modparam("acc", "log_extra", "src_user=$fU;src_domain=$fd;src_ip=$si;" "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd") modparam("acc", "failed_transaction_flag", FLT_ACCFAILED) /* enhanced DB accounting */ #!ifdef WITH_ACCDB modparam("acc", "db_flag", FLT_ACC) modparam("acc", "db_missed_flag", FLT_ACCMISSED) modparam("acc", "db_url", DBURL) modparam("acc", "db_extra", "src_user=$fU;src_domain=$fd;src_ip=$si;" "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd") #!endif # ----- usrloc params ----- /* enable DB persistency for location entries */ #!ifdef WITH_USRLOCDB modparam("usrloc", "db_url", DBURL) modparam("usrloc", "db_mode", 2) modparam("usrloc", "use_domain", MULTIDOMAIN) #!endif # ----- auth_db params ----- #!ifdef WITH_AUTH modparam("auth_db", "db_url", DBURL) modparam("auth_db", "calculate_ha1", yes) modparam("auth_db", "password_column", "password") modparam("auth_db", "load_credentials", "") modparam("auth_db", "use_domain", MULTIDOMAIN) # ----- permissions params ----- #!ifdef WITH_IPAUTH modparam("permissions", "db_url", DBURL) modparam("permissions", "db_mode", 1) #!endif #!endif # ----- alias_db params ----- #!ifdef WITH_ALIASDB modparam("alias_db", "db_url", DBURL) modparam("alias_db", "use_domain", MULTIDOMAIN) #!endif # ----- speeddial params ----- #!ifdef WITH_SPEEDDIAL modparam("speeddial", "db_url", DBURL) modparam("speeddial", "use_domain", MULTIDOMAIN) #!endif # ----- dialplan params ----- #!ifdef WITH_DIALPLAN modparam("dialplan", "db_url", DBURL) #!endif # ----- domain params ----- #!ifdef WITH_MULTIDOMAIN modparam("domain", "db_url", DBURL) # register callback to match myself condition with domains list modparam("domain", "register_myself", 1) #!endif #!ifdef WITH_PRESENCE # ----- presence params ----- modparam("presence", "db_url", DBURL) # ----- presence_xml params ----- modparam("presence_xml", "db_url", DBURL) modparam("presence_xml", "force_active", 1) #!endif #!ifdef WITH_NAT # ----- rtpproxy params ----- modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722") # ----- nathelper params ----- modparam("nathelper", "natping_interval", 30) modparam("nathelper", "ping_nated_only", 1) modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) modparam("nathelper", "sipping_from", "sip:pin...@kamailio.org") # params needed for NAT traversal in other modules modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)") modparam("usrloc", "nat_bflag", FLB_NATB) #!endif #!ifdef WITH_TLS # ----- tls params ----- modparam("tls", "config", "//etc/kamailio/tls.cfg") #!endif #!ifdef WITH_ANTIFLOOD # ----- pike params ----- modparam("pike", "sampling_time_unit", 2) modparam("pike", "reqs_density_per_unit", 16) modparam("pike", "remove_latency", 4) # ----- htable params ----- # ip ban htable with autoexpire after 5 minutes modparam("htable", "htable", "ipban=>size=8;autoexpire=300;") #!endif #!ifdef WITH_XMLRPC # ----- xmlrpc params ----- modparam("xmlrpc", "route", "XMLRPC"); modparam("xmlrpc", "url_match", "^/RPC") #!endif #!ifdef WITH_DEBUG # ----- debugger params ----- modparam("debugger", "cfgtrace", 1) #!endif ####### Routing Logic ######## # Main SIP request routing logic # - processing of any incoming SIP request starts with this route # - note: this is the same as route { ... } request_route { route(CHECK_AUTHORIZED); # per request initial checks route(REQINIT); # NAT detection route(NATDETECT); # CANCEL processing if (is_method("CANCEL")) { if (t_check_trans()) { route(RELAY); } exit; } # handle requests within SIP dialogs route(WITHINDLG); ### only initial requests (no To tag) t_check_trans(); # authentication route(AUTH); # record routing for dialog forming requests (in case they are routed) # - remove preloaded route headers remove_hf("Route"); if (is_method("INVITE|SUBSCRIBE")) record_route(); # account only INVITEs if (is_method("INVITE")) { setflag(FLT_ACC); # do accounting } # dispatch requests to foreign domains route(SIPOUT); ### requests for my local domains # handle presence related requests route(PRESENCE); # handle registrations route(REGISTRAR); if ($rU==$null) { # request with no Username in RURI sl_send_reply("484","Address Incomplete"); exit; } # dispatch destinations to PSTN route(PSTN); # user location service route(LOCATION); } route[RELAY] { # enable additional event routes for forwarded requests # - serial forking, RTP relaying handling, a.s.o. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); } if (is_method("INVITE|SUBSCRIBE|UPDATE")) { if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY"); } if (is_method("INVITE")) { if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); } if (!t_relay()) { sl_reply_error(); } exit; } # Per SIP request initial checks route[REQINIT] { #!ifdef WITH_ANTIFLOOD # flood dection from same IP and traffic ban for a while # be sure you exclude checking trusted peers, such as pstn gateways # - local host excluded (e.g., loop to self) if(src_ip!=myself) { if($sht(ipban=>$si)!=$null) { # ip is already blocked xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n"); exit; } if (!pike_check_req()) { xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n"); $sht(ipban=>$si) = 1; exit; } } #!endif if (!mf_process_maxfwd_header("10")) { sl_send_reply("483","Too Many Hops"); exit; } if(!sanity_check("1511", "7")) { xlog("Malformed SIP message from $si:$sp\n"); exit; } } # Handle requests within SIP dialogs route[WITHINDLG] { if (has_totag()) { # sequential request withing a dialog should # take the path determined by record-routing if (loose_route()) { route(DLGURI); if (is_method("BYE")) { setflag(FLT_ACC); # do accounting ... setflag(FLT_ACCFAILED); # ... even if the transaction fails } else if ( is_method("ACK") ) { # ACK is forwarded statelessy route(NATMANAGE); } else if ( is_method("NOTIFY") ) { # Add Record-Route for in-dialog NOTIFY as per RFC 6665. record_route(); } route(RELAY); } else { if (is_method("SUBSCRIBE") && uri == myself) { # in-dialog subscribe requests route(PRESENCE); exit; } if ( is_method("ACK") ) { if ( t_check_trans() ) { # no loose-route, but stateful ACK; # must be an ACK after a 487 # or e.g. 404 from upstream server route(RELAY); exit; } else { # ACK without matching transaction ... ignore and discard exit; } } sl_send_reply("404","Not here"); } exit; } } # Handle SIP registrations route[REGISTRAR] { if (is_method("REGISTER")) { if(isflagset(FLT_NATS)) { setbflag(FLB_NATB); # uncomment next line to do SIP NAT pinging ## setbflag(FLB_NATSIPPING); } if (!save("location")) sl_reply_error(); exit; } } # USER location service route[LOCATION] { # Replace the +CALLED_NUMBER to 00CALLED_NUMBER if($rU=~"^[+].*") { $rU = "00" + $(rU{s.substr,1,0}); } #!ifdef WITH_DIALPLAN # default translation $rU.user/$rU.user dp_translate( "1", "$rU/$rU" ); #!endif #!ifdef WITH_SPEEDDIAL # search for short dialing - 2-digit extension if($rU=~"^[0-9][0-9]$") if(sd_lookup("speed_dial")) route(SIPOUT); #!endif #!ifdef WITH_ALIASDB # search in DB-based aliases if(alias_db_lookup("dbaliases")) route(SIPOUT); #!endif $avp(oexten) = $rU; if (!lookup("location")) { $var(rc) = $rc; route(TOVOICEMAIL); t_newtran(); switch ($var(rc)) { case -1: case -3: send_reply("404", "Not Found"); exit; case -2: send_reply("405", "Method Not Allowed"); exit; } } # if src_user == dst__user && src_domain == dst_domain if ( $fU == $rU && $fd == $rd ) { xlog("CHECK: You are calling yourself -> $fU == $rU && $fd == $rd (IP:$si:$sp)\n"); send_reply("405", "You are calling yourself"); exit; } # when routing via usrloc, log the missed calls also if (is_method("INVITE")) { setflag(FLT_ACCMISSED); } route(RELAY); exit; } # Presence server route route[PRESENCE] { if(!is_method("PUBLISH|SUBSCRIBE")) return; #!ifdef WITH_PRESENCE if (!t_newtran()) { sl_reply_error(); exit; }; if(is_method("PUBLISH")) { handle_publish(); t_release(); } else if( is_method("SUBSCRIBE")) { handle_subscribe(); t_release(); } exit; #!endif # if presence enabled, this part will not be executed if (is_method("PUBLISH") || $rU==$null) { sl_send_reply("404", "Not here"); exit; } return; } # Authentication route route[AUTH] { #!ifdef WITH_AUTH #!ifdef WITH_IPAUTH if((!is_method("REGISTER")) && allow_source_address()) { # source IP allowed return; } #!endif if (is_method("REGISTER") || from_uri==myself) { # authenticate requests if (!auth_check("$fd", "subscriber", "1")) { auth_challenge("$fd", "0"); exit; } # user authenticated - remove auth header if(!is_method("REGISTER|PUBLISH")) consume_credentials(); } # if caller is not local subscriber, then check if it calls # a local destination, otherwise deny, not an open relay here if (from_uri!=myself && uri!=myself) { sl_send_reply("403","Not relaying"); exit; } #!endif return; } # Caller NAT detection route route[NATDETECT] { #!ifdef WITH_NAT force_rport(); if (nat_uac_test("19")) { if (is_method("REGISTER")) { fix_nated_register(); } else { add_contact_alias(); } setflag(FLT_NATS); } #!endif return; } # RTPProxy control route[NATMANAGE] { #!ifdef WITH_NAT if (is_request()) { if(has_totag()) { if(check_route_param("nat=yes")) { setbflag(FLB_NATB); } } } if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return; rtpproxy_manage("co"); if (is_request()) { if (!has_totag()) { if(t_is_branch_route()) { add_rr_param(";nat=yes"); } } } if (is_reply()) { if(isbflagset(FLB_NATB)) { add_contact_alias(); } } #!endif return; } # URI update for dialog requests route[DLGURI] { #!ifdef WITH_NAT if(!isdsturiset()) { handle_ruri_alias(); } #!endif return; } # Routing to foreign domains route[SIPOUT] { if (!uri==myself) { append_hf("P-hint: outbound\r\n"); route(RELAY); } } # PSTN GW routing route[PSTN] { #!ifdef WITH_PSTN # check if PSTN GW IP is defined if (strempty($sel(cfg_get.pstn.gw_ip))) { xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n"); return; } # route to PSTN dialed numbers starting with '+' or '00' # (international format) # - update the condition to match your dialing rules for PSTN routing if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$")) return; # only local users allowed to call if(from_uri!=myself) { sl_send_reply("403", "Not Allowed"); exit; } if (strempty($sel(cfg_get.pstn.gw_port))) { $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip); } else { $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":" + $sel(cfg_get.pstn.gw_port); } route(RELAY); exit; #!endif return; } # XMLRPC routing #!ifdef WITH_XMLRPC route[XMLRPC] { # allow XMLRPC from localhost if ((method=="POST" || method=="GET") && (src_ip==127.0.0.1)) { # close connection only for xmlrpclib user agents (there is a bug in # xmlrpclib: it waits for EOF before interpreting the response). if ($hdr(User-Agent) =~ "xmlrpclib") set_reply_close(); set_reply_no_connect(); dispatch_rpc(); exit; } send_reply("403", "Forbidden"); exit; } #!endif # route to voicemail server route[TOVOICEMAIL] { #!ifdef WITH_VOICEMAIL if(!is_method("INVITE")) return; # check if VoiceMail server IP is defined if (strempty($sel(cfg_get.voicemail.srv_ip))) { xlog("SCRIPT: VoiceMail rotuing enabled but IP not defined\n"); return; } if($avp(oexten)==$null) return; $ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip) + ":" + $sel(cfg_get.voicemail.srv_port); route(RELAY); exit; #!endif return; } # manage outgoing branches branch_route[MANAGE_BRANCH] { xdbg("new branch [$T_branch_idx] to $ru\n"); route(NATMANAGE); } # manage incoming replies onreply_route[MANAGE_REPLY] { xdbg("incoming reply\n"); if(status=~"[12][0-9][0-9]") route(NATMANAGE); } # manage failure routing cases failure_route[MANAGE_FAILURE] { route(NATMANAGE); if (t_is_canceled()) { exit; } #!ifdef WITH_BLOCK3XX # block call redirect based on 3xx replies. if (t_check_status("3[0-9][0-9]")) { t_reply("404","Not found"); exit; } #!endif #!ifdef WITH_VOICEMAIL # serial forking # - route to voicemail on busy or no answer (timeout) if (t_check_status("486|408")) { $du = $null; route(TOVOICEMAIL); exit; } #!endif } route[CHECK_AUTHORIZED] { if (is_method("INVITE")) { if( !registered("location", "$fu")) { sl_send_reply("403", "Unauthorized: From username does not match digest credentials"); exit; } }; }
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users