pjsip Content-Length padding and my landlord's router

32 views
Skip to first unread message

Nicholas Riley

unread,
Jan 10, 2016, 12:40:03 PM1/10/16
to Telephone Discussions
Hi,

Just a note for anyone else who may have run into this problem.

I used Telephone successfully for years (aside from having to restart it when my audio device configuration changed, which seems like it's being worked on) but about a month ago it stopped working.  I hadn't changed my hardware, OS (10.10) or SIP configuration that I was aware of.  Other UAs on my Mac still worked when connecting to the same account — but they're so ugly…

I could register fine, and my Mac would ring, but when I click "Answer" nothing happened, and if I made an outgoing call it sat there "calling…" until I eventually get "Request Timeout".

Same thing happened with 1.1.4 and a version I built from GitHub.

I discovered packets were getting mangled between my Mac and the SIP server.  pjsip leaves room in a packet for a Content-Length of at most 5 digits, so it can fill it back in before by padding with spaces (e.g., "Content-Length:    295").  I think my landlord's router was "upgraded" and now modifies SIP packets, but it fails to support this and overwrites it with "Content-Length: 3010" regardless of the actual length.

The SIP specification allows arbitrary amounts of space on either side of the colon, but also states "implementations should avoid spaces between the field name and the colon and use a single space (SP) between the colon and the field-value." So what pjsip is doing is valid but not really recommended.

Given the body of my SIP messages all end up as 100-999 bytes, I just did this:

Index: pjsip/src/pjsip/sip_msg.c

===================================================================

--- pjsip/src/pjsip/sip_msg.c (revision 5233)

+++ pjsip/src/pjsip/sip_msg.c (working copy)

@@ -476,7 +476,7 @@

 

     /* Process message body. */

     if (msg->body) {

- enum { CLEN_SPACE = 5 };

+ enum { CLEN_SPACE = 3 };

  char *clen_pos = NULL;

 

  /* Automaticly adds Content-Type and Content-Length headers, only


which is horrible, but does at least stop the mangling.  I'm not suggesting this change actually be incorporated, just for anyone's reference until this can be fixed a better way.

--Nicholas

Jean-François Comeau

unread,
Oct 21, 2016, 11:11:08 AM10/21/16
to Telephone Discussions
Hi,

I'm having the exact same issue (see my post) and I think your solution would work.

Unfortunately I can not build the project from the Github repo.

any idea what I could do? Why is your fix not part of the main distribution? :/


Regards,
JF

Alexey Kuznetsov

unread,
Oct 21, 2016, 11:44:34 AM10/21/16
to Telephone Discussions
Hello Nicholas,

Thanks a lot for the research. The best way to be sure it is fixed once and for all is to actually report it to PJSIP. You’ve come a long way already investigating this, so please consider reporting it back to PJSIP. As far as I understand, you don’t have to submit a patch yourself. The developers can recognize the problem and write the proper fix themselves.

Here’s the link to the PJSIP mailing list: http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

By the way, which Telephone version are you using or when did you build from the sources? You mentioned 1.1.4, but the last version in the App Store is 1.2.4.

Alexey
> --
> You received this message because you are subscribed to the Google Groups "Telephone Discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to telephone-ap...@googlegroups.com.
> To post to this group, send email to teleph...@googlegroups.com.
> Visit this group at https://groups.google.com/group/telephone-app.
> For more options, visit https://groups.google.com/d/optout.

Jean-François Comeau

unread,
Oct 21, 2016, 12:59:14 PM10/21/16
to Telephone Discussions
Hello again,

Just wanted to let you know that I managed to fix my issue thanks to Alexey's help.

Since I have access to my router I was able to disable "SIP ALG" and everything works again.

Thanks again for pointing out the PJSIP "issue". It was tremendously helpful in my investigation.


Cheers,
JF

Alexey Kuznetsov

unread,
Oct 22, 2016, 9:06:13 AM10/22/16
to teleph...@googlegroups.com

> On 10 Jan 2016, at 18:40, Nicholas Riley <njr...@illinois.edu> wrote:
>
>
> (aside from having to restart it when my audio device configuration changed, which seems like it's being worked on)

By the way, it should work (again). There was a period of time when certain Telephone releases under certain macOS versions didn’t handle that.

> I think my landlord's router was "upgraded" and now modifies SIP packets

If you can, you could ask somebody who has access to that router and try to find a so-called SIP ALG “feature” and disable it. I haven’t seen a SIP provider who would want their customers to have it enabled.

Alexey
Reply all
Reply to author
Forward
0 new messages