1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/**
* @file ike_sa_id.c
*
* @brief Class for identification of an IKE_SA
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <string.h>
#include "ike_sa_id.h"
#include "types.h"
#include "utils/allocator.h"
/**
* Private data of an ike_sa_id object
*/
typedef struct private_ike_sa_id_s private_ike_sa_id_t;
struct private_ike_sa_id_s {
/**
* Public part of a ike_sa_id object
*/
ike_sa_id_t public;
/* Private values */
/**
* SPI of Initiator
*/
spi_t initiator_spi;
/**
* SPI of Responder
*/
spi_t responder_spi;
/**
* Role for specific IKE_SA
*/
ike_sa_role_t role;
};
/**
* @brief implements function set_responder_spi of ike_sa_id_t
*/
static status_t set_responder_spi (private_ike_sa_id_t *this, spi_t responder_spi)
{
this->responder_spi = responder_spi;
return SUCCESS;
}
static status_t set_initiator_spi(private_ike_sa_id_t *this, spi_t initiator_spi)
{
this->initiator_spi = initiator_spi;
return SUCCESS;
}
/**
* @brief implements function initiator_spi_is_set of ike_sa_id_t
*/
static bool initiator_spi_is_set (private_ike_sa_id_t *this)
{
return (!((this->initiator_spi.high == 0) && (this->initiator_spi.low == 0)));
}
/**
* @brief implements function responder_spi_is_set of ike_sa_id_t
*/
static bool responder_spi_is_set (private_ike_sa_id_t *this)
{
return (!((this->responder_spi.high == 0) && (this->responder_spi.low == 0)));
}
/**
* @brief implements function equals of ike_sa_id_t
*/
static status_t equals (private_ike_sa_id_t *this,private_ike_sa_id_t *other, bool *are_equal)
{
if ((this == NULL)||(other == NULL))
{
return FAILED;
}
if ( (this->role == other->role) &&
(this->initiator_spi.high == other->initiator_spi.high) &&
(this->initiator_spi.low == other->initiator_spi.low) &&
(this->responder_spi.high == other->responder_spi.high) &&
(this->responder_spi.low == other->responder_spi.low))
{
/* private_ike_sa_id's are equal */
*are_equal = TRUE;
}
else
{
/* private_ike_sa_id's are not equal */
*are_equal = FALSE;
}
return SUCCESS;
}
/**
* @brief implements function replace_values of ike_sa_id_t
*/
status_t replace_values (private_ike_sa_id_t *this, private_ike_sa_id_t *other)
{
if ((this == NULL) || (other == NULL))
{
return FAILED;
}
this->initiator_spi = other->initiator_spi;
this->responder_spi = other->responder_spi;
this->role = other->role;
return SUCCESS;
}
/**
* @brief implements function ike_sa_id_t.get_values
*/
static status_t get_values(private_ike_sa_id_t *this, spi_t *initiator, spi_t *responder, ike_sa_role_t *role)
{
memcpy(initiator, &(this->initiator_spi), sizeof(initiator));
memcpy(responder, &(this->responder_spi), sizeof(responder));
*role = this->role;
return SUCCESS;
}
/**
* @brief implements function clone of ike_sa_id_t
*/
static status_t clone (private_ike_sa_id_t *this, ike_sa_id_t **clone_of_this)
{
*clone_of_this = ike_sa_id_create(this->initiator_spi, this->responder_spi, this->role);
return (*clone_of_this == NULL) ? OUT_OF_RES : SUCCESS;
}
/**
* @brief implements function destroy of ike_sa_id_t
*/
static status_t destroy (private_ike_sa_id_t *this)
{
allocator_free(this);
return SUCCESS;
}
/*
* Described in Header-File
*/
ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, ike_sa_role_t role)
{
private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t);
if (this == NULL)
{
return NULL;
}
/* Public functions */
this->public.set_responder_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_responder_spi;
this->public.set_initiator_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_initiator_spi;
this->public.responder_spi_is_set = (bool(*)(ike_sa_id_t*)) responder_spi_is_set;
this->public.initiator_spi_is_set = (bool(*)(ike_sa_id_t*)) initiator_spi_is_set;
this->public.equals = (status_t(*)(ike_sa_id_t*,ike_sa_id_t*,bool*)) equals;
this->public.replace_values = (status_t(*)(ike_sa_id_t*,ike_sa_id_t*)) replace_values;
this->public.get_values = (status_t(*)(ike_sa_id_t*,spi_t*,spi_t*,ike_sa_role_t*)) get_values;
this->public.clone = (status_t(*)(ike_sa_id_t*,ike_sa_id_t**)) clone;
this->public.destroy = (status_t(*)(ike_sa_id_t*))destroy;
/* private data */
this->initiator_spi = initiator_spi;
this->responder_spi = responder_spi;
this->role = role;
return (&this->public);
}
|