From: Felix Fietkau Date: Sat, 10 Sep 2022 10:33:03 +0000 (+0200) Subject: pex: keep active pex hosts after the specified timeout X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=be175767bc67aad0cc0df2c28e7caddb988843d0;p=project%2Funetd.git pex: keep active pex hosts after the specified timeout Keep them as long as they have sent us a valid message in the last minute Signed-off-by: Felix Fietkau --- diff --git a/pex.c b/pex.c index 64e2bd2..7a76cf7 100644 --- a/pex.c +++ b/pex.c @@ -795,12 +795,16 @@ void network_pex_close(struct network *net) { struct network_pex *pex = &net->pex; struct network_pex_host *host, *tmp; + uint64_t now = unet_gettime(); uloop_timeout_cancel(&pex->request_update_timer); list_for_each_entry_safe(host, tmp, &pex->hosts, list) { if (host->timeout) continue; + if (host->last_active + UNETD_PEX_HOST_ACITVE_TIMEOUT >= now) + continue; + list_del(&host->list); free(host); } @@ -837,6 +841,20 @@ global_pex_find_network(const uint8_t *id) return NULL; } +static void +global_pex_set_active(struct network *net, struct sockaddr_in6 *addr) +{ + struct network_pex *pex = &net->pex; + struct network_pex_host *host; + + list_for_each_entry(host, &pex->hosts, list) { + if (memcmp(&host->endpoint.in6, addr, sizeof(*addr)) != 0) + continue; + + host->last_active = unet_gettime(); + } +} + static void global_pex_recv(struct pex_hdr *hdr, struct sockaddr_in6 *addr) { @@ -856,6 +874,8 @@ global_pex_recv(struct pex_hdr *hdr, struct sockaddr_in6 *addr) *(uint64_t *)hdr->id ^= pex_network_hash(net->config.auth_key, ehdr->nonce); + global_pex_set_active(net, addr); + D("PEX global rx op=%d", hdr->opcode); switch (hdr->opcode) { case PEX_MSG_HELLO: diff --git a/pex.h b/pex.h index f16f77c..d5d0887 100644 --- a/pex.h +++ b/pex.h @@ -12,6 +12,7 @@ struct network; struct network_pex_host { struct list_head list; uint64_t timeout; + uint64_t last_active; union network_endpoint endpoint; }; diff --git a/unetd.h b/unetd.h index 6b9ce92..365e738 100644 --- a/unetd.h +++ b/unetd.h @@ -45,6 +45,8 @@ extern int global_pex_port; #define UNETD_DATA_UPDATE_DELAY (10 * 1000) +#define UNETD_PEX_HOST_ACITVE_TIMEOUT 60 + void unetd_write_hosts(void); int unetd_attach_mssfix(int ifindex, int mtu);