Skip to content

[BUG] Incorrect SUBSCRIBE route set on early NOTIFY / subscription renew fail #314

@digiboridev

Description

@digiboridev

Description: When client wants to subscribe using sofia-sip and sip server is behind proxy, sometimes sip server/proxy/transport has race condition and NOTIFY arrived before 200 OK. In this case NOTIFY not contains Record-Route header but has Contact that points to sip server directly, and then sofia tries to send all further re-subscribe directly to sip server that obviously fails.

Expected behavior: use the same route as for initial SUBSCRIBE request or wait for 200 OK to create correct dialog usage using Record-Route and Contact headers from 200 OK response.

Examples

proxy: 111.111.111.111
sip server: 111.111.111.333

Negative dialog example:

SUBSCRIBE sip:123456@111.111.111.111 SIP/2.0
Via: SIP/2.0/TCP 192.168.65.3:58835;branch=z9hG4bKmNyyc9FZ4Z2DQ;received=185.38.209.777
Max-Forwards: 70
Contact: <sip:456789@192.168.65.3:58835;transport=tcp>
To: <sip:123456@111.111.111.111>
From: <sip:456789@192.168.65.3:58835;transport=tcp>;tag=ejcmmtaU87t2p
Call-ID: presence_sub_456789_123456_e5dfc1d5-d736-40ce-bfbb-cd4412c490f3
CSeq: 110807583 SUBSCRIBE
Expires: 3600
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, REFER, MESSAGE, INFO, NOTIFY, PUBLISH
Supported: replaces
Event: presence
Content-Length: 0

Here is early NOTIFY

NOTIFY sip:456789@192.168.65.3:58835;transport=tcp SIP/2.0
Via: SIP/2.0/TCP 111.111.111.111:5060;branch=z9hG4bK-524287-1---ac9b2bc1;rport
Via: SIP/2.0/TCP 111.111.111.333:5066;branch=z9hG4bK-524287-1---6005ce5b3d6a2f77;rport=48299
Max-Forwards: 69
Contact: <sip:123456@111.111.111.333:5066;transport=tcp>
To: <sip:456789@192.168.65.3:58835;transport=tcp>;tag=ejcmmtaU87t2p
From: <sip:123456@111.111.111.111>;tag=d45e6c38
Call-ID: presence_sub_456789_123456_e5dfc1d5-d736-40ce-bfbb-cd4412c490f3
CSeq: 2 NOTIFY
Content-Type: application/pidf+xml
Subscription-State: active;expires=3600
Event: presence
Content-Length: 209

<?xml version="1.0" encoding="UTF-8"?>
  <presence xmlns="urn:ietf:params:xml:ns:pidf" entity="sip:123456@111.111.111.111:5060">
    <tuple id="eeeca10c0960">
      <status><basic>closed</basic></status>
    </tuple>
  </presence>

Then 200 OK for NOTIFY

SIP/2.0 200 OK
Via: SIP/2.0/TCP 192.168.65.3:58835;branch=z9hG4bKmNyyc9FZ4Z2DQ;received=185.38.209.777;rport=52522
Record-Route: <sip:111.111.111.111;transport=tcp;lr;ep;ipnt=_c0n-umur25>
Contact: <sip:123456@111.111.111.333:5066;transport=tcp>
To: <sip:123456@111.111.111.111>;tag=d45e6c38
From: <sip:456789@192.168.65.3:58835;transport=tcp>;tag=ejcmmtaU87t2p
Call-ID: presence_sub_456789_123456_e5dfc1d5-d736-40ce-bfbb-cd4412c490f3
CSeq: 110807583 SUBSCRIBE
Expires: 3600
Content-Length: 0

Near the expiration of subscription sofia tries to re-subscribe but uses NOTIFY Contact header IP instead of Record-Route from 200 OK and fails to reach sip server

SUBSCRIBE sip:123456@111.111.111.333:5066;transport=tcp SIP/2.0
Via: SIP/2.0/TCP 192.168.65.3:58835;branch=z9hG4bK45jB9SXQpe7rg;received=185.38.209.777
Max-Forwards: 70
Contact: <sip:456789@192.168.65.3:58835;transport=tcp>
To: <sip:123456@111.111.111.111>;tag=d45e6c38
From: <sip:456789@192.168.65.3:58835;transport=tcp>;tag=ejcmmtaU87t2p
Call-ID: presence_sub_456789_123456_e5dfc1d5-d736-40ce-bfbb-cd4412c490f3
CSeq: 110807584 SUBSCRIBE
Expires: 3600
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, REFER, MESSAGE, INFO, NOTIFY, PUBLISH
Supported: replaces
Event: presence
Content-Length: 0

