554078cdaad65cce7d0207f629dfcb3b43c4d450
[strongswan.git] / src / charon / sa / child_sa.c
1 /**
2 * @file child_sa.c
3 *
4 * @brief Implementation of child_sa_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #include <netdb.h>
25
26 #include "child_sa.h"
27
28 #include <daemon.h>
29
30
31 typedef struct sa_policy_t sa_policy_t;
32
33 /**
34 * Struct used to store information for a policy. This
35 * is needed since we must provide all this information
36 * for deleting a policy...
37 */
38 struct sa_policy_t {
39
40 struct {
41 /** subnet address behind peer peer */
42 host_t *net;
43 /** netmask used for net */
44 u_int8_t net_mask;
45 } me, other;
46
47 /**
48 * Protocol for this policy, such as TCP/UDP/ICMP...
49 */
50 int upper_proto;
51 };
52
53 typedef struct private_child_sa_t private_child_sa_t;
54
55 /**
56 * Private data of a child_sa_t object.
57 */
58 struct private_child_sa_t {
59 /**
60 * Public interface of child_sa_t.
61 */
62 child_sa_t public;
63
64 struct {
65 /** address of peer */
66 host_t *addr;
67 /** actual used SPI, 0 if unused */
68 u_int32_t spi;
69 } me, other;
70
71 /**
72 * Allocated SPI for a ESP proposal candidates
73 */
74 u_int32_t alloc_esp_spi;
75
76 /**
77 * Allocated SPI for a AH proposal candidates
78 */
79 u_int32_t alloc_ah_spi;
80
81 /**
82 * Protocol used to protect this SA, ESP|AH
83 */
84 protocol_id_t protocol;
85
86 /**
87 * List containing sa_policy_t objects
88 */
89 linked_list_t *policies;
90
91 /**
92 * reqid used for this child_sa
93 */
94 u_int32_t reqid;
95
96 /**
97 * time, on which SA was installed
98 */
99 time_t install_time;
100
101 /**
102 * Lifetime before rekeying
103 */
104 u_int32_t soft_lifetime;
105
106 /**
107 * Lifetime before delete
108 */
109 u_int32_t hard_lifetime;
110
111 /**
112 * has this CHILD_SA been rekeyed?
113 */
114 bool rekeyed;
115
116 /**
117 * Specifies if NAT traversal is used
118 */
119 bool use_natt;
120
121 /**
122 * CHILD_SAs own logger
123 */
124 logger_t *logger;
125 };
126
127 /**
128 * Implements child_sa_t.get_reqid
129 */
130 static u_int32_t get_reqid(private_child_sa_t *this)
131 {
132 return this->reqid;
133 }
134
135 /**
136 * Implements child_sa_t.get_spi
137 */
138 u_int32_t get_spi(private_child_sa_t *this, bool inbound)
139 {
140 if (inbound)
141 {
142 return this->me.spi;
143 }
144 return this->other.spi;
145 }
146
147 /**
148 * Implements child_sa_t.get_protocol
149 */
150 protocol_id_t get_protocol(private_child_sa_t *this)
151 {
152 return this->protocol;
153 }
154
155 /**
156 * Allocate SPI for a single proposal
157 */
158 static status_t alloc_proposal(private_child_sa_t *this, proposal_t *proposal)
159 {
160 protocol_id_t protocol = proposal->get_protocol(proposal);
161
162 if (protocol == PROTO_AH)
163 {
164 /* get a new spi for AH, if not already done */
165 if (this->alloc_ah_spi == 0)
166 {
167 if (charon->kernel_interface->get_spi(
168 charon->kernel_interface,
169 this->other.addr, this->me.addr,
170 PROTO_AH, this->reqid,
171 &this->alloc_ah_spi) != SUCCESS)
172 {
173 return FAILED;
174 }
175 }
176 proposal->set_spi(proposal, this->alloc_ah_spi);
177 }
178 if (protocol == PROTO_ESP)
179 {
180 /* get a new spi for ESP, if not already done */
181 if (this->alloc_esp_spi == 0)
182 {
183 if (charon->kernel_interface->get_spi(
184 charon->kernel_interface,
185 this->other.addr, this->me.addr,
186 PROTO_ESP, this->reqid,
187 &this->alloc_esp_spi) != SUCCESS)
188 {
189 return FAILED;
190 }
191 }
192 proposal->set_spi(proposal, this->alloc_esp_spi);
193 }
194 return SUCCESS;
195 }
196
197
198 /**
199 * Implements child_sa_t.alloc
200 */
201 static status_t alloc(private_child_sa_t *this, linked_list_t *proposals)
202 {
203 iterator_t *iterator;
204 proposal_t *proposal;
205
206 /* iterator through proposals to update spis */
207 iterator = proposals->create_iterator(proposals, TRUE);
208 while(iterator->has_next(iterator))
209 {
210 iterator->current(iterator, (void**)&proposal);
211 if (alloc_proposal(this, proposal) != SUCCESS)
212 {
213 iterator->destroy(iterator);
214 return FAILED;
215 }
216 }
217 iterator->destroy(iterator);
218 return SUCCESS;
219 }
220
221 static status_t install(private_child_sa_t *this, proposal_t *proposal, prf_plus_t *prf_plus, bool mine)
222 {
223 u_int32_t spi;
224 algorithm_t *enc_algo, *int_algo;
225 algorithm_t enc_algo_none = {ENCR_UNDEFINED, 0};
226 algorithm_t int_algo_none = {AUTH_UNDEFINED, 0};
227 host_t *src;
228 host_t *dst;
229 natt_conf_t *natt;
230 status_t status;
231
232 this->protocol = proposal->get_protocol(proposal);
233
234 /* now we have to decide which spi to use. Use self allocated, if "mine",
235 * or the one in the proposal, if not "mine" (others). Additionally,
236 * source and dest host switch depending on the role */
237 if (mine)
238 {
239 /* if we have allocated SPIs for AH and ESP, we must delete the unused
240 * one. */
241 if (this->protocol == PROTO_ESP)
242 {
243 this->me.spi = this->alloc_esp_spi;
244 if (this->alloc_ah_spi)
245 {
246 charon->kernel_interface->del_sa(charon->kernel_interface, this->me.addr,
247 this->alloc_ah_spi, PROTO_AH);
248 }
249 }
250 else
251 {
252 this->me.spi = this->alloc_ah_spi;
253 if (this->alloc_esp_spi)
254 {
255 charon->kernel_interface->del_sa(charon->kernel_interface, this->me.addr,
256 this->alloc_esp_spi, PROTO_ESP);
257 }
258 }
259 spi = this->me.spi;
260 dst = this->me.addr;
261 src = this->other.addr;
262 }
263 else
264 {
265 this->other.spi = proposal->get_spi(proposal);
266 spi = this->other.spi;
267 src = this->me.addr;
268 dst = this->other.addr;
269 }
270
271 this->logger->log(this->logger, CONTROL|LEVEL1, "Adding %s %s SA",
272 mine ? "inbound" : "outbound",
273 mapping_find(protocol_id_m, this->protocol));
274
275 /* select encryption algo */
276 if (proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM, &enc_algo))
277 {
278 this->logger->log(this->logger, CONTROL|LEVEL2, " using %s for encryption",
279 mapping_find(encryption_algorithm_m, enc_algo->algorithm));
280 }
281 else
282 {
283 enc_algo = &enc_algo_none;
284 }
285
286 /* select integrity algo */
287 if (proposal->get_algorithm(proposal, INTEGRITY_ALGORITHM, &int_algo))
288 {
289 this->logger->log(this->logger, CONTROL|LEVEL2, " using %s for integrity",
290 mapping_find(integrity_algorithm_m, int_algo->algorithm));
291 }
292 else
293 {
294 int_algo = &int_algo_none;
295 }
296
297 /* setup nat-t */
298 if (this->use_natt)
299 {
300 natt = alloca(sizeof(natt_conf_t));
301 natt->sport = src->get_port(src);
302 natt->dport = dst->get_port(dst);
303 }
304 else
305 {
306 natt = NULL;
307 }
308
309
310 /* send SA down to the kernel */
311 this->logger->log(this->logger, CONTROL|LEVEL2,
312 " SPI 0x%.8x, src %s dst %s",
313 ntohl(spi), src->get_address(src), dst->get_address(dst));
314 status = charon->kernel_interface->add_sa(charon->kernel_interface,
315 src, dst,
316 spi, this->protocol,
317 this->reqid,
318 mine ? 0 : this->soft_lifetime,
319 this->hard_lifetime,
320 enc_algo, int_algo,
321 prf_plus, natt, mine);
322
323 this->install_time = time(NULL);
324
325 return status;
326 }
327
328 static status_t add(private_child_sa_t *this, proposal_t *proposal, prf_plus_t *prf_plus)
329 {
330 linked_list_t *list;
331 u_int32_t outbound_spi, inbound_spi;
332
333 /* backup outbound spi, as alloc overwrites it */
334 outbound_spi = proposal->get_spi(proposal);
335
336 /* get SPIs inbound SAs */
337 if (alloc_proposal(this, proposal) != SUCCESS)
338 {
339 return FAILED;
340 }
341 inbound_spi = proposal->get_spi(proposal);
342
343 /* install inbound SAs */
344 if (install(this, proposal, prf_plus, TRUE) != SUCCESS)
345 {
346 return FAILED;
347 }
348
349 /* install outbound SAs, restore spi*/
350 proposal->set_spi(proposal, outbound_spi);
351 if (install(this, proposal, prf_plus, FALSE) != SUCCESS)
352 {
353 return FAILED;
354 }
355 proposal->set_spi(proposal, inbound_spi);
356
357 return SUCCESS;
358 }
359
360 static status_t update(private_child_sa_t *this, proposal_t *proposal, prf_plus_t *prf_plus)
361 {
362 u_int32_t inbound_spi;
363
364 /* backup received spi, as install() overwrites it */
365 inbound_spi = proposal->get_spi(proposal);
366
367 /* install outbound SAs */
368 if (install(this, proposal, prf_plus, FALSE) != SUCCESS)
369 {
370 return FAILED;
371 }
372
373 /* restore spi */
374 proposal->set_spi(proposal, inbound_spi);
375 /* install inbound SAs */
376 if (install(this, proposal, prf_plus, TRUE) != SUCCESS)
377 {
378 return FAILED;
379 }
380
381 return SUCCESS;
382 }
383
384 static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list, linked_list_t *other_ts_list)
385 {
386 iterator_t *my_iter, *other_iter;
387 traffic_selector_t *my_ts, *other_ts;
388
389 /* iterate over both lists */
390 my_iter = my_ts_list->create_iterator(my_ts_list, TRUE);
391 other_iter = other_ts_list->create_iterator(other_ts_list, TRUE);
392 while (my_iter->has_next(my_iter))
393 {
394 my_iter->current(my_iter, (void**)&my_ts);
395 other_iter->reset(other_iter);
396 while (other_iter->has_next(other_iter))
397 {
398 /* set up policies for every entry in my_ts_list to every entry in other_ts_list */
399 int family;
400 chunk_t from_addr;
401 u_int16_t from_port, to_port;
402 sa_policy_t *policy;
403 status_t status;
404
405 other_iter->current(other_iter, (void**)&other_ts);
406
407 /* only set up policies if protocol matches */
408 if (my_ts->get_protocol(my_ts) != other_ts->get_protocol(other_ts))
409 {
410 continue;
411 }
412 policy = malloc_thing(sa_policy_t);
413 policy->upper_proto = my_ts->get_protocol(my_ts);
414
415 /* calculate net and ports for local side */
416 family = my_ts->get_type(my_ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
417 from_addr = my_ts->get_from_address(my_ts);
418 from_port = my_ts->get_from_port(my_ts);
419 to_port = my_ts->get_to_port(my_ts);
420 from_port = (from_port != to_port) ? 0 : from_port;
421 policy->me.net = host_create_from_chunk(family, from_addr, from_port);
422 policy->me.net_mask = my_ts->get_netmask(my_ts);
423 chunk_free(&from_addr);
424
425 /* calculate net and ports for remote side */
426 family = other_ts->get_type(other_ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
427 from_addr = other_ts->get_from_address(other_ts);
428 from_port = other_ts->get_from_port(other_ts);
429 to_port = other_ts->get_to_port(other_ts);
430 from_port = (from_port != to_port) ? 0 : from_port;
431 policy->other.net = host_create_from_chunk(family, from_addr, from_port);
432 policy->other.net_mask = other_ts->get_netmask(other_ts);
433 chunk_free(&from_addr);
434
435 /* install 3 policies: out, in and forward */
436 status = charon->kernel_interface->add_policy(charon->kernel_interface,
437 this->me.addr, this->other.addr,
438 policy->me.net, policy->other.net,
439 policy->me.net_mask, policy->other.net_mask,
440 XFRM_POLICY_OUT, policy->upper_proto,
441 this->protocol, this->reqid);
442
443 status |= charon->kernel_interface->add_policy(charon->kernel_interface,
444 this->other.addr, this->me.addr,
445 policy->other.net, policy->me.net,
446 policy->other.net_mask, policy->me.net_mask,
447 XFRM_POLICY_IN, policy->upper_proto,
448 this->protocol, this->reqid);
449
450 status |= charon->kernel_interface->add_policy(charon->kernel_interface,
451 this->other.addr, this->me.addr,
452 policy->other.net, policy->me.net,
453 policy->other.net_mask, policy->me.net_mask,
454 XFRM_POLICY_FWD, policy->upper_proto,
455 this->protocol, this->reqid);
456
457 if (status != SUCCESS)
458 {
459 my_iter->destroy(my_iter);
460 other_iter->destroy(other_iter);
461 policy->me.net->destroy(policy->me.net);
462 policy->other.net->destroy(policy->other.net);
463 free(policy);
464 return status;
465 }
466
467 /* add it to the policy list, since we want to know which policies we own */
468 this->policies->insert_last(this->policies, policy);
469 }
470 }
471 my_iter->destroy(my_iter);
472 other_iter->destroy(other_iter);
473 return SUCCESS;
474 }
475
476 /**
477 * Implementation of child_sa_t.set_rekeyed.
478 */
479 static void set_rekeyed(private_child_sa_t *this)
480 {
481 this->rekeyed = TRUE;
482 }
483
484 /**
485 * Implementation of child_sa_t.log_status.
486 */
487 static void log_status(private_child_sa_t *this, logger_t *logger, char* name)
488 {
489 iterator_t *iterator;
490 sa_policy_t *policy;
491 struct protoent *proto;
492 char proto_buf[8] = "";
493 char *proto_name = proto_buf;
494
495 if (logger == NULL)
496 {
497 logger = this->logger;
498 }
499 if (this->soft_lifetime)
500 {
501 logger->log(logger, CONTROL|LEVEL1, " \"%s\": protected with %s (0x%x/0x%x), reqid %d, rekeying in %ds:",
502 name,
503 this->protocol == PROTO_ESP ? "ESP" : "AH",
504 htonl(this->me.spi), htonl(this->other.spi),
505 this->reqid,
506 this->soft_lifetime - (time(NULL) - this->install_time));
507 }
508 else
509 {
510
511 logger->log(logger, CONTROL|LEVEL1, " \"%s\": protected with %s (0x%x/0x%x), reqid %d, no rekeying:",
512 name,
513 this->protocol == PROTO_ESP ? "ESP" : "AH",
514 htonl(this->me.spi), htonl(this->other.spi),
515 this->reqid);
516 }
517 iterator = this->policies->create_iterator(this->policies, TRUE);
518 while (iterator->has_next(iterator))
519 {
520 iterator->current(iterator, (void**)&policy);
521 if (policy->upper_proto)
522 {
523 proto = getprotobynumber(policy->upper_proto);
524 if (proto)
525 {
526 proto_name = proto->p_name;
527 }
528 else
529 {
530 snprintf(proto_buf, sizeof(proto_buf), "<%d>", policy->upper_proto);
531 }
532 }
533 logger->log(logger, CONTROL, " \"%s\": %s/%d==%s==%s/%d",
534 name,
535 policy->me.net->get_address(policy->me.net), policy->me.net_mask,
536 proto_name,
537 policy->other.net->get_address(policy->other.net), policy->other.net_mask);
538 }
539 iterator->destroy(iterator);
540 }
541
542 /**
543 * Update the host adress/port of a SA
544 */
545 static status_t update_sa_hosts(private_child_sa_t *this, host_t *new_me, host_t *new_other,
546 int my_changes, int other_changes, bool mine)
547 {
548 host_t *src, *dst, *new_src, *new_dst;
549 int src_changes, dst_changes;
550 status_t status;
551 u_int32_t spi;
552
553 if (mine)
554 {
555 src = this->me.addr;
556 dst = this->other.addr;
557 new_src = new_me;
558 new_dst = new_other;
559 src_changes = my_changes;
560 dst_changes = other_changes;
561 spi = this->me.spi;
562 }
563 else
564 {
565 src = this->other.addr;
566 dst = this->me.addr;
567 new_src = new_other;
568 new_dst = new_me;
569 src_changes = other_changes;
570 dst_changes = my_changes;
571 spi = this->other.spi;
572 }
573
574 this->logger->log(this->logger, CONTROL|LEVEL1,
575 "updating %s SA 0x%x, from %s:%d..%s:%d to %s:%d..%s:%d",
576 mapping_find(protocol_id_m, this->protocol), ntohl(spi),
577 src->get_address(src), src->get_port(src),
578 dst->get_address(dst), dst->get_port(dst),
579 new_src->get_address(new_src), new_src->get_port(new_src),
580 new_dst->get_address(new_dst), new_dst->get_port(new_dst));
581
582 status = charon->kernel_interface->update_sa_hosts(
583 charon->kernel_interface,
584 src, dst, new_src, new_dst,
585 src_changes, dst_changes,
586 spi, this->protocol);
587
588 if (status != SUCCESS)
589 {
590 return FAILED;
591 }
592 return SUCCESS;
593 }
594
595 /**
596 * Update the host adress/port of a policy
597 */
598 static status_t update_policy_hosts(private_child_sa_t *this, host_t *new_me, host_t *new_other)
599 {
600 iterator_t *iterator;
601 sa_policy_t *policy;
602 status_t status;
603
604 iterator = this->policies->create_iterator(this->policies, TRUE);
605 while (iterator->iterate(iterator, (void**)&policy))
606 {
607 this->logger->log(this->logger, CONTROL|LEVEL1,
608 "updating policy: %s/%d====%s/%d",
609 policy->me.net->get_address(policy->me.net), policy->me.net_mask,
610 policy->other.net->get_address(policy->other.net), policy->other.net_mask);
611
612 status = charon->kernel_interface->add_policy(
613 charon->kernel_interface,
614 new_me, new_other,
615 policy->me.net, policy->other.net,
616 policy->me.net_mask, policy->other.net_mask,
617 XFRM_POLICY_OUT, policy->upper_proto,
618 this->protocol, this->reqid);
619
620 status |= charon->kernel_interface->add_policy(
621 charon->kernel_interface,
622 new_other, new_me,
623 policy->other.net, policy->me.net,
624 policy->other.net_mask, policy->me.net_mask,
625 XFRM_POLICY_IN, policy->upper_proto,
626 this->protocol, this->reqid);
627
628 status |= charon->kernel_interface->add_policy(
629 charon->kernel_interface,
630 new_other, new_me,
631 policy->other.net, policy->me.net,
632 policy->other.net_mask, policy->me.net_mask,
633 XFRM_POLICY_FWD, policy->upper_proto,
634 this->protocol, this->reqid);
635
636 if (status != SUCCESS)
637 {
638 iterator->destroy(iterator);
639 return FAILED;
640 }
641 }
642 iterator->destroy(iterator);
643
644 return SUCCESS;
645 }
646
647 /**
648 * Implementation of child_sa_t.update_hosts.
649 */
650 static status_t update_hosts(private_child_sa_t *this, host_t *new_me, host_t *new_other,
651 int my_changes, int other_changes)
652 {
653 if (!my_changes || !other_changes)
654 {
655 return SUCCESS;
656 }
657
658 /* update our (initator) SAs */
659 if (update_sa_hosts(this, new_me, new_other, my_changes, other_changes, TRUE) != SUCCESS)
660 {
661 return FAILED;
662 }
663
664 /* update his (responder) SAs */
665 if (update_sa_hosts(this, new_me, new_other, my_changes, other_changes, FALSE) != SUCCESS)
666 {
667 return FAILED;
668 }
669
670 /* update policies */
671 if (my_changes & HOST_DIFF_ADDR || other_changes & HOST_DIFF_ADDR)
672 {
673 if (update_policy_hosts(this, new_me, new_other) != SUCCESS)
674 {
675 return FAILED;
676 }
677 }
678
679 /* update hosts */
680 if (my_changes)
681 {
682 this->me.addr->destroy(this->me.addr);
683 this->me.addr = new_me->clone(new_me);
684 }
685
686 if (other_changes)
687 {
688 this->other.addr->destroy(this->other.addr);
689 this->other.addr = new_other->clone(new_other);
690 }
691
692 return SUCCESS;
693 }
694
695 /**
696 * Implementation of child_sa_t.destroy.
697 */
698 static void destroy(private_child_sa_t *this)
699 {
700 sa_policy_t *policy;
701
702 /* delete SAs in the kernel, if they are set up */
703 if (this->me.spi)
704 {
705 charon->kernel_interface->del_sa(charon->kernel_interface,
706 this->me.addr, this->me.spi, this->protocol);
707 }
708 if (this->alloc_esp_spi && this->alloc_esp_spi != this->me.spi)
709 {
710 charon->kernel_interface->del_sa(charon->kernel_interface,
711 this->me.addr, this->alloc_esp_spi, PROTO_ESP);
712 }
713 if (this->alloc_ah_spi && this->alloc_ah_spi != this->me.spi)
714 {
715 charon->kernel_interface->del_sa(charon->kernel_interface,
716 this->me.addr, this->alloc_ah_spi, PROTO_AH);
717 }
718 if (this->other.spi)
719 {
720 charon->kernel_interface->del_sa(charon->kernel_interface,
721 this->other.addr, this->other.spi, this->protocol);
722 }
723
724 /* delete all policies in the kernel */
725 while (this->policies->remove_last(this->policies, (void**)&policy) == SUCCESS)
726 {
727 if (!this->rekeyed)
728 {
729 /* let rekeyed policies, as they are used by another child_sa */
730 charon->kernel_interface->del_policy(charon->kernel_interface,
731 this->me.addr, this->other.addr,
732 policy->me.net, policy->other.net,
733 policy->me.net_mask, policy->other.net_mask,
734 XFRM_POLICY_OUT, policy->upper_proto);
735
736 charon->kernel_interface->del_policy(charon->kernel_interface,
737 this->other.addr, this->me.addr,
738 policy->other.net, policy->me.net,
739 policy->other.net_mask, policy->me.net_mask,
740 XFRM_POLICY_IN, policy->upper_proto);
741
742 charon->kernel_interface->del_policy(charon->kernel_interface,
743 this->other.addr, this->me.addr,
744 policy->other.net, policy->me.net,
745 policy->other.net_mask, policy->me.net_mask,
746 XFRM_POLICY_FWD, policy->upper_proto);
747 }
748 policy->me.net->destroy(policy->me.net);
749 policy->other.net->destroy(policy->other.net);
750 free(policy);
751 }
752 this->policies->destroy(this->policies);
753
754 free(this);
755 }
756
757 /*
758 * Described in header.
759 */
760 child_sa_t * child_sa_create(u_int32_t rekey, host_t *me, host_t* other,
761 u_int32_t soft_lifetime, u_int32_t hard_lifetime,
762 bool use_natt)
763 {
764 static u_int32_t reqid = REQID_START;
765 private_child_sa_t *this = malloc_thing(private_child_sa_t);
766
767 /* public functions */
768 this->public.get_reqid = (u_int32_t(*)(child_sa_t*))get_reqid;
769 this->public.get_spi = (u_int32_t(*)(child_sa_t*, bool))get_spi;
770 this->public.get_protocol = (protocol_id_t(*)(child_sa_t*))get_protocol;
771 this->public.alloc = (status_t(*)(child_sa_t*,linked_list_t*))alloc;
772 this->public.add = (status_t(*)(child_sa_t*,proposal_t*,prf_plus_t*))add;
773 this->public.update = (status_t(*)(child_sa_t*,proposal_t*,prf_plus_t*))update;
774 this->public.add_policies = (status_t (*)(child_sa_t*, linked_list_t*,linked_list_t*))add_policies;
775 this->public.set_rekeyed = (void (*)(child_sa_t*))set_rekeyed;
776 this->public.log_status = (void (*)(child_sa_t*, logger_t*, char*))log_status;
777 this->public.destroy = (void(*)(child_sa_t*))destroy;
778
779 /* private data */
780 this->logger = logger_manager->get_logger(logger_manager, CHILD_SA);
781 this->me.addr = me;
782 this->other.addr = other;
783 this->me.spi = 0;
784 this->other.spi = 0;
785 this->alloc_ah_spi = 0;
786 this->alloc_esp_spi = 0;
787 this->use_natt = use_natt;
788 this->soft_lifetime = soft_lifetime;
789 this->hard_lifetime = hard_lifetime;
790 /* reuse old reqid if we are rekeying an existing CHILD_SA */
791 this->reqid = rekey ? rekey : ++reqid;
792 this->policies = linked_list_create();
793 this->protocol = PROTO_NONE;
794 this->rekeyed = FALSE;
795
796 return &this->public;
797 }