Asterisk 18.4.0 - Kamailio 5.5.0 Integration (PJSIP Realtime)

Hello all,

I’m trying to integrate Asterisk with Kamailio. For now, my only aim is to use Kamailio as a SIP proxy, handling the user authentication and registration.

-Ubuntu 20.04.2 LTS on VirtualBox on MacOS
-Zoiper5

I used the below tutorials and this forum as a guide;

https://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb

https://wiki.asterisk.org/wiki/display/AST/Setting+up+PJSIP+Realtime

And managed to register endpoints and make calls on Asterisk using Realtime PJSIP. I also successfully installed Kamailio and was able to register endpoints and make calls (without the Asterisk). However once I integrated them together, I encountered a few problems.

When I enter the creds on the Zoiper it confirms that the endpoint is “registered” and I get 200 OK from the Kamailio. Also when I monitor my Kamailio I see the online endpoints. But when I do pjsip show endpoints they appear offline. Same goes for the pjsip show contacts. Below is the log from the Asterisk and Kamailio.

Kamailio Logs

{
  "jsonrpc":  "2.0",
  "result": {
    "Domains":  [{
        "Domain": {
          "Domain": "location",
          "Size": 1024,
          "AoRs": [{
              "Info": {
                "AoR":  "102",
                "HashID": 3612366,
                "Contacts": [{
                    "Contact":  {
                      "Address":  "sip:102@10.0.0.115:5060;ob",
                      "Expires":  188,
                      "Q":  -1,
                      "Call-ID":  "fGzIGyjWXb8XM3YPcmC2NO2a6UGoPGVQ",
                      "CSeq": 64116,
                      "User-Agent": "PJSUA v2.11-dev Darwin-20.5/x86_64",
                      "Received": "[not set]",
                      "Path": "[not set]",
                      "State":  "CS_SYNC",
                      "Flags":  0,
                      "CFlags": 0,
                      "Socket": "udp:10.0.0.116:5060",
                      "Methods":  8159,
                      "Ruid": "uloc-60c6fe90-861-81",
                      "Instance": "[not set]",
                      "Reg-Id": 0,
                      "Server-Id":  0,
                      "Tcpconn-Id": -1,
                      "Keepalive":  0,
                      "Last-Keepalive": 1623688155,
                      "KA-Roundtrip": 0,
                      "Last-Modified":  1623688155
                    }
                  }, {
                    "Contact":  {
                      "Address":  "sip:102@10.0.0.115:41348;rinstance=a1757106a1dcc579;transport=UDP",
                      "Expires":  20,
                      "Q":  -1,
                      "Call-ID":  "Zqz3iI3qvNWdZuVDOE3dFA..",
                      "CSeq": 46,
                      "User-Agent": "Z 5.4.12 v2.10.13.2",
                      "Received": "[not set]",
                      "Path": "[not set]",
                      "State":  "CS_SYNC",
                      "Flags":  0,
                      "CFlags": 0,
                      "Socket": "udp:10.0.0.116:5060",
                      "Methods":  5087,
                      "Ruid": "uloc-60c774a9-24fd-81",
                      "Instance": "[not set]",
                      "Reg-Id": 0,
                      "Server-Id":  0,
                      "Tcpconn-Id": -1,
                      "Keepalive":  0,
                      "Last-Keepalive": 1623688227,
                      "KA-Roundtrip": 0,
                      "Last-Modified":  1623688227
                    }
                  }]
              }
            }, {
              "Info": {
                "AoR":  "101",
                "HashID": 3612369,
                "Contacts": [{
                    "Contact":  {
                      "Address":  "sip:101@10.0.0.100:44042;rinstance=6288a17193003a27;transport=UDP",
                      "Expires":  41,
                      "Q":  -1,
                      "Call-ID":  "g_mkaXbj512gbM-dBE5QyA..",
                      "CSeq": 106,
                      "User-Agent": "Z 5.4.12 v2.10.13.2-mod",
                      "Received": "[not set]",
                      "Path": "[not set]",
                      "State":  "CS_DIRTY",
                      "Flags":  0,
                      "CFlags": 0,
                      "Socket": "udp:10.0.0.116:5060",
                      "Methods":  5087,
                      "Ruid": "uloc-60c7716f-21cf-2",
                      "Instance": "[not set]",
                      "Reg-Id": 0,
                      "Server-Id":  0,
                      "Tcpconn-Id": -1,
                      "Keepalive":  0,
                      "Last-Keepalive": 1623688248,
                      "KA-Roundtrip": 0,
                      "Last-Modified":  1623688248
                    }
                  }]
              }
            }
  ],
          "Stats":  {
            "Records":  2,
            "Max-Slots":  1
          }
        }
      }]
  },
  "id": 46452
}

Asterisk Logs

<--- Received SIP request (411 bytes) from UDP:10.0.0.116:5060 --->
REGISTER sip:localhost:5080 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bKe186.b9964c33000000000000000000000000.0
To: <sip:102@localhost>
From: <sip:102@localhost>;tag=3393f0703fb0ccaca74109ff37de39f5-7c38ff3a
CSeq: 10 REGISTER
Call-ID: 5c48c0100ccf804b-9474@127.0.0.1
Max-Forwards: 70
Content-Length: 0
User-Agent: kamailio (5.5.0 (x86_64/linux))
Contact: <sip:102@localhost:5060>
Expires: 60


