Also avoid returning 0 and disabling rekeying in the rare case of
`jitter = rekey` and the `1/jitter` chance of that happening (returning
1 at least doesn't disable rekeying).
Co-authored-by: Tobias Brunner <tobias@strongswan.org>
Closes strongswan/strongswan#1414
return rekey;
}
jitter = (jitter == UINT64_MAX) ? jitter : jitter + 1;
- return rekey - jitter * (random() / (RAND_MAX + 1.0));
+ return rekey - (uint64_t)(min(jitter, rekey) * (random() / (RAND_MAX + 1.0)));
}
#define APPLY_JITTER(l) l.rekey = apply_jitter(l.rekey, l.jitter)