Summary: | ASTERISK-24807: Missing mandatory field Max-Forwards | ||||
Reporter: | Anatoli (anatoli) | Labels: | |||
Date Opened: | 2015-02-18 11:17:21.000-0600 | Date Closed: | 2015-03-11 10:26:08 | ||
Priority: | Critical | Regression? | |||
Status: | Closed/Complete | Components: | pjproject/pjsip | ||
Versions: | 13.2.0 | Frequency of Occurrence | Constant | ||
Related Issues: |
| ||||
Environment: | OS: Ubuntu 12.04 inside VirtualBox, with all updates Kernel: 3.8.0-29-generic pjsip: 2.3 from http://www.pjsip.org/release/2.3/pjproject-2.3.tar.bz2 (./configure --prefix=/usr --enable-shared --enable-epoll; make; sudo make install) Asterisk: 13.2.0 from http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13.2.0.tar.gz (./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var; make; sudo make install) | Attachments: | |||
Description: | While evaluating the latest Asterisk and PJSIP (both compiled from sources), when calling to/from softphones (in particular the latest Linphone v.3.7.0) the INVITE messages from Asterisk are rejected due to the specification violation.
Here are more people having the same problem: http://comments.gmane.org/gmane.comp.telephony.pbx.asterisk.user/281228 and http://lists.digium.com/pipermail/asterisk-dev/2003-July/001114.html. Linphone has a debug option: {{linphone.exe --logfile "c:\Temp\logs.txt"}} and in the generated logfile one can see something like: {code}[error] Missing mandatory header [Max-Forwards] for message [INVITE]{code} \\ And this is what Asterisk sends to it: {code} INVITE sip:6002@192.168.56.102 SIP/2.0 Via: SIP/2.0/UDP 192.168.56.3:5060;rport;branch=z9hG4bKPjbf53c93c-a424-4b9e-9e6a-b50d0e606965 From: <sip:6001@192.168.56.3>;tag=deeff9b9-50ab-410e-b683-94fdeb9f87b3 To: <sip:6002@192.168.56.102> Contact: <sip:9426fd27-7ccd-4e1e-ab7a-e6c27fc59a5c@192.168.56.3:5060> Call-ID: 5b517cda-634b-4036-bb81-95a43379c09d CSeq: 6848 INVITE Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER Supported: 100rel, timer, replaces, norefersub Session-Expires: 1800 Min-SE: 90 Content-Type: application/sdp Content-Length: 254 {code} So indeed, there is no "Max-Forwards" header sent with the INVITE requests, but, according to the SIP RFC 3261: "A valid SIP request formulated by a UAC MUST, at a minimum, contain the following header fields: To, From, CSeq, Call-ID, Max-Forwards, and Via; all of these header fields are mandatory in all SIP requests." \\ After researching a bit the source code of pjsip, I found that actually almost all messages originating from it don't have Max-Forwards fields. I've tried to add the header manually and it solves the problem (this is not a definitive solution; it has some minor issues): {code} --- pjproject-2.3/pjsip/src/pjsip/sip_util.c.orig 2014-08-18 05:54:43.000000000 -0300 +++ pjproject-2.3/pjsip/src/pjsip/sip_util.c 2015-02-17 10:52:23.839673699 -0300 @@ -465,6 +465,8 @@ PJ_DEF(pj_status_t) pjsip_endpt_create_r } PJ_END; + pjsip_msg_add_hdr(tdata->msg, pjsip_max_fwd_hdr_create(tdata->pool, 70)); + *p_tdata = tdata; return PJ_SUCCESS; {code} But then I've discussed it with people at pjsip@lists.pjsip.org (here is the thread: http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/2015-February/018120.html) and they suggest that the issue is actually within the code that integrates pjsip with asterisk (e.g. {{res/res_pjsip/config_global.c}}) and suggested filling an issue here. \\ This problem is a show-stopper when there are softphones among the endpoints. \\ \\ \\ *UPDATE*: Harald Radke pointed out in the discussion at pjsip at lists.pjsip.org: {quote}having a quick look at res_pjsip.c of the asterisk res(ource?): {noformat} /* PJSIP will automatically try to add a Max-Forwards header. Since we want to control that, * we need to stop PJSIP from doing it automatically */ remove_request_headers(ast_pjsip_endpoint); {noformat} Thus this asterisk code clearly modifies the default behaviour of PJSIP thus it is up to either the user to configure it properly (maybe there is a Max-Forwards option in a config file which, if not set, will result in not putting in a max-forwards header field with a default value) or it is a bug in res-pjsip. {quote} So indeed, it looks like a bug in res_pjsip. \\ \\ ---- \\ \\ STEPS TO REPRODUCE *extensions.conf* {code} [general] language=en static=yes writeprotect=no autofallthrough=yes [internal] exten => 6001,1,Dial(PJSIP/6001,20) same => n,Hangup() exten => 6002,1,Dial(PJSIP/6002,20) same => n,Hangup() {code} *pjsip.conf* {code} [transport-udp] type=transport protocol=udp bind=192.168.56.3 [6001] type=endpoint transport=transport-udp context=internal allow=ulaw allow=gsm auth=6001 aors=6001 device_state_busy_at=1 allow_subscribe=yes sub_min_expiry=30 [6001] type=auth auth_type=userpass password=6001 username=6001 [6001] type=aor max_contacts=1 contact=sip:6001@192.168.56.101 [6002] type=endpoint transport=transport-udp context=internal allow=ulaw allow=gsm auth=6002 aors=6002 device_state_busy_at=1 allow_subscribe=yes sub_min_expiry=30 [6002] type=auth auth_type=userpass password=6002 username=6002 [6002] type=aor max_contacts=1 contact=sip:6002@192.168.56.102 {code} Start asterisk: {{# /usr/sbin/asterisk}} Then configure the extensions in 2 Linphones (in wizard: user/pass = 600x/600x and domain: 192.168.56.3) and try to make a call from one Linphone to another. | ||||
Comments: | By: Mark Michelson (mmichelson) 2015-02-20 11:01:47.479-0600 The intent is for Max-Forwards to be added by default to outbound SIP requests. In res_pjsip/config_global.c, the Max-Forwards and User-Agent headers are configured to be added to outbound requests. Then the PJSIP module in res_pjsip/pjsip_global_headers.c is intended to send those headers out on each request. My guess here is that this is another instance of that all-too-common config framework/sorcery mistake where the absence of a configuration section results in expected default values not being applied. As an experiment, in your pjsip.conf file, can you add the following: {noformat} [global] type = global {noformat} Adding a global configuration section should result in the default Max-Forwards and User-agent headers being applied. If this fixes the problem, it should be easy to create a patch to fix this. By: Rusty Newton (rnewton) 2015-02-20 12:21:09.093-0600 Be sure to use the Send Back or Enter Feedback buttons to get the issue back to us with your response. By: Anatoli (anatoli) 2015-02-20 15:33:30.836-0600 Adding type global fixes the problem! Without it {{pjsip set logger on}} shows no Max-Forwards header field and getting {{SIP/2.0 400 Bad request}} replies from the softphones. With this option there is {{Max-Forwards: 70}} header field and the softphones reach each other. By: Rusty Newton (rnewton) 2015-02-20 15:58:24.127-0600 Thanks for the follow up Anatoli. We'll get this fixed. |