Module: kamailio
Branch: master
Commit: d893f3af1444c8c4c5db6cd53fb577703007c90c
URL:
https://github.com/kamailio/kamailio/commit/d893f3af1444c8c4c5db6cd53fb5777…
Author: Walter Schober <walter.schober(a)neotel.at>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-08-07T19:32:53+02:00
core: Add TCP_USER_TIMEOUT socket option on listening socket.
Use tcp_send_timeout config option also on listening socket to timeout outbound messages
sent on passive inbound connections.
---
Modified: src/core/tcp_main.c
Modified: src/core/tcp_options.h
---
Diff:
https://github.com/kamailio/kamailio/commit/d893f3af1444c8c4c5db6cd53fb5777…
Patch:
https://github.com/kamailio/kamailio/commit/d893f3af1444c8c4c5db6cd53fb5777…
---
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index e96d68c40b2..7f07d724108 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -3172,6 +3172,18 @@ int tcp_init(struct socket_info *sock_info)
}
#endif
init_sock_keepalive(sock_info->socket);
+#ifdef HAVE_TCP_USER_TIMEOUT
+ if((optval = TICKS_TO_S(cfg_get(tcp, tcp_cfg, send_timeout)))) {
+ optval *= 1000;
+ if(setsockopt(sock_info->socket, IPPROTO_TCP, TCP_USER_TIMEOUT, &optval,
+ sizeof(optval))
+ < 0) {
+ LM_WARN("failed to set TCP_USER_TIMEOUT: %s\n", strerror(errno));
+ } else {
+ LM_INFO("Set TCP_USER_TIMEOUT=%d ms\n", optval);
+ }
+ }
+#endif
if(bind(sock_info->socket, &addr->s, sockaddru_len(*addr)) == -1) {
LM_ERR("bind(%x, %p, %d) on %s:%d : %s\n", sock_info->socket,
&addr->s,
(unsigned)sockaddru_len(*addr), sock_info->address_str.s,
diff --git a/src/core/tcp_options.h b/src/core/tcp_options.h
index d5a628a1128..84c551e2a3b 100644
--- a/src/core/tcp_options.h
+++ b/src/core/tcp_options.h
@@ -68,6 +68,13 @@
#endif /* __OS_ */
#endif /* NO_TCP_LINGER2 */
+/* tcp user_timeout */
+#ifndef NO_TCP_USER_TIMEOUT
+#ifdef __OS_linux
+#define HAVE_TCP_USER_TIMEOUT
+#endif /* __OS_ */
+#endif /* NO_TCP_LINGER2 */
+
/* keepalive */
#ifndef NO_TCP_KEEPALIVE
#define HAVE_SO_KEEPALIVE