livekit / sip

SIP to WebRTC bridge for LiveKit
70 stars 18 forks source link

Closing room, BYE To Participant fails - 481 Call/Transaction Does Not Exist #112

Open ftsef opened 2 weeks ago

ftsef commented 2 weeks ago

Hello, I’ve discovered an issue that a BYE send from the LIVEKIT-SIP Server is not recognized by Asterisk. The SIP log showed a 481 Call/Transaction Does Not Exist.

It's reproducable on multiple Systems by on of the following steps:

The SIP participant will not be hung up and stays connected (to the void). I've used the latest docker image as well as build from master branch.

I'm going to check the RFC specifications but I thing it has something to do with the missing FROM tag in the BYE package.

Do you have a hint what it could be?

Thanks in advance.

<--- Received SIP request (923 bytes) from UDP:192.168.178.21:57881 --->
INVITE sip:100@192.168.178.42 SIP/2.0
Via: SIP/2.0/UDP 192.168.178.21:57881;branch=z9hG4bK.u4EqNs7xF;rport
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: sip:100@192.168.178.42
CSeq: 20 INVITE
Call-ID: sWT0ND51UG
Max-Forwards: 70
Supported: replaces, outbound, gruu, path, record-aware
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK, UPDATE
Content-Type: application/sdp
Content-Length: 300
Contact: <sip:1108@192.168.178.21:57881;transport=udp>;expires=3599
User-Agent: Linphone-Desktop/5.2.4 (MBP.fritz.box) osx/14.5 Qt/5.15.2 LinphoneSDK/5.3.41

v=0
o=1108 3224 3649 IN IP4 192.168.178.21
s=Talk
c=IN IP4 192.168.178.21
t=0 0
a=rtcp-xr:rcvr-rtt=all:10000 stat-summary=loss,dup,jitt,TTL voip-metrics
a=record:off
m=audio 56905 RTP/AVP 0 101
a=rtpmap:101 telephone-event/8000
a=rtcp:51058
a=rtcp-fb:* trr-int 1000
a=rtcp-fb:* ccm tmmbr

<--- Transmitting SIP response (482 bytes) to UDP:192.168.178.21:57881 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.178.21:57881;rport=57881;received=192.168.178.21;branch=z9hG4bK.u4EqNs7xF
Call-ID: sWT0ND51UG
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: <sip:100@192.168.178.42>;tag=z9hG4bK.u4EqNs7xF
CSeq: 20 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1718736342/d004502f6d285bc24f0a1c981e36686f",opaque="7811bc271253cad3",algorithm=MD5,qop="auth"
Server: Asterisk PBX GIT-master-ea3b520bed
Content-Length:  0

<--- Received SIP request (336 bytes) from UDP:192.168.178.21:57881 --->
ACK sip:100@192.168.178.42 SIP/2.0
Via: SIP/2.0/UDP 192.168.178.21:57881;branch=z9hG4bK.u4EqNs7xF;rport
Call-ID: sWT0ND51UG
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: <sip:100@192.168.178.42>;tag=z9hG4bK.u4EqNs7xF
Contact: <sip:1108@192.168.178.21:57881;transport=udp>;expires=3599
Max-Forwards: 70
CSeq: 20 ACK

<--- Received SIP request (1202 bytes) from UDP:192.168.178.21:57881 --->
INVITE sip:100@192.168.178.42 SIP/2.0
Via: SIP/2.0/UDP 192.168.178.21:57881;branch=z9hG4bK.Gg81mw2HT;rport
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: sip:100@192.168.178.42
CSeq: 21 INVITE
Call-ID: sWT0ND51UG
Max-Forwards: 70
Supported: replaces, outbound, gruu, path, record-aware
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK, UPDATE
Content-Type: application/sdp
Content-Length: 300
Contact: <sip:1108@192.168.178.21:57881;transport=udp>;expires=3599
User-Agent: Linphone-Desktop/5.2.4 (MBP.fritz.box) osx/14.5 Qt/5.15.2 LinphoneSDK/5.3.41
Authorization:  Digest realm="asterisk", nonce="1718736342/d004502f6d285bc24f0a1c981e36686f", algorithm=MD5, opaque="7811bc271253cad3", username="1108",  uri="sip:100@192.168.178.42", response="59dbf5c01fdd269f4e55c4829eb55d83", cnonce="loefkneFJoVy9DSW", nc=00000001, qop=auth

