Module: kamailio
Branch: master
Commit: c0c1dcc1008e74ed51987506d96bd8ebc88f3c9d
URL:
https://github.com/kamailio/kamailio/commit/c0c1dcc1008e74ed51987506d96bd8e…
Author: Stefan Mititelu <stefan-cristian.mititelu(a)1and1.ro>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-08-17T10:31:55+02:00
tls: add timestamp and sni info for a session
---
Modified: src/core/tcp_conn.h
Modified: src/core/tcp_main.c
Modified: src/modules/tls/tls_rpc.c
---
Diff:
https://github.com/kamailio/kamailio/commit/c0c1dcc1008e74ed51987506d96bd8e…
Patch:
https://github.com/kamailio/kamailio/commit/c0c1dcc1008e74ed51987506d96bd8e…
---
diff --git a/src/core/tcp_conn.h b/src/core/tcp_conn.h
index aaf1f2fcb05..fb6bbe63277 100644
--- a/src/core/tcp_conn.h
+++ b/src/core/tcp_conn.h
@@ -220,6 +220,7 @@ typedef struct tcp_connection {
enum tcp_conn_states state; /* connection state */
void* extra_data; /* extra data associated to the connection, 0 for tcp*/
struct timer_ln timer;
+ time_t timestamp;/* connection creation timestamp */
ticks_t timeout;/* connection timeout, after this it will be removed*/
ticks_t lifetime;/* connection lifetime */
unsigned id_hash; /* hash index in the id_hash */
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index 9edbe79a361..2114e390f4c 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -1220,6 +1220,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union*
su,
c->rcv.proto_reserved2=0;
c->state=state;
c->extra_data=0;
+ c->timestamp=time(NULL);
#ifdef USE_TLS
if (type==PROTO_TLS){
if (tls_tcpconn_init(c, sock)==-1) goto error;
diff --git a/src/modules/tls/tls_rpc.c b/src/modules/tls/tls_rpc.c
index 9c7f980e71e..a7ad254a1b5 100644
--- a/src/modules/tls/tls_rpc.c
+++ b/src/modules/tls/tls_rpc.c
@@ -115,6 +115,9 @@ static void tls_list(rpc_t* rpc, void* c)
struct tls_extra_data* tls_d;
struct tcp_connection* con;
int i, len, timeout;
+ struct tm timestamp;
+ char timestamp_s[128];
+ const char* sni;
TCPCONN_LOCK;
for(i = 0; i < TCP_ID_HASH_SIZE; i++) {
@@ -132,8 +135,29 @@ static void tls_list(rpc_t* rpc, void* c)
BUG("failed to convert destination ip");
dst_ip[len] = 0;
timeout = TICKS_TO_S(con->timeout - get_ticks_raw());
- rpc->struct_add(handle, "ddsdsd",
+ timestamp = *localtime(&con->timestamp);
+ if (snprintf(timestamp_s, 128, "%d-%02d-%02d %02d:%02d:%02d",
timestamp.tm_year + 1900,
+ timestamp.tm_mon + 1, timestamp.tm_mday, timestamp.tm_hour,
+ timestamp.tm_min, timestamp.tm_sec) < 0) {
+ timestamp_s[0] = 'N';
+ timestamp_s[1] = '/';
+ timestamp_s[2] = 'A';
+ timestamp_s[3] = '\0';
+ }
+
+ if (tls_d) {
+ sni = SSL_get_servername(tls_d->ssl, TLSEXT_NAMETYPE_host_name);
+ if (sni == NULL) {
+ sni = "N/A";
+ }
+ } else {
+ sni = "N/A";
+ }
+
+ rpc->struct_add(handle, "dssdsdsd",
"id", con->id,
+ "sni", sni,
+ "timestamp", timestamp_s,
"timeout", timeout,
"src_ip", src_ip,
"src_port", con->rcv.src_port,