Explorar o código

core, sctp: check if IP_FREEBIND is defined

- not all os-es have it
Daniel-Constantin Mierla %!s(int64=8) %!d(string=hai) anos
pai
achega
ff3cf17ff3
Modificáronse 3 ficheiros con 18 adicións e 9 borrados
  1. 6 2
      src/core/tcp_main.c
  2. 5 3
      src/core/udp_server.c
  3. 7 4
      src/modules/sctp/sctp_server.c

+ 6 - 2
src/core/tcp_main.c

@@ -2783,12 +2783,16 @@ int tcp_init(struct socket_info* sock_info)
 		}
 	}
 
-	/* Allow bind to non local address. Required when daemon started before network initialized */
+#if defined(IP_FREEBIND)
+	/* allow bind to non local address.
+	 * useful 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));
+		LM_WARN("setsockopt freebind failed: %s\n", strerror(errno));
 		/* continue since this is not critical */
 	}
+#endif
+
 #ifdef HAVE_TCP_DEFER_ACCEPT
 	/* linux only */
 	if ((optval=cfg_get(tcp, tcp_cfg, defer_accept))){

+ 5 - 3
src/core/udp_server.c

@@ -339,14 +339,16 @@ int udp_init(struct socket_info* sock_info)
 	}
 #endif
 
-	/* Allow bind to non local address. Required when daemon started before network initialized */
+#if defined(IP_FREEBIND)
+	/* allow bind to non local address.
+	 * useful 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));
+		LM_WARN("setsockopt freebind failed: %s\n", strerror(errno));
 		/* continue since this is not critical */
 	}
-
+#endif
 #ifdef USE_MCAST
 	if ((sock_info->flags & SI_IS_MCAST)
 	    && (setup_mcast_rcvr(sock_info->socket, addr, sock_info->mcast.s)<0)){

+ 7 - 4
src/modules/sctp/sctp_server.c

@@ -468,14 +468,17 @@ static int sctp_init_sock_opt_common(int s, int af)
 			/* continue since this is not critical */
 		}
 	}
-	
-	/* Allow bind to non local address. Required when daemon started before network initialized */
+
+#if defined(IP_FREEBIND)
+	/* allow bind to non local address.
+	 * useful 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));
+		LM_WARN("setsockopt freebind failed: %s\n", strerror(errno));
 		/* continue since this is not critical */
 	}
+#endif
 
 	/* set receive buffer: SO_RCVBUF*/
 	if (cfg_get(sctp, sctp_cfg, so_rcvbuf)){
@@ -487,7 +490,7 @@ static int sctp_init_sock_opt_common(int s, int af)
 			/* continue, non-critical */
 		}
 	}
-	
+
 	/* set send buffer: SO_SNDBUF */
 	if (cfg_get(sctp, sctp_cfg, so_sndbuf)){
 		optval=cfg_get(sctp, sctp_cfg, so_sndbuf);