2 * @file ike_auth_lifetime.c
4 * @brief Implementation of the ike_auth_lifetime task.
9 * Copyright (C) 2007 Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #include "ike_auth_lifetime.h"
26 #include <encoding/payloads/notify_payload.h>
29 typedef struct private_ike_auth_lifetime_t private_ike_auth_lifetime_t
;
32 * Private members of a ike_auth_lifetime_t task.
34 struct private_ike_auth_lifetime_t
{
37 * Public methods and task_t interface.
39 ike_auth_lifetime_t
public;
48 * add the AUTH_LIFETIME notify to the message
50 static void add_auth_lifetime(private_ike_auth_lifetime_t
*this, message_t
*message
)
55 lifetime
= this->ike_sa
->get_statistic(this->ike_sa
, STAT_REAUTH_TIME
);
58 chunk
= chunk_from_thing(lifetime
);
59 *(u_int32_t
*)chunk
.ptr
= htonl(lifetime
);
60 message
->add_notify(message
, FALSE
, AUTH_LIFETIME
, chunk
);
65 * read notifys from message and evaluate them
67 static void process_payloads(private_ike_auth_lifetime_t
*this, message_t
*message
)
71 notify_payload_t
*notify
;
73 iterator
= message
->get_payload_iterator(message
);
74 while (iterator
->iterate(iterator
, (void**)&payload
))
76 if (payload
->get_type(payload
) == NOTIFY
)
78 notify
= (notify_payload_t
*)payload
;
79 switch (notify
->get_notify_type(notify
))
83 chunk_t data
= notify
->get_notification_data(notify
);
84 u_int32_t lifetime
= ntohl(*(u_int32_t
*)data
.ptr
);
85 this->ike_sa
->set_auth_lifetime(this->ike_sa
, lifetime
);
93 iterator
->destroy(iterator
);
97 * Implementation of task_t.process for initiator
99 static status_t
build_i(private_ike_auth_lifetime_t
*this, message_t
*message
)
101 if (message
->get_exchange_type(message
) == INFORMATIONAL
)
103 add_auth_lifetime(this, message
);
110 * Implementation of task_t.process for responder
112 static status_t
process_r(private_ike_auth_lifetime_t
*this, message_t
*message
)
114 if (message
->get_exchange_type(message
) == INFORMATIONAL
)
116 process_payloads(this, message
);
123 * Implementation of task_t.build for responder
125 static status_t
build_r(private_ike_auth_lifetime_t
*this, message_t
*message
)
127 if (message
->get_exchange_type(message
) == IKE_AUTH
&&
128 this->ike_sa
->get_state(this->ike_sa
) == IKE_ESTABLISHED
)
130 add_auth_lifetime(this, message
);
137 * Implementation of task_t.process for initiator
139 static status_t
process_i(private_ike_auth_lifetime_t
*this, message_t
*message
)
141 if (message
->get_exchange_type(message
) == IKE_AUTH
&&
142 this->ike_sa
->get_state(this->ike_sa
) == IKE_ESTABLISHED
)
144 process_payloads(this, message
);
151 * Implementation of task_t.get_type
153 static task_type_t
get_type(private_ike_auth_lifetime_t
*this)
155 return IKE_AUTH_LIFETIME
;
159 * Implementation of task_t.migrate
161 static void migrate(private_ike_auth_lifetime_t
*this, ike_sa_t
*ike_sa
)
163 this->ike_sa
= ike_sa
;
167 * Implementation of task_t.destroy
169 static void destroy(private_ike_auth_lifetime_t
*this)
175 * Described in header.
177 ike_auth_lifetime_t
*ike_auth_lifetime_create(ike_sa_t
*ike_sa
, bool initiator
)
179 private_ike_auth_lifetime_t
*this = malloc_thing(private_ike_auth_lifetime_t
);
181 this->public.task
.get_type
= (task_type_t(*)(task_t
*))get_type
;
182 this->public.task
.migrate
= (void(*)(task_t
*,ike_sa_t
*))migrate
;
183 this->public.task
.destroy
= (void(*)(task_t
*))destroy
;
187 this->public.task
.build
= (status_t(*)(task_t
*,message_t
*))build_i
;
188 this->public.task
.process
= (status_t(*)(task_t
*,message_t
*))process_i
;
192 this->public.task
.build
= (status_t(*)(task_t
*,message_t
*))build_r
;
193 this->public.task
.process
= (status_t(*)(task_t
*,message_t
*))process_r
;
196 this->ike_sa
= ike_sa
;
198 return &this->public;