<--- Transmitting SIP response (547 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bKe186.b9964c33000000000000000000000000.0
Call-ID: 5c48c0100ccf804b-9474@127.0.0.1
From: <sip:102@localhost>;tag=3393f0703fb0ccaca74109ff37de39f5-7c38ff3a
To: <sip:102@localhost>;tag=z9hG4bKe186.b9964c33000000000000000000000000.0
CSeq: 10 REGISTER
WWW-Authenticate: Digest realm="asterisk",nonce="1623686053/447282fc71f803d6671d6eda7e038a7c",opaque="6e25258e10f76405",algorithm=md5,qop="auth"
Server: Asterisk PBX 18.4.0
Content-Length:  0

If I try to make a call from my semi-registered endpoints I get 100-Trying followed by the 500 - Service Unavailable from both Kamailio and Asterisk. Below are the logs from Asterisk

<--- Received SIP request (1041 bytes) from UDP:10.0.0.116:5060 --->
INVITE sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Record-Route: <sip:10.0.0.116;lr;ftag=51ca0752>
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bKbd72.e074883d723e892e2f4d88e09655b471.0
Via: SIP/2.0/UDP 10.0.0.115:41348;received=10.0.0.115;branch=z9hG4bK-524287-1---4696a585dedddc45;rport=41348
Max-Forwards: 69
Contact: <sip:102@10.0.0.115:41348;transport=UDP>
To: <sip:101@10.0.0.116:5060>
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=51ca0752
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
CSeq: 2 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2
Allow-Events: presence, kpml, talk
Content-Length: 328

v=0
o=Z 1623687109485 1 IN IP4 10.0.0.115
s=Z
c=IN IP4 10.0.0.115
t=0 0
m=audio 8000 RTP/AVP 106 9 98 101 0 8 3
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (665 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bKbd72.e074883d723e892e2f4d88e09655b471.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---4696a585dedddc45
Record-Route: <sip:10.0.0.116;lr;ftag=51ca0752>
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
From: <sip:102@10.0.0.116>;tag=51ca0752
To: <sip:101@10.0.0.116>;tag=z9hG4bKbd72.e074883d723e892e2f4d88e09655b471.0
CSeq: 2 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1623687109/a11d3cc17fa0fb4140877e94cdcb47b9",opaque="4aceccb6629e4c9c",algorithm=md5,qop="auth"
Server: Asterisk PBX 18.4.0
Content-Length:  0


<--- Received SIP request (358 bytes) from UDP:10.0.0.116:5060 --->
ACK sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bKbd72.e074883d723e892e2f4d88e09655b471.0
Max-Forwards: 69
To: <sip:101@10.0.0.116>;tag=z9hG4bKbd72.e074883d723e892e2f4d88e09655b471.0
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=51ca0752
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
CSeq: 2 ACK
Content-Length: 0


<--- Received SIP request (1339 bytes) from UDP:10.0.0.116:5060 --->
INVITE sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Record-Route: <sip:10.0.0.116;lr;ftag=51ca0752>
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bKcd72.8f6892a9c0174bbd1781fef8c8a8f14b.0
Via: SIP/2.0/UDP 10.0.0.115:41348;received=10.0.0.115;branch=z9hG4bK-524287-1---4b7566e6eb57a703;rport=41348
Max-Forwards: 69
Contact: <sip:102@10.0.0.115:41348;transport=UDP>
To: <sip:101@10.0.0.116:5060>
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=51ca0752
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
CSeq: 3 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2
Authorization: Digest username="102",realm="asterisk",nonce="1623687109/a11d3cc17fa0fb4140877e94cdcb47b9",uri="sip:101@10.0.0.116:5060;transport=UDP",response="b56c8dfd2856883ad465512e86a3953e",cnonce="f318efa24f1be2edc84a932fe2a6c79d",nc=00000001,qop=auth,algorithm=md5,opaque="4aceccb6629e4c9c"
Allow-Events: presence, kpml, talk
Content-Length: 328

v=0
o=Z 1623687109485 1 IN IP4 10.0.0.115
s=Z
c=IN IP4 10.0.0.115
t=0 0
m=audio 8000 RTP/AVP 106 9 98 101 0 8 3
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (462 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bKcd72.8f6892a9c0174bbd1781fef8c8a8f14b.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---4b7566e6eb57a703
Record-Route: <sip:10.0.0.116;lr;ftag=51ca0752>
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
From: <sip:102@10.0.0.116>;tag=51ca0752
To: <sip:101@10.0.0.116>
CSeq: 3 INVITE
Server: Asterisk PBX 18.4.0
Content-Length:  0


    -- Executing [101@testing:1] NoOp("PJSIP/102-00000000", "") in new stack
    -- Executing [101@testing:2] Dial("PJSIP/102-00000000", "") in new stack
    -- No devices or endpoints to dial (technology/resource)
    -- Auto fallthrough, channel 'PJSIP/102-00000000' status is 'CHANUNAVAIL'
<--- Transmitting SIP response (540 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 503 Service Unavailable
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bKcd72.8f6892a9c0174bbd1781fef8c8a8f14b.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---4b7566e6eb57a703
Record-Route: <sip:10.0.0.116;lr;ftag=51ca0752>
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
From: <sip:102@10.0.0.116>;tag=51ca0752
To: <sip:101@10.0.0.116>;tag=35ab10b7-63ad-4ecb-bd8a-316eb5a140fb
CSeq: 3 INVITE
Server: Asterisk PBX 18.4.0
Reason: Q.850;cause=34
Content-Length:  0


<--- Received SIP request (348 bytes) from UDP:10.0.0.116:5060 --->
ACK sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bKcd72.8f6892a9c0174bbd1781fef8c8a8f14b.0
Max-Forwards: 69
To: <sip:101@10.0.0.116>;tag=35ab10b7-63ad-4ecb-bd8a-316eb5a140fb
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=51ca0752
Call-ID: U3uG3IVPsvIZxR-3U4QbcQ..
CSeq: 3 ACK
Content-Length: 0


It is clear to me that my Kamailio is somehow able to use the Asterisk’s realtime db and authenticate however it seems the Asterisk is not aware that these users are registered. I’m not surprised that Asterisk complains “No devices or endpoints to dial (technology/resource)” since I could not see my endpoints on the CLI.

However the interesting part is; if I register an endpoint directly, by only using Asterisk (registering through port 5080), the kamailio-registered users are able to call the asterisk-registered ones (but not vice-versa). So although they appear offline from Asterisk’s side and not able to receive calls, they are able to make calls to other online users. Below are the logs from Asterisk for this scenario.

<--- Received SIP request (1041 bytes) from UDP:10.0.0.116:5060 --->
INVITE sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bK291b.f357491517345f60e00930360d573c92.0
Via: SIP/2.0/UDP 10.0.0.115:41348;received=10.0.0.115;branch=z9hG4bK-524287-1---1b5a025756044343;rport=41348
Max-Forwards: 69
Contact: <sip:102@10.0.0.115:41348;transport=UDP>
To: <sip:101@10.0.0.116:5060>
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=722c1558
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
CSeq: 2 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2
Allow-Events: presence, kpml, talk
Content-Length: 328

v=0
o=Z 1623688810957 1 IN IP4 10.0.0.115
s=Z
c=IN IP4 10.0.0.115
t=0 0
m=audio 8000 RTP/AVP 106 9 98 101 0 8 3
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (665 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bK291b.f357491517345f60e00930360d573c92.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---1b5a025756044343
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
From: <sip:102@10.0.0.116>;tag=722c1558
To: <sip:101@10.0.0.116>;tag=z9hG4bK291b.f357491517345f60e00930360d573c92.0
CSeq: 2 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1623688811/41cd1e9dd1dca4b25cf96eaff94cf251",opaque="4be8ac5a643c8ec8",algorithm=md5,qop="auth"
Server: Asterisk PBX 18.4.0
Content-Length:  0


<--- Received SIP request (358 bytes) from UDP:10.0.0.116:5060 --->
ACK sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bK291b.f357491517345f60e00930360d573c92.0
Max-Forwards: 69
To: <sip:101@10.0.0.116>;tag=z9hG4bK291b.f357491517345f60e00930360d573c92.0
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=722c1558
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
CSeq: 2 ACK
Content-Length: 0


<--- Received SIP request (1339 bytes) from UDP:10.0.0.116:5060 --->
INVITE sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bK391b.a683c4bac3da18d7a384f7cf517b6975.0
Via: SIP/2.0/UDP 10.0.0.115:41348;received=10.0.0.115;branch=z9hG4bK-524287-1---b09caa8639e8b115;rport=41348
Max-Forwards: 69
Contact: <sip:102@10.0.0.115:41348;transport=UDP>
To: <sip:101@10.0.0.116:5060>
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=722c1558
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
CSeq: 3 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2
Authorization: Digest username="102",realm="asterisk",nonce="1623688811/41cd1e9dd1dca4b25cf96eaff94cf251",uri="sip:101@10.0.0.116:5060;transport=UDP",response="a95f147a032daee8654274dd6ed3fd37",cnonce="53456f5a037bc4ef60a841e1ff9a4b97",nc=00000001,qop=auth,algorithm=md5,opaque="4be8ac5a643c8ec8"
Allow-Events: presence, kpml, talk
Content-Length: 328

v=0
o=Z 1623688810957 1 IN IP4 10.0.0.115
s=Z
c=IN IP4 10.0.0.115
t=0 0
m=audio 8000 RTP/AVP 106 9 98 101 0 8 3
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (462 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bK391b.a683c4bac3da18d7a384f7cf517b6975.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---b09caa8639e8b115
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
From: <sip:102@10.0.0.116>;tag=722c1558
To: <sip:101@10.0.0.116>
CSeq: 3 INVITE
Server: Asterisk PBX 18.4.0
Content-Length:  0


    -- Executing [101@testing:1] NoOp("PJSIP/102-00000005", "") in new stack
    -- Executing [101@testing:2] Dial("PJSIP/102-00000005", "PJSIP/101/sip:101@10.0.0.100:44042;transport=UDP;rinstance=059e5a3c5f9bffb6") in new stack
    -- Called PJSIP/101/sip:101@10.0.0.100:44042;transport=UDP;rinstance=059e5a3c5f9bffb6
<--- Transmitting SIP request (947 bytes) to UDP:10.0.0.100:44042 --->
INVITE sip:101@10.0.0.100:44042;transport=UDP;rinstance=059e5a3c5f9bffb6 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116:5080;rport;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>
Contact: <sip:asterisk@10.0.0.116:5080>
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 18.4.0
Content-Type: application/sdp
Content-Length:   231

v=0
o=- 778574967 778574967 IN IP4 10.0.0.116
s=Asterisk
c=IN IP4 10.0.0.116
t=0 0
m=audio 12890 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<--- Received SIP response (328 bytes) from UDP:10.0.0.100:44042 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.116:5080;rport=5080;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Content-Length: 0


<--- Received SIP response (535 bytes) from UDP:10.0.0.100:44042 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.0.0.116:5080;rport=5080;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
Contact: <sip:101@10.0.0.100:44042>
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>;tag=00ad4401
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
User-Agent: Z 5.4.12 v2.10.13.2-mod
Allow-Events: presence, kpml, talk
Content-Length: 0


    -- PJSIP/101-00000006 is ringing
<--- Transmitting SIP response (647 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bK391b.a683c4bac3da18d7a384f7cf517b6975.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---b09caa8639e8b115
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
From: <sip:102@10.0.0.116>;tag=722c1558
To: <sip:101@10.0.0.116>;tag=4210f8b6-ea80-4414-8739-0f664c53cb38
CSeq: 3 INVITE
Server: Asterisk PBX 18.4.0
Contact: <sip:10.0.0.116:5080>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Content-Length:  0


<--- Received SIP response (932 bytes) from UDP:10.0.0.100:44042 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.116:5080;rport=5080;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
Require: timer
Contact: <sip:101@10.0.0.100:44042>
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>;tag=00ad4401
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Session-Expires: 1800;refresher=uac
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2-mod
Allow-Events: presence, kpml, talk
Content-Length: 316

v=0
o=Z 0 1 IN IP4 10.0.0.100
s=Z
c=IN IP4 10.0.0.100
t=0 0
m=audio 8000 RTP/AVP 0 106 9 8 3 101 98
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=sendrecv

       > 0x7f5fb4047800 -- Strict RTP learning after remote address set to: 10.0.0.100:8000
<--- Transmitting SIP request (403 bytes) to UDP:10.0.0.100:44042 --->
ACK sip:101@10.0.0.100:44042 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116:5080;rport;branch=z9hG4bKPj9db6ecdb-99ac-4661-bc96-3069ac37df80
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>;tag=00ad4401
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 18.4.0
Content-Length:  0


       > 0x7f5fb4047800 -- Strict RTP switching to RTP target address 10.0.0.100:8000 as source
    -- PJSIP/101-00000006 answered PJSIP/102-00000005
       > 0x7f5fb409c610 -- Strict RTP learning after remote address set to: 10.0.0.115:8000

MY CONFIG

/etc/asterisk/extconfig.conf

[settings]

ps_endpoints => odbc,asterisk

ps_auths => odbc,asterisk

ps_aors => odbc,asterisk

ps_domain_aliases => odbc,asterisk

ps_endpoint_id_ips => odbc,asterisk

ps_contacts => odbc,asterisk

/etc/asterisk/extensions.conf

[testing]

exten => _1XX,1,NoOp()

same => n,Dial(${PJSIP_DIAL_CONTACTS(${EXTEN})})

/etc/asterisk/extconfig.conf

[settings]

ps_endpoints => odbc,asterisk

ps_auths => odbc,asterisk

ps_aors => odbc,asterisk

ps_domain_aliases => odbc,asterisk

ps_endpoint_id_ips => odbc,asterisk

ps_contacts => odbc,asterisk

/etc/asterisk/res_odbc.conf

[asterisk]

enabled =>yes

dsn =>asterisk

username =>root

password =>verysecretpassword

pre-connect =>yes

**/etc/odbc.ini **

[asterisk]

Driver= MySQL

Description= MySQL connection to ‘asterisk’ database

Server=localhost

Port=3306

Database=asterisk

UserName=root

Password=verysecretpassword

Socket= /var/run/mysqld/mysqld.sock

**/etc/odbcinst.ini **

[MySQL]

Description=ODBC for MySQL

Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so

Setup=/usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so

UsageCount=2

[MySQL ODBC 8.0 Unicode Driver]

Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so

UsageCount=1

[MySQL ODBC 8.0 ANSI Driver]

Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so

UsageCount=1

I am terribly sorry for the extremely long post. Frankly, I’m surprised that I made this far. And I feel like I’m pretty close too. But I have been working on this issue for the last few days and I feel like I can’t generate new theories about why would my config not work. My suspicions is that there is something wrong with my kamailio.cfg? Your help is much appreciated :slightly_smiling_face:

/usr/local/etc/kamailio/kamailio.cfg

#!KAMAILIO
#
# Kamailio SIP Server v5.5 - default configuration script
#     - web: https://www.kamailio.org
#     - git: https://github.com/kamailio/kamailio
#
# Direct your questions about this file to: <sr-users@lists.kamailio.org>
#
# Refer to the Core CookBook at https://www.kamailio.org/wiki/
# for an explanation of possible statements, functions and parameters.
#
# Note: the comments can be:
#     - lines starting with #, but not the pre-processor directives,
#       which start with #!, like #!define, #!ifdef, #!endif, #!else, #!trydef,
#       #!subst, #!substdef, ...
#     - lines starting with //
#     - blocks enclosed in between /* */
# Note: the config performs symmetric SIP signaling
#     - it sends the reply to the source address of the request
#     - remove the use of force_rport() for asymmetric SIP signaling
#
# Several features can be enabled using '#!define WITH_FEATURE' directives:
#
# *** To run in debug mode:
#     - define WITH_DEBUG
#     - debug level increased to 3, logs still sent to syslog
#     - debugger module loaded with cfgtrace endabled
#
# *** To enable mysql:
#     - define WITH_MYSQL
#
# *** To enable authentication execute:
#     - enable mysql
#     - define WITH_AUTH
#     - add users using 'kamctl' or 'kamcli'
#
# *** 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
#     - if modified headers or body in config must be used by presence handling:
#     - define WITH_MSGREBUILD
#
# *** To enable nat traversal execute:
#     - define WITH_NAT
#     - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING
#     - install RTPProxy: http://www.rtpproxy.org
#     - start RTPProxy:
#        rtpproxy -l _your_public_ip_ -s udp:localhost:7722
#
# *** To use RTPEngine (instead of RTPProxy) for nat traversal execute:
#     - define WITH_RTPENGINE
#     - install RTPEngine: https://github.com/sipwise/rtpengine
#     - start RTPEngine:
#        rtpengine --listen-ng=127.0.0.1:2223 ...
#
# *** 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 JSONRPC over HTTP(S) support execute:
#     - define WITH_JSONRPC
#     - adjust event_route[xhttp:request] 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 block 401 and 407 authentication replies execute:
#     - define WITH_BLOCK401407
#
# *** 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


#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_ASTERISK



####### Include Local Config If Exists #########
import_file "kamailio-local.cfg"

####### Defined Values #########

# *** Value defines - IDs used later in config
#!ifdef WITH_DEBUG
#!define DBGLEVEL 3
#!else
#!define DBGLEVEL 2
#!endif

#!ifdef WITH_MYSQL
# - database URL - used to connect to database server by modules such
#       as: auth_db, acc, usrloc, a.s.o.
#!trydef DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
#!ifdef WITH_ASTERISK
#!define DBASTURL "mysql://root:verysecretpass@localhost/asterisk"
#!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
#!define FLT_ACC 1
#!define FLT_ACCMISSED 2
#!define FLT_ACCFAILED 3
#!define FLT_NATS 5

#	FLB_ - per branch flags
#!define FLB_NATB 6
#!define FLB_NATSIPPING 7

####### Global Parameters #########

/* LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR, ... */
debug=DBGLEVEL

/* set to 'yes' to print log messages to terminal or use '-E' cli option */
log_stderror=yes #Added for Python

fork=yes #Added for Python
children=2 #Added for Python

memdbg=5
memlog=5

log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "

/* number of SIP routing processes for each UDP socket
 * - value inherited by tcp_children and sctp_children when not set explicitely */
children=8

/* uncomment the next line to disable TCP (default on) */
# disable_tcp=yes

/* number of SIP routing processes for all TCP/TLS sockets */
# tcp_children=8

/* 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 - it can be set many times */
# alias="sip.mydomain.com"

/* listen sockets - if none set, Kamailio binds to all local IP addresses
 * - basic prototype (full prototype can be found in Wiki - Core Cookbook):
 *      listen=[proto]:[localip]:[lport] advertise [publicip]:[pport]
 * - it can be set many times to add more sockets to listen to */
# listen=udp:10.0.0.10:5060

/* 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

/* upper limit for TCP connections (it includes the TLS connections) */
tcp_max_connections=2048

#!ifdef WITH_JSONRPC
tcp_accept_no_cl=yes
#!endif

#!ifdef WITH_TLS
enable_tls=yes

/* upper limit for TLS connections */
tls_max_connections=2048
#!endif

/* set it to yes to enable sctp and load sctp.so module */
enable_sctp=no

####### 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


#!ifdef WITH_ASTERISK
asterisk.bindip = "localhost" desc "Asterisk IP Address"
asterisk.bindport = "5080" desc "Asterisk Port"
kamailio.bindip = "localhost" desc "Kamailio IP Address"
kamailio.bindport = "5060" desc "Kamailio Port"
#!endif










####### Modules Section ########

/* set paths to location of modules */
# mpath="/usr/local/lib64/kamailio/modules/"

#!ifdef WITH_MYSQL
loadmodule "db_mysql.so"
#!endif

#!ifdef WITH_JSONRPC
loadmodule "xhttp.so"
#!endif
loadmodule "jsonrpcs.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 "textopsx.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "cfg_rpc.so"
loadmodule "acc.so"
loadmodule "counters.so"
loadmodule "debugger.so" #Added for Python
#loadmodule "app_python3.so" #Added for Python
#!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_MULTIDOMAIN
loadmodule "domain.so"
#!endif

#!ifdef WITH_PRESENCE
loadmodule "presence.so"
loadmodule "presence_xml.so"
#!endif

#!ifdef WITH_NAT
loadmodule "nathelper.so"
#!ifdef WITH_RTPENGINE
loadmodule "rtpengine.so"
#!else
loadmodule "rtpproxy.so"
#!endif
#!endif

#!ifdef WITH_TLS
loadmodule "tls.so"
#!endif

#!ifdef WITH_ANTIFLOOD
loadmodule "htable.so"
loadmodule "pike.so"
#!endif

#!ifdef WITH_DEBUG
loadmodule "debugger.so"
#!endif

#!ifdef WITH_ASTERISK
loadmodule "uac.so"
#!endif

# ----------------- setting module-specific parameters ---------------


# ----- jsonrpcs params -----
modparam("jsonrpcs", "pretty_format", 1)
/* set the path to RPC fifo control file */
# modparam("jsonrpcs", "fifo_name", "/run/kamailio/kamailio_rpc.fifo")
/* set the path to RPC unix socket control file */
# modparam("jsonrpcs", "dgram_socket", "/run/kamailio/kamailio_rpc.sock")
#!ifdef WITH_JSONRPC
modparam("jsonrpcs", "transport", 7)
#!endif

# ----- ctl params -----
/* set the path to RPC unix socket control file */
# modparam("ctl", "binrpc", "unix:/run/kamailio/kamailio_ctl")

# ----- sanity params -----
modparam("sanity", "autodrop", 0)

# ----- 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 -----
# set next param to 1 to add value to ;lr param (helps with some UAs)
modparam("rr", "enable_full_lr", 0)
# do not append from tag to the RR (no need for this script)
#!ifdef WITH_ASTERISK
modparam("rr", "append_fromtag", 1)
#!else
modparam("rr", "append_fromtag", 0)
#!endif


# ----- 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", 3600)
/* set it to 1 to enable GRUU */
modparam("registrar", "gruu_enabled", 0)
/* set it to 0 to disable Path handling */
modparam("registrar", "use_path", 1)
/* save Path even if not listed in Supported header */
modparam("registrar", "path_mode", 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 -----
modparam("usrloc", "timer_interval", 60)
modparam("usrloc", "timer_procs", 1)
modparam("usrloc", "use_domain", MULTIDOMAIN)
/* enable DB persistency for location entries */
#!ifdef WITH_USRLOCDB
modparam("usrloc", "db_url", DBURL)
modparam("usrloc", "db_mode", 2)
#!endif

# ----- auth_db params -----
#!ifdef WITH_AUTH
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "load_credentials", "")


#!ifdef WITH_ASTERISK
modparam("auth_db", "user_column", "id")
modparam("auth_db", "password_column", "password")
modparam("auth_db", "db_url", DBASTURL)
modparam("auth_db", "version_table", 0)
#!else


modparam("auth_db", "db_url", DBURL)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "use_domain", MULTIDOMAIN)
#!endif


# ----- permissions params -----
#!ifdef WITH_IPAUTH
modparam("permissions", "db_url", DBURL)
modparam("permissions", "load_backends", 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

# ----- 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
#!ifdef WITH_RTPENGINE
# ----- rtpengine params -----
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
#!else
# ----- rtpproxy params -----
modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
#!endif
# ----- nathelper params -----
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "sipping_from", "sip:pinger@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", "/usr/local/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_DEBUG
# ----- debugger params -----
modparam("debugger", "cfgtrace", 1)
modparam("debugger", "log_level_name", "exec")
#!endif

####### Routing Logic ########

#modparam("app_python3", "load", "/usr/local/etc/kamailio/kemi.py")

#cfgengine "python"


/* Main SIP request routing logic
 * - processing of any incoming SIP request starts with this route
 * - note: this is the same as route { ... } */
request_route {

	# per request initial checks
	route(REQINIT);

	# NAT detection
	route(NATDETECT);

	# CANCEL processing
	if (is_method("CANCEL")) {
		if (t_check_trans()) {
			route(RELAY);
		}
		exit;
	}

	# handle retransmissions
	if (!is_method("ACK")) {
		if(t_precheck_trans()) {
			t_check_trans();
			exit;
		}
		t_check_trans();
	}

	# handle requests within SIP dialogs
	route(WITHINDLG);

	### only initial requests (no To tag)

	# 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);
}

# Wrapper for relaying requests
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] {
	# no connect for sending replies
	set_reply_no_connect();
	# enforce symmetric signaling
	# - send back replies to the source address of request
	force_rport();

#!ifdef WITH_ANTIFLOOD
	# flood detection 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($ua =~ "friendly|scanner|sipcli|sipvicious|VaxSIPUserAgent") {
		# silent drop for scanners - uncomment next line if want to reply
		# sl_send_reply("200", "OK");
		exit;
	}

	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483","Too Many Hops");
		exit;
	}

	if(is_method("OPTIONS") && uri==myself && $rU==$null) {
		sl_send_reply("200","Keepalive");
		exit;
	}

	if(!sanity_check("17895", "7")) {
		xlog("Malformed SIP request from $si:$sp\n");
		exit;
	}
}

# Handle requests within SIP dialogs
route[WITHINDLG] {
	if (!has_totag()) return;

	# 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 statelessly
			route(NATMANAGE);
		} else if ( is_method("NOTIFY") ) {
			# Add Record-Route for in-dialog NOTIFY as per RFC 6665.
			record_route();
		}
		route(RELAY);
		exit;
	}

	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")) return;

	if(isflagset(FLT_NATS)) {
		setbflag(FLB_NATB);
#!ifdef WITH_NATSIPPING
		# do SIP NAT pinging
		setbflag(FLB_NATSIPPING);
#!endif
	}
	if (!save("location")) {
		sl_reply_error();
	}
#!ifdef WITH_ASTERISK
		route(REGFWD);
#!endif
	exit;
}

# User location service
route[LOCATION] {

#!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

#!ifdef WITH_ASTERISK
	if(is_method("INVITE") && (!route(FROMASTERISK))) {
		# if new call from out there - send to Asterisk
		# - non-INVITE request are routed directly by Kamailio
		# - traffic from Asterisk is routed also directy by Kamailio
		route(TOASTERISK);
		exit;
	}
#!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;
		}
	}

	# when routing via usrloc, log the missed calls also
	if (is_method("INVITE")) {
		setflag(FLT_ACCMISSED);
	}
	xlog("L_INFO", "From header value: $hdr(WG67-Version)\n");#Kaan added this line

	replace_hdrs_str("phone.02","Test", "a"); #Kaan added this
	append_hf("WG67-Version: $hdr(WG67-Version)\r\n"); #Kaan added this
	route(RELAY);
	exit;
}

