Module: kamailio
Branch: master
Commit: 97215407635c61ab9d1702f5c6e300f5bd15b69b
URL:
https://github.com/kamailio/kamailio/commit/97215407635c61ab9d1702f5c6e300f…
Author: Camille Oudot <camille.oudot(a)orange.com>
Committer: Camille Oudot <camille.oudot(a)orange.com>
Date: 2016-10-06T16:45:39+02:00
tcpops: use dedicated routes for tcp close events
- tcp:closed for "normal" close by the other side
- tcp:timeout for timeouts
- tcp:reset for connections closed with RST
---
Modified: modules/tcpops/tcpops.c
Modified: modules/tcpops/tcpops.h
Modified: modules/tcpops/tcpops_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/97215407635c61ab9d1702f5c6e300f…
Patch:
https://github.com/kamailio/kamailio/commit/97215407635c61ab9d1702f5c6e300f…
---
diff --git a/modules/tcpops/tcpops.c b/modules/tcpops/tcpops.c
index 624e887..43340ca 100644
--- a/modules/tcpops/tcpops.c
+++ b/modules/tcpops/tcpops.c
@@ -38,6 +38,9 @@
/* globally enabled by default */
int tcp_closed_event = 1;
+int tcp_closed_routes[_TCP_CLOSED_REASON_MAX] =
+ {[0 ... sizeof(tcp_closed_routes)/sizeof(*tcp_closed_routes)-1] = -1};
+
/**
* gets the fd of the current message source connection
*
@@ -192,20 +195,14 @@ int tcpops_set_connection_lifetime(struct tcp_connection* con, int
time) {
return 1;
}
-static void tcpops_tcp_closed_run_route(struct tcp_connection *con)
+static void tcpops_tcp_closed_run_route(tcp_closed_event_info_t *tev)
{
int rt, backup_rt;
struct run_act_ctx ctx;
sip_msg_t *fmsg;
- LM_DBG("tcp_closed_run_route event_route[tcp:closed]\n");
-
- rt = route_get(&event_rt, "tcp:closed");
- if (rt < 0 || event_rt.rlist[rt] == NULL)
- {
- LM_DBG("route does not exist");
- return;
- }
+ rt = tcp_closed_routes[tev->reason];
+ if (rt == -1) return;
if (faked_msg_init() < 0)
{
@@ -213,7 +210,7 @@ static void tcpops_tcp_closed_run_route(struct tcp_connection *con)
return;
}
fmsg = faked_msg_next();
- fmsg->rcv = con->rcv;
+ fmsg->rcv = tev->con->rcv;
backup_rt = get_route_type();
set_route_type(EVENT_ROUTE);
@@ -224,7 +221,7 @@ static void tcpops_tcp_closed_run_route(struct tcp_connection *con)
int tcpops_handle_tcp_closed(void *data)
{
- tcp_event_info_t *tev = (tcp_event_info_t *) data;
+ tcp_closed_event_info_t *tev = (tcp_closed_event_info_t *) data;
if (tev == NULL || tev->con == NULL) {
LM_WARN("received bad TCP closed event\n");
@@ -234,7 +231,7 @@ int tcpops_handle_tcp_closed(void *data)
/* run event route if tcp_closed_event == 1 or if the
* F_CONN_CLOSE_EV flag is explicitly set */
if (tcp_closed_event == 1 || (tev->con->flags & F_CONN_CLOSE_EV))
- tcpops_tcp_closed_run_route(tev->con);
+ tcpops_tcp_closed_run_route(tev);
return 0;
}
diff --git a/modules/tcpops/tcpops.h b/modules/tcpops/tcpops.h
index 8e1c823..bde142b 100644
--- a/modules/tcpops/tcpops.h
+++ b/modules/tcpops/tcpops.h
@@ -28,6 +28,7 @@
#include "../../events.h"
extern int tcp_closed_event;
+extern int tcp_closed_routes[_TCP_CLOSED_REASON_MAX];
int tcpops_get_current_fd(int conid, int *fd);
int tcpops_acquire_fd_from_tcpmain(int conid, int *fd);
diff --git a/modules/tcpops/tcpops_mod.c b/modules/tcpops/tcpops_mod.c
index 60c7b88..b235cd4 100644
--- a/modules/tcpops/tcpops_mod.c
+++ b/modules/tcpops/tcpops_mod.c
@@ -118,11 +118,17 @@ static int mod_init(void)
return -1;
}
- if (tcp_closed_event /* register event only if tcp_closed_event != 0 */
- && (sr_event_register_cb(SREV_TCP_CLOSED, tcpops_handle_tcp_closed) != 0))
- {
- LM_ERR("problem registering tcpops_handle_tcp_closed call-back\n");
- return -1;
+ if (tcp_closed_event) {
+ /* register event only if tcp_closed_event != 0 */
+ if (sr_event_register_cb(SREV_TCP_CLOSED, tcpops_handle_tcp_closed) != 0) {
+ LM_ERR("problem registering tcpops_handle_tcp_closed call-back\n");
+ return -1;
+ }
+
+ /* get event routes */
+ tcp_closed_routes[TCP_CLOSED_EOF] = route_get(&event_rt, "tcp:closed");
+ tcp_closed_routes[TCP_CLOSED_TIMEOUT] = route_get(&event_rt,
"tcp:timeout");
+ tcp_closed_routes[TCP_CLOSED_RESET] = route_get(&event_rt, "tcp:reset");
}
return 0;