[OpenSIPS-Devel] Improved socket error messages

Michael Schloh develop2009 at schloh.com
Sun Jan 27 16:58:38 CET 2013


Hello list,

While trying to debug a difficult to find problem (where ntop,
tcpdump, and snoop were no help) I finally figured out where
OpenSIPS was trying to send misdirected messages by hacking
the sources. It might be useful to always accompany log text
with network stack information. So instead of:

  Jan 02 18:18:02 hostname <error> opensips[1234]: ERROR:core:tcp_blocking_connect: failed to retrieve SO_ERROR (146) Connection refused

...we would see:

  Jan 02 18:18:02 hostname <error> opensips[1234]: ERROR:core:tcp_blocking_connect: addr (1.2.3.4) port (98765), failed to retrieve SO_ERROR (146) Connection refused

...which of course is much more useful.

To integrate the improvement above, I hacked tcp_main.c like this:

  $ sed -e 's;\(LM_ERR("\)\(failed to retrieve SO_ERROR (%d) %s\\n",\);\1addr (%s) port (%d), \2 inet_ntoa(((struct sockaddr_in *)servaddr)->sin_addr), ntohs(((struct sockaddr_in *)servaddr)->sin_port),;' tcp_main.c

...or if you prefer here's a unified diff that does the same thing:

diff -Nau tcp_main.c.orig tcp_main.c
--- tcp_main.c.orig	2012-10-17 00:09:05.000000000 +0200
+++ tcp_main.c	2013-01-27 16:44:47.803235857 +0100
@@ -340,7 +340,7 @@
 			getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &err_len);
 			if ((err==0) && (poll_err==0)) goto end;
 			if (err!=EINPROGRESS && err!=EALREADY){
-				LM_ERR("failed to retrieve SO_ERROR (%d) %s\n", err,
+				LM_ERR("addr (%s) port (%d), failed to retrieve SO_ERROR (%d) %s\n", inet_ntoa(((struct sockaddr_in *)servaddr)->sin_addr), ntohs(((struct sockaddr_in *)servaddr)->sin_port), err,
 						strerror(err));
 				goto error;
 			}

This hack applies cleanly to OpenSIPS 1.7.2 and 1.8.2 although I've
tested only on 1.7.2 (because of the database access bugs in 1.8.*.)

Unfortunately there are other socket related operations which
write unhelpful log text, so this is not a complete solution.

Regards,
Michael



More information about the Devel mailing list