aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2014-01-09 14:30:55 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-01-20 08:10:43 +0100
commit859807261e021eafe07792af901e5485b6fbe794 (patch)
tree948bbaa37bb7783c275d8b61d0eef35c160dbe31
parent63ddf4645c1af041001060e91f982eb59b3deb5c (diff)
ipaccess: Enable TCP keepalive by default on all BTS connections
This way we can find out fast if the connection is broken. Ticket: OW#1060
-rw-r--r--src/input/ipaccess.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c
index 9722b2f..8f9865e 100644
--- a/src/input/ipaccess.c
+++ b/src/input/ipaccess.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
+#include <netinet/tcp.h>
#include <string.h>
#include <time.h>
#include <sys/fcntl.h>
@@ -50,6 +51,10 @@ static void *tall_ipa_ctx;
#define TS1_ALLOC_SIZE 900
+#define DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT 30
+#define DEFAULT_TCP_KEEPALIVE_INTERVAL 3
+#define DEFAULT_TCP_KEEPALIVE_RETRY_COUNT 10
+
/*
* Common propietary IPA messages:
* - PONG: in reply to PING.
@@ -610,7 +615,7 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
{
int ret;
int idx = 0;
- int i;
+ int i, val;
struct e1inp_line *line;
struct e1inp_ts *e1i_ts;
struct osmo_fd *bfd;
@@ -643,6 +648,34 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
goto err_line;
}
+ /* Enable TCP keepalive to find out if the connection is gone */
+ val = 1;
+ ret = setsockopt(bfd->fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
+ if (ret < 0)
+ LOGP(DLINP, LOGL_NOTICE, "Failed to set keepalive: %s\n",
+ strerror(errno));
+ else
+ LOGP(DLINP, LOGL_NOTICE, "Keepalive is set: %i\n", ret);
+
+#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) && defined(TCP_KEEPCNT)
+ /* The following options are not portable! */
+ val = DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT;
+ ret = setsockopt(bfd->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;
+ ret = setsockopt(bfd->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;
+ ret = setsockopt(bfd->fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val));
+ if (ret < 0)
+ LOGP(DLINP, LOGL_NOTICE, "Failed to set keepalive count: %s\n",
+ strerror(errno));
+#endif
+
/* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
ret = ipaccess_send_id_req(bfd->fd);
if (ret < 0) {