From 6301b880df0ac3ed8d1dbf656252cc18d38f3090 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 23 Jun 2022 16:13:02 +0200 Subject: [PATCH] child-sa: Query policies only if querying SAs doesn't update the use time --- src/libcharon/sa/child_sa.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libcharon/sa/child_sa.c b/src/libcharon/sa/child_sa.c index 8f101e1ff0..d76d7aebcb 100644 --- a/src/libcharon/sa/child_sa.c +++ b/src/libcharon/sa/child_sa.c @@ -759,19 +759,19 @@ METHOD(child_sa_t, get_usestats, void, private_child_sa_t *this, bool inbound, time_t *time, uint64_t *bytes, uint64_t *packets) { - if ((!bytes && !packets) || update_usebytes(this, inbound) != FAILED) + status_t status = NOT_SUPPORTED; + bool sa_use_time; + + sa_use_time = charon->kernel->get_features(charon->kernel) & KERNEL_SA_USE_TIME; + + if (bytes || packets || sa_use_time) { - /* there was traffic since last update or the kernel interface - * does not support querying the number of usebytes. - */ - if (time) - { - if (!update_usetime(this, inbound) && !bytes && !packets) - { - /* if policy query did not yield a usetime, query SAs instead */ - update_usebytes(this, inbound); - } - } + status = update_usebytes(this, inbound); + } + if (time && !sa_use_time && status != FAILED) + { /* query policies only if last use time is not available from SAs and + * there was either traffic or querying the SA wasn't supported */ + update_usetime(this, inbound); } if (time) { -- 2.47.2