Explorar o código

Merge pull request #1104 from sergey-safarov/FREEBIND

src/core: Added IP_FREEBIND flag durring socket initialization
Daniel-Constantin Mierla %!s(int64=8) %!d(string=hai) anos
pai
achega
1af9fe3607
Modificáronse 3 ficheiros con 23 adicións e 0 borrados
  1. 7 0
      src/core/tcp_main.c
  2. 8 0
      src/core/udp_server.c
  3. 8 0
      src/modules/sctp/sctp_server.c

+ 7 - 0
src/core/tcp_main.c

@@ -2782,6 +2782,13 @@ int tcp_init(struct socket_info* sock_info)
 			/* continue since this is not critical */
 		}
 	}
+
+	/* Allow bind to non local address. Required when daemon started before network initialized */
+	if (setsockopt(sock_info->socket, IPPROTO_IP, IP_FREEBIND,
+				(void*)&optval, sizeof(optval)) ==-1) {
+		LM_WARN("setsockopt freebind: %s\n", strerror(errno));
+		/* continue since this is not critical */
+	}
 #ifdef HAVE_TCP_DEFER_ACCEPT
 	/* linux only */
 	if ((optval=cfg_get(tcp, tcp_cfg, defer_accept))){

+ 8 - 0
src/core/udp_server.c

@@ -339,6 +339,14 @@ int udp_init(struct socket_info* sock_info)
 	}
 #endif
 
+	/* Allow bind to non local address. Required when daemon started before network initialized */
+	optval = 1;
+	if (setsockopt(sock_info->socket, IPPROTO_IP, IP_FREEBIND,
+				(void*)&optval, sizeof(optval)) ==-1) {
+		LM_WARN("setsockopt freebind: %s\n", strerror(errno));
+		/* continue since this is not critical */
+	}
+
 #ifdef USE_MCAST
 	if ((sock_info->flags & SI_IS_MCAST)
 	    && (setup_mcast_rcvr(sock_info->socket, addr, sock_info->mcast.s)<0)){

+ 8 - 0
src/modules/sctp/sctp_server.c

@@ -469,6 +469,14 @@ static int sctp_init_sock_opt_common(int s, int af)
 		}
 	}
 	
+	/* Allow bind to non local address. Required when daemon started before network initialized */
+	optval = 1;
+	if (setsockopt(s, IPPROTO_IP, IP_FREEBIND,
+				(void*)&optval, sizeof(optval)) ==-1) {
+		LM_WARN("sctp_init_sock_opt_common: setsockopt freebind %s\n", strerror(errno));
+		/* continue since this is not critical */
+	}
+
 	/* set receive buffer: SO_RCVBUF*/
 	if (cfg_get(sctp, sctp_cfg, so_rcvbuf)){
 		optval=cfg_get(sctp, sctp_cfg, so_rcvbuf);