Skip to content

Commit

Permalink
tls: Add rpc function to kill session by id
Browse files Browse the repository at this point in the history
Note that it may take few seconds for session to be killed.
  • Loading branch information
smititelu authored and miconda committed May 9, 2023
1 parent 439a1c7 commit ad8c668
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/modules/tls/doc/rpc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
35 changes: 35 additions & 0 deletions src/modules/tls/tls_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,48 @@ 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[] = {
{"tls.reload", tls_reload, tls_reload_doc, RPC_EXEC_DELTA},
{"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}
};

0 comments on commit ad8c668

Please sign in to comment.