2 * Copyright (C) 2007-2011 Tobias Brunner
3 * Copyright (C) 2007-2011 Martin Willi
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "task_manager_v1.h"
22 #include <sa/tasks/main_mode.h>
23 #include <sa/tasks/quick_mode.h>
24 #include <sa/tasks/xauth.h>
25 #include <sa/tasks/mode_config.h>
26 #include <sa/tasks/informational.h>
27 #include <sa/tasks/ike_natd_v1.h>
28 #include <sa/tasks/ike_vendor_v1.h>
29 #include <sa/tasks/isakmp_cert_pre.h>
30 #include <sa/tasks/isakmp_cert_post.h>
31 #include <processing/jobs/retransmit_job.h>
32 #include <processing/jobs/delete_ike_sa_job.h>
35 * Number of old messages hashes we keep for retransmission.
37 * In Main Mode, we must ignore messages from a previous message pair if
38 * we already continued to the next. Otherwise a late retransmission
39 * could be considered as a reply to the newer request.
41 #define MAX_OLD_HASHES 2
43 typedef struct exchange_t exchange_t
;
46 * An exchange in the air, used do detect and handle retransmission
51 * Message ID used for this transaction
56 * generated packet for retransmission
61 typedef struct private_task_manager_t private_task_manager_t
;
64 * private data of the task manager
66 struct private_task_manager_t
{
71 task_manager_v1_t
public;
74 * associated IKE_SA we are serving
79 * RNG to create message IDs
84 * Exchange we are currently handling as responder
88 * Hash of a previously received message
93 * packet for retransmission
100 * Exchange we are currently handling as initiator
104 * Message ID of the exchange
109 * Hashes of old responses we can ignore
111 u_int32_t old_hashes
[MAX_OLD_HASHES
];
114 * Position in old hash array
119 * Sequence number of the last sent message
124 * how many times we have retransmitted so far
129 * packet for retransmission
134 * type of the initated exchange
136 exchange_type_t type
;
141 * List of queued tasks not yet in action
143 linked_list_t
*queued_tasks
;
146 * List of active tasks, initiated by ourselve
148 linked_list_t
*active_tasks
;
151 * List of tasks initiated by peer
153 linked_list_t
*passive_tasks
;
156 * Queued messages not yet ready to process
161 * Number of times we retransmit messages before giving up
163 u_int retransmit_tries
;
166 * Retransmission timeout
168 double retransmit_timeout
;
171 * Base to calculate retransmission timeout
173 double retransmit_base
;
177 * Flush a single task queue
179 static void flush_queue(private_task_manager_t
*this, linked_list_t
*list
)
185 this->queued
->destroy(this->queued
);
188 while (list
->remove_last(list
, (void**)&task
) == SUCCESS
)
195 * flush all tasks in the task manager
197 static void flush(private_task_manager_t
*this)
199 flush_queue(this, this->queued_tasks
);
200 flush_queue(this, this->passive_tasks
);
201 flush_queue(this, this->active_tasks
);
205 * move a task of a specific type from the queue to the active list
207 static bool activate_task(private_task_manager_t
*this, task_type_t type
)
209 enumerator_t
*enumerator
;
213 enumerator
= this->queued_tasks
->create_enumerator(this->queued_tasks
);
214 while (enumerator
->enumerate(enumerator
, (void**)&task
))
216 if (task
->get_type(task
) == type
)
218 DBG2(DBG_IKE
, " activating %N task", task_type_names
, type
);
219 this->queued_tasks
->remove_at(this->queued_tasks
, enumerator
);
220 this->active_tasks
->insert_last(this->active_tasks
, task
);
225 enumerator
->destroy(enumerator
);
229 METHOD(task_manager_t
, retransmit
, status_t
,
230 private_task_manager_t
*this, u_int32_t message_seqnr
)
232 /* this.initiating packet used as marker for received response */
233 if (message_seqnr
== this->initiating
.seqnr
&& this->initiating
.packet
)
239 if (this->initiating
.retransmitted
<= this->retransmit_tries
)
241 timeout
= (u_int32_t
)(this->retransmit_timeout
* 1000.0 *
242 pow(this->retransmit_base
, this->initiating
.retransmitted
));
246 DBG1(DBG_IKE
, "giving up after %d retransmits",
247 this->initiating
.retransmitted
- 1);
248 if (this->ike_sa
->get_state(this->ike_sa
) != IKE_CONNECTING
)
250 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
255 if (this->initiating
.retransmitted
)
257 DBG1(DBG_IKE
, "retransmit %d of request with message ID %u seqnr (%d)",
258 this->initiating
.retransmitted
, this->initiating
.mid
, message_seqnr
);
260 packet
= this->initiating
.packet
->clone(this->initiating
.packet
);
261 charon
->sender
->send(charon
->sender
, packet
);
263 this->initiating
.retransmitted
++;
264 job
= (job_t
*)retransmit_job_create(this->initiating
.seqnr
,
265 this->ike_sa
->get_id(this->ike_sa
));
266 lib
->scheduler
->schedule_job_ms(lib
->scheduler
, job
, timeout
);
271 METHOD(task_manager_t
, initiate
, status_t
,
272 private_task_manager_t
*this)
274 enumerator_t
*enumerator
;
279 exchange_type_t exchange
= EXCHANGE_TYPE_UNDEFINED
;
280 bool new_mid
= FALSE
, expect_response
= FALSE
, flushed
= FALSE
;
284 DBG1(DBG_IKE
, "no RNG supported");
288 if (this->initiating
.type
!= EXCHANGE_TYPE_UNDEFINED
)
290 DBG2(DBG_IKE
, "delaying task initiation, %N exchange in progress",
291 exchange_type_names
, this->initiating
.type
);
292 /* do not initiate if we already have a message in the air */
296 if (this->active_tasks
->get_count(this->active_tasks
) == 0)
298 DBG2(DBG_IKE
, "activating new tasks");
299 switch (this->ike_sa
->get_state(this->ike_sa
))
302 activate_task(this, TASK_VENDOR_V1
);
303 activate_task(this, TASK_ISAKMP_CERT_PRE
);
304 if (activate_task(this, TASK_MAIN_MODE
))
307 activate_task(this, TASK_ISAKMP_CERT_POST
);
308 activate_task(this, TASK_IKE_NATD_V1
);
312 if (activate_task(this, TASK_ISAKMP_DELETE
))
314 exchange
= INFORMATIONAL_V1
;
318 if (activate_task(this, TASK_XAUTH
))
320 exchange
= TRANSACTION
;
324 if (activate_task(this, TASK_INFORMATIONAL
))
326 exchange
= INFORMATIONAL_V1
;
331 case IKE_ESTABLISHED
:
332 if (activate_task(this, TASK_MODE_CONFIG
))
334 exchange
= TRANSACTION
;
338 if (activate_task(this, TASK_QUICK_MODE
))
340 exchange
= QUICK_MODE
;
344 if (activate_task(this, TASK_INFORMATIONAL
))
346 exchange
= INFORMATIONAL_V1
;
350 if (activate_task(this, TASK_ISAKMP_DELETE
))
352 exchange
= INFORMATIONAL_V1
;
356 if (activate_task(this, TASK_QUICK_DELETE
))
358 exchange
= INFORMATIONAL_V1
;
369 DBG2(DBG_IKE
, "reinitiating already active tasks");
370 enumerator
= this->active_tasks
->create_enumerator(this->active_tasks
);
371 while (enumerator
->enumerate(enumerator
, (void**)&task
))
373 DBG2(DBG_IKE
, " %N task", task_type_names
, task
->get_type(task
));
374 switch (task
->get_type(task
))
379 case TASK_QUICK_MODE
:
380 exchange
= QUICK_MODE
;
383 exchange
= TRANSACTION
;
391 enumerator
->destroy(enumerator
);
394 if (exchange
== EXCHANGE_TYPE_UNDEFINED
)
396 DBG2(DBG_IKE
, "nothing to initiate");
397 /* nothing to do yet... */
401 me
= this->ike_sa
->get_my_host(this->ike_sa
);
402 other
= this->ike_sa
->get_other_host(this->ike_sa
);
404 message
= message_create(IKEV1_MAJOR_VERSION
, IKEV1_MINOR_VERSION
);
407 this->rng
->get_bytes(this->rng
, sizeof(this->initiating
.mid
),
408 (void*)&this->initiating
.mid
);
410 message
->set_message_id(message
, this->initiating
.mid
);
411 message
->set_source(message
, me
->clone(me
));
412 message
->set_destination(message
, other
->clone(other
));
413 message
->set_exchange_type(message
, exchange
);
414 this->initiating
.type
= exchange
;
415 this->initiating
.retransmitted
= 0;
417 enumerator
= this->active_tasks
->create_enumerator(this->active_tasks
);
418 while (enumerator
->enumerate(enumerator
, (void*)&task
))
420 switch (task
->build(task
, message
))
423 /* task completed, remove it */
424 this->active_tasks
->remove_at(this->active_tasks
, enumerator
);
428 expect_response
= TRUE
;
429 /* processed, but task needs another exchange */
432 flush_queue(this, this->active_tasks
);
437 if (this->ike_sa
->get_state(this->ike_sa
) != IKE_CONNECTING
)
439 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
443 /* critical failure, destroy IKE_SA */
444 enumerator
->destroy(enumerator
);
445 message
->destroy(message
);
451 enumerator
->destroy(enumerator
);
453 if (this->active_tasks
->get_count(this->active_tasks
) == 0)
454 { /* tasks completed, no exchange active anymore */
455 this->initiating
.type
= EXCHANGE_TYPE_UNDEFINED
;
459 message
->destroy(message
);
460 return initiate(this);
462 this->initiating
.seqnr
++;
464 status
= this->ike_sa
->generate_message(this->ike_sa
, message
,
465 &this->initiating
.packet
);
466 if (status
!= SUCCESS
)
468 /* message generation failed. There is nothing more to do than to
470 message
->destroy(message
);
472 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
475 message
->destroy(message
);
479 return retransmit(this, this->initiating
.seqnr
);
481 charon
->sender
->send(charon
->sender
,
482 this->initiating
.packet
->clone(this->initiating
.packet
));
483 this->initiating
.packet
->destroy(this->initiating
.packet
);
484 this->initiating
.packet
= NULL
;
486 if (exchange
== INFORMATIONAL_V1
)
488 switch (this->ike_sa
->get_state(this->ike_sa
))
491 /* close after sending an INFORMATIONAL when unestablished */
494 /* close after sending a DELETE */
504 * handle exchange collisions
506 static bool handle_collisions(private_task_manager_t
*this, task_t
*task
)
512 * build a response depending on the "passive" task list
514 static status_t
build_response(private_task_manager_t
*this, message_t
*request
)
516 enumerator_t
*enumerator
;
520 bool delete = FALSE
, flushed
= FALSE
;
523 me
= request
->get_destination(request
);
524 other
= request
->get_source(request
);
526 message
= message_create(IKEV1_MAJOR_VERSION
, IKEV1_MINOR_VERSION
);
527 message
->set_exchange_type(message
, request
->get_exchange_type(request
));
528 /* send response along the path the request came in */
529 message
->set_source(message
, me
->clone(me
));
530 message
->set_destination(message
, other
->clone(other
));
531 message
->set_message_id(message
, request
->get_message_id(request
));
532 message
->set_request(message
, FALSE
);
534 enumerator
= this->passive_tasks
->create_enumerator(this->passive_tasks
);
535 while (enumerator
->enumerate(enumerator
, (void*)&task
))
537 switch (task
->build(task
, message
))
540 /* task completed, remove it */
541 this->passive_tasks
->remove_at(this->passive_tasks
, enumerator
);
542 if (!handle_collisions(this, task
))
548 /* processed, but task needs another exchange */
549 if (handle_collisions(this, task
))
551 this->passive_tasks
->remove_at(this->passive_tasks
,
556 flush_queue(this, this->passive_tasks
);
561 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
564 /* destroy IKE_SA, but SEND response first */
570 enumerator
->destroy(enumerator
);
572 DESTROY_IF(this->responding
.packet
);
573 this->responding
.packet
= NULL
;
576 message
->destroy(message
);
577 return initiate(this);
579 status
= this->ike_sa
->generate_message(this->ike_sa
, message
,
580 &this->responding
.packet
);
581 message
->destroy(message
);
582 if (status
!= SUCCESS
)
584 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
588 charon
->sender
->send(charon
->sender
,
589 this->responding
.packet
->clone(this->responding
.packet
));
598 * Send a notify in a separate INFORMATIONAL exchange back to the sender.
599 * The notify protocol_id is set to ISAKMP
601 static void send_notify(private_task_manager_t
*this, message_t
*request
,
609 if (request
&& request
->get_exchange_type(request
) == INFORMATIONAL_V1
)
610 { /* don't respond to INFORMATIONAL requests to avoid a notify war */
611 DBG1(DBG_IKE
, "ignore malformed INFORMATIONAL request");
615 response
= message_create(IKEV1_MAJOR_VERSION
, IKEV1_MINOR_VERSION
);
616 response
->set_exchange_type(response
, INFORMATIONAL_V1
);
617 response
->set_request(response
, TRUE
);
618 this->rng
->get_bytes(this->rng
, sizeof(mid
), (void*)&mid
);
619 response
->set_message_id(response
, mid
);
620 response
->add_payload(response
, (payload_t
*)
621 notify_payload_create_from_protocol_and_type(NOTIFY_V1
,
624 me
= this->ike_sa
->get_my_host(this->ike_sa
);
625 if (me
->is_anyaddr(me
))
627 me
= request
->get_destination(request
);
628 this->ike_sa
->set_my_host(this->ike_sa
, me
->clone(me
));
630 other
= this->ike_sa
->get_other_host(this->ike_sa
);
631 if (other
->is_anyaddr(other
))
633 other
= request
->get_source(request
);
634 this->ike_sa
->set_other_host(this->ike_sa
, other
->clone(other
));
636 response
->set_source(response
, me
->clone(me
));
637 response
->set_destination(response
, other
->clone(other
));
638 if (this->ike_sa
->generate_message(this->ike_sa
, response
,
641 charon
->sender
->send(charon
->sender
, packet
);
643 response
->destroy(response
);
647 * handle an incoming request message
649 static status_t
process_request(private_task_manager_t
*this,
652 enumerator_t
*enumerator
;
654 bool send_response
= FALSE
;
656 if (this->passive_tasks
->get_count(this->passive_tasks
) == 0)
657 { /* create tasks depending on request type, if not already some queued */
658 switch (message
->get_exchange_type(message
))
661 task
= (task_t
*)ike_vendor_v1_create(this->ike_sa
, FALSE
);
662 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
663 task
= (task_t
*)isakmp_cert_pre_create(this->ike_sa
, FALSE
);
664 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
665 task
= (task_t
*)main_mode_create(this->ike_sa
, FALSE
);
666 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
667 task
= (task_t
*)isakmp_cert_post_create(this->ike_sa
, FALSE
);
668 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
669 task
= (task_t
*)ike_natd_v1_create(this->ike_sa
, FALSE
);
670 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
673 /* TODO-IKEv1: agressive mode */
676 if (this->ike_sa
->get_state(this->ike_sa
) != IKE_ESTABLISHED
)
678 DBG1(DBG_IKE
, "received quick mode request for "
679 "unestablished IKE_SA, ignored");
682 task
= (task_t
*)quick_mode_create(this->ike_sa
, NULL
,
684 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
686 case INFORMATIONAL_V1
:
687 task
= (task_t
*)informational_create(this->ike_sa
, NULL
);
688 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
691 if (this->ike_sa
->get_state(this->ike_sa
) == IKE_ESTABLISHED
)
693 task
= (task_t
*)mode_config_create(this->ike_sa
, FALSE
);
697 task
= (task_t
*)xauth_create(this->ike_sa
, FALSE
);
699 this->passive_tasks
->insert_last(this->passive_tasks
, task
);
705 /* let the tasks process the message */
706 enumerator
= this->passive_tasks
->create_enumerator(this->passive_tasks
);
707 while (enumerator
->enumerate(enumerator
, (void*)&task
))
709 switch (task
->process(task
, message
))
712 /* task completed, remove it */
713 this->passive_tasks
->remove_at(this->passive_tasks
, enumerator
);
717 /* processed, but task needs at least another call to build() */
718 send_response
= TRUE
;
721 send_response
= FALSE
;
722 flush_queue(this, this->passive_tasks
);
726 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
729 /* critical failure, destroy IKE_SA */
730 this->passive_tasks
->remove_at(this->passive_tasks
, enumerator
);
731 enumerator
->destroy(enumerator
);
737 enumerator
->destroy(enumerator
);
741 if (build_response(this, message
) != SUCCESS
)
747 { /* We don't send a response, so don't retransmit one if we get
748 * the same message again. */
749 DESTROY_IF(this->responding
.packet
);
750 this->responding
.packet
= NULL
;
752 if (this->passive_tasks
->get_count(this->passive_tasks
) == 0 &&
753 this->queued_tasks
->get_count(this->queued_tasks
) > 0)
755 /* passive tasks completed, check if an active task has been queued,
756 * such as XAUTH or modeconfig push */
757 return initiate(this);
763 * handle an incoming response message
765 static status_t
process_response(private_task_manager_t
*this,
768 enumerator_t
*enumerator
;
772 if (message
->get_exchange_type(message
) != this->initiating
.type
)
774 DBG1(DBG_IKE
, "received %N response, but expected %N",
775 exchange_type_names
, message
->get_exchange_type(message
),
776 exchange_type_names
, this->initiating
.type
);
777 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
781 enumerator
= this->active_tasks
->create_enumerator(this->active_tasks
);
782 while (enumerator
->enumerate(enumerator
, (void*)&task
))
784 switch (task
->process(task
, message
))
787 /* task completed, remove it */
788 this->active_tasks
->remove_at(this->active_tasks
, enumerator
);
792 /* processed, but task needs another exchange */
795 flush_queue(this, this->active_tasks
);
799 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
802 /* critical failure, destroy IKE_SA */
803 this->active_tasks
->remove_at(this->active_tasks
, enumerator
);
804 enumerator
->destroy(enumerator
);
810 enumerator
->destroy(enumerator
);
812 this->initiating
.type
= EXCHANGE_TYPE_UNDEFINED
;
813 this->initiating
.packet
->destroy(this->initiating
.packet
);
814 this->initiating
.packet
= NULL
;
816 if (this->queued
&& this->active_tasks
->get_count(this->active_tasks
) == 0)
818 status
= this->public.task_manager
.process_message(
819 &this->public.task_manager
, this->queued
);
820 this->queued
->destroy(this->queued
);
822 if (status
== DESTROY_ME
)
828 return initiate(this);
832 * Parse the given message and verify that it is valid.
834 static status_t
parse_message(private_task_manager_t
*this, message_t
*msg
)
838 status
= msg
->parse_body(msg
, this->ike_sa
->get_keymat(this->ike_sa
));
840 if (status
!= SUCCESS
)
845 DBG1(DBG_IKE
, "unsupported exchange type");
846 send_notify(this, msg
, INVALID_EXCHANGE_TYPE
);
849 DBG1(DBG_IKE
, "message parsing failed");
850 send_notify(this, msg
, PAYLOAD_MALFORMED
);
853 DBG1(DBG_IKE
, "message verification failed");
854 send_notify(this, msg
, PAYLOAD_MALFORMED
);
857 DBG1(DBG_IKE
, "integrity check failed");
858 send_notify(this, msg
, INVALID_HASH_INFORMATION
);
861 DBG1(DBG_IKE
, "found encrypted message, but no keys available");
862 send_notify(this, msg
, PAYLOAD_MALFORMED
);
866 DBG1(DBG_IKE
, "%N %s with message ID %u processing failed",
867 exchange_type_names
, msg
->get_exchange_type(msg
),
868 msg
->get_request(msg
) ?
"request" : "response",
869 msg
->get_message_id(msg
));
871 if (this->ike_sa
->get_state(this->ike_sa
) == IKE_CREATED
)
872 { /* invalid initiation attempt, close SA */
879 METHOD(task_manager_t
, process_message
, status_t
,
880 private_task_manager_t
*this, message_t
*msg
)
882 u_int32_t hash
, mid
, i
;
886 /* TODO-IKEv1: update hosts more selectively */
887 me
= msg
->get_destination(msg
);
888 other
= msg
->get_source(msg
);
889 mid
= msg
->get_message_id(msg
);
890 hash
= chunk_hash(msg
->get_packet_data(msg
));
891 for (i
= 0; i
< MAX_OLD_HASHES
; i
++)
893 if (this->initiating
.old_hashes
[i
] == hash
)
895 DBG1(DBG_IKE
, "received retransmit of response with ID %u, "
896 "but next request already sent", mid
);
901 if ((mid
&& mid
== this->initiating
.mid
) ||
902 (this->initiating
.mid
== 0 &&
903 msg
->get_exchange_type(msg
) == this->initiating
.type
&&
904 this->active_tasks
->get_count(this->active_tasks
)))
906 msg
->set_request(msg
, FALSE
);
907 status
= parse_message(this, msg
);
908 if (status
!= SUCCESS
)
912 this->ike_sa
->set_statistic(this->ike_sa
, STAT_INBOUND
,
913 time_monotonic(NULL
));
914 this->ike_sa
->update_hosts(this->ike_sa
, me
, other
, TRUE
);
915 charon
->bus
->message(charon
->bus
, msg
, FALSE
);
916 if (process_response(this, msg
) != SUCCESS
)
921 this->initiating
.old_hashes
[(this->initiating
.old_hash_pos
++) %
922 MAX_OLD_HASHES
] = hash
;
926 if (hash
== this->responding
.hash
)
928 if (this->responding
.packet
)
930 DBG1(DBG_IKE
, "received retransmit of request with ID %u, "
931 "retransmitting response", mid
);
932 charon
->sender
->send(charon
->sender
,
933 this->responding
.packet
->clone(this->responding
.packet
));
937 DBG1(DBG_IKE
, "received retransmit of request with ID %u, "
938 "but no response to retransmit", mid
);
942 if (msg
->get_exchange_type(msg
) == TRANSACTION
&&
943 this->active_tasks
->get_count(this->active_tasks
))
944 { /* main mode not yet complete, queue XAuth/Mode config tasks */
947 DBG1(DBG_IKE
, "ignoring additional %N request, queue full",
948 exchange_type_names
, TRANSACTION
);
951 this->queued
= message_create_from_packet(msg
->get_packet(msg
));
952 if (this->queued
->parse_header(this->queued
) != SUCCESS
)
954 this->queued
->destroy(this->queued
);
958 DBG1(DBG_IKE
, "queueing %N request as tasks still active",
959 exchange_type_names
, TRANSACTION
);
963 msg
->set_request(msg
, TRUE
);
964 status
= parse_message(this, msg
);
965 if (status
!= SUCCESS
)
969 /* if this IKE_SA is virgin, we check for a config */
970 if (this->ike_sa
->get_ike_cfg(this->ike_sa
) == NULL
)
972 ike_sa_id_t
*ike_sa_id
;
975 ike_cfg
= charon
->backends
->get_ike_cfg(charon
->backends
, me
, other
);
978 /* no config found for these hosts, destroy */
979 DBG1(DBG_IKE
, "no IKE config found for %H...%H, sending %N",
980 me
, other
, notify_type_names
, NO_PROPOSAL_CHOSEN
);
981 send_notify(this, msg
, NO_PROPOSAL_CHOSEN
);
984 this->ike_sa
->set_ike_cfg(this->ike_sa
, ike_cfg
);
985 ike_cfg
->destroy(ike_cfg
);
986 /* add a timeout if peer does not establish it completely */
987 ike_sa_id
= this->ike_sa
->get_id(this->ike_sa
);
988 job
= (job_t
*)delete_ike_sa_job_create(ike_sa_id
, FALSE
);
989 lib
->scheduler
->schedule_job(lib
->scheduler
, job
,
990 lib
->settings
->get_int(lib
->settings
,
991 "charon.half_open_timeout", HALF_OPEN_IKE_SA_TIMEOUT
));
993 this->ike_sa
->set_statistic(this->ike_sa
, STAT_INBOUND
,
994 time_monotonic(NULL
));
995 this->ike_sa
->update_hosts(this->ike_sa
, me
, other
, TRUE
);
996 charon
->bus
->message(charon
->bus
, msg
, TRUE
);
997 if (process_request(this, msg
) != SUCCESS
)
1002 this->responding
.hash
= hash
;
1007 METHOD(task_manager_t
, queue_task
, void,
1008 private_task_manager_t
*this, task_t
*task
)
1010 DBG2(DBG_IKE
, "queueing %N task", task_type_names
, task
->get_type(task
));
1011 this->queued_tasks
->insert_last(this->queued_tasks
, task
);
1014 METHOD(task_manager_t
, adopt_tasks
, void,
1015 private_task_manager_t
*this, task_manager_t
*other_public
)
1017 private_task_manager_t
*other
= (private_task_manager_t
*)other_public
;
1020 /* move queued tasks from other to this */
1021 while (other
->queued_tasks
->remove_last(other
->queued_tasks
,
1022 (void**)&task
) == SUCCESS
)
1024 DBG2(DBG_IKE
, "migrating %N task", task_type_names
, task
->get_type(task
));
1025 task
->migrate(task
, this->ike_sa
);
1026 this->queued_tasks
->insert_first(this->queued_tasks
, task
);
1030 METHOD(task_manager_t
, busy
, bool,
1031 private_task_manager_t
*this)
1033 return (this->active_tasks
->get_count(this->active_tasks
) > 0);
1036 METHOD(task_manager_t
, incr_mid
, void,
1037 private_task_manager_t
*this, bool initiate
)
1041 METHOD(task_manager_t
, reset
, void,
1042 private_task_manager_t
*this, u_int32_t initiate
, u_int32_t respond
)
1046 METHOD(task_manager_t
, create_task_enumerator
, enumerator_t
*,
1047 private_task_manager_t
*this, task_queue_t queue
)
1051 case TASK_QUEUE_ACTIVE
:
1052 return this->active_tasks
->create_enumerator(this->active_tasks
);
1053 case TASK_QUEUE_PASSIVE
:
1054 return this->passive_tasks
->create_enumerator(this->passive_tasks
);
1055 case TASK_QUEUE_QUEUED
:
1056 return this->queued_tasks
->create_enumerator(this->queued_tasks
);
1058 return enumerator_create_empty();
1062 METHOD(task_manager_t
, destroy
, void,
1063 private_task_manager_t
*this)
1067 this->active_tasks
->destroy(this->active_tasks
);
1068 this->queued_tasks
->destroy(this->queued_tasks
);
1069 this->passive_tasks
->destroy(this->passive_tasks
);
1071 DESTROY_IF(this->queued
);
1072 DESTROY_IF(this->responding
.packet
);
1073 DESTROY_IF(this->initiating
.packet
);
1074 DESTROY_IF(this->rng
);
1081 task_manager_v1_t
*task_manager_v1_create(ike_sa_t
*ike_sa
)
1083 private_task_manager_t
*this;
1088 .process_message
= _process_message
,
1089 .queue_task
= _queue_task
,
1090 .initiate
= _initiate
,
1091 .retransmit
= _retransmit
,
1092 .incr_mid
= _incr_mid
,
1094 .adopt_tasks
= _adopt_tasks
,
1096 .create_task_enumerator
= _create_task_enumerator
,
1097 .destroy
= _destroy
,
1101 .initiating
.type
= EXCHANGE_TYPE_UNDEFINED
,
1102 .rng
= lib
->crypto
->create_rng(lib
->crypto
, RNG_WEAK
),
1103 .queued_tasks
= linked_list_create(),
1104 .active_tasks
= linked_list_create(),
1105 .passive_tasks
= linked_list_create(),
1106 .retransmit_tries
= lib
->settings
->get_int(lib
->settings
,
1107 "charon.retransmit_tries", RETRANSMIT_TRIES
),
1108 .retransmit_timeout
= lib
->settings
->get_double(lib
->settings
,
1109 "charon.retransmit_timeout", RETRANSMIT_TIMEOUT
),
1110 .retransmit_base
= lib
->settings
->get_double(lib
->settings
,
1111 "charon.retransmit_base", RETRANSMIT_BASE
),
1114 return &this->public;