[sr-dev] git:master: core/forward.c Fixed mhomed behavior.

Marius Zbihlei marius.zbihlei at 1and1.ro
Thu Nov 4 15:18:40 CET 2010


Module: sip-router
Branch: master
Commit: ef0dd4e3f0837753ac18d58606078d8595f24dc6
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ef0dd4e3f0837753ac18d58606078d8595f24dc6

Author: Marius Zbihlei <marius.zbihlei at 1and1.ro>
Committer: Marius Zbihlei <marius.zbihlei at 1and1.ro>
Date:   Thu Nov  4 16:11:41 2010 +0200

core/forward.c Fixed mhomed behavior.

As connect() dones't re-bound a UDP sock if the socket is already
bound to an interface, first unbind the socket by connecting to AF_UNSPEC

---

 forward.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/forward.c b/forward.c
index 25bc11d..3d7aed1 100644
--- a/forward.c
+++ b/forward.c
@@ -131,6 +131,10 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
 	union sockaddr_union from; 
 	struct socket_info* si;
 	struct ip_addr ip;
+	union sockaddr_union uncon;
+
+	memset(&uncon, 0, sizeof(union sockaddr_union));
+	uncon.sin.sin_family = AF_UNSPEC;
 
 	if (unlikely(proto!=PROTO_UDP)) {
 		LOG(L_CRIT, "BUG: get_out_socket can only be called for UDP\n");
@@ -167,6 +171,14 @@ retry:
 		return 0;
 	}
 	}
+
+	if( !mhomed_sock_cache_disabled ){
+		/* some Linux kernel versions (all?) along with other UNIXes don't re-bound the sock if already bound */
+		/* to un-bound a socket set sin_family to AF_UNSPEC and zero out the rest*/
+		if (unlikely(connect(*temp_sock, &uncon.s, sockaddru_len(uncon))) < 0)
+				mhomed_sock_cache_disabled = 1;
+	}
+
 	if (unlikely(connect(*temp_sock, &to->s, sockaddru_len(*to))==-1)) {
 		if (unlikely(errno==EISCONN && !mhomed_sock_cache_disabled)){
 			/*  no multiple connects support on the same socket */




More information about the sr-dev mailing list