[OpenSIPS-Users] BUG in nathelper - can miss contacts to ping
James Lamanna
jlamanna at gmail.com
Sun May 15 19:06:26 CEST 2011
Hi,
I've been investigating a problem where I was noticing that nathelper
was not pinging all the contacts it should be pinging.
I've narrowed down the problem to this code in nh_timer() in nathelper.c:
rval = ul.get_all_ucontacts(buf, cblen, (ping_nated_only?ul.nat_flag:0),
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
natping_processes*natping_interval);
if (rval<0) {
LM_ERR("failed to fetch contacts\n");
goto done;
}
if (rval > 0) {
if (buf != NULL)
pkg_free(buf);
cblen = rval * 2;
buf = pkg_malloc(cblen);
if (buf == NULL) {
LM_ERR("out of pkg memory\n");
goto done;
}
rval = ul.get_all_ucontacts(buf,cblen,(ping_nated_only?ul.nat_flag:0),
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
natping_processes*natping_interval);
if (rval != 0) {
pkg_free(buf);
goto done;
}
}
The problem here is if the first call to ul.get_all_ucontacts fails
for insufficent buffer size
(such as if it returns more than 1 contact), the second call
multiplies the shortage by 2 and then tries it!
This results in the second buffer actually being smaller than the
first in many cases, which causes the
contacts in that call to be skipped due to insufficient buffer size again...
I would propose that the second call actually allocates the correct
amount of memory like this patch:
Index: modules/nathelper/nathelper.c
===================================================================
--- modules/nathelper/nathelper.c (revision 7939)
+++ modules/nathelper/nathelper.c (working copy)
@@ -1130,7 +1130,7 @@
if (rval > 0) {
if (buf != NULL)
pkg_free(buf);
- cblen = rval * 2;
+ cblen += rval;
buf = pkg_malloc(cblen);
if (buf == NULL) {
LM_ERR("out of pkg memory\n");
This problem looks like it has been around a long time, so if you use
NATed contacts, and have had issues
with firewalls closing connections on you, you should apply this patch
to see if your problem is fixed.
Thanks.
-- James
More information about the Users
mailing list