summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-11-04 17:20:46 +0100
committerDaniel Willmann <daniel@totalueberwachung.de>2011-11-04 17:22:57 +0100
commitba6cff41245cca89a2700a73bef3744a8f408e91 (patch)
treef5704c982aad23e93baad35c884dc0cdeb507da6
parentb8a512a320f6688c66377d29ce3e6f24e15782a0 (diff)
libabis: Enable TCP keepalive by default on all BTS connectionsdaniel/wip-msc-local-call-routing2
This way we can find out fast if the connection is broken.
-rw-r--r--openbsc/src/libabis/input/ipaccess.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/openbsc/src/libabis/input/ipaccess.c b/openbsc/src/libabis/input/ipaccess.c
index cc2a7a0..e0cd5bb 100644
--- a/openbsc/src/libabis/input/ipaccess.c
+++ b/openbsc/src/libabis/input/ipaccess.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
+#include <netinet/tcp.h>
#include <string.h>
#include <time.h>
#include <sys/fcntl.h>
@@ -677,7 +678,7 @@ static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
{
int ret;
int idx = 0;
- int i;
+ int i, val;
struct e1inp_line *line;
struct e1inp_ts *e1i_ts;
struct osmo_fd *bfd;
@@ -725,6 +726,30 @@ static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
return ret;
}
+ /* 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(DINP, LOGL_NOTICE, "Failed to set keepalive: %s\n", strerror(errno));
+ else
+ LOGP(DINP, 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 = 30;
+ ret = setsockopt(bfd->fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val));
+ if (ret < 0)
+ LOGP(DINP, LOGL_NOTICE, "Failed to set keepalive idle time: %s\n", strerror(errno));
+ val = 3;
+ ret = setsockopt(bfd->fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val));
+ if (ret < 0)
+ LOGP(DINP, LOGL_NOTICE, "Failed to set keepalive interval: %s\n", strerror(errno));
+ val = 10;
+ ret = setsockopt(bfd->fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val));
+ if (ret < 0)
+ LOGP(DINP, 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);