[sr-dev] git:5.1:37f847af: tcpops: set tcp keepalive values when available per option

Daniel-Constantin Mierla miconda at gmail.com
Wed Apr 3 11:59:17 CEST 2019


Module: kamailio
Branch: 5.1
Commit: 37f847af805ec20762348898c6427c8df8d02025
URL: https://github.com/kamailio/kamailio/commit/37f847af805ec20762348898c6427c8df8d02025

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-04-03T11:54:56+02:00

tcpops: set tcp keepalive values when available per option

- cover macos and *bsd for couple of options

(cherry picked from commit 278fd5a892c14f23e9f2b8d1f3fd3232c1d319f3)
(cherry picked from commit eb5f2096282e93b14fecfc64f22aba0db467dec5)

---

Modified: src/modules/tcpops/tcpops.c

---

Diff:  https://github.com/kamailio/kamailio/commit/37f847af805ec20762348898c6427c8df8d02025.diff
Patch: https://github.com/kamailio/kamailio/commit/37f847af805ec20762348898c6427c8df8d02025.patch

---

diff --git a/src/modules/tcpops/tcpops.c b/src/modules/tcpops/tcpops.c
index 6815bf4897..9bf4eaa8e0 100644
--- a/src/modules/tcpops/tcpops.c
+++ b/src/modules/tcpops/tcpops.c
@@ -107,8 +107,13 @@ int tcpops_acquire_fd_from_tcpmain(int conid, int *fd)
 	return 0;
 }
 
-#if !defined(HAVE_SO_KEEPALIVE) || !defined(HAVE_TCP_KEEPIDLE) || !defined(HAVE_TCP_KEEPCNT) || !defined(HAVE_TCP_KEEPINTVL)
-	#warning "TCP keepalive is not fully supported by your platform"
+#if !defined(HAVE_SO_KEEPALIVE) || !defined(HAVE_TCP_KEEPCNT) || !defined(HAVE_TCP_KEEPINTVL)
+	#define KSR_TCPOPS_NOKEEPALIVE
+#endif
+
+#ifdef KSR_TCPOPS_NOKEEPALIVE
+
+#warning "TCP keepalive options not supported by this platform"
 
 int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int closefd)
 {
@@ -121,6 +126,7 @@ int tcpops_keepalive_disable(int fd, int closefd)
 	LM_ERR("tcp_keepalive_disable() failed: this module does not support your platform\n");
 	return -1;
 }
+
 #else
 
 int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int closefd)
@@ -133,11 +139,15 @@ int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int close
 		LM_ERR("failed to enable SO_KEEPALIVE: %s\n", strerror(errno));
 		return -1;
 	} else {
-
+#ifdef HAVE_TCP_KEEPIDLE
 		if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle,
 						sizeof(idle))<0){
 			LM_ERR("failed to set keepalive idle interval: %s\n", strerror(errno));
 		}
+#else
+		#warning "TCP_KEEPIDLE option not supported by this platform"
+		LM_DBG("TCP_KEEPIDLE option not available - ignoring\n");
+#endif
 
 		if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &count,
 						sizeof(count))<0){




More information about the sr-dev mailing list