<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="https://reviewboard.asterisk.org/r/2330/">https://reviewboard.asterisk.org/r/2330/</a>
</td>
</tr>
</table>
<br />
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/media/rb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
<tr>
<td>
<div>Review request for Asterisk Developers.</div>
<div>By elguero.</div>
<p style="color: grey;"><i>Updated Feb. 21, 2013, 5:33 p.m.</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Changes</h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">* Take care of last round of review comments</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">When adding IPv6 support to FastAGI, it appears that the intent was to have the ability to check all addresses resolved for a host since we might receive an IPv4 address and an IPv6 address. We attempt to create a socket() and issue a connect() and then continue on if that succeeds. The problem, though, is that we set the flag O_NONBLOCK, which is fine, but then do not handle EINPROGRESS after the call to connect(); we ignore it. We then break out of the loop and continue on. We later on call ast_poll(), which succeeds but we never check if we have a connection or not on the socket level. Therefore, we then proceed to send data to the host address that we think is setup and it fails. We then check errno and see that we have "Connection refused".
The reporter came across this issue when using "localhost" which resolved to 127.0.0.1 and ::1 but his daemon was only listening on 127.0.0.1. The IPv6 address was being returned first in the list of addresses resolved.
When I was trying to recreate this situation, my system always returned 127.0.01 first. So, this issue can be random, depending on the setup, configuration and which address is returned first in the list of addresses.
This patch does the following:
* Handle EINPROGRESS
- Move the call to ast_poll() up into the loop that is determining which host address to connect to.
- Check the results on the socket level after calling ast_poll().
* Continue to the next address if the above fails</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Tested this on a dev box.
Reporter tested this in his environment and confirmed that it was working as intended.</pre>
</td>
</tr>
</table>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>
<a href="https://issues.asterisk.org/jira/browse/ASTERISK-21065">ASTERISK-21065</a>
</div>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> (updated)</h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>/branches/11/res/res_agi.c <span style="color: grey">(381425)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/2330/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>