# Presence server processing
route[PRESENCE] {
	if(!is_method("PUBLISH|SUBSCRIBE")) return;

	if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {
		route(TOVOICEMAIL);
		# returns here if no voicemail server is configured
		sl_send_reply("404", "No voicemail service");
		exit;
	}

#!ifdef WITH_PRESENCE
#!ifdef WITH_MSGREBUILD
	# apply changes in case the request headers or body were modified
	msg_apply_changes();
#!endif
	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;
}

# IP authorization and user authentication
route[AUTH] {
#!ifdef WITH_AUTH

#!ifdef WITH_ASTERISK
	# do not auth traffic from Asterisk - trusted!
	if(route(FROMASTERISK))
		return;
#!endif



#!ifdef WITH_IPAUTH
	if((!is_method("REGISTER")) && allow_source_address()) {
		# source IP allowed
		return;
	}
#!endif

	if (is_method("REGISTER") || from_uri==myself) {
		# authenticate requests
#!ifdef WITH_ASTERISK
		if (!auth_check("$fd", "ps_auths", "1")) {
#!else
		if (!auth_check("$fd", "subscriber", "1")) {
#!endif
			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;
	}

#!else

	# authentication not enabled - do not relay at all to foreign networks
	if(uri!=myself) {
		sl_send_reply("403","Not relaying");
		exit;
	}

#!endif
	return;
}

# Caller NAT detection
route[NATDETECT] {
#!ifdef WITH_NAT
	if (nat_uac_test("19")) {
		if (is_method("REGISTER")) {
			fix_nated_register();
		} else {
			if(is_first_hop()) {
				set_contact_alias();
			}
		}
		setflag(FLT_NATS);
	}
#!endif
	return;
}

# RTPProxy control and signaling updates for NAT traversal
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;

#!ifdef WITH_RTPENGINE
	if(nat_uac_test("8")) {
		rtpengine_manage("SIP-source-address replace-origin replace-session-connection");
	} else {
		rtpengine_manage("replace-origin replace-session-connection");
	}
#!else
	if(nat_uac_test("8")) {
		rtpproxy_manage("co");
	} else {
		rtpproxy_manage("cor");
	}
#!endif

	if (is_request()) {
		if (!has_totag()) {
			if(t_is_branch_route()) {
				add_rr_param(";nat=yes");
			}
		}
	}
	if (is_reply()) {
		if(isbflagset(FLB_NATB)) {
			if(is_first_hop())
				set_contact_alias();
		}
	}

	if(isbflagset(FLB_NATB)) {
		# no connect message in a dialog involving NAT traversal
		if (is_request()) {
			if(has_totag()) {
				set_forward_no_connect();
			}
		}
	}
#!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) return;

	append_hf("P-Hint: outbound\r\n");
	route(RELAY);
	exit;
}

# 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 routing 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;
	}

	# normalize target number for pstn gateway
	# - convert leading 00 to +
	if (starts_with("$rU", "00")) {
		strip(2);
		prefix("+");
	}

	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;
}