v=0
o=1108 3224 3649 IN IP4 192.168.178.21
s=Talk
c=IN IP4 192.168.178.21
t=0 0
a=rtcp-xr:rcvr-rtt=all:10000 stat-summary=loss,dup,jitt,TTL voip-metrics
a=record:off
m=audio 56905 RTP/AVP 0 101
a=rtpmap:101 telephone-event/8000
a=rtcp:51058
a=rtcp-fb:* trr-int 1000
a=rtcp-fb:* ccm tmmbr

<--- Transmitting SIP response (308 bytes) to UDP:192.168.178.21:57881 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.178.21:57881;rport=57881;received=192.168.178.21;branch=z9hG4bK.Gg81mw2HT
Call-ID: sWT0ND51UG
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: <sip:100@192.168.178.42>
CSeq: 21 INVITE
Server: Asterisk PBX GIT-master-ea3b520bed
Content-Length:  0

    -- Executing [100@livekit:1] NoOp("PJSIP/1108-000004ce", "") in new stack
    -- Executing [100@livekit:2] Dial("PJSIP/1108-000004ce", "PJSIP/livekit") in new stack
    -- Called PJSIP/livekit
<--- Transmitting SIP request (951 bytes) to UDP:156.156.156.156:5060 --->
INVITE sip:+1234567890@testserver:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.178.42:5060;rport;branch=z9hG4bKPjbed0c2c0-e22d-44a2-91c0-2d7d4f54a284
From: "1108" <sip:1108@192.168.178.42>;tag=d3cd97c4-5ffd-424d-a37c-e2a7597cd274
To: <sip:+1234567890@testserver>
Contact: <sip:asterisk@192.168.178.42:5060>
Call-ID: 0f1f0682-90d5-4a62-b54e-e2a8cbfe0086
CSeq: 12643 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, INFO, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX GIT-master-ea3b520bed
Content-Type: application/sdp
Content-Length:   239

v=0
o=- 626213718 626213718 IN IP4 192.168.178.42
s=Asterisk
c=IN IP4 192.168.178.42
t=0 0
m=audio 22188 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:140
a=sendrecv

<--- Received SIP response (666 bytes) from UDP:156.156.156.156:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.178.42:5060;rport;branch=z9hG4bKPjbed0c2c0-e22d-44a2-91c0-2d7d4f54a284
From: "1108" <sip:1108@192.168.178.42:5060>;tag=d3cd97c4-5ffd-424d-a37c-e2a7597cd274
To: <sip:+1234567890@testserver>;tag=ab420917-013e-4c75-9006-7c0b032d3b2e
Call-ID: 0f1f0682-90d5-4a62-b54e-e2a8cbfe0086
CSeq: 12643 INVITE
Content-Length:   232
Contact: <sip:156.156.156.156:5060>
Content-Type: application/sdp

v=0
o=- 626213718 626213720 IN IP4 156.156.156.156
s=LiveKit
c=IN IP4 156.156.156.156
t=0 0
m=audio 14510 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

       > 0x7fff0c050440 -- Strict RTP learning after remote address set to: 156.156.156.156:14510
<--- Transmitting SIP request (443 bytes) to UDP:156.156.156.156:5060 --->
ACK sip:156.156.156.156:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.178.42:5060;rport;branch=z9hG4bKPj46ddddc3-d282-4767-867c-87dc62ff8734
From: "1108" <sip:1108@192.168.178.42>;tag=d3cd97c4-5ffd-424d-a37c-e2a7597cd274
To: <sip:+1234567890@testserver>;tag=ab420917-013e-4c75-9006-7c0b032d3b2e
Call-ID: 0f1f0682-90d5-4a62-b54e-e2a8cbfe0086
CSeq: 12643 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX GIT-master-ea3b520bed
Content-Length:  0

    -- PJSIP/livekit-000004cf answered PJSIP/1108-000004ce
       > 0x7fff0c0657d0 -- Strict RTP learning after remote address set to: 192.168.178.21:56905
<--- Transmitting SIP response (808 bytes) to UDP:192.168.178.21:57881 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.178.21:57881;rport=57881;received=192.168.178.21;branch=z9hG4bK.Gg81mw2HT
Call-ID: sWT0ND51UG
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: <sip:100@192.168.178.42>;tag=13e525fa-cac5-480f-a338-2dd2de15664c
CSeq: 21 INVITE
Server: Asterisk PBX GIT-master-ea3b520bed
Contact: <sip:192.168.178.42:5060>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, INFO, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub
Content-Type: application/sdp
Content-Length:   228

v=0
o=- 3224 3651 IN IP4 192.168.178.42
s=Asterisk
c=IN IP4 192.168.178.42
t=0 0
m=audio 5388 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:140
a=sendrecv

    -- Channel PJSIP/livekit-000004cf joined 'simple_bridge' basic-bridge <3f4147bd-3ed0-472f-94a5-6d3d9a817817>
    -- Channel PJSIP/1108-000004ce joined 'simple_bridge' basic-bridge <3f4147bd-3ed0-472f-94a5-6d3d9a817817>
       > Bridge 3f4147bd-3ed0-472f-94a5-6d3d9a817817: switching from simple_bridge technology to native_rtp
       > Locally RTP bridged 'PJSIP/1108-000004ce' and 'PJSIP/livekit-000004cf' in stack
       > 0x7fff0c050440 -- Strict RTP switching to RTP target address 156.156.156.156:14510 as source
<--- Received SIP request (664 bytes) from UDP:192.168.178.21:57881 --->
ACK sip:192.168.178.42:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.178.21:57881;rport;branch=z9hG4bK.qDgHTsJk3
From: "1108" <sip:1108@192.168.178.42>;tag=4c95ddtPY
To: <sip:100@192.168.178.42>;tag=13e525fa-cac5-480f-a338-2dd2de15664c
CSeq: 21 ACK
Call-ID: sWT0ND51UG
Max-Forwards: 70
Authorization:  Digest realm="asterisk", nonce="1718736342/d004502f6d285bc24f0a1c981e36686f", algorithm=MD5, opaque="7811bc271253cad3", username="1108",  uri="sip:100@192.168.178.42", response="59dbf5c01fdd269f4e55c4829eb55d83", cnonce="loefkneFJoVy9DSW", nc=00000001, qop=auth
User-Agent: Linphone-Desktop/5.2.4 (MBP.fritz.box) osx/14.5 Qt/5.15.2 LinphoneSDK/5.3.41

       > 0x7fff0c0657d0 -- Strict RTP switching to RTP target address 192.168.178.21:56905 as source
       > 0x7fff0c050440 -- Strict RTP learning complete - Locking on source address 156.156.156.156:14510
       > 0x7fff0c0657d0 -- Strict RTP learning complete - Locking on source address 192.168.178.21:56905
<--- Received SIP request (354 bytes) from UDP:156.156.156.156:5060 --->
BYE sip:asterisk@192.168.178.42:5060 SIP/2.0
Via: SIP/2.0/UDP 123.123.123.123:5060;rport;branch=z9hG4bK.EycnBDy9dYjujMoL;alias
Max-Forwards: 70
Call-ID: 0f1f0682-90d5-4a62-b54e-e2a8cbfe0086
CSeq: 12644 BYE
Content-Length: 0
From: <sip:+1234567890@testserver>
To: "1108" <sip:1108@192.168.178.42:5060>;tag=d3cd97c4-5ffd-424d-a37c-e2a7597cd274

<--- Transmitting SIP response (401 bytes) to UDP:156.156.156.156:5060 --->
SIP/2.0 481 Call/Transaction Does Not Exist
Via: SIP/2.0/UDP 123.123.123.123:5060;rport=5060;received=156.156.156.156;branch=z9hG4bK.EycnBDy9dYjujMoL;alias
Call-ID: 0f1f0682-90d5-4a62-b54e-e2a8cbfe0086
From: <sip:+1234567890@testserver>
To: "1108" <sip:1108@192.168.178.42>;tag=d3cd97c4-5ffd-424d-a37c-e2a7597cd274
CSeq: 12644 BYE
Server: Asterisk PBX GIT-master-ea3b520bed
Content-Length:  0

<--- Transmitting SIP request (460 bytes) to UDP:192.168.178.21:57881 --->
OPTIONS sip:1108@192.168.178.21:57881;transport=udp SIP/2.0
Via: SIP/2.0/UDP 192.168.178.42:5060;rport;branch=z9hG4bKPjaacda32c-e442-4391-a638-0e365bb80e33
From: <sip:1108@192.168.178.42>;tag=ca840901-ac46-4bdb-908c-0098218166ef
To: <sip:1108@192.168.178.21>
Contact: <sip:1108@192.168.178.42:5060>
Call-ID: a9352936-ad99-4080-8f73-17c43d9985f4
CSeq: 13343 OPTIONS
Max-Forwards: 70
User-Agent: Asterisk PBX GIT-master-ea3b520bed
Content-Length:  0

<--- Received SIP response (298 bytes) from UDP:192.168.178.21:57881 --->
SIP/2.0 200 Ok
Via: SIP/2.0/UDP 192.168.178.42:5060;rport;branch=z9hG4bKPjaacda32c-e442-4391-a638-0e365bb80e33
From: <sip:1108@192.168.178.42>;tag=ca840901-ac46-4bdb-908c-0098218166ef
To: <sip:1108@192.168.178.21>;tag=Y8rYb
Call-ID: a9352936-ad99-4080-8f73-17c43d9985f4
CSeq: 13343 OPTIONS
ftsef commented 2 weeks ago

I was able to send a BYE package manually to hangup the SIP-participant. As I previously suspected adding the right tag to the BYE FROM header works.

For the given sip log above the BYE package the FROM header should've looked like:

From: <sip:+1234567890@testserver>;tag=ab420917-013e-4c75-9006-7c0b032d3b2ez

Full example:

BYE sip:asterisk@192.168.178.42:5060 SIP/2.0
Via: SIP/2.0/UDP 123.123.123.123:5060;rport;branch=z9hG4bK.EycnBDy9dYjujMoL;alias
Max-Forwards: 70
Call-ID: 0f1f0682-90d5-4a62-b54e-e2a8cbfe0086
CSeq: 12644 BYE
Content-Length: 0
From: <sip:+1234567890@testserver>;tag=ab420917-013e-4c75-9006-7c0b032d3b2e
To: "1108" <sip:1108@192.168.178.42:5060>;tag=d3cd97c4-5ffd-424d-a37c-e2a7597cd274
ftsef commented 2 weeks ago

My fix/workaround so far is to read the FROM-tag from the next ACK and store it in the current calls TO-tag. This works in my use case. I don't know if that a good solution in general.

https://github.com/ftsef/sip/commit/8971505c1ec8dbe551ecd56a6231bba047d13f08

dennwc commented 3 hours ago

Hmm, interesting. Could you please open a PR then? I can test it with other SIP Trunk Providers too.