merging modularized kernel interface back to trunk
[strongswan.git] / src / charon / sa / tasks / ike_me.c
1 /*
2 * Copyright (C) 2007-2008 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "ike_me.h"
19
20 #include <string.h>
21
22 #include <daemon.h>
23 #include <config/peer_cfg.h>
24 #include <encoding/payloads/id_payload.h>
25 #include <encoding/payloads/notify_payload.h>
26 #include <encoding/payloads/endpoint_notify.h>
27 #include <processing/jobs/mediation_job.h>
28
29 #define ME_CONNECTID_LEN 4
30 #define ME_CONNECTKEY_LEN 16
31
32 typedef struct private_ike_me_t private_ike_me_t;
33
34 /**
35 * Private members of a ike_me_t task.
36 */
37 struct private_ike_me_t {
38
39 /**
40 * Public methods and task_t interface.
41 */
42 ike_me_t public;
43
44 /**
45 * Assigned IKE_SA.
46 */
47 ike_sa_t *ike_sa;
48
49 /**
50 * Are we the initiator?
51 */
52 bool initiator;
53
54 /**
55 * Is this a mediation connection?
56 */
57 bool mediation;
58
59 /**
60 * Is this the response from another peer?
61 */
62 bool response;
63
64 /**
65 * Gathered endpoints
66 */
67 linked_list_t *local_endpoints;
68
69 /**
70 * Parsed endpoints
71 */
72 linked_list_t *remote_endpoints;
73
74 /**
75 * Did the peer request a callback?
76 */
77 bool callback;
78
79 /**
80 * Did the connect fail?
81 */
82 bool failed;
83
84 /**
85 * Was there anything wrong with the payloads?
86 */
87 bool invalid_syntax;
88
89 /**
90 * The requested peer
91 */
92 identification_t *peer_id;
93 /**
94 * Received ID used for connectivity checks
95 */
96 chunk_t connect_id;
97
98 /**
99 * Received key used for connectivity checks
100 */
101 chunk_t connect_key;
102
103 /**
104 * Peer config of the mediated connection
105 */
106 peer_cfg_t *mediated_cfg;
107
108 };
109
110 /**
111 * Adds a list of endpoints as notifies to a given message
112 */
113 static void add_endpoints_to_message(message_t *message, linked_list_t *endpoints)
114 {
115 iterator_t *iterator;
116 endpoint_notify_t *endpoint;
117
118 iterator = endpoints->create_iterator(endpoints, TRUE);
119 while (iterator->iterate(iterator, (void**)&endpoint))
120 {
121 message->add_payload(message, (payload_t*)endpoint->build_notify(endpoint));
122 }
123 iterator->destroy(iterator);
124 }
125
126 /**
127 * Gathers endpoints and adds them to the current message
128 */
129 static void gather_and_add_endpoints(private_ike_me_t *this, message_t *message)
130 {
131 enumerator_t *enumerator;
132 host_t *addr, *host;
133 u_int16_t port;
134
135 /* get the port that is used to communicate with the ms */
136 host = this->ike_sa->get_my_host(this->ike_sa);
137 port = host->get_port(host);
138
139 enumerator = charon->kernel_interface->create_address_enumerator(
140 charon->kernel_interface, FALSE, FALSE);
141 while (enumerator->enumerate(enumerator, (void**)&addr))
142 {
143 host = addr->clone(addr);
144 host->set_port(host, port);
145
146 this->local_endpoints->insert_last(this->local_endpoints,
147 endpoint_notify_create_from_host(HOST, host, NULL));
148
149 host->destroy(host);
150 }
151 enumerator->destroy(enumerator);
152
153 host = this->ike_sa->get_server_reflexive_host(this->ike_sa);
154 if (host)
155 {
156 this->local_endpoints->insert_last(this->local_endpoints,
157 endpoint_notify_create_from_host(SERVER_REFLEXIVE, host,
158 this->ike_sa->get_my_host(this->ike_sa)));
159 }
160
161 add_endpoints_to_message(message, this->local_endpoints);
162 }
163
164 /**
165 * read notifys from message and evaluate them
166 */
167 static void process_payloads(private_ike_me_t *this, message_t *message)
168 {
169 iterator_t *iterator;
170 payload_t *payload;
171
172 iterator = message->get_payload_iterator(message);
173 while (iterator->iterate(iterator, (void**)&payload))
174 {
175 if (payload->get_type(payload) != NOTIFY)
176 {
177 continue;
178 }
179
180 notify_payload_t *notify = (notify_payload_t*)payload;
181
182 switch (notify->get_notify_type(notify))
183 {
184 case ME_CONNECT_FAILED:
185 {
186 DBG2(DBG_IKE, "received ME_CONNECT_FAILED notify");
187 this->failed = TRUE;
188 break;
189 }
190 case ME_MEDIATION:
191 {
192 DBG2(DBG_IKE, "received ME_MEDIATION notify");
193 this->mediation = TRUE;
194 break;
195 }
196 case ME_ENDPOINT:
197 {
198 endpoint_notify_t *endpoint = endpoint_notify_create_from_payload(notify);
199 if (!endpoint)
200 {
201 DBG1(DBG_IKE, "received invalid ME_ENDPOINT notify");
202 break;
203 }
204 DBG1(DBG_IKE, "received %N ME_ENDPOINT %#H", me_endpoint_type_names,
205 endpoint->get_type(endpoint), endpoint->get_host(endpoint));
206
207 this->remote_endpoints->insert_last(this->remote_endpoints, endpoint);
208 break;
209 }
210 case ME_CALLBACK:
211 {
212 DBG2(DBG_IKE, "received ME_CALLBACK notify");
213 this->callback = TRUE;
214 break;
215 }
216 case ME_CONNECTID:
217 {
218 chunk_free(&this->connect_id);
219 this->connect_id = chunk_clone(notify->get_notification_data(notify));
220 DBG2(DBG_IKE, "received ME_CONNECTID %#B", &this->connect_id);
221 break;
222 }
223 case ME_CONNECTKEY:
224 {
225 chunk_free(&this->connect_key);
226 this->connect_key = chunk_clone(notify->get_notification_data(notify));
227 DBG4(DBG_IKE, "received ME_CONNECTKEY %#B", &this->connect_key);
228 break;
229 }
230 case ME_RESPONSE:
231 {
232 DBG2(DBG_IKE, "received ME_RESPONSE notify");
233 this->response = TRUE;
234 break;
235 }
236 default:
237 break;
238 }
239 }
240 iterator->destroy(iterator);
241 }
242
243 /**
244 * Implementation of task_t.build for initiator
245 */
246 static status_t build_i(private_ike_me_t *this, message_t *message)
247 {
248 switch(message->get_exchange_type(message))
249 {
250 case IKE_SA_INIT:
251 {
252 peer_cfg_t *peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
253 if (peer_cfg->is_mediation(peer_cfg))
254 {
255 DBG2(DBG_IKE, "adding ME_MEDIATION");
256 message->add_notify(message, FALSE, ME_MEDIATION, chunk_empty);
257 }
258 else
259 {
260 return SUCCESS;
261 }
262 break;
263 }
264 case IKE_AUTH:
265 {
266 if (this->ike_sa->has_condition(this->ike_sa, COND_NAT_HERE))
267 {
268 endpoint_notify_t *endpoint = endpoint_notify_create_from_host(SERVER_REFLEXIVE, NULL, NULL);
269 message->add_payload(message, (payload_t*)endpoint->build_notify(endpoint));
270 endpoint->destroy(endpoint);
271 }
272 break;
273 }
274 case ME_CONNECT:
275 {
276 id_payload_t *id_payload;
277 rng_t *rng;
278
279 id_payload = id_payload_create_from_identification(ID_PEER, this->peer_id);
280 message->add_payload(message, (payload_t*)id_payload);
281
282 rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
283 if (!rng)
284 {
285 DBG1(DBG_IKE, "unable to generate connect ID for ME_CONNECT");
286 return FAILED;
287 }
288 if (!this->response)
289 {
290 /* only the initiator creates a connect ID. the responder returns
291 * the connect ID that it received from the initiator */
292 rng->allocate_bytes(rng, ME_CONNECTID_LEN, &this->connect_id);
293 }
294 rng->allocate_bytes(rng, ME_CONNECTKEY_LEN, &this->connect_key);
295 rng->destroy(rng);
296
297 message->add_notify(message, FALSE, ME_CONNECTID, this->connect_id);
298 message->add_notify(message, FALSE, ME_CONNECTKEY, this->connect_key);
299
300 if (this->response)
301 {
302 message->add_notify(message, FALSE, ME_RESPONSE, chunk_empty);
303 }
304 else
305 {
306 /* FIXME: should we make that configurable? */
307 message->add_notify(message, FALSE, ME_CALLBACK, chunk_empty);
308 }
309
310 gather_and_add_endpoints(this, message);
311
312 break;
313 }
314 default:
315 break;
316 }
317 return NEED_MORE;
318 }
319
320 /**
321 * Implementation of task_t.process for responder
322 */
323 static status_t process_r(private_ike_me_t *this, message_t *message)
324 {
325 switch(message->get_exchange_type(message))
326 {
327 case ME_CONNECT:
328 {
329 id_payload_t *id_payload;
330 id_payload = (id_payload_t*)message->get_payload(message, ID_PEER);
331 if (!id_payload)
332 {
333 DBG1(DBG_IKE, "received ME_CONNECT without ID_PEER payload, aborting");
334 break;
335 }
336 this->peer_id = id_payload->get_identification(id_payload);
337
338 process_payloads(this, message);
339
340 if (this->callback)
341 {
342 DBG1(DBG_IKE, "received ME_CALLBACK for '%D'", this->peer_id);
343 break;
344 }
345
346 if (!this->connect_id.ptr)
347 {
348 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTID notify, aborting");
349 this->invalid_syntax = TRUE;
350 break;
351 }
352
353 if (!this->connect_key.ptr)
354 {
355 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTKEY notify, aborting");
356 this->invalid_syntax = TRUE;
357 break;
358 }
359
360 if (!this->remote_endpoints->get_count(this->remote_endpoints))
361 {
362 DBG1(DBG_IKE, "received ME_CONNECT without any ME_ENDPOINT payloads, aborting");
363 this->invalid_syntax = TRUE;
364 break;
365 }
366
367 DBG1(DBG_IKE, "received ME_CONNECT");
368 break;
369 }
370 default:
371 break;
372 }
373 return NEED_MORE;
374 }
375
376 /**
377 * Implementation of task_t.build for responder
378 */
379 static status_t build_r(private_ike_me_t *this, message_t *message)
380 {
381 switch(message->get_exchange_type(message))
382 {
383 case ME_CONNECT:
384 {
385 if (this->invalid_syntax)
386 {
387 message->add_notify(message, TRUE, INVALID_SYNTAX, chunk_empty);
388 break;
389 }
390
391 if (this->callback)
392 {
393 charon->connect_manager->check_and_initiate(charon->connect_manager,
394 this->ike_sa->get_id(this->ike_sa),
395 this->ike_sa->get_my_id(this->ike_sa), this->peer_id);
396 return SUCCESS;
397 }
398
399 if (this->response)
400 {
401 /* FIXME: handle result of set_responder_data
402 * as initiator, upon receiving a response from another peer,
403 * update the checklist and start sending checks */
404 charon->connect_manager->set_responder_data(charon->connect_manager,
405 this->connect_id, this->connect_key, this->remote_endpoints);
406 }
407 else
408 {
409 /* FIXME: handle result of set_initiator_data
410 * as responder, create a checklist with the initiator's data */
411 charon->connect_manager->set_initiator_data(charon->connect_manager,
412 this->peer_id, this->ike_sa->get_my_id(this->ike_sa),
413 this->connect_id, this->connect_key, this->remote_endpoints,
414 FALSE);
415 if (this->ike_sa->respond(this->ike_sa, this->peer_id,
416 this->connect_id) != SUCCESS)
417 {
418 return FAILED;
419 }
420 }
421 break;
422 }
423 default:
424 break;
425 }
426 return SUCCESS;
427 }
428
429 /**
430 * Implementation of task_t.process for initiator
431 */
432 static status_t process_i(private_ike_me_t *this, message_t *message)
433 {
434 switch(message->get_exchange_type(message))
435 {
436 case IKE_SA_INIT:
437 {
438 process_payloads(this, message);
439
440 if (!this->mediation)
441 {
442 DBG1(DBG_IKE, "server did not return a ME_MEDIATION, aborting");
443 return FAILED;
444 }
445
446 return NEED_MORE;
447 }
448 case IKE_AUTH:
449 {
450 process_payloads(this, message);
451 /* FIXME: we should update the server reflexive endpoint somehow,
452 * if mobike notices a change */
453 endpoint_notify_t *reflexive;
454 if (this->remote_endpoints->get_first(this->remote_endpoints,
455 (void**)&reflexive) == SUCCESS &&
456 reflexive->get_type(reflexive) == SERVER_REFLEXIVE)
457 { /* FIXME: should we accept this endpoint even if we did not send
458 * a request? */
459 host_t *endpoint = reflexive->get_host(reflexive);
460
461 this->ike_sa->set_server_reflexive_host(this->ike_sa, endpoint->clone(endpoint));
462 }
463 /* FIXME: what if it failed? e.g. AUTH failure */
464 SIG_CHD(UP_SUCCESS, NULL, "established mediation connection "
465 "without CHILD_SA successfully");
466
467 break;
468 }
469 case ME_CONNECT:
470 {
471 process_payloads(this, message);
472
473 if (this->failed)
474 {
475 DBG1(DBG_IKE, "peer '%D' is not online", this->peer_id);
476 /* FIXME: notify the mediated connection (job?) */
477 }
478 else
479 {
480 if (this->response)
481 {
482 /* FIXME: handle result of set_responder_data.
483 * as responder, we update the checklist and start sending checks */
484 charon->connect_manager->set_responder_data(charon->connect_manager,
485 this->connect_id, this->connect_key, this->local_endpoints);
486 }
487 else
488 {
489 /* FIXME: handle result of set_initiator_data
490 * as initiator, we create a checklist and set the initiator's data */
491 charon->connect_manager->set_initiator_data(charon->connect_manager,
492 this->ike_sa->get_my_id(this->ike_sa), this->peer_id,
493 this->connect_id, this->connect_key, this->local_endpoints,
494 TRUE);
495 /* FIXME: also start a timer for the whole transaction (maybe
496 * within the connect_manager?) */
497 }
498 }
499 break;
500 }
501 default:
502 break;
503 }
504 return SUCCESS;
505 }
506
507 /**
508 * Implementation of task_t.build for initiator (mediation server)
509 */
510 static status_t build_i_ms(private_ike_me_t *this, message_t *message)
511 {
512 switch(message->get_exchange_type(message))
513 {
514 case ME_CONNECT:
515 {
516 id_payload_t *id_payload = id_payload_create_from_identification(ID_PEER, this->peer_id);
517 message->add_payload(message, (payload_t*)id_payload);
518
519 if (this->callback)
520 {
521 message->add_notify(message, FALSE, ME_CALLBACK, chunk_empty);
522 }
523 else
524 {
525 if (this->response)
526 {
527 message->add_notify(message, FALSE, ME_RESPONSE, chunk_empty);
528 }
529 message->add_notify(message, FALSE, ME_CONNECTID, this->connect_id);
530 message->add_notify(message, FALSE, ME_CONNECTKEY, this->connect_key);
531
532 add_endpoints_to_message(message, this->remote_endpoints);
533 }
534 break;
535 }
536 default:
537 break;
538 }
539
540 return NEED_MORE;
541 }
542
543 /**
544 * Implementation of task_t.process for responder (mediation server)
545 */
546 static status_t process_r_ms(private_ike_me_t *this, message_t *message)
547 {
548 switch(message->get_exchange_type(message))
549 {
550 case IKE_SA_INIT:
551 {
552 /* FIXME: we should check for SA* and TS* payloads
553 * if any are there send NO_ADDITIONAL_SAS back and delete this SA */
554 process_payloads(this, message);
555 return this->mediation ? NEED_MORE : SUCCESS;
556 }
557 case IKE_AUTH:
558 {
559 /* FIXME: we should check whether the current peer_config is configured
560 * as mediation connection */
561 process_payloads(this, message);
562 break;
563 }
564 case CREATE_CHILD_SA:
565 {
566 /* FIXME: if this is not to rekey the IKE SA we have to return a
567 * NO_ADDITIONAL_SAS and then delete the SA */
568 break;
569 }
570 case ME_CONNECT:
571 {
572 id_payload_t *id_payload;
573 id_payload = (id_payload_t*)message->get_payload(message, ID_PEER);
574 if (!id_payload)
575 {
576 DBG1(DBG_IKE, "received ME_CONNECT without ID_PEER payload, aborting");
577 this->invalid_syntax = TRUE;
578 break;
579 }
580
581 this->peer_id = id_payload->get_identification(id_payload);
582
583 process_payloads(this, message);
584
585 if (!this->connect_id.ptr)
586 {
587 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTID notify, aborting");
588 this->invalid_syntax = TRUE;
589 break;
590 }
591
592 if (!this->connect_key.ptr)
593 {
594 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTKEY notify, aborting");
595 this->invalid_syntax = TRUE;
596 break;
597 }
598
599 if (!this->remote_endpoints->get_count(this->remote_endpoints))
600 {
601 DBG1(DBG_IKE, "received ME_CONNECT without any ME_ENDPOINT payloads, aborting");
602 this->invalid_syntax = TRUE;
603 break;
604 }
605 break;
606 }
607 default:
608 break;
609 }
610
611 return NEED_MORE;
612 }
613
614 /**
615 * Implementation of task_t.build for responder (mediation server)
616 */
617 static status_t build_r_ms(private_ike_me_t *this, message_t *message)
618 {
619 switch(message->get_exchange_type(message))
620 {
621 case IKE_SA_INIT:
622 {
623 message->add_notify(message, FALSE, ME_MEDIATION, chunk_empty);
624 return NEED_MORE;
625 }
626 case IKE_AUTH:
627 {
628 endpoint_notify_t *endpoint;
629 if (this->remote_endpoints->get_first(this->remote_endpoints, (void**)&endpoint) == SUCCESS &&
630 endpoint->get_type(endpoint) == SERVER_REFLEXIVE)
631 {
632 host_t *host = this->ike_sa->get_other_host(this->ike_sa);
633
634 DBG2(DBG_IKE, "received request for a server reflexive endpoint "
635 "sending: %#H", host);
636
637 endpoint = endpoint_notify_create_from_host(SERVER_REFLEXIVE, host, NULL);
638 message->add_payload(message, (payload_t*)endpoint->build_notify(endpoint));
639 endpoint->destroy(endpoint);
640 }
641
642 /* FIXME: we actually must delete any existing IKE_SAs with the same remote id */
643 this->ike_sa->act_as_mediation_server(this->ike_sa);
644
645 SIG_CHD(UP_SUCCESS, NULL, "established mediation connection "
646 "without CHILD_SA successfully");
647
648 break;
649 }
650 case ME_CONNECT:
651 {
652 if (this->invalid_syntax)
653 {
654 message->add_notify(message, TRUE, INVALID_SYNTAX, chunk_empty);
655 break;
656 }
657
658 ike_sa_id_t *peer_sa;
659 if (this->callback)
660 {
661 peer_sa = charon->mediation_manager->check_and_register(charon->mediation_manager,
662 this->peer_id, this->ike_sa->get_other_id(this->ike_sa));
663 }
664 else
665 {
666 peer_sa = charon->mediation_manager->check(charon->mediation_manager,
667 this->peer_id);
668 }
669
670 if (!peer_sa)
671 {
672 /* the peer is not online */
673 message->add_notify(message, TRUE, ME_CONNECT_FAILED, chunk_empty);
674 break;
675 }
676
677 job_t *job = (job_t*)mediation_job_create(this->peer_id,
678 this->ike_sa->get_other_id(this->ike_sa), this->connect_id,
679 this->connect_key, this->remote_endpoints, this->response);
680 charon->processor->queue_job(charon->processor, job);
681
682 break;
683 }
684 default:
685 break;
686 }
687 return SUCCESS;
688 }
689
690 /**
691 * Implementation of task_t.process for initiator (mediation server)
692 */
693 static status_t process_i_ms(private_ike_me_t *this, message_t *message)
694 {
695 /* FIXME: theoretically we should be prepared to receive a ME_CONNECT_FAILED
696 * here if the responding peer is not able to proceed. in this case we shall
697 * notify the initiating peer with a ME_CONNECT request containing only a
698 * ME_CONNECT_FAILED */
699 return SUCCESS;
700 }
701
702 /**
703 * Implementation of ike_me.connect
704 */
705 static void me_connect(private_ike_me_t *this, identification_t *peer_id)
706 {
707 this->peer_id = peer_id->clone(peer_id);
708 }
709
710 /**
711 * Implementation of ike_me.respond
712 */
713 static void me_respond(private_ike_me_t *this, identification_t *peer_id,
714 chunk_t connect_id)
715 {
716 this->peer_id = peer_id->clone(peer_id);
717 this->connect_id = chunk_clone(connect_id);
718 this->response = TRUE;
719 }
720
721 /**
722 * Implementation of ike_me.callback
723 */
724 static void me_callback(private_ike_me_t *this, identification_t *peer_id)
725 {
726 this->peer_id = peer_id->clone(peer_id);
727 this->callback = TRUE;
728 }
729
730 /**
731 * Implementation of ike_me.relay
732 */
733 static void relay(private_ike_me_t *this, identification_t *requester, chunk_t connect_id,
734 chunk_t connect_key, linked_list_t *endpoints, bool response)
735 {
736 this->peer_id = requester->clone(requester);
737 this->connect_id = chunk_clone(connect_id);
738 this->connect_key = chunk_clone(connect_key);
739
740 this->remote_endpoints->destroy_offset(this->remote_endpoints, offsetof(endpoint_notify_t, destroy));
741 this->remote_endpoints = endpoints->clone_offset(endpoints, offsetof(endpoint_notify_t, clone));
742
743 this->response = response;
744 }
745
746 /**
747 * Implementation of task_t.get_type
748 */
749 static task_type_t get_type(private_ike_me_t *this)
750 {
751 return IKE_ME;
752 }
753
754 /**
755 * Implementation of task_t.migrate
756 */
757 static void migrate(private_ike_me_t *this, ike_sa_t *ike_sa)
758 {
759 this->ike_sa = ike_sa;
760 }
761
762 /**
763 * Implementation of task_t.destroy
764 */
765 static void destroy(private_ike_me_t *this)
766 {
767 DESTROY_IF(this->peer_id);
768
769 chunk_free(&this->connect_id);
770 chunk_free(&this->connect_key);
771
772 this->local_endpoints->destroy_offset(this->local_endpoints, offsetof(endpoint_notify_t, destroy));
773 this->remote_endpoints->destroy_offset(this->remote_endpoints, offsetof(endpoint_notify_t, destroy));
774
775 DESTROY_IF(this->mediated_cfg);
776 free(this);
777 }
778
779 /*
780 * Described in header.
781 */
782 ike_me_t *ike_me_create(ike_sa_t *ike_sa, bool initiator)
783 {
784 private_ike_me_t *this = malloc_thing(private_ike_me_t);
785
786 this->public.task.get_type = (task_type_t(*)(task_t*))get_type;
787 this->public.task.migrate = (void(*)(task_t*,ike_sa_t*))migrate;
788 this->public.task.destroy = (void(*)(task_t*))destroy;
789
790 if (ike_sa->is_ike_initiator(ike_sa))
791 {
792 if (initiator)
793 {
794 this->public.task.build = (status_t(*)(task_t*,message_t*))build_i;
795 this->public.task.process = (status_t(*)(task_t*,message_t*))process_i;
796 }
797 else
798 {
799 this->public.task.build = (status_t(*)(task_t*,message_t*))build_r;
800 this->public.task.process = (status_t(*)(task_t*,message_t*))process_r;
801 }
802 }
803 else
804 {
805 /* mediation server */
806 if (initiator)
807 {
808 this->public.task.build = (status_t(*)(task_t*,message_t*))build_i_ms;
809 this->public.task.process = (status_t(*)(task_t*,message_t*))process_i_ms;
810 }
811 else
812 {
813 this->public.task.build = (status_t(*)(task_t*,message_t*))build_r_ms;
814 this->public.task.process = (status_t(*)(task_t*,message_t*))process_r_ms;
815 }
816 }
817
818 this->public.connect = (void(*)(ike_me_t*,identification_t*))me_connect;
819 this->public.respond = (void(*)(ike_me_t*,identification_t*,chunk_t))me_respond;
820 this->public.callback = (void(*)(ike_me_t*,identification_t*))me_callback;
821 this->public.relay = (void(*)(ike_me_t*,identification_t*,chunk_t,chunk_t,linked_list_t*,bool))relay;
822
823 this->ike_sa = ike_sa;
824 this->initiator = initiator;
825
826 this->peer_id = NULL;
827 this->connect_id = chunk_empty;
828 this->connect_key = chunk_empty;
829 this->local_endpoints = linked_list_create();
830 this->remote_endpoints = linked_list_create();
831 this->mediation = FALSE;
832 this->response = FALSE;
833 this->callback = FALSE;
834 this->failed = FALSE;
835 this->invalid_syntax = FALSE;
836
837 this->mediated_cfg = NULL;
838
839 return &this->public;
840 }