# JSONRPC over HTTP(S) routing
#!ifdef WITH_JSONRPC
event_route[xhttp:request] {
	set_reply_close();
	set_reply_no_connect();
	if(src_ip!=127.0.0.1) {
		xhttp_reply("403", "Forbidden", "text/html",
				"<html><body>Not allowed from $si</body></html>");
		exit;
	}
	if ($hu =~ "^/RPC") {
		jsonrpc_dispatch();
		exit;
	}

	xhttp_reply("200", "OK", "text/html",
				"<html><body>Wrong URL $hu</body></html>");
    exit;
}
#!endif

# Routing to voicemail server
route[TOVOICEMAIL] {
#!ifdef WITH_VOICEMAIL
	if(!is_method("INVITE|SUBSCRIBE")) return;

	# check if VoiceMail server IP is defined
	if (strempty($sel(cfg_get.voicemail.srv_ip))) {
		xlog("SCRIPT: VoiceMail routing enabled but IP not defined\n");
		return;
	}
	if(is_method("INVITE")) {
		if($avp(oexten)==$null) return;

		$ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip)
				+ ":" + $sel(cfg_get.voicemail.srv_port);
	} else {
		if($rU==$null) return;

		$ru = "sip:" + $rU + "@" + $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
reply_route {
	if(!sanity_check("17604", "6")) {
		xlog("Malformed SIP response from $si:$sp\n");
		drop;
	}
}

# Manage incoming replies in transaction context
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_BLOCK401407
	# block call redirect based on 401, 407 replies.
	if (t_check_status("401|407")) {
		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
}



#!ifdef WITH_ASTERISK
# Test if coming from Asterisk
route[FROMASTERISK] {
	if($si==$sel(cfg_get.asterisk.bindip)
			&& $sp==$sel(cfg_get.asterisk.bindport))
		return 1;
	return -1;
}
 
# Send to Asterisk
route[TOASTERISK] {
	$du = "sip:" + $sel(cfg_get.asterisk.bindip) + ":"
			+ $sel(cfg_get.asterisk.bindport);
	route(RELAY);
	exit;
}
 
# Forward REGISTER to Asterisk
route[REGFWD] {
	if(!is_method("REGISTER"))
	{
		return;
	}
	$var(rip) = $sel(cfg_get.asterisk.bindip);
	$uac_req(method)="REGISTER";
	$uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport);
	$uac_req(furi)="sip:" + $au + "@" + $var(rip);
	$uac_req(turi)="sip:" + $au + "@" + $var(rip);
	$uac_req(hdrs)="Contact: <sip:" + $au + "@"
				+ $sel(cfg_get.kamailio.bindip)
				+ ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
	if($sel(contact.expires) != $null)
		$uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
	else
		$uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
	uac_req_send();
}
#!endif

