[PATCH 4/4] ipaccess: Make TCP keep-alive configurable

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Thu Jan 9 13:30:58 UTC 2014


This patch changes the implementation to use the keep-alive
configuration fields instead of constants.

Ticket: OW#1060
Sponsored-by: On-Waves ehf
---
 src/input/ipaccess.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c
index 6b9d93e..4684520 100644
--- a/src/input/ipaccess.c
+++ b/src/input/ipaccess.c
@@ -608,6 +608,7 @@ struct e1inp_driver ipaccess_driver = {
 	.line_update = ipaccess_line_update,
 	.close = ipaccess_close,
 	.default_delay = 0,
+	.has_keepalive = 1,
 };
 
 static void update_fd_settings(struct e1inp_line *line, int fd)
@@ -615,7 +616,7 @@ static void update_fd_settings(struct e1inp_line *line, int fd)
 	int ret;
 	int val;
 
-	if (DEFAULT_TCP_KEEPALIVE_RETRY_COUNT) {
+	if (line->keepalive_num_probes) {
 		/* Enable TCP keepalive to find out if the connection is gone */
 		val = 1;
 		ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
@@ -627,21 +628,27 @@ static void update_fd_settings(struct e1inp_line *line, int fd)
 
 #if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) && defined(TCP_KEEPCNT)
 		/* The following options are not portable! */
-		val = DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT;
+		val = line->keepalive_idle_timeout > 0 ?
+			line->keepalive_idle_timeout :
+			DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT;
 		ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
 				 &val, sizeof(val));
 		if (ret < 0)
 			LOGP(DLINP, LOGL_NOTICE,
 			     "Failed to set keepalive idle time: %s\n",
 			     strerror(errno));
-		val = DEFAULT_TCP_KEEPALIVE_INTERVAL;
+		val = line->keepalive_probe_interval > -1 ?
+			line->keepalive_probe_interval :
+			DEFAULT_TCP_KEEPALIVE_INTERVAL;
 		ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL,
 				 &val, sizeof(val));
 		if (ret < 0)
 			LOGP(DLINP, LOGL_NOTICE,
 			     "Failed to set keepalive interval: %s\n",
 			     strerror(errno));
-		val = DEFAULT_TCP_KEEPALIVE_RETRY_COUNT;
+		val = line->keepalive_num_probes > 0 ?
+			line->keepalive_num_probes :
+			DEFAULT_TCP_KEEPALIVE_RETRY_COUNT;
 		ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT,
 				 &val, sizeof(val));
 		if (ret < 0)
-- 
1.7.9.5





More information about the OpenBSC mailing list