summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-11-04 17:20:46 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-05-02 20:13:42 +0200
commit8c2591d95e17eb6fa868e4d886a63ac62f3ca8af (patch)
treec8c647248373f03ec78439c0e1027d842dba7caa
parent9ed07004acd7aa3e0c33f5e580e61c347b3064bc (diff)
libabis: Enable TCP keepalive by default on all BTS connections
This way we can find out fast if the connection is broken. Z says: Tabs vs. spaces, magic numbers... more work needed :)
-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 0b0d1551f..a5046f59e 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>
@@ -678,7 +679,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;
@@ -726,6 +727,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);