You are challenging the incoming calls to Asterisk and Asterisk expects those challenges to be properly responded to with proper auth details. You have nothing in Kamailio to support that.

1 Like

Thank you for your response! I think I understand what you’re saying, but I’m not very sure what I should do next. Do you suggest that the problem lies within the route[TOASTERISK] or route[AUTH]? Asterisk is able to authenticate and forward my calls coming from Kamailio-registered users IF the callee is registered through Asterisk. Please see the logs below. I thought I was missing something in the route[REGFWD] part as I don’t see my endpoints online on the Asterisk side.

<--- Received SIP request (1041 bytes) from UDP:10.0.0.116:5060 --->
INVITE sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bK291b.f357491517345f60e00930360d573c92.0
Via: SIP/2.0/UDP 10.0.0.115:41348;received=10.0.0.115;branch=z9hG4bK-524287-1---1b5a025756044343;rport=41348
Max-Forwards: 69
Contact: <sip:102@10.0.0.115:41348;transport=UDP>
To: <sip:101@10.0.0.116:5060>
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=722c1558
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
CSeq: 2 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2
Allow-Events: presence, kpml, talk
Content-Length: 328

v=0
o=Z 1623688810957 1 IN IP4 10.0.0.115
s=Z
c=IN IP4 10.0.0.115
t=0 0
m=audio 8000 RTP/AVP 106 9 98 101 0 8 3
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (665 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bK291b.f357491517345f60e00930360d573c92.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---1b5a025756044343
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
From: <sip:102@10.0.0.116>;tag=722c1558
To: <sip:101@10.0.0.116>;tag=z9hG4bK291b.f357491517345f60e00930360d573c92.0
CSeq: 2 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1623688811/41cd1e9dd1dca4b25cf96eaff94cf251",opaque="4be8ac5a643c8ec8",algorithm=md5,qop="auth"
Server: Asterisk PBX 18.4.0
Content-Length:  0


<--- Received SIP request (358 bytes) from UDP:10.0.0.116:5060 --->
ACK sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bK291b.f357491517345f60e00930360d573c92.0
Max-Forwards: 69
To: <sip:101@10.0.0.116>;tag=z9hG4bK291b.f357491517345f60e00930360d573c92.0
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=722c1558
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
CSeq: 2 ACK
Content-Length: 0


<--- Received SIP request (1339 bytes) from UDP:10.0.0.116:5060 --->
INVITE sip:101@10.0.0.116:5060;transport=UDP SIP/2.0
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Via: SIP/2.0/UDP 10.0.0.116;branch=z9hG4bK391b.a683c4bac3da18d7a384f7cf517b6975.0
Via: SIP/2.0/UDP 10.0.0.115:41348;received=10.0.0.115;branch=z9hG4bK-524287-1---b09caa8639e8b115;rport=41348
Max-Forwards: 69
Contact: <sip:102@10.0.0.115:41348;transport=UDP>
To: <sip:101@10.0.0.116:5060>
From: <sip:102@10.0.0.116:5060;transport=UDP>;tag=722c1558
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
CSeq: 3 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2
Authorization: Digest username="102",realm="asterisk",nonce="1623688811/41cd1e9dd1dca4b25cf96eaff94cf251",uri="sip:101@10.0.0.116:5060;transport=UDP",response="a95f147a032daee8654274dd6ed3fd37",cnonce="53456f5a037bc4ef60a841e1ff9a4b97",nc=00000001,qop=auth,algorithm=md5,opaque="4be8ac5a643c8ec8"
Allow-Events: presence, kpml, talk
Content-Length: 328

v=0
o=Z 1623688810957 1 IN IP4 10.0.0.115
s=Z
c=IN IP4 10.0.0.115
t=0 0
m=audio 8000 RTP/AVP 106 9 98 101 0 8 3
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv

<--- Transmitting SIP response (462 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bK391b.a683c4bac3da18d7a384f7cf517b6975.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---b09caa8639e8b115
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
From: <sip:102@10.0.0.116>;tag=722c1558
To: <sip:101@10.0.0.116>
CSeq: 3 INVITE
Server: Asterisk PBX 18.4.0
Content-Length:  0


    -- Executing [101@testing:1] NoOp("PJSIP/102-00000005", "") in new stack
    -- Executing [101@testing:2] Dial("PJSIP/102-00000005", "PJSIP/101/sip:101@10.0.0.100:44042;transport=UDP;rinstance=059e5a3c5f9bffb6") in new stack
    -- Called PJSIP/101/sip:101@10.0.0.100:44042;transport=UDP;rinstance=059e5a3c5f9bffb6
<--- Transmitting SIP request (947 bytes) to UDP:10.0.0.100:44042 --->
INVITE sip:101@10.0.0.100:44042;transport=UDP;rinstance=059e5a3c5f9bffb6 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.116:5080;rport;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>
Contact: <sip:asterisk@10.0.0.116:5080>
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 18.4.0
Content-Type: application/sdp
Content-Length:   231

v=0
o=- 778574967 778574967 IN IP4 10.0.0.116
s=Asterisk
c=IN IP4 10.0.0.116
t=0 0
m=audio 12890 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<--- Received SIP response (328 bytes) from UDP:10.0.0.100:44042 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.116:5080;rport=5080;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Content-Length: 0


<--- Received SIP response (535 bytes) from UDP:10.0.0.100:44042 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.0.0.116:5080;rport=5080;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
Contact: <sip:101@10.0.0.100:44042>
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>;tag=00ad4401
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
User-Agent: Z 5.4.12 v2.10.13.2-mod
Allow-Events: presence, kpml, talk
Content-Length: 0


    -- PJSIP/101-00000006 is ringing
<--- Transmitting SIP response (647 bytes) to UDP:10.0.0.116:5060 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.0.0.116;rport=5060;received=10.0.0.116;branch=z9hG4bK391b.a683c4bac3da18d7a384f7cf517b6975.0
Via: SIP/2.0/UDP 10.0.0.115:41348;rport=41348;received=10.0.0.115;branch=z9hG4bK-524287-1---b09caa8639e8b115
Record-Route: <sip:10.0.0.116;lr;ftag=722c1558>
Call-ID: eSAgST8AWS9BGCkLJsDrzw..
From: <sip:102@10.0.0.116>;tag=722c1558
To: <sip:101@10.0.0.116>;tag=4210f8b6-ea80-4414-8739-0f664c53cb38
CSeq: 3 INVITE
Server: Asterisk PBX 18.4.0
Contact: <sip:10.0.0.116:5080>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Content-Length:  0


<--- Received SIP response (932 bytes) from UDP:10.0.0.100:44042 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.116:5080;rport=5080;branch=z9hG4bKPj58c17fc1-06ce-4a0a-904d-096cc39bd888
Require: timer
Contact: <sip:101@10.0.0.100:44042>
To: <sip:101@10.0.0.100;rinstance=059e5a3c5f9bffb6>;tag=00ad4401
From: <sip:102@10.0.0.116>;tag=321199ea-3acd-42a5-89c1-659dca60b069
Call-ID: 3d7c5fa4-c072-4d04-bf34-5b052ad06d1c
CSeq: 13112 INVITE
Session-Expires: 1800;refresher=uac
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
User-Agent: Z 5.4.12 v2.10.13.2-mod
Allow-Events: presence, kpml, talk
Content-Length: 316

v=0
o=Z 0 1 IN IP4 10.0.0.100
s=Z
c=IN IP4 10.0.0.100
t=0 0
m=audio 8000 RTP/AVP 0 106 9 8 3 101 98
a=rtpmap:106 opus/48000/2
a=fmtp:106 sprop-maxcapturerate=16000; minptime=20; useinbandfec=1
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=rtpmap:98 telephone-event/48000
a=fmtp:98 0-16
a=sendrecv

Some updates and clarification: I’m trying to achieve the most basic call functionality using Asterisk and Kamailio. My PBX is defined in Asterisk and my Kamailio is responsible as a SIP proxy. I want my Kamailio to authenticate my endpoints and forward my call to the callee.

As you can see from the Asterisk logs below, Kamailio is sending the Register packet to Asterisk and the Asterisk responds with 401 (which is expected) but Kamailio stops there. It’s supposed to send a second Register with the Authorization: Digest. I found this e-mail thread which talks about a similar issue but the solution they provided is not very clear to me. Any suggestions are welcome.

https://lists.kamailio.org/pipermail/sr-users/2017-April/096792.html

<— Received SIP request (411 bytes) from UDP:10.0.0.124:5060 —>

REGISTER sip:localhost:5080 SIP/2.0

Via: SIP/2.0/UDP 10.0.0.124;branch=z9hG4bK033d.e2443b87000000000000000000000000.0

To: sip:102@localhost

From: sip:102@localhost;tag=3393f0703fb0ccaca74109ff37de39f5-0f49ff3a

CSeq: 10 REGISTER

Call-ID: 3d90997042ff4fd7-2132@127.0.0.1

Max-Forwards: 70

Content-Length: 0

User-Agent: kamailio (5.5.0 (x86_64/linux))

Contact: sip:102@localhost:5060

Expires: 60

<— Transmitting SIP response (547 bytes) to UDP:10.0.0.124:5060 —>

SIP/2.0 401 Unauthorized

Via: SIP/2.0/UDP 10.0.0.124;rport=5060;received=10.0.0.124;branch=z9hG4bK033d.e2443b87000000000000000000000000.0

Call-ID: 3d90997042ff4fd7-2132@127.0.0.1

From: sip:102@localhost;tag=3393f0703fb0ccaca74109ff37de39f5-0f49ff3a

To: sip:102@localhost;tag=z9hG4bK033d.e2443b87000000000000000000000000.0

CSeq: 10 REGISTER

WWW-Authenticate: Digest realm=“asterisk”,nonce=“1623833906/afa99de43cbec4b2a3241c804e601b36”,opaque=“2216545f3f425995”,algorithm=md5,qop=“auth”

Server: Asterisk PBX 18.4.0

Content-Length: 0

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.