Positive dialog example:

SUBSCRIBE sip:1037788@111.111.111.111 SIP/2.0
Via: SIP/2.0/TCP 192.168.65.3:57987;branch=z9hG4bK8aZ1XjtFjt9aK;received=185.38.209.13
Max-Forwards: 70
Contact: <sip:1037787@192.168.65.3:57987;transport=tcp>
To: <sip:1037788@111.111.111.111>
From: <sip:1037787@192.168.65.3:57987;transport=tcp>;tag=532p6m9StNX6g
Call-ID: presence_sub_1037787_1037788_7025a4d2-d9cc-4ebf-ab0f-fb5526787b6a
CSeq: 110846106 SUBSCRIBE
Expires: 3600
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, REFER, MESSAGE, INFO, NOTIFY, PUBLISH
Supported: replaces
Event: presence
Content-Length: 0

200 OK for SUBSCRIBE with Record-Route header

SIP/2.0 200 OK
Via: SIP/2.0/TCP 192.168.65.3:57987;branch=z9hG4bK9KrtZDBKF3ZXe;received=185.38.209.777;rport=59620
Record-Route: <sip:111.111.111.111;transport=tcp;lr;ep;ipnt=_c0n-umur25>
Contact: <sip:123456@111.111.111.333:5066;transport=tcp>
To: <sip:123456@111.111.111.111>;tag=ec8f8e27
From: <sip:456789@192.168.65.3:57987;transport=tcp>;tag=532p6m9StNX6g
Call-ID: presence_sub_456789_123456_7025a4d2-d9cc-4ebf-ab0f-fb5526787b6a
CSeq: 110846106 SUBSCRIBE
Expires: 3600
Content-Length: 0

Then NOTIFY

NOTIFY sip:456789@192.168.65.3:57987;transport=tcp SIP/2.0
Via: SIP/2.0/TCP 111.111.111.111:5060;branch=z9hG4bK-524287-1---69a355d6;rport
Via: SIP/2.0/TCP 111.111.111.333:5066;branch=z9hG4bK-524287-1---c90945674998494d;rport=48299
Max-Forwards: 69
Contact: <sip:123456@111.111.111.333:5066;transport=tcp>
To: <sip:456789@192.168.65.3:57987;transport=tcp>;tag=532p6m9StNX6g
From: <sip:123456@111.111.111.111>;tag=ec8f8e27
Call-ID: presence_sub_456789_123456_7025a4d2-d9cc-4ebf-ab0f-fb5526787b6a
CSeq: 2 NOTIFY
Content-Type: application/pidf+xml
Subscription-State: active;expires=3600
Event: presence
Content-Length: 209
	
<?xml version="1.0" encoding="UTF-8"?>
  <presence xmlns="urn:ietf:params:xml:ns:pidf" entity="sip:123456@111.111.111.111:5060">
    <tuple id="6895831e73a9">
      <status><basic>closed</basic></status>
    </tuple>
  </presence>

Then near the expiration of subscription sofia tries to re-subscribe using Route from 200 OK and successfully reaches sip server

SUBSCRIBE sip:123456@111.111.111.333:5066;transport=tcp SIP/2.0
Via: SIP/2.0/TCP 192.168.65.3:57987;branch=z9hG4bKcgDyX0reaUBcm;received=185.38.209.777
Max-Forwards: 70
Route: <sip:111.111.111.111;transport=tcp;lr;ep;ipnt=_c0n-umur25>
Contact: <sip:456789@192.168.65.3:57987;transport=tcp>
To: <sip:123456@111.111.111.111>;tag=ec8f8e27
From: <sip:456789@192.168.65.3:57987;transport=tcp>;tag=532p6m9StNX6g
Call-ID: presence_sub_456789_123456_7025a4d2-d9cc-4ebf-ab0f-fb5526787b6a
CSeq: 110846107 SUBSCRIBE
Expires: 3600
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, REFER, MESSAGE, INFO, NOTIFY, PUBLISH
Supported: replaces
Event: presence
Content-Length: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions