From 5d583af29b3ba76f9acaeb77c0e0457268776dcb Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 11 Apr 2020 17:27:39 +0200 Subject: [PATCH] Add a probe point for SPTPS renewal and devtool_force_sptps_renewal(). The latter function just sets the timers so they should time out immediately. --- src/devtools.c | 22 ++++++++++++++++++++++ src/devtools.h | 8 ++++++++ src/net.c | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/src/devtools.c b/src/devtools.c index 5bd06180..fb6ab257 100644 --- a/src/devtools.c +++ b/src/devtools.c @@ -44,10 +44,16 @@ static void inviter_commits_first_nop_probe(bool stage) { return; } +static void sptps_renewal_nop_probe(meshlink_node_t *node) { + (void)node; + return; +} + void (*devtool_trybind_probe)(void) = nop_probe; void (*devtool_keyrotate_probe)(int stage) = keyrotate_nop_probe; void (*devtool_set_inviter_commits_first)(bool inviter_commited_first) = inviter_commits_first_nop_probe; void (*devtool_adns_resolve_probe)(void) = nop_probe; +void (*devtool_sptps_renewal_probe)(meshlink_node_t *node) = sptps_renewal_nop_probe; /* Return an array of edges in the current network graph. * Data captures the current state and will not be updated. @@ -337,3 +343,19 @@ meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name, return handle; } + +void devtool_force_sptps_renewal(meshlink_handle_t *mesh, meshlink_node_t *node) { + if(!mesh || !node) { + meshlink_errno = MESHLINK_EINVAL; + return; + } + + node_t *n = (node_t *)node; + connection_t *c = n->connection; + + n->last_req_key = 0; + + if(c) { + c->last_key_renewal = 0; + } +} diff --git a/src/devtools.h b/src/devtools.h index 79aef33a..2981d6d3 100644 --- a/src/devtools.h +++ b/src/devtools.h @@ -169,6 +169,14 @@ extern void (*devtool_keyrotate_probe)(int stage); /// Debug function pointer variable for asynchronous DNS resolving extern void (*devtool_adns_resolve_probe)(void); +/// Debug function pointer variable for SPTPS key renewal +/** This function pointer variable is a userspace tracepoint or debugger callback for + * SPTPS key renewal. + * + * @param node The node whose SPTPS key(s) are being renewed + */ +extern void (*devtool_sptps_renewal_probe)(meshlink_node_t *node); + /// Debug function pointer variable for asserting inviter/invitee committing sequence /** This function pointer variable is a userspace tracepoint or debugger callback which * invokes either after inviter writing invitees host file into the disk diff --git a/src/net.c b/src/net.c index 2ee8aee4..0aa20439 100644 --- a/src/net.c +++ b/src/net.c @@ -22,6 +22,7 @@ #include "utils.h" #include "conf.h" #include "connection.h" +#include "devtools.h" #include "graph.h" #include "logger.h" #include "meshlink_internal.h" @@ -124,6 +125,8 @@ static void timeout_handler(event_loop_t *loop, void *data) { } if(c->status.active && c->last_key_renewal + 3600 < mesh->loop.now.tv_sec) { + devtool_sptps_renewal_probe((meshlink_node_t *)c->node); + if(!sptps_force_kex(&c->sptps)) { logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for connection with %s failed", c->name); terminate_connection(mesh, c, true); @@ -622,6 +625,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { if(n->status.validkey && n->last_req_key + 3600 < mesh->loop.now.tv_sec) { logger(mesh, MESHLINK_DEBUG, "SPTPS key renewal for node %s", n->name); + devtool_sptps_renewal_probe((meshlink_node_t *)n); if(!sptps_force_kex(&n->sptps)) { logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for node %s failed", n->name); -- 2.39.5