Module: kamailio
Branch: master
Commit: ad8c6688d43d3d5913efa12ae1a85ef6ee3e162f
URL:
https://github.com/kamailio/kamailio/commit/ad8c6688d43d3d5913efa12ae1a85ef…
Author: Stefan Mititelu <stefan-cristian.mititelu(a)1and1.ro>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-05-09T20:24:13+02:00
tls: Add rpc function to kill session by id
Note that it may take few seconds for session to be killed.
---
Modified: src/modules/tls/doc/rpc.xml
Modified: src/modules/tls/tls_rpc.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ad8c6688d43d3d5913efa12ae1a85ef…
Patch:
https://github.com/kamailio/kamailio/commit/ad8c6688d43d3d5913efa12ae1a85ef…
---
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 @@
</para></listitem>
</itemizedlist>
</section>
+ <section id="tls.r.tls.kill">
+ <title><function>tls.kill</function></title>
+ <para>
+ Kill a TLS session by id.
+ </para>
+ <para>Parameters: </para>
+ <itemizedlist>
+ <listitem><para>
+ None.
+ </para></listitem>
+ </itemizedlist>
+ </section>
<section id="tls.r.tls.reload">
<title><function>tls.reload</function></title>
<para>
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}
};