From 635f3fb5387713181a3492278bcf72d34738afd2 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 20 Dec 2021 12:14:31 +0200 Subject: [PATCH] tcpclose event_routes issue --- src/core/tcp_main.c | 26 ++++++++++++++++++++++++++ src/core/tcp_read.c | 26 -------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c index ba9ed925754..458093b22d6 100644 --- a/src/core/tcp_main.c +++ b/src/core/tcp_main.c @@ -79,6 +79,7 @@ #include "tcp_stats.h" #include "tcp_ev.h" #include "tsend.h" +#include "events.h" #include "timer_ticks.h" #include "local_timer.h" #ifdef CORE_TLS @@ -3548,6 +3549,26 @@ int _tcpconn_write_nb(int fd, struct tcp_connection* c, } +static int tcp_emit_closed_event(struct tcp_connection *con, enum tcp_closed_reason reason) +{ + int ret; + tcp_closed_event_info_t tev; + sr_event_param_t evp = {0}; + + ret = 0; + LM_DBG("TCP closed event creation triggered (reason: %d)\n", reason); + if(likely(sr_event_enabled(SREV_TCP_CLOSED))) { + memset(&tev, 0, sizeof(tcp_closed_event_info_t)); + tev.reason = reason; + tev.con = con; + evp.data = (void*)(&tev); + ret = sr_event_exec(SREV_TCP_CLOSED, &evp); + } else { + LM_DBG("no callback registering for handling TCP closed event\n"); + } + return ret; +} + /* handles io from a tcp child process * params: tcp_c - pointer in the tcp_children array, to the entry for @@ -3628,6 +3649,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i) /* if refcnt was 1 => it was used only in the tcp reader => it's not hashed or watched for IO anymore => no need to io_watch_del() */ + tcp_emit_closed_event(c, TCP_CLOSED_EOF); tcpconn_destroy(tcpconn); break; } @@ -3639,6 +3661,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i) tcpconn->flags &= ~F_CONN_WRITE_W; } #endif /* TCP_ASYNC */ + tcp_emit_closed_event(c, TCP_CLOSED_EOF); tcpconn_put_destroy(tcpconn); } #ifdef TCP_ASYNC @@ -3690,6 +3713,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i) io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING); tcpconn->flags&=~F_CONN_WRITE_W; } + tcp_emit_closed_event(c, TCP_CLOSED_EOF); tcpconn_put_destroy(tcpconn); } else if (unlikely(tcpconn->flags & F_CONN_WRITE_W)){ BUG("unhashed connection watched for write\n"); @@ -3726,6 +3750,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i) tcpconn->flags&=~F_CONN_WRITE_W; } #endif /* TCP_ASYNC */ + tcp_emit_closed_event(c, TCP_CLOSED_EOF); tcpconn_put_destroy(tcpconn); } #ifdef TCP_ASYNC @@ -3757,6 +3782,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i) #endif /* TCP_ASYNC */ if (tcpconn_try_unhash(tcpconn)) tcpconn_put(tcpconn); + tcp_emit_closed_event(c, TCP_CLOSED_EOF); tcpconn_put_destroy(tcpconn); /* deref & delete if refcnt==0 */ break; default: diff --git a/src/core/tcp_read.c b/src/core/tcp_read.c index 48a683d32ff..db8e1025018 100644 --- a/src/core/tcp_read.c +++ b/src/core/tcp_read.c @@ -174,26 +174,6 @@ int tcp_http11_continue(struct tcp_connection *c) } #endif /* HTTP11 */ -static int tcp_emit_closed_event(struct tcp_connection *con, enum tcp_closed_reason reason) -{ - int ret; - tcp_closed_event_info_t tev; - sr_event_param_t evp = {0}; - - ret = 0; - LM_DBG("TCP closed event creation triggered (reason: %d)\n", reason); - if(likely(sr_event_enabled(SREV_TCP_CLOSED))) { - memset(&tev, 0, sizeof(tcp_closed_event_info_t)); - tev.reason = reason; - tev.con = con; - evp.data = (void*)(&tev); - ret = sr_event_exec(SREV_TCP_CLOSED, &evp); - } else { - LM_DBG("no callback registering for handling TCP closed event\n"); - } - return ret; -} - /** reads data from an existing tcp connection. * Side-effects: blocklisting, sets connection state to S_CONN_OK, tcp stats. @@ -288,11 +268,6 @@ int tcp_read_data(int fd, struct tcp_connection *c, ip_addr2a(&c->rcv.src_ip), c->rcv.src_port); LOG(cfg_get(core, core_cfg, corelog),"-> [%s]:%u)\n", ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port); - if (errno == ETIMEDOUT) { - tcp_emit_closed_event(c, TCP_CLOSED_TIMEOUT); - } else if (errno == ECONNRESET) { - tcp_emit_closed_event(c, TCP_CLOSED_RESET); - } return -1; } }else if (unlikely((bytes_read==0) || @@ -304,7 +279,6 @@ int tcp_read_data(int fd, struct tcp_connection *c, ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port); c->state=S_CONN_EOF; *flags|=RD_CONN_EOF; - tcp_emit_closed_event(c, TCP_CLOSED_EOF); }else{ if (unlikely(c->state==S_CONN_CONNECT || c->state==S_CONN_ACCEPT)){ TCP_STATS_ESTABLISHED(c->state);