Summary:ASTERISK-17209: [patch] Codec negotiation fails on IAX calls from to
Reporter:John Covert (jcovert)Labels:
Date Opened:2011-01-06 08:41:47.000-0600Date Closed:2011-02-16 02:47:49.000-0600
Versions:Frequency of
Environment:Attachments:( 0) 20110110__issue18583.diff.txt
( 1) failure.txt
( 2) iax2-parser.c.patch
( 3) success.txt
Description:In the example below, an originating system with the ONLY change in iax.conf being changing one line from bandwidth=low to bandwidth=high is not able to connect to a terminating system with the only CODEC change relevant to a guest user being (a) the change of bandwidth=low to bandwidth=high and (b) codecpriority=caller inserted.

An originating system with a configuration identical to the failing originating system is able to connect to the same terminating system, no problem.


I have uploaded logs of the failure case and the success case.
Comments:By: John Covert (jcovert) 2011-01-06 08:45:33.000-0600

Removing codecpriority=caller from the terminating system's config file has no effect on the problem.

By: John Covert (jcovert) 2011-01-06 10:25:55.000-0600

Further testing indicates that is a problem only when

a.  Both systems are 1.8


b. One system is Linux and the other system is Mac OS X Power PC.

i.e. Mac OS X Power PC systems running 1.8 can only communicate with other Mac OS X Power PC systems running 1.8, or with non-Mac systems running 1.6 or below.

By: John Covert (jcovert) 2011-01-06 10:42:08.000-0600

This appears related to issue ASTERISK-1755804

I am guessing at this point that Endianness was not considered when moving the uint64 into and out of the protocol message, and I am reading the code now to see if this guess is correct.

By: John Covert (jcovert) 2011-01-07 20:07:38.000-0600

Endianness is definitely the problem.

On BIG_ENDIAN machines, the ntohll and htonll functions do nothing, since network byte order is big endian.

The fix is to still do the byte swap, even on BIG_ENDIAN machines (or at least on Darwin PPC).  The implication is that ntohll and htonll should not have ever been called.

The patch takes care of this for Darwin.  I do not have any other BIG_ENDIAN machines to test against.


By: Tilghman Lesher (tilghman) 2011-01-10 13:28:40.000-0600

It appears the problem is actually in include/asterisk/compat.h, where it assumes that all machines that are not SPARC are little endian.

By: Tilghman Lesher (tilghman) 2011-01-10 13:45:54.000-0600

Oh, while that is a problem, it's actually in strcompat.c, where the implementation of htonll is faulty.  This will work correctly on platforms which have that function, so we need to apply the correct fix.  We can certainly increment the version number on the capability2 and format2 IEs to compensate for this change.

By: John Covert (jcovert) 2011-01-10 14:18:30.000-0600

Not so fast.  That's only if it's undef in compat.h, and it won't be because of things which are included before the #ifndef in compat.h

#include "include/asterisk/autoconfig.h"
#include "include/asterisk/compat.h"
main() {printf("Big=%d BYTE_ORDER=%d\n",BIG_ENDIAN,BYTE_ORDER);}

asterisk:~/asterisk/asterisk- root# cc x.c
asterisk:~/asterisk/asterisk- root# ./a.out

Big=4321 Endian=4321

By: John Covert (jcovert) 2011-01-10 14:34:58.000-0600

Yes, you are correct about the little endian faulty implementation of both htonll and ntohll.

That means that my Darwin patch makes me compatible with little endian machines which don't have the xtoyll functions, but incompatible with any which do.

Since this is iax only, and iax appears to really not be ready for prime time in for other reasons, it might not be worth a version change in the protocol, since only little endian machines without xtoyll create the faulty packets.


By: John Covert (jcovert) 2011-01-10 14:40:29.000-0600

Did you test your patch?

In the current version of your patch, you change only one of the xtoyll implementations; they are both wrong.


By: Digium Subversion (svnbot) 2011-01-10 16:39:33.000-0600

Repository: asterisk
Revision: 301263

U   branches/1.8/main/strcompat.c

r301263 | tilghman | 2011-01-10 16:39:33 -0600 (Mon, 10 Jan 2011) | 8 lines

Little endian machines were not converted properly.

(closes issue ASTERISK-17209)
Reported by: jcovert
     20110110__issue18583.diff.txt uploaded by tilghman (license 14)
Tested by: jcovert



By: Digium Subversion (svnbot) 2011-01-10 16:40:24.000-0600

Repository: asterisk
Revision: 301264

_U  trunk/
U   trunk/main/strcompat.c

r301264 | tilghman | 2011-01-10 16:40:23 -0600 (Mon, 10 Jan 2011) | 15 lines

Merged revisions 301263 via svnmerge from

 r301263 | tilghman | 2011-01-10 16:39:31 -0600 (Mon, 10 Jan 2011) | 8 lines
 Little endian machines were not converted properly.
 (closes issue ASTERISK-17209)
 Reported by: jcovert
       20110110__issue18583.diff.txt uploaded by tilghman (license 14)
 Tested by: jcovert