[OpenSIPS-Devel] Improved socket error messages

Saúl Ibarra Corretgé saul at ag-projects.com
Mon Jan 28 09:50:01 CET 2013


Hi,

On Jan 27, 2013, at 8:17 PM, Michael Schloh von Bennewitz wrote:

> 
> Hello developers,
> 
> 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.
> 

Improved logging messages are of course great :-) I have a few unfinished patches in this regard as well, so if you send over partial improvements I'll incorporate them. However, the patch you sent is not correct because it doesn't deal with IPv6 addresses, you need to check the sa_family field of the sockaddr struct before casting it to sockaddr_in or sockaddr_in6.


Regards,

--
Saúl Ibarra Corretgé
AG Projects






More information about the Devel mailing list