refactored connect_manager_t to use the find functions on linked lists
[strongswan.git] / src / charon / sa / connect_manager.c
1 /**
2 * @file connect_manager.c
3 *
4 * @brief Implementation of connect_manager_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2007 Tobias Brunner
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 "connect_manager.h"
24
25 #include <pthread.h>
26 #include <math.h>
27
28 #include <daemon.h>
29 #include <utils/linked_list.h>
30 #include <crypto/hashers/hasher.h>
31
32 #include <processing/jobs/callback_job.h>
33 #include <processing/jobs/initiate_mediation_job.h>
34 #include <encoding/payloads/endpoint_notify.h>
35
36 /* base timeout
37 * the sending interval is P2P_INTERVAL * active checklists (N)
38 * retransmission timeout is P2P_INTERVAL * N * checks in waiting state (NW) */
39 #define P2P_INTERVAL 20 /* ms */
40 /* min retransmission timeout (RTO is P2P_INTERVAL * N * checks in waiting state) */
41 #define P2P_RTO_MIN 100 /* ms */
42 /* max number of retransmissions (+ the initial check) */
43 #define P2P_MAX_RETRANS 2
44
45
46 typedef struct private_connect_manager_t private_connect_manager_t;
47
48 /**
49 * Additional private members of connect_manager_t.
50 */
51 struct private_connect_manager_t {
52 /**
53 * Public interface of connect_manager_t.
54 */
55 connect_manager_t public;
56
57 /**
58 * Lock for exclusivly accessing the manager.
59 */
60 pthread_mutex_t mutex;
61
62 /**
63 * Hasher to generate signatures
64 */
65 hasher_t *hasher;
66
67 /**
68 * Linked list with initiated mediated connections
69 */
70 linked_list_t *initiated;
71
72 /**
73 * Linked list with checklists (hash table with session ID as key would be better).
74 */
75 linked_list_t *checklists;
76 };
77
78 typedef enum check_state_t check_state_t;
79
80 enum check_state_t {
81 CHECK_NONE,
82 CHECK_WAITING,
83 CHECK_IN_PROGRESS,
84 CHECK_SUCCEEDED,
85 CHECK_FAILED
86 };
87
88 typedef struct endpoint_pair_t endpoint_pair_t;
89
90 /**
91 * An entry in the check list.
92 */
93 struct endpoint_pair_t {
94 /** pair id */
95 u_int32_t id;
96
97 /** priority */
98 u_int64_t priority;
99
100 /** local endpoint */
101 host_t *local;
102
103 /** remote endpoint */
104 host_t *remote;
105
106 /** state */
107 check_state_t state;
108
109 /** number of retransmissions */
110 u_int32_t retransmitted;
111
112 /** the generated packet */
113 packet_t *packet;
114 };
115
116 /**
117 * Destroys an endpoint pair
118 */
119 static void endpoint_pair_destroy(endpoint_pair_t *this)
120 {
121 DESTROY_IF(this->local);
122 DESTROY_IF(this->remote);
123 DESTROY_IF(this->packet);
124 free(this);
125 }
126
127 /**
128 * Creates a new entry for the list.
129 */
130 static endpoint_pair_t *endpoint_pair_create(endpoint_notify_t *initiator,
131 endpoint_notify_t *responder, bool initiator_is_local)
132 {
133 endpoint_pair_t *this = malloc_thing(endpoint_pair_t);
134
135 this->id = 0;
136
137 u_int32_t pi = initiator->get_priority(initiator);
138 u_int32_t pr = responder->get_priority(responder);
139 this->priority = pow(2, 32) * min(pi, pr) + 2 * max(pi, pr) + (pi > pr ? 1 : 0);
140
141 this->local = initiator_is_local ? initiator->get_base(initiator) : responder->get_base(responder);
142 this->local = this->local->clone(this->local);
143 this->remote = initiator_is_local ? responder->get_host(responder) : initiator->get_host(initiator);
144 this->remote = this->remote->clone(this->remote);
145
146 this->state = CHECK_WAITING;
147 this->retransmitted = 0;
148 this->packet = NULL;
149
150 return this;
151 }
152
153
154 typedef struct check_list_t check_list_t;
155
156 /**
157 * An entry in the linked list.
158 */
159 struct check_list_t {
160
161 struct {
162 /** initiator's id */
163 identification_t *id;
164
165 /** initiator's key */
166 chunk_t key;
167
168 /** initiator's endpoints */
169 linked_list_t *endpoints;
170 } initiator;
171
172 struct {
173 /** responder's id */
174 identification_t *id;
175
176 /** responder's key */
177 chunk_t key;
178
179 /** responder's endpoints */
180 linked_list_t *endpoints;
181 } responder;
182
183 /** session id */
184 chunk_t session_id;
185
186 /** list of endpoint pairs */
187 linked_list_t *pairs;
188
189 /** pairs queued for triggered checks */
190 linked_list_t *triggered;
191
192 /** state */
193 check_state_t state;
194
195 /** TRUE if this is the initiator */
196 bool is_initiator;
197
198 };
199
200 /**
201 * Destroys a checklist
202 */
203 static void check_list_destroy(check_list_t *this)
204 {
205 DESTROY_IF(this->initiator.id);
206 DESTROY_IF(this->responder.id);
207
208 chunk_free(&this->session_id);
209 chunk_free(&this->initiator.key);
210 chunk_free(&this->responder.key);
211
212 DESTROY_OFFSET_IF(this->initiator.endpoints, offsetof(endpoint_notify_t, destroy));
213 DESTROY_OFFSET_IF(this->responder.endpoints, offsetof(endpoint_notify_t, destroy));
214
215 DESTROY_FUNCTION_IF(this->pairs, (void*)endpoint_pair_destroy);
216 /* this list contains some of the same elements as contained in this->pairs */
217 DESTROY_IF(this->triggered);
218
219 free(this);
220 }
221
222 /**
223 * Creates a new checklist
224 */
225 static check_list_t *check_list_create(identification_t *initiator, identification_t *responder,
226 chunk_t session_id, chunk_t initiator_key, linked_list_t *initiator_endpoints,
227 bool is_initiator)
228 {
229 check_list_t *this = malloc_thing(check_list_t);
230
231 this->session_id = chunk_clone(session_id);
232
233 this->initiator.id = initiator->clone(initiator);
234 this->initiator.key = chunk_clone(initiator_key);
235 this->initiator.endpoints = initiator_endpoints->clone_offset(initiator_endpoints, offsetof(endpoint_notify_t, clone));
236
237 this->responder.id = responder->clone(responder);
238 this->responder.key = chunk_empty;
239 this->responder.endpoints = NULL;
240
241 this->pairs = linked_list_create();
242 this->triggered = linked_list_create();
243 this->state = CHECK_NONE;
244 this->is_initiator = is_initiator;
245
246 return this;
247 }
248
249
250 typedef struct waiting_sa_t waiting_sa_t;
251
252 /**
253 * For an initiator, the data stored about a waiting mediated sa
254 */
255 struct waiting_sa_t {
256 /** ike sa id */
257 ike_sa_id_t *ike_sa_id;
258
259 /** list of child_cfg_t */
260 linked_list_t *childs;
261 };
262
263 /**
264 * Destroys a queued mediated sa
265 */
266 static void waiting_sa_destroy(waiting_sa_t *this)
267 {
268 DESTROY_IF(this->ike_sa_id);
269 this->childs->destroy_offset(this->childs, offsetof(child_cfg_t, destroy));
270 free(this);
271 }
272
273 /**
274 * Creates a new mediated sa object
275 */
276 static waiting_sa_t *waiting_sa_create(ike_sa_id_t *ike_sa_id)
277 {
278 waiting_sa_t *this = malloc_thing(waiting_sa_t);
279
280 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
281 this->childs = linked_list_create();
282
283 return this;
284 }
285
286 typedef struct initiated_t initiated_t;
287
288 /**
289 * For an initiator, the data stored about initiated mediation connections
290 */
291 struct initiated_t {
292 /** my id */
293 identification_t *id;
294
295 /** peer id */
296 identification_t *peer_id;
297
298 /** list of mediated sas */
299 linked_list_t *mediated;
300 };
301
302 /**
303 * Destroys a queued initiation
304 */
305 static void initiated_destroy(initiated_t *this)
306 {
307 DESTROY_IF(this->id);
308 DESTROY_IF(this->peer_id);
309 this->mediated->destroy_function(this->mediated, (void*)waiting_sa_destroy);
310 free(this);
311 }
312
313 /**
314 * Creates a queued initiation
315 */
316 static initiated_t *initiated_create(identification_t *id, identification_t *peer_id)
317 {
318 initiated_t *this = malloc_thing(initiated_t);
319
320 this->id = id->clone(id);
321 this->peer_id = peer_id->clone(peer_id);
322 this->mediated = linked_list_create();
323
324 return this;
325 }
326
327
328 typedef struct check_t check_t;
329
330 /**
331 * Data exchanged in a connectivity check
332 */
333 struct check_t {
334 /** message id */
335 u_int32_t mid;
336
337 /** source of the connectivity check */
338 host_t *src;
339
340 /** destination of the connectivity check */
341 host_t *dst;
342
343 /** session id */
344 chunk_t session_id;
345
346 /** endpoint */
347 endpoint_notify_t *endpoint;
348
349 /** raw endpoint payload (to verify the signature) */
350 chunk_t endpoint_raw;
351
352 /** cookie */
353 chunk_t cookie;
354 };
355
356 /**
357 * Destroys a connectivity check
358 */
359 static void check_destroy(check_t *this)
360 {
361 chunk_free(&this->session_id);
362 chunk_free(&this->endpoint_raw);
363 chunk_free(&this->cookie);
364 DESTROY_IF(this->endpoint);
365 free(this);
366 }
367
368 /**
369 * Creates a new connectivity check
370 */
371 static check_t *check_create()
372 {
373 check_t *this = malloc_thing(check_t);
374
375 this->session_id = chunk_empty;
376 this->cookie = chunk_empty;
377 this->endpoint_raw = chunk_empty;
378 this->endpoint = NULL;
379
380 this->mid = 0;
381
382 return this;
383 }
384
385 typedef struct sender_data_t sender_data_t;
386
387 /**
388 * Data required by the sender
389 */
390 struct sender_data_t {
391 /** connect manager */
392 private_connect_manager_t *connect_manager;
393
394 /** session id */
395 chunk_t session_id;
396 };
397
398 /**
399 * Destroys a sender data object
400 */
401 static void sender_data_destroy(sender_data_t *this)
402 {
403 chunk_free(&this->session_id);
404 free(this);
405 }
406
407 /**
408 * Creates a new sender data object
409 */
410 static sender_data_t *sender_data_create(private_connect_manager_t *connect_manager, chunk_t session_id)
411 {
412 sender_data_t *this = malloc_thing(sender_data_t);
413 this->connect_manager = connect_manager;
414 this->session_id = session_id;
415 return this;
416 }
417
418 typedef struct retransmit_data_t retransmit_data_t;
419
420 /**
421 * Data required by the retransmission job
422 */
423 struct retransmit_data_t {
424 /** connect manager */
425 private_connect_manager_t *connect_manager;
426
427 /** session id */
428 chunk_t session_id;
429
430 /** message (pair) id */
431 u_int32_t mid;
432 };
433
434 /**
435 * Destroys a retransmission data object
436 */
437 static void retransmit_data_destroy(retransmit_data_t *this)
438 {
439 chunk_free(&this->session_id);
440 free(this);
441 }
442
443 /**
444 * Creates a new retransmission data object
445 */
446 static retransmit_data_t *retransmit_data_create(private_connect_manager_t *connect_manager,
447 chunk_t session_id, u_int32_t mid)
448 {
449 retransmit_data_t *this = malloc_thing(retransmit_data_t);
450
451 this->connect_manager = connect_manager;
452 this->session_id = session_id;
453 this->mid = mid;
454
455 return this;
456 }
457
458 typedef struct initiate_data_t initiate_data_t;
459
460 /**
461 * Data required by the initiate mediated
462 */
463 struct initiate_data_t {
464 /** checklist */
465 check_list_t *checklist;
466
467 /** waiting mediated connections */
468 initiated_t *initiated;
469 };
470
471 /**
472 * Destroys a initiate data object
473 */
474 static void initiate_data_destroy(initiate_data_t *this)
475 {
476 check_list_destroy(this->checklist);
477 initiated_destroy(this->initiated);
478 free(this);
479 }
480
481 /**
482 * Creates a new initiate data object
483 */
484 static initiate_data_t *initiate_data_create(check_list_t *checklist, initiated_t *initiated)
485 {
486 initiate_data_t *this = malloc_thing(initiate_data_t);
487
488 this->checklist = checklist;
489 this->initiated = initiated;
490
491 return this;
492 }
493
494 /**
495 * Find an initiated connection by the peers' ids
496 */
497 static bool match_initiated_by_ids(initiated_t *current, identification_t *id,
498 identification_t *peer_id)
499 {
500 return id->equals(id, current->id) && peer_id->equals(peer_id, current->peer_id);
501 }
502
503 static status_t get_initiated_by_ids(private_connect_manager_t *this,
504 identification_t *id, identification_t *peer_id, initiated_t **initiated)
505 {
506 return this->initiated->find_first(this->initiated,
507 (linked_list_match_t)match_initiated_by_ids,
508 (void**)initiated, id, peer_id);
509 }
510
511 /**
512 * Removes data about initiated connections
513 */
514 static void remove_initiated(private_connect_manager_t *this, initiated_t *initiated)
515 {
516 iterator_t *iterator;
517 initiated_t *current;
518
519 iterator = this->initiated->create_iterator(this->initiated, TRUE);
520 while (iterator->iterate(iterator, (void**)&current))
521 {
522 if (current == initiated)
523 {
524 iterator->remove(iterator);
525 break;
526 }
527 }
528 iterator->destroy(iterator);
529 }
530
531 /**
532 * Finds a waiting sa
533 */
534 static bool match_waiting_sa(waiting_sa_t *current, ike_sa_id_t *ike_sa_id)
535 {
536 return ike_sa_id->equals(ike_sa_id, current->ike_sa_id);
537 }
538
539 static status_t get_waiting_sa(initiated_t *initiated, ike_sa_id_t *ike_sa_id, waiting_sa_t **waiting_sa)
540 {
541 return initiated->mediated->find_first(initiated->mediated,
542 (linked_list_match_t)match_waiting_sa,
543 (void**)waiting_sa, ike_sa_id);
544 }
545
546 /**
547 * Find the checklist with a specific session ID
548 */
549 static bool match_checklist_by_id(check_list_t *current, chunk_t *session_id)
550 {
551 return chunk_equals(*session_id, current->session_id);
552 }
553
554 static status_t get_checklist_by_id(private_connect_manager_t *this,
555 chunk_t session_id, check_list_t **check_list)
556 {
557 return this->checklists->find_first(this->checklists,
558 (linked_list_match_t)match_checklist_by_id,
559 (void**)check_list, &session_id);
560 }
561
562 /**
563 * Removes a checklist
564 */
565 static void remove_checklist(private_connect_manager_t *this, check_list_t *checklist)
566 {
567 iterator_t *iterator;
568 check_list_t *current;
569
570 iterator = this->checklists->create_iterator(this->checklists, TRUE);
571 while (iterator->iterate(iterator, (void**)&current))
572 {
573 if (current == checklist)
574 {
575 iterator->remove(iterator);
576 break;
577 }
578 }
579 iterator->destroy(iterator);
580 }
581
582 /**
583 * Checks if a list of endpoint_notify_t contains a certain host_t
584 */
585 static bool match_endpoint_by_host(endpoint_notify_t *current, host_t *host)
586 {
587 return host->equals(host, current->get_host(current));
588 }
589
590 static status_t endpoints_contain(linked_list_t *endpoints, host_t *host, endpoint_notify_t **endpoint)
591 {
592 return endpoints->find_first(endpoints,
593 (linked_list_match_t)match_endpoint_by_host,
594 (void**)endpoint, host);
595 }
596
597 /**
598 * Updates the state of the whole checklist
599 */
600 static void update_checklist_state(check_list_t *checklist)
601 {
602 iterator_t *iterator;
603 endpoint_pair_t *current;
604 bool in_progress = FALSE, succeeded = FALSE;
605
606 iterator = checklist->pairs->create_iterator(checklist->pairs, TRUE);
607 while (iterator->iterate(iterator, (void**)&current))
608 {
609 switch(current->state)
610 {
611 case CHECK_WAITING:
612 /* at least one is still waiting -> checklist remains
613 * in waiting state */
614 iterator->destroy(iterator);
615 return;
616 case CHECK_IN_PROGRESS:
617 in_progress = TRUE;
618 break;
619 case CHECK_SUCCEEDED:
620 succeeded = TRUE;
621 break;
622 default:
623 break;
624 }
625 }
626 iterator->destroy(iterator);
627
628 if (in_progress)
629 {
630 checklist->state = CHECK_IN_PROGRESS;
631 }
632 else if (succeeded)
633 {
634 checklist->state = CHECK_SUCCEEDED;
635 }
636 else
637 {
638 checklist->state = CHECK_FAILED;
639 }
640 }
641
642 /**
643 * Inserts an endpoint pair into the list of pairs ordered by priority (high to low)
644 */
645 static void insert_pair_by_priority(linked_list_t *pairs, endpoint_pair_t *pair)
646 {
647 iterator_t *iterator;
648 endpoint_pair_t *current;
649 bool inserted = FALSE;
650
651 iterator = pairs->create_iterator(pairs, TRUE);
652 while (iterator->iterate(iterator, (void**)&current))
653 {
654 if (current->priority < pair->priority)
655 {
656 iterator->insert_before(iterator, pair);
657 inserted = TRUE;
658 break;
659 }
660 }
661 iterator->destroy(iterator);
662
663 if (!inserted)
664 {
665 pairs->insert_last(pairs, pair);
666 }
667 }
668
669 /**
670 * Searches a list of endpoint_pair_t for a pair with specific host_ts
671 */
672 static bool match_pair_by_hosts(endpoint_pair_t *current, host_t *local, host_t *remote)
673 {
674 return local->equals(local, current->local) && remote->equals(remote, current->remote);
675 }
676
677 static status_t get_pair_by_hosts(linked_list_t *pairs, host_t *local, host_t *remote, endpoint_pair_t **pair)
678 {
679 return pairs->find_first(pairs,
680 (linked_list_match_t)match_pair_by_hosts,
681 (void**)pair, local, remote);
682 }
683
684 /**
685 * Searches for a pair with a specific id
686 */
687 static bool match_pair_by_id(endpoint_pair_t *current, u_int32_t *id)
688 {
689 return current->id == *id;
690 }
691
692 static status_t get_pair_by_id(check_list_t *checklist, u_int32_t id, endpoint_pair_t **pair)
693 {
694 return checklist->pairs->find_first(checklist->pairs,
695 (linked_list_match_t)match_pair_by_id,
696 (void**)pair, &id);
697 }
698
699 /**
700 * Returns the best pair of state CHECK_SUCCEEDED from a checklist.
701 */
702 static bool match_succeeded_pair(endpoint_pair_t *current)
703 {
704 return current->state == CHECK_SUCCEEDED;
705 }
706
707 static status_t get_best_valid_pair(check_list_t *checklist, endpoint_pair_t **pair)
708 {
709 return checklist->pairs->find_first(checklist->pairs,
710 (linked_list_match_t)match_succeeded_pair,
711 (void**)pair);
712 }
713
714 /**
715 * Returns and *removes* the first triggered pair in state CHECK_WAITING.
716 */
717 static bool match_waiting_pair(endpoint_pair_t *current)
718 {
719 return current->state == CHECK_WAITING;
720 }
721
722 static status_t get_triggered_pair(check_list_t *checklist, endpoint_pair_t **pair)
723 {
724 iterator_t *iterator;
725 endpoint_pair_t *current;
726 status_t status = NOT_FOUND;
727
728 iterator = checklist->triggered->create_iterator(checklist->triggered, TRUE);
729 while (iterator->iterate(iterator, (void**)&current))
730 {
731 iterator->remove(iterator);
732
733 if (current->state == CHECK_WAITING)
734 {
735 if (pair)
736 {
737 *pair = current;
738 }
739 status = SUCCESS;
740 break;
741 }
742 }
743 iterator->destroy(iterator);
744
745 return status;
746 }
747
748 /**
749 * Prunes identical pairs with lower priority from the list
750 * Note: this function also numbers the remaining pairs serially
751 */
752 static void prune_pairs(linked_list_t *pairs)
753 {
754 iterator_t *iterator, *search;
755 endpoint_pair_t *current, *other;
756 u_int32_t id = 0;
757
758 iterator = pairs->create_iterator(pairs, TRUE);
759 search = pairs->create_iterator(pairs, TRUE);
760 while (iterator->iterate(iterator, (void**)&current))
761 {
762 current->id = ++id;
763
764 while (search->iterate(search, (void**)&other))
765 {
766 if (current == other)
767 {
768 continue;
769 }
770
771 if (current->local->equals(current->local, other->local) &&
772 current->remote->equals(current->remote, other->remote))
773 {
774 /* since the list of pairs is sorted by priority in descending
775 * order, and we iterate the list from the beginning, we are
776 * sure that the priority of 'other' is lower than that of
777 * 'current', remove it */
778 DBG1(DBG_IKE, "pruning endpoint pair %H - %H with priority %d",
779 other->local, other->remote, other->priority);
780 search->remove(search);
781 endpoint_pair_destroy(other);
782 }
783 }
784 search->reset(search);
785 }
786 search->destroy(search);
787 iterator->destroy(iterator);
788 }
789
790 /**
791 * Builds a list of endpoint pairs
792 */
793 static void build_pairs(check_list_t *checklist)
794 {
795 iterator_t *iterator_i, *iterator_r;
796 endpoint_notify_t *initiator, *responder;
797
798 iterator_i = checklist->initiator.endpoints->create_iterator(checklist->initiator.endpoints, TRUE);
799 while (iterator_i->iterate(iterator_i, (void**)&initiator))
800 {
801 iterator_r = checklist->responder.endpoints->create_iterator(checklist->responder.endpoints, TRUE);
802 while (iterator_r->iterate(iterator_r, (void**)&responder))
803 {
804 if (initiator->get_family(initiator) != responder->get_family(responder))
805 {
806 continue;
807 }
808
809 insert_pair_by_priority(checklist->pairs,
810 endpoint_pair_create(initiator, responder, checklist->is_initiator));
811 }
812 iterator_r->destroy(iterator_r);
813 }
814 iterator_i->destroy(iterator_i);
815
816 prune_pairs(checklist->pairs);
817 }
818
819 /**
820 * Processes the payloads of a connectivity check and returns the extracted data
821 */
822 static status_t process_payloads(message_t *message, check_t *check)
823 {
824 iterator_t *iterator;
825 payload_t *payload;
826
827 iterator = message->get_payload_iterator(message);
828 while (iterator->iterate(iterator, (void**)&payload))
829 {
830 if (payload->get_type(payload) != NOTIFY)
831 {
832 DBG1(DBG_IKE, "ignoring payload of type '%N' while processing "
833 "connectivity check", payload_type_names, payload->get_type(payload));
834 continue;
835 }
836
837 notify_payload_t *notify = (notify_payload_t*)payload;
838
839 switch (notify->get_notify_type(notify))
840 {
841 case P2P_ENDPOINT:
842 {
843 if (check->endpoint)
844 {
845 DBG1(DBG_IKE, "connectivity check contains multiple P2P_ENDPOINT notifies");
846 break;
847 }
848
849 endpoint_notify_t *endpoint = endpoint_notify_create_from_payload(notify);
850 if (!endpoint)
851 {
852 DBG1(DBG_IKE, "received invalid P2P_ENDPOINT notify");
853 break;
854 }
855 check->endpoint = endpoint;
856 check->endpoint_raw = chunk_clone(notify->get_notification_data(notify));
857 DBG2(DBG_IKE, "received P2P_ENDPOINT notify");
858 break;
859 }
860 case P2P_SESSIONID:
861 {
862 if (check->session_id.ptr)
863 {
864 DBG1(DBG_IKE, "connectivity check contains multiple P2P_SESSIONID notifies");
865 break;
866 }
867 check->session_id = chunk_clone(notify->get_notification_data(notify));
868 DBG3(DBG_IKE, "received p2p_sessionid %B", &check->session_id);
869 break;
870 }
871 case COOKIE:
872 {
873 if (check->cookie.ptr)
874 {
875 DBG1(DBG_IKE, "connectivity check contains multiple COOKIE notifies");
876 break;
877 }
878 check->cookie = chunk_clone(notify->get_notification_data(notify));
879 DBG3(DBG_IKE, "received cookie %B", &check->cookie);
880 break;
881 }
882 default:
883 break;
884 }
885 }
886 iterator->destroy(iterator);
887
888 if (!check->session_id.ptr || !check->endpoint || !check->cookie.ptr)
889 {
890 DBG1(DBG_IKE, "at least one payload was missing from the connectivity check");
891 return FAILED;
892 }
893
894 return SUCCESS;
895 }
896
897 /**
898 * Builds the signature for a connectivity check
899 */
900 static chunk_t build_signature(private_connect_manager_t *this,
901 check_list_t *checklist, check_t *check, bool outbound)
902 {
903 chunk_t mid_chunk, key_chunk, sig_chunk;
904 chunk_t sig_hash;
905
906 mid_chunk = chunk_from_thing(check->mid);
907
908 key_chunk = (checklist->is_initiator && outbound) || (!checklist->is_initiator && !outbound)
909 ? checklist->initiator.key : checklist->responder.key;
910
911 /* signature = SHA1( MID | P2P_SESSIONID | P2P_ENDPOINT | P2P_SESSIONKEY ) */
912 sig_chunk = chunk_cat("cccc", mid_chunk, check->session_id, check->endpoint_raw, key_chunk);
913 this->hasher->allocate_hash(this->hasher, sig_chunk, &sig_hash);
914 DBG3(DBG_IKE, "sig_chunk %B", &sig_chunk);
915 DBG3(DBG_IKE, "sig_hash %B", &sig_hash);
916
917 chunk_free(&sig_chunk);
918 return sig_hash;
919 }
920
921 static void queue_retransmission(private_connect_manager_t *this, chunk_t session_id, u_int32_t mid);
922 static void schedule_checks(private_connect_manager_t *this, check_list_t *checklist, u_int32_t time);
923 static void finish_checks(private_connect_manager_t *this, check_list_t *checklist);
924
925 /**
926 * This function is triggered for each sent check after a specific timeout
927 */
928 static job_requeue_t retransmit(retransmit_data_t *data)
929 {
930 private_connect_manager_t *this = data->connect_manager;
931
932 pthread_mutex_lock(&(this->mutex));
933
934 check_list_t *checklist;
935 if (get_checklist_by_id(this, data->session_id, &checklist) != SUCCESS)
936 {
937 DBG1(DBG_IKE, "checklist with id '%B' not found, can't retransmit connectivity check",
938 &data->session_id);
939 pthread_mutex_unlock(&(this->mutex));
940 return JOB_REQUEUE_NONE;
941 }
942
943 endpoint_pair_t *pair;
944 if (get_pair_by_id(checklist, data->mid, &pair) != SUCCESS)
945 {
946 DBG1(DBG_IKE, "pair with id '%d' not found, can't retransmit connectivity check",
947 data->mid);
948 goto retransmit_end;
949 }
950
951 if (pair->state != CHECK_IN_PROGRESS)
952 {
953 DBG2(DBG_IKE, "pair with id '%d' is in wrong state [%d], don't retransmit the connectivity check",
954 data->mid, pair->state);
955 goto retransmit_end;
956 }
957
958 if (++pair->retransmitted >= P2P_MAX_RETRANS)
959 {
960 DBG2(DBG_IKE, "pair with id '%d' failed after %d tries",
961 data->mid, pair->retransmitted);
962 pair->state = CHECK_FAILED;
963 goto retransmit_end;
964 }
965
966 charon->sender->send(charon->sender, pair->packet->clone(pair->packet));
967
968 queue_retransmission(this, checklist->session_id, pair->id);
969
970 retransmit_end:
971 update_checklist_state(checklist);
972
973 switch(checklist->state)
974 {
975 case CHECK_SUCCEEDED:
976 case CHECK_FAILED:
977 finish_checks(this, checklist);
978 break;
979 default:
980 break;
981 }
982
983 pthread_mutex_unlock(&(this->mutex));
984
985 /* we reschedule it manually */
986 return JOB_REQUEUE_NONE;
987 }
988
989 /**
990 * Queues a retransmission job
991 */
992 static void queue_retransmission(private_connect_manager_t *this, chunk_t session_id, u_int32_t mid)
993 {
994 retransmit_data_t *data = retransmit_data_create(this, chunk_clone(session_id), mid);
995 job_t *job = (job_t*)callback_job_create((callback_job_cb_t)retransmit, data, (callback_job_cleanup_t)retransmit_data_destroy, NULL);
996 charon->scheduler->schedule_job(charon->scheduler, (job_t*)job, P2P_RTO_MIN);
997 }
998
999 /**
1000 * Sends a check
1001 */
1002 static void send_check(private_connect_manager_t *this, check_list_t *checklist,
1003 check_t *check, endpoint_pair_t *pair, bool request)
1004 {
1005 message_t *message = message_create();
1006 message->set_message_id(message, check->mid);
1007 message->set_exchange_type(message, INFORMATIONAL);
1008 message->set_request(message, request);
1009 message->set_destination(message, check->dst->clone(check->dst));
1010 message->set_source(message, check->src->clone(check->src));
1011
1012 message->set_ike_sa_id(message, ike_sa_id_create(0, 0, request));
1013
1014 message->add_notify(message, FALSE, P2P_SESSIONID, check->session_id);
1015
1016 notify_payload_t *endpoint = check->endpoint->build_notify(check->endpoint);
1017 check->endpoint_raw = chunk_clone(endpoint->get_notification_data(endpoint));
1018 message->add_payload(message, (payload_t*)endpoint);
1019
1020 check->cookie = build_signature(this, checklist, check, TRUE);
1021 message->add_notify(message, FALSE, COOKIE, check->cookie);
1022
1023 packet_t *packet;
1024 if (message->generate(message, NULL, NULL, &packet) == SUCCESS)
1025 {
1026 charon->sender->send(charon->sender, packet->clone(packet));
1027
1028 if (request)
1029 {
1030 DESTROY_IF(pair->packet);
1031 pair->packet = packet;
1032 queue_retransmission(this, checklist->session_id, pair->id);
1033 }
1034 else
1035 {
1036 packet->destroy(packet);
1037 }
1038 }
1039 }
1040
1041 /**
1042 * Queues a triggered check
1043 */
1044 static void queue_triggered_check(check_list_t *checklist, endpoint_pair_t *pair)
1045 {
1046 pair->state = CHECK_WAITING;
1047 checklist->triggered->insert_last(checklist->triggered, pair);
1048 }
1049
1050 /**
1051 * This function is triggered for each checklist at a specific interval
1052 */
1053 static job_requeue_t sender(sender_data_t *data)
1054 {
1055 private_connect_manager_t *this = data->connect_manager;
1056
1057 pthread_mutex_lock(&(this->mutex));
1058
1059 check_list_t *checklist;
1060 if (get_checklist_by_id(this, data->session_id, &checklist) != SUCCESS)
1061 {
1062 DBG1(DBG_IKE, "checklist with id '%B' not found, can't send connectivity check",
1063 &data->session_id);
1064 pthread_mutex_unlock(&(this->mutex));
1065 return JOB_REQUEUE_NONE;
1066 }
1067
1068 endpoint_pair_t *pair;
1069 if (get_triggered_pair(checklist, &pair) != SUCCESS)
1070 {
1071 DBG1(DBG_IKE, "no triggered check queued, sending an ordinary check");
1072
1073 if (checklist->pairs->find_first(checklist->pairs,
1074 (linked_list_match_t)match_waiting_pair, (void**)&pair) != SUCCESS)
1075 {
1076 pthread_mutex_unlock(&(this->mutex));
1077 DBG1(DBG_IKE, "no pairs in waiting state, aborting");
1078 return JOB_REQUEUE_NONE;
1079 }
1080 }
1081 else
1082 {
1083 DBG1(DBG_IKE, "triggered check found");
1084 }
1085
1086 check_t *check = check_create();
1087 check->mid = pair->id;
1088 check->src = pair->local->clone(pair->local);
1089 check->dst = pair->remote->clone(pair->remote);
1090 check->session_id = chunk_clone(checklist->session_id);
1091 check->endpoint = endpoint_notify_create();
1092
1093 pair->state = CHECK_IN_PROGRESS;
1094
1095 send_check(this, checklist, check, pair, TRUE);
1096
1097 check_destroy(check);
1098
1099 /* schedule this job again */
1100 u_int32_t N = this->checklists->get_count(this->checklists);
1101 schedule_checks(this, checklist, P2P_INTERVAL * N);
1102
1103 pthread_mutex_unlock(&(this->mutex));
1104
1105 /* we reschedule it manually */
1106 return JOB_REQUEUE_NONE;
1107 }
1108
1109 /**
1110 * Schedules checks for a checklist (time in ms)
1111 */
1112 static void schedule_checks(private_connect_manager_t *this, check_list_t *checklist, u_int32_t time)
1113 {
1114 chunk_t session_id = chunk_clone(checklist->session_id);
1115 sender_data_t *data = sender_data_create(this, session_id);
1116 job_t *job = (job_t*)callback_job_create((callback_job_cb_t)sender, data, (callback_job_cleanup_t)sender_data_destroy, NULL);
1117 charon->scheduler->schedule_job(charon->scheduler, job, time);
1118 }
1119
1120 /**
1121 * Initiates waiting mediated connections
1122 */
1123 static job_requeue_t initiate_mediated(initiate_data_t *data)
1124 {
1125 check_list_t *checklist = data->checklist;
1126 initiated_t *initiated = data->initiated;
1127
1128 endpoint_pair_t *pair;
1129 if (get_best_valid_pair(checklist, &pair) == SUCCESS)
1130 {
1131 waiting_sa_t *waiting_sa;
1132 iterator_t *iterator = initiated->mediated->create_iterator(initiated->mediated, TRUE);
1133 while (iterator->iterate(iterator, (void**)&waiting_sa))
1134 {
1135 ike_sa_t *sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, waiting_sa->ike_sa_id);
1136 if (sa->initiate_mediated(sa, pair->local, pair->remote, waiting_sa->childs) != SUCCESS)
1137 {
1138 SIG(IKE_UP_FAILED, "establishing the mediated connection failed");
1139 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, sa);
1140 }
1141 charon->ike_sa_manager->checkin(charon->ike_sa_manager, sa);
1142 }
1143 iterator->destroy(iterator);
1144 }
1145 else
1146 {
1147 /* this should (can?) not happen */
1148 }
1149
1150 return JOB_REQUEUE_NONE;
1151 }
1152
1153 /**
1154 * Finishes checks for a checklist
1155 */
1156 static void finish_checks(private_connect_manager_t *this, check_list_t *checklist)
1157 {
1158 if (checklist->is_initiator)
1159 {
1160 initiated_t *initiated;
1161 if (get_initiated_by_ids(this, checklist->initiator.id,
1162 checklist->responder.id, &initiated) == SUCCESS)
1163 {
1164 remove_checklist(this, checklist);
1165 remove_initiated(this, initiated);
1166
1167 initiate_data_t *data = initiate_data_create(checklist, initiated);
1168 job_t *job = (job_t*)callback_job_create((callback_job_cb_t)initiate_mediated, data, (callback_job_cleanup_t)initiate_data_destroy, NULL);
1169 charon->processor->queue_job(charon->processor, job);
1170 return;
1171 }
1172 else
1173 {
1174 DBG1(DBG_IKE, "there is no mediated connection waiting between '%D' "
1175 "and '%D'", checklist->initiator.id, checklist->responder.id);
1176 }
1177 }
1178
1179 /* remove_checklist(this, checklist);
1180 * check_list_destroy(checklist);
1181 * FIXME: we should do this ^^^ after a specific timeout on the
1182 * responder side */
1183 }
1184
1185 /**
1186 * Process the response to one of our requests
1187 */
1188 static void process_response(private_connect_manager_t *this, check_t *check,
1189 check_list_t *checklist)
1190 {
1191 endpoint_pair_t *pair;
1192 if (get_pair_by_id(checklist, check->mid, &pair) == SUCCESS)
1193 {
1194 if (pair->local->equals(pair->local, check->dst) &&
1195 pair->remote->equals(pair->remote, check->src))
1196 {
1197 DBG1(DBG_IKE, "endpoint pair '%d' is valid: '%#H' - '%#H'", pair->id,
1198 pair->local, pair->remote);
1199 pair->state = CHECK_SUCCEEDED;
1200 }
1201
1202 linked_list_t *local_endpoints = checklist->is_initiator ?
1203 checklist->initiator.endpoints : checklist->responder.endpoints;
1204
1205 endpoint_notify_t *local_endpoint;
1206 if (endpoints_contain(local_endpoints,
1207 check->endpoint->get_host(check->endpoint), &local_endpoint) != SUCCESS)
1208 {
1209 local_endpoint = endpoint_notify_create_from_host(PEER_REFLEXIVE,
1210 check->endpoint->get_host(check->endpoint), pair->local);
1211 local_endpoint->set_priority(local_endpoint, check->endpoint->get_priority(check->endpoint));
1212 local_endpoints->insert_last(local_endpoints, local_endpoint);
1213 }
1214
1215 update_checklist_state(checklist);
1216
1217 switch(checklist->state)
1218 {
1219 case CHECK_SUCCEEDED:
1220 case CHECK_FAILED:
1221 finish_checks(this, checklist);
1222 break;
1223 default:
1224 break;
1225 }
1226 }
1227 else
1228 {
1229 DBG1(DBG_IKE, "pair with id '%d' not found", check->mid);
1230 }
1231 }
1232
1233 static void process_request(private_connect_manager_t *this, check_t *check,
1234 check_list_t *checklist)
1235 {
1236 linked_list_t *remote_endpoints = checklist->is_initiator ?
1237 checklist->responder.endpoints : checklist->initiator.endpoints;
1238
1239 endpoint_notify_t *peer_reflexive, *remote_endpoint;
1240 peer_reflexive = endpoint_notify_create_from_host(PEER_REFLEXIVE, check->src, NULL);
1241 peer_reflexive->set_priority(peer_reflexive, check->endpoint->get_priority(check->endpoint));
1242
1243 if (endpoints_contain(remote_endpoints, check->src, &remote_endpoint) != SUCCESS)
1244 {
1245 remote_endpoint = peer_reflexive->clone(peer_reflexive);
1246 remote_endpoints->insert_last(remote_endpoints, remote_endpoint);
1247 }
1248
1249 endpoint_pair_t *pair;
1250 if (get_pair_by_hosts(checklist->pairs, check->dst, check->src, &pair) == SUCCESS)
1251 {
1252 switch(pair->state)
1253 {
1254 case CHECK_IN_PROGRESS:
1255 /* prevent retransmissions */
1256 pair->retransmitted = P2P_MAX_RETRANS;
1257 /* FIXME: we should wait to the next rto to send the triggered check
1258 * fall-through */
1259 case CHECK_WAITING:
1260 case CHECK_FAILED:
1261 queue_triggered_check(checklist, pair);
1262 break;
1263 case CHECK_SUCCEEDED:
1264 default:
1265 break;
1266 }
1267 }
1268 else
1269 {
1270 endpoint_notify_t *local_endpoint = endpoint_notify_create_from_host(HOST, check->dst, NULL);
1271
1272 endpoint_notify_t *initiator = checklist->is_initiator ? local_endpoint : remote_endpoint;
1273 endpoint_notify_t *responder = checklist->is_initiator ? remote_endpoint : local_endpoint;
1274
1275 pair = endpoint_pair_create(initiator, responder, checklist->is_initiator);
1276 pair->id = checklist->pairs->get_count(checklist->pairs) + 1;
1277
1278 insert_pair_by_priority(checklist->pairs, pair);
1279
1280 queue_triggered_check(checklist, pair);
1281
1282 local_endpoint->destroy(local_endpoint);
1283 }
1284
1285
1286 check_t *response = check_create();
1287
1288 response->mid = check->mid;
1289 response->src = check->dst->clone(check->dst);
1290 response->dst = check->src->clone(check->src);
1291 response->session_id = chunk_clone(check->session_id);
1292 response->endpoint = peer_reflexive;
1293
1294 send_check(this, checklist, response, pair, FALSE);
1295
1296 check_destroy(response);
1297 }
1298
1299 /**
1300 * Implementation of connect_manager_t.process_check.
1301 */
1302 static void process_check(private_connect_manager_t *this, message_t *message)
1303 {
1304 if (message->parse_body(message, NULL, NULL) != SUCCESS)
1305 {
1306 DBG1(DBG_IKE, "%N %s with message ID %d processing failed",
1307 exchange_type_names, message->get_exchange_type(message),
1308 message->get_request(message) ? "request" : "response",
1309 message->get_message_id(message));
1310 return;
1311 }
1312
1313 check_t *check = check_create();
1314 check->mid = message->get_message_id(message);
1315 check->src = message->get_source(message);
1316 check->dst = message->get_destination(message);
1317
1318 if (process_payloads(message, check) != SUCCESS)
1319 {
1320 DBG1(DBG_IKE, "invalid connectivity check %s received",
1321 message->get_request(message) ? "request" : "response");
1322 check_destroy(check);
1323 return;
1324 }
1325
1326 pthread_mutex_lock(&(this->mutex));
1327
1328 check_list_t *checklist;
1329 if (get_checklist_by_id(this, check->session_id, &checklist) != SUCCESS)
1330 {
1331 DBG1(DBG_IKE, "checklist with id '%B' not found",
1332 &check->session_id);
1333 check_destroy(check);
1334 pthread_mutex_unlock(&(this->mutex));
1335 return;
1336 }
1337
1338 chunk_t sig = build_signature(this, checklist, check, FALSE);
1339 if (!chunk_equals(sig, check->cookie))
1340 {
1341 DBG1(DBG_IKE, "connectivity check verification failed");
1342 check_destroy(check);
1343 chunk_free(&sig);
1344 pthread_mutex_unlock(&(this->mutex));
1345 return;
1346 }
1347 chunk_free(&sig);
1348
1349 if (message->get_request(message))
1350 {
1351 process_request(this, check, checklist);
1352 }
1353 else
1354 {
1355 process_response(this, check, checklist);
1356 }
1357
1358 pthread_mutex_unlock(&(this->mutex));
1359
1360 check_destroy(check);
1361 }
1362
1363 /**
1364 * Implementation of connect_manager_t.check_and_register.
1365 */
1366 static bool check_and_register(private_connect_manager_t *this,
1367 identification_t *id, identification_t *peer_id,
1368 ike_sa_id_t *mediated_sa, child_cfg_t *child)
1369 {
1370 initiated_t *initiated;
1371 bool already_there = TRUE;
1372
1373 pthread_mutex_lock(&(this->mutex));
1374
1375 if (get_initiated_by_ids(this, id, peer_id, &initiated) != SUCCESS)
1376 {
1377 DBG2(DBG_IKE, "registered waiting mediated connection with '%D'", peer_id);
1378 initiated = initiated_create(id, peer_id);
1379 this->initiated->insert_last(this->initiated, initiated);
1380 already_there = FALSE;
1381 }
1382
1383 waiting_sa_t *waiting_sa;
1384 if (get_waiting_sa(initiated, mediated_sa, &waiting_sa) != SUCCESS)
1385 {
1386 waiting_sa = waiting_sa_create(mediated_sa);
1387 initiated->mediated->insert_last(initiated->mediated, waiting_sa);
1388 }
1389
1390 child->get_ref(child);
1391 waiting_sa->childs->insert_last(waiting_sa->childs, child);
1392
1393 pthread_mutex_unlock(&(this->mutex));
1394
1395 return already_there;
1396 }
1397
1398 /**
1399 * Implementation of connect_manager_t.check_and_initiate.
1400 */
1401 static void check_and_initiate(private_connect_manager_t *this, ike_sa_id_t *mediation_sa,
1402 identification_t *id, identification_t *peer_id)
1403 {
1404 initiated_t *initiated;
1405
1406 pthread_mutex_lock(&(this->mutex));
1407
1408 if (get_initiated_by_ids(this, id, peer_id, &initiated) != SUCCESS)
1409 {
1410 DBG2(DBG_IKE, "no waiting mediated connections with '%D'", peer_id);
1411 pthread_mutex_unlock(&(this->mutex));
1412 return;
1413 }
1414
1415 waiting_sa_t *waiting_sa;
1416 iterator_t *iterator = initiated->mediated->create_iterator(initiated->mediated, TRUE);
1417 while (iterator->iterate(iterator, (void**)&waiting_sa))
1418 {
1419 job_t *job = (job_t*)reinitiate_mediation_job_create(mediation_sa,
1420 waiting_sa->ike_sa_id);
1421 charon->processor->queue_job(charon->processor, job);
1422 }
1423
1424 pthread_mutex_unlock(&(this->mutex));
1425 }
1426
1427 /**
1428 * Implementation of connect_manager_t.set_initiator_data.
1429 */
1430 static status_t set_initiator_data(private_connect_manager_t *this,
1431 identification_t *initiator, identification_t *responder,
1432 chunk_t session_id, chunk_t key, linked_list_t *endpoints, bool is_initiator)
1433 {
1434 check_list_t *checklist;
1435
1436 pthread_mutex_lock(&(this->mutex));
1437
1438 if (get_checklist_by_id(this, session_id, NULL) == SUCCESS)
1439 {
1440 DBG1(DBG_IKE, "checklist with id '%B' already exists, aborting",
1441 &session_id);
1442 pthread_mutex_unlock(&(this->mutex));
1443 return FAILED;
1444 }
1445
1446 checklist = check_list_create(initiator, responder, session_id, key, endpoints, is_initiator);
1447 this->checklists->insert_last(this->checklists, checklist);
1448
1449 pthread_mutex_unlock(&(this->mutex));
1450
1451 return SUCCESS;
1452 }
1453
1454 /**
1455 * Implementation of connect_manager_t.set_responder_data.
1456 */
1457 static status_t set_responder_data(private_connect_manager_t *this,
1458 chunk_t session_id, chunk_t key, linked_list_t *endpoints)
1459 {
1460 check_list_t *checklist;
1461
1462 pthread_mutex_lock(&(this->mutex));
1463
1464 if (get_checklist_by_id(this, session_id, &checklist) != SUCCESS)
1465 {
1466 DBG1(DBG_IKE, "checklist with id '%B' not found",
1467 &session_id);
1468 pthread_mutex_unlock(&(this->mutex));
1469 return NOT_FOUND;
1470 }
1471
1472 checklist->responder.key = chunk_clone(key);
1473 checklist->responder.endpoints = endpoints->clone_offset(endpoints, offsetof(endpoint_notify_t, clone));
1474 checklist->state = CHECK_WAITING;
1475
1476 build_pairs(checklist);
1477
1478 /* send the first check immediately */
1479 schedule_checks(this, checklist, 0);
1480
1481 pthread_mutex_unlock(&(this->mutex));
1482
1483 return SUCCESS;
1484 }
1485
1486 /**
1487 * Implementation of connect_manager_t.destroy.
1488 */
1489 static void destroy(private_connect_manager_t *this)
1490 {
1491 pthread_mutex_lock(&(this->mutex));
1492
1493 this->hasher->destroy(this->hasher);
1494 this->checklists->destroy_function(this->checklists, (void*)check_list_destroy);
1495 this->initiated->destroy_function(this->initiated, (void*)initiated_destroy);
1496
1497 pthread_mutex_unlock(&(this->mutex));
1498 pthread_mutex_destroy(&(this->mutex));
1499 free(this);
1500 }
1501
1502 /*
1503 * Described in header.
1504 */
1505 connect_manager_t *connect_manager_create()
1506 {
1507 private_connect_manager_t *this = malloc_thing(private_connect_manager_t);
1508
1509 this->public.destroy = (void(*)(connect_manager_t*))destroy;
1510 this->public.check_and_register = (bool(*)(connect_manager_t*,identification_t*,identification_t*,ike_sa_id_t*,child_cfg_t*))check_and_register;
1511 this->public.check_and_initiate = (void(*)(connect_manager_t*,ike_sa_id_t*,identification_t*,identification_t*))check_and_initiate;
1512 this->public.set_initiator_data = (status_t(*)(connect_manager_t*,identification_t*,identification_t*,chunk_t,chunk_t,linked_list_t*,bool))set_initiator_data;
1513 this->public.set_responder_data = (status_t(*)(connect_manager_t*,chunk_t,chunk_t,linked_list_t*))set_responder_data;
1514 this->public.process_check = (void(*)(connect_manager_t*,message_t*))process_check;
1515
1516 this->hasher = hasher_create(HASH_SHA1);
1517 this->checklists = linked_list_create();
1518 this->initiated = linked_list_create();
1519
1520 pthread_mutex_init(&(this->mutex), NULL);
1521
1522 return (connect_manager_t*)this;
1523 }