task-manager: Add helper function to calculate the total retransmit timeout
This commit is contained in:
@@ -15,10 +15,40 @@
|
|||||||
|
|
||||||
#include "task_manager.h"
|
#include "task_manager.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <sa/ikev1/task_manager_v1.h>
|
#include <sa/ikev1/task_manager_v1.h>
|
||||||
#include <sa/ikev2/task_manager_v2.h>
|
#include <sa/ikev2/task_manager_v2.h>
|
||||||
|
|
||||||
/**
|
/*
|
||||||
|
* See header
|
||||||
|
*/
|
||||||
|
u_int task_manager_total_retransmit_timeout()
|
||||||
|
{
|
||||||
|
double timeout, base, limit = 0, total = 0;
|
||||||
|
int tries, i;
|
||||||
|
|
||||||
|
tries = lib->settings->get_int(lib->settings, "%s.retransmit_tries",
|
||||||
|
RETRANSMIT_TRIES, lib->ns);
|
||||||
|
base = lib->settings->get_double(lib->settings, "%s.retransmit_base",
|
||||||
|
RETRANSMIT_BASE, lib->ns);
|
||||||
|
timeout = lib->settings->get_double(lib->settings, "%s.retransmit_timeout",
|
||||||
|
RETRANSMIT_TIMEOUT, lib->ns);
|
||||||
|
limit = lib->settings->get_double(lib->settings, "%s.retransmit_limit",
|
||||||
|
0, lib->ns);
|
||||||
|
|
||||||
|
for (i = 0; i <= tries; i++)
|
||||||
|
{
|
||||||
|
double interval = timeout * pow(base, i);
|
||||||
|
if (limit)
|
||||||
|
{
|
||||||
|
interval = min(interval, limit);
|
||||||
|
}
|
||||||
|
total += interval;
|
||||||
|
}
|
||||||
|
return (u_int)total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
* See header
|
* See header
|
||||||
*/
|
*/
|
||||||
task_manager_t *task_manager_create(ike_sa_t *ike_sa)
|
task_manager_t *task_manager_create(ike_sa_t *ike_sa)
|
||||||
|
|||||||
@@ -302,6 +302,17 @@ struct task_manager_t {
|
|||||||
void (*destroy) (task_manager_t *this);
|
void (*destroy) (task_manager_t *this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate total timeout of the retransmission mechanism.
|
||||||
|
*
|
||||||
|
* This is affected by modifications of retransmit_base, retransmit_timeout,
|
||||||
|
* retransmit_limit or retransmit_tries. The resulting value can then be used
|
||||||
|
* e.g. in kernel plugins to set the system's acquire timeout properly.
|
||||||
|
*
|
||||||
|
* @return calculated total retransmission timeout in seconds
|
||||||
|
*/
|
||||||
|
u_int task_manager_total_retransmit_timeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a task manager instance for the correct IKE version.
|
* Create a task manager instance for the correct IKE version.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user