Annotation of embedaddon/strongswan/src/libcharon/sa/task_manager.c, revision 1.1.1.2
1.1 misho 1: /*
2: * Copyright (C) 2011 Tobias Brunner
3: * HSR Hochschule fuer Technik Rapperswil
4: *
5: * This program is free software; you can redistribute it and/or modify it
6: * under the terms of the GNU General Public License as published by the
7: * Free Software Foundation; either version 2 of the License, or (at your
8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9: *
10: * This program is distributed in the hope that it will be useful, but
11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: * for more details.
14: */
15:
16: #include "task_manager.h"
17:
18: #include <math.h>
19: #include <sa/ikev1/task_manager_v1.h>
20: #include <sa/ikev2/task_manager_v2.h>
21:
22: /*
23: * See header
24: */
25: u_int task_manager_total_retransmit_timeout()
26: {
27: double timeout, base, limit = 0, total = 0;
1.1.1.2 ! misho 28: int tries, max_tries = 0, i;
1.1 misho 29:
30: tries = lib->settings->get_int(lib->settings, "%s.retransmit_tries",
31: RETRANSMIT_TRIES, lib->ns);
32: base = lib->settings->get_double(lib->settings, "%s.retransmit_base",
33: RETRANSMIT_BASE, lib->ns);
34: timeout = lib->settings->get_double(lib->settings, "%s.retransmit_timeout",
35: RETRANSMIT_TIMEOUT, lib->ns);
36: limit = lib->settings->get_double(lib->settings, "%s.retransmit_limit",
37: 0, lib->ns);
38:
1.1.1.2 ! misho 39: if (base > 1)
! 40: {
! 41: max_tries = log(UINT32_MAX/(1000.0 * timeout))/log(base);
! 42: }
! 43:
1.1 misho 44: for (i = 0; i <= tries; i++)
45: {
1.1.1.2 ! misho 46: double interval = UINT32_MAX/1000.0;
! 47: if (max_tries && i <= max_tries)
! 48: {
! 49: interval = timeout * pow(base, i);
! 50: }
1.1 misho 51: if (limit)
52: {
53: interval = min(interval, limit);
54: }
55: total += interval;
56: }
57: return (u_int)total;
58: }
59:
60: /*
61: * See header
62: */
63: task_manager_t *task_manager_create(ike_sa_t *ike_sa)
64: {
65: switch (ike_sa->get_version(ike_sa))
66: {
67: case IKEV1:
68: #ifdef USE_IKEV1
69: return &task_manager_v1_create(ike_sa)->task_manager;
70: #endif
71: break;
72: case IKEV2:
73: #ifdef USE_IKEV2
74: return &task_manager_v2_create(ike_sa)->task_manager;
75: #endif
76: break;
77: default:
78: break;
79: }
80: return NULL;
81: }
82:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>