Skip to content

ReferSubscriber: Fix, build Replaces from the dialog local and remote tags - #992

Open
michele-lunardi-vianova wants to merge 1 commit into
versatica:masterfrom
michele-lunardi-vianova:fix-replaces-dialog-tags
Open

michele-lunardi-vianova wants to merge 1 commit into
versatica:masterfrom
michele-lunardi-vianova:fix-replaces-dialog-tags

Conversation

@michele-lunardi-vianova

Copy link
Copy Markdown

Fixes #817.

Problem

When RTCSession.refer() is called with options.replaces and the session to replace was established by an incoming INVITE, the to-tag and from-tag of the Replaces header in the Refer-To URI are swapped. A server that follows RFC 3891 then cannot find the dialog: the attended transfer fails and the NOTIFY carries SIP/2.0 481 Call leg/transaction does not exist.

Cause

ReferSubscriber.sendRefer() builds the header from _to_tag and _from_tag, that is the To and From tags of the initial INVITE (code).

RFC 3891, section 3:

The User Agent Server (UAS) matches the to-tag and from-tag parameters as if they were tags present in an incoming request. In other words, the to-tag parameter is compared to the local tag, and the from-tag parameter is compared to the remote tag.

So, seen from the referrer, to-tag must be the remote tag and from-tag the local tag of the dialog to replace. For an outgoing session the From tag is the local one, so the result is right. For an incoming session it is the other way round.

This does not show up between two JsSIP endpoints, because UA._findDialog() accepts both tag orders (code).

Fix

Build Replaces from _dialog.id, which Dialog already fills correctly for both UAC and UAS (code): to-tag = remote_tag, from-tag = local_tag. This is the change proposed by @michelepra in #817.

If the session has no confirmed dialog yet, the previous code is kept, so nothing changes there.

Compatibility

  • Outgoing sessions: the Refer-To header is identical, byte for byte.
  • Incoming sessions: fixed. Against servers that follow RFC 3891 these transfers always failed, so nothing can rely on the old output.
  • No API or typings changes.

Tests

New src/test/test-ReferSubscriber.ts checks the Refer-To header for an outgoing session, an incoming session and a session without a confirmed dialog. The incoming-session test fails without the fix. npm run lint and npm test pass.

I did not touch CHANGELOG.md; happy to add an entry under NEXT if you want.

Manual test

Against an Asterisk-based PBX, with JsSIP 3.13.8 plus this same change (the modified code is the same in 3.13.8 and master).

Bob calls Alice (JsSIP). Alice puts Bob on hold and calls Carol, then sends a REFER on the dialog with Carol, with Refer-To Bob and Replaces of the dialog with Bob. That dialog was established by an incoming INVITE. The PBX's tags start with as.

Before (3.13.8), to-tag is Alice's tag:

REFER sip:carol@192.0.2.10:5060 SIP/2.0
Refer-To: <sip:bob@example.com?Replaces=5e2d8c41f0a9b7360d1c4e8a92f3b6d7%40192.0.2.10%3A5060%3Bto-tag%3Dk3j9x2m7qp%3Bfrom-tag%3Das4f2c9e1a>

NOTIFY (Event: refer)
SIP/2.0 481 Call leg/transaction does not exist

After (3.13.8 + this change), to-tag is the PBX's tag:

REFER sip:carol@192.0.2.10:5060 SIP/2.0
Refer-To: <sip:bob@example.com?Replaces=0b7a3f9e2c6d184a5e9f1b2c3d4e5f60%40192.0.2.10%3A5060%3Bto-tag%3Das7d0b3e58%3Bfrom-tag%3Dr2v8n5c1wd>

NOTIFY (Event: refer)
SIP/2.0 200 OK

Bob and Carol end up connected, with two-way audio. A transfer where the replaced dialog was established by Alice still works, with the same Refer-To as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

refer of 2 incoming call failed

1 participant