From 5c428533fcc608a82d47ed90c48140b0014c7ef2 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Fri, 28 Apr 2023 11:15:36 +0300 Subject: [PATCH] tls: Add rpc function to kill session by id Note that it may take few seconds for session to be killed. --- src/modules/tls/doc/rpc.xml | 12 ++++++++++++ src/modules/tls/tls_rpc.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/modules/tls/doc/rpc.xml b/src/modules/tls/doc/rpc.xml index 30c67d5c8fe..495fc7b31c2 100644 --- a/src/modules/tls/doc/rpc.xml +++ b/src/modules/tls/doc/rpc.xml @@ -50,6 +50,18 @@ +
+ <function>tls.kill</function> + + Kill a TLS session by id. + + Parameters: + + + None. + + +
<function>tls.reload</function> diff --git a/src/modules/tls/tls_rpc.c b/src/modules/tls/tls_rpc.c index 566191a8760..c55f45b72d7 100644 --- a/src/modules/tls/tls_rpc.c +++ b/src/modules/tls/tls_rpc.c @@ -275,7 +275,41 @@ static void tls_options(rpc_t* rpc, void* c) ); } +static const char* tls_kill_doc[2] = { + "Kills a tls session, identified via id.", + 0 }; + +static void tls_kill(rpc_t* rpc, void* c) +{ + struct tcp_connection* con; + int i, kill_id = 0; + + if (rpc->scan(c, "d", &kill_id) < 0) { + /* Reply is set automatically by scan upon failure, + * no need to do anything here + */ + return; + } + TCPCONN_LOCK; + for(i = 0; i < TCP_ID_HASH_SIZE; i++) { + for (con = tcpconn_id_hash[i]; con; con = con->id_next) { + if (con->rcv.proto != PROTO_TLS) continue; + if (con->id == kill_id) { + con->state = -2; + con->timeout = get_ticks_raw(); + + TCPCONN_UNLOCK; + + rpc->add(c, "s", "OK"); + return; + } + } + } + TCPCONN_UNLOCK; + + rpc->add(c, "s", "TLS connection id not found"); +} rpc_export_t tls_rpc[] = { @@ -283,5 +317,6 @@ rpc_export_t tls_rpc[] = { {"tls.list", tls_list, tls_list_doc, RET_ARRAY}, {"tls.info", tls_info, tls_info_doc, 0}, {"tls.options",tls_options, tls_options_doc, 0}, + {"tls.kill", tls_kill, tls_kill_doc, 0}, {0, 0, 0, 0} };