Summary:ASTERISK-07666: [patch] chan_iax2 ignores "sourceaddress" when "bindaddr" is set to INADDR_ANY (the default).
Reporter:Stefano Brandimarte (stevens)Labels:
Date Opened:2006-09-02 19:52:14Date Closed:2007-07-09 21:20:42
Versions:Frequency of
Environment:Attachments:( 0) chan_iax2+netsock_reuseaddr-1.2.11.diff
( 1) chan_iax2+netsock-reuseaddr.diff
( 2) chan_iax2+netsock-reuseaddr-2006090401.diff
Description:if "bindaddr" is unset or set to "" into iax.conf isn't possible to make
use of the "sourceaddress" setting, even if the ip[:port] specified is valid and

****** STEPS TO REPRODUCE ******



then set a peer with a valid and local "sourceaddress": it won't be used and the
default address will be used instead; a warning is issued.


we've some central machine with a lot of IP addresses (dozens, even hundreds) and
they are often added/removed; so it's unmanageable to specify into iax.conf a
"bindaddr" directive for every needed ip.

INADDR_ANY matches every local IP address, so it's a bug to fix anyway.

Fix included, for SVN trunk and 1.2.11.
Comments:By: Stefano Brandimarte (stevens) 2006-09-02 22:02:39

the patches are incomplete and can be deleted. There's more work to do on this.

By: Stefano Brandimarte (stevens) 2006-09-03 09:03:51

latest two patches uploaded, for svn and 1.2.11.
There's another ast_netsock_list, in the svn patch, to distinguish between the
list of "bindaddr" sockets and the one generated by "sourceaddress" settings.
This is not needed, in fact the patch for 1.2.11 doesn't implement it, but could
be useful just in the case we want to close any unused socket after a reload. In
our new situation, when a peer contains a "sourceaddress" directive, chan_iax2
will open another socket (if not already in the "netsock" or "outsock" lists) and will bind to it; changing one of the "sourceaddress" will leave the
previous fd untouched and the socket referenced, so it could be used again.
This requires that ast_netsock_bindaddr set the SO_REUSEADDR option on every
opened socket.

By: Stefano Brandimarte (stevens) 2006-09-03 20:01:06

After a bit of testing i'm uploading an update of svn patch, that implements the
destruction of the outsock list on reload, so every "stale" socket is removed. A
stale socket could be one that binds to a no-more-bounded IP address. Added also
the SO_LINGER socket option. We're testing a patched asterisk+chan_iax2 on some
production environment, where IAX2 is in use. As for now it seems to do its job.
A "netstat -na | grep 4569" shows:

udp        0      0*
udp        0      0*
udp        0      0*
udp        0      0  *

last socket in this list is the one opened as a result of a "bindaddr" setting
and the others are there because of corresponding "sourceaddress" directive.

By: jmls (jmls) 2006-11-01 06:49:58.000-0600

housekeeping: can a developer look at this ?

By: Anthony LaMantia (alamantia) 2006-11-27 15:47:16.000-0600

after taking a glance at the code, and the problem, would it not be sufficant
to solve this problem, in ast_get_ip_or_srv() inside acl.c ... or from within
the peer_set_srcaddr() code itself rather then going about building
new ast_netsock_list's ?

By: Stefano Brandimarte (stevens) 2006-11-27 17:51:05.000-0600

alamantia, will try to look at this suggestion and let you know shortly (this
week, if possible).

By: Anthony LaMantia (alamantia) 2006-11-28 11:23:36.000-0600

cool, keep us posted

By: Stefano Brandimarte (stevens) 2006-12-05 02:46:09.000-0600

ok, so, the static struct ast_netsock_list *netsock, defined into chan_iax2.c
is populated by the "bindaddr"s found into iax.conf. When, later in that cfg
someone try to use a "sourceaddress" directive, that IP is check against that
list of "bindaddr"s and it's rejected if there isn't a "bindaddr" matching
value. So if we put "" as the only "bindaddr" it's not sufficient to
make the "sourceaddress" valid, but it is actually valid and usable. So my try
is to compensate this strange kind of TCP/IP networking implementation. We could
also add the sourceaddress found, without matching "bindaddr" to the same list,
netsock. The distinction i made is to not touch at all the original code and let
us decide what to do for both lists.

By: Anthony LaMantia (alamantia) 2006-12-21 18:19:33.000-0600

sorry about the last update to this bug, it was a path and a comment ment for a diffrent issue(they have been deleted from this issue)

By: Stefano Brandimarte (stevens) 2006-12-31 07:41:23.000-0600

alamantia, I've not found any other place where to put the changes. What I'm
trying to add is the capability to use "sourceaddress=<whatever_valid_and_local>"
if "bindaddr=". I've found no reason to insert a single "bindaddr" for the
corresponding "sourceaddress": INADDR_ANY is meant to be used for cases like this.
Let's know if You could implement it.

By: Stefano Brandimarte (stevens) 2007-02-26 16:14:58.000-0600

there's some interest to implement these features ? I can make a diff for SVN, in the case.

By: Russell Bryant (russell) 2007-03-27 13:10:04

This patch has been merged into 1.2, 1.4, and trunk in reivisions 59258, 59259, and 59260.  However, I did not merge the changes to netsock.c, because I did not see why they were necessary.  If you feel they should be added, feel free to contact me on the asterisk-dev mailing list to discuss it.