*/
#define DEFAULT_METADATA_AVAILABILITY_WAIT_TIME 200000 /* usec */
+/*
+ * The usual value for the maximum TCP SYN retries time and TCP FIN timeout is
+ * 180 and 60 seconds on most Linux system and the default value since kernel
+ * 2.2 thus using the highest value. See tcp(7) for more details.
+ */
+#define DEFAULT_INET_TCP_TIMEOUT 180 /* sec */
+
/*
* Default receiving and sending timeout for an application socket.
*/
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
+#include <fcntl.h>
#include <common/common.h>
.sendmsg = lttcomm_sendmsg_inet_sock,
};
+unsigned long lttcomm_inet_tcp_timeout;
+
/*
* Creates an PF_INET socket.
*/
return ret;
}
+
+/*
+ * Return value read from /proc or else 0 if value is not found.
+ */
+static unsigned long read_proc_value(const char *path)
+{
+ int ret, fd;
+ long r_val;
+ unsigned long val = 0;
+ char buf[64];
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ goto error;
+ }
+
+ ret = read(fd, buf, sizeof(buf));
+ if (ret < 0) {
+ PERROR("read proc failed");
+ goto error_close;
+ }
+
+ errno = 0;
+ r_val = strtol(buf, NULL, 10);
+ if (errno != 0 || r_val < -1L) {
+ val = 0;
+ goto error_close;
+ } else {
+ if (r_val > 0) {
+ val = r_val;
+ }
+ }
+
+error_close:
+ ret = close(fd);
+ if (ret) {
+ PERROR("close /proc value");
+ }
+error:
+ return val;
+}
+
+LTTNG_HIDDEN
+void lttcomm_inet_init(void)
+{
+ unsigned long syn_retries, fin_timeout, syn_timeout;
+
+ /* Assign default value and see if we can change it. */
+ lttcomm_inet_tcp_timeout = DEFAULT_INET_TCP_TIMEOUT;
+
+ syn_retries = read_proc_value(LTTCOMM_INET_PROC_SYN_RETRIES_PATH);
+ fin_timeout = read_proc_value(LTTCOMM_INET_PROC_FIN_TIMEOUT_PATH);
+
+ syn_timeout = syn_retries * LTTCOMM_INET_SYN_TIMEOUT_FACTOR;
+
+ /*
+ * Get the maximum between the two possible timeout value and use that to
+ * get the maximum with the default timeout.
+ */
+ lttcomm_inet_tcp_timeout = max_t(unsigned long,
+ max_t(unsigned long, syn_timeout, fin_timeout),
+ lttcomm_inet_tcp_timeout);
+
+ DBG("TCP inet operation timeout set to %lu sec", lttcomm_inet_tcp_timeout);
+}
#include "sessiond-comm.h"
+/* See man tcp(7) for more detail about this value. */
+#define LTTCOMM_INET_PROC_SYN_RETRIES_PATH "/proc/sys/net/ipv4/tcp_syn_retries"
+#define LTTCOMM_INET_PROC_FIN_TIMEOUT_PATH "/proc/sys/net/ipv4/tcp_fin_timeout"
+
+/*
+ * The timeout value of a connect() is computed with an algorithm inside the
+ * kernel using the defined TCP SYN retries so the end value in time is
+ * approximative. According to tcp(7) man page, a value of 5 is roughly 180
+ * seconds of timeout. With that information, we've computed a factor of 36
+ * (180/5) by considering that it grows linearly. This is of course uncertain
+ * but this is the best approximation we can do at runtime.
+ */
+#define LTTCOMM_INET_SYN_TIMEOUT_FACTOR 36
+
+/*
+ * Maximum timeout value in seconds of a TCP connection for both send/recv and
+ * connect operations.
+ */
+extern unsigned long lttcomm_inet_tcp_timeout;
+
/* Stub */
struct lttcomm_sock;
extern ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf,
size_t len, int flags);
+/* Initialize inet communication layer. */
+extern void lttcomm_inet_init(void);
+
#endif /* _LTTCOMM_INET_H */