Module: kamailio
Branch: master
Commit: 1af9fe360780fbf723006f8e569d019788e5a2fa
URL:
https://github.com/kamailio/kamailio/commit/1af9fe360780fbf723006f8e569d019…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2017-05-02T10:24:30+02:00
Merge pull request #1104 from sergey-safarov/FREEBIND
src/core: Added IP_FREEBIND flag durring socket initialization
---
Modified: src/core/tcp_main.c
Modified: src/core/udp_server.c
Modified: src/modules/sctp/sctp_server.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1af9fe360780fbf723006f8e569d019…
Patch:
https://github.com/kamailio/kamailio/commit/1af9fe360780fbf723006f8e569d019…
---
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index 14dcaea..b9af4e8 100644
--- a/src/core/tcp_main.c
+++ b/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))){
diff --git a/src/core/udp_server.c b/src/core/udp_server.c
index cff4ef0..96ba8eb 100644
--- a/src/core/udp_server.c
+++ b/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)){
diff --git a/src/modules/sctp/sctp_server.c b/src/modules/sctp/sctp_server.c
index e2301f0..686139c 100644
--- a/src/modules/sctp/sctp_server.c
+++ b/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);