]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/charon/charon/config/configuration.c
(no commit message)
[people/ms/strongswan.git] / src / charon / charon / config / configuration.c
1 /**
2 * @file configuration.c
3 *
4 * @brief Implementation of configuration_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <stdlib.h>
24
25 #include "configuration.h"
26
27 #include <types.h>
28
29 /**
30 * First retransmit timeout in milliseconds.
31 * Timeout value is increasing in each retransmit round.
32 */
33 #define RETRANSMIT_TIMEOUT 3000
34
35 /**
36 * Timeout in milliseconds after that a half open IKE_SA gets deleted.
37 */
38 #define HALF_OPEN_IKE_SA_TIMEOUT 30000
39
40 /**
41 * Max retransmit count.
42 * 0 for infinite. The max time a half open IKE_SA is alive is set by
43 * RETRANSMIT_TIMEOUT.
44 */
45 #define MAX_RETRANSMIT_COUNT 0
46
47
48 typedef struct private_configuration_t private_configuration_t;
49
50 /**
51 * Private data of an configuration_t object.
52 */
53 struct private_configuration_t {
54
55 /**
56 * Public part of configuration_t object.
57 */
58 configuration_t public;
59
60 };
61
62 /**
63 * Implementation of configuration_t.get_retransmit_timeout.
64 */
65 static status_t get_retransmit_timeout (private_configuration_t *this, u_int32_t retransmit_count, u_int32_t *timeout)
66 {
67 int new_timeout = RETRANSMIT_TIMEOUT, i;
68 if (retransmit_count > MAX_RETRANSMIT_COUNT && MAX_RETRANSMIT_COUNT != 0)
69 {
70 return FAILED;
71 }
72
73 for (i = 0; i < retransmit_count; i++)
74 {
75 new_timeout *= 2;
76 }
77
78 *timeout = new_timeout;
79
80 return SUCCESS;
81 }
82
83 /**
84 * Implementation of configuration_t.get_half_open_ike_sa_timeout.
85 */
86 static u_int32_t get_half_open_ike_sa_timeout (private_configuration_t *this)
87 {
88 return HALF_OPEN_IKE_SA_TIMEOUT;
89 }
90
91 /**
92 * Implementation of configuration_t.destroy.
93 */
94 static void destroy(private_configuration_t *this)
95 {
96 free(this);
97 }
98
99 /*
100 * Described in header-file
101 */
102 configuration_t *configuration_create()
103 {
104 private_configuration_t *this = malloc_thing(private_configuration_t);
105
106 /* public functions */
107 this->public.destroy = (void(*)(configuration_t*))destroy;
108 this->public.get_retransmit_timeout = (status_t (*) (configuration_t *, u_int32_t retransmit_count, u_int32_t *timeout))get_retransmit_timeout;
109 this->public.get_half_open_ike_sa_timeout = (u_int32_t (*) (configuration_t *)) get_half_open_ike_sa_timeout;
110
111 return (&this->public);
112 }