[Home]

Summary:ASTERISK-01781: Call drops during socket bind in rtp.c
Reporter:rmarchev (rmarchev)Labels:
Date Opened:2004-06-08 18:56:59Date Closed:2004-09-25 02:43:29
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) rtp.diffs
Description:In rtp.c ast_rtp_new() there is if statement with two bind calls if second bind call for rtpc failed with EADDRINUSE first socket for rtp will not be closed and next attempt to bind gives error ENVAL since this socket is still bound. This is happening a lot on busy system.


****** ADDITIONAL INFORMATION ******

Here is code excerpt from rtp.c:
for (;;) {
/* Must be an even port number by RTP spec */
rtp->us.sin_port = htons(x);
if (rtp->rtcp)
rtp->rtcp->us.sin_port = htons(x + 1);
if (!bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us)) &&
(!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us))))
break;
if (errno != EADDRINUSE) {
ast_log(LOG_WARNING, "Unexpected bind error rtp(%d):"
"bind(%d,%s) %d(%s)\n", x,rtp->s,
inet_ntoa(rtp->us.sin_addr),errno,
strerror(errno));
close(rtp->s);
if (rtp->rtcp) {
close(rtp->rtcp->s);
free(rtp->rtcp);
}
free(rtp);
return NULL;
}
x += 2;
if (x > rtpend)
x = (rtpstart + 1) & ~1;
if (x == startplace) {
ast_log(LOG_WARNING, "No RTP ports remaining\n");
close(rtp->s);
if (rtp->rtcp) {
close(rtp->rtcp->s);
free(rtp->rtcp);
}
free(rtp);
return NULL;
}
}

Comments:By: Mark Spencer (markster) 2004-06-08 20:30:59

Thanks, fixed in CVS.  There was nothing wrong with your patch, but I kinda structured it just more to my subjective liking.  Re-open if I made any mistakes.