53b8324b72329933a3b54c4b18e2757ce7bcd9ee
[strongswan.git] / src / libhydra / kernel / kernel_interface.c
1 /*
2 * Copyright (C) 2008-2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 * Copyright (C) 2010 Martin Willi
5 * Copyright (C) 2010 revosec AG
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /*
19 * Copyright (c) 2012 Nanoteq Pty Ltd
20 *
21 * Permission is hereby granted, free of charge, to any person obtaining a copy
22 * of this software and associated documentation files (the "Software"), to deal
23 * in the Software without restriction, including without limitation the rights
24 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25 * copies of the Software, and to permit persons to whom the Software is
26 * furnished to do so, subject to the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be included in
29 * all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37 * THE SOFTWARE.
38 */
39
40 #include "kernel_interface.h"
41
42 #include <hydra.h>
43 #include <utils/debug.h>
44 #include <threading/mutex.h>
45 #include <collections/linked_list.h>
46
47 typedef struct private_kernel_interface_t private_kernel_interface_t;
48
49 typedef struct kernel_algorithm_t kernel_algorithm_t;
50
51 /**
52 * Mapping of IKE algorithms to kernel-specific algorithm identifiers
53 */
54 struct kernel_algorithm_t {
55
56 /**
57 * Transform type of the algorithm
58 */
59 transform_type_t type;
60
61 /**
62 * Identifier specified in IKE
63 */
64 u_int16_t ike;
65
66 /**
67 * Identifier as defined in pfkeyv2.h
68 */
69 u_int16_t kernel;
70
71 /**
72 * Name of the algorithm in linux crypto API
73 */
74 char *name;
75 };
76
77 /**
78 * Private data of a kernel_interface_t object.
79 */
80 struct private_kernel_interface_t {
81
82 /**
83 * Public part of kernel_interface_t object.
84 */
85 kernel_interface_t public;
86
87 /**
88 * Registered IPsec constructor
89 */
90 kernel_ipsec_constructor_t ipsec_constructor;
91
92 /**
93 * Registered net constructor
94 */
95 kernel_net_constructor_t net_constructor;
96
97 /**
98 * ipsec interface
99 */
100 kernel_ipsec_t *ipsec;
101
102 /**
103 * network interface
104 */
105 kernel_net_t *net;
106
107 /**
108 * mutex for listeners
109 */
110 mutex_t *mutex;
111
112 /**
113 * list of registered listeners
114 */
115 linked_list_t *listeners;
116
117 /**
118 * mutex for algorithm mappings
119 */
120 mutex_t *mutex_algs;
121
122 /**
123 * List of algorithm mappings (kernel_algorithm_t*)
124 */
125 linked_list_t *algorithms;
126
127 /**
128 * List of interface names to include or exclude (char*), NULL if interfaces
129 * are not filtered
130 */
131 linked_list_t *ifaces_filter;
132
133 /**
134 * TRUE to exclude interfaces listed in ifaces_filter, FALSE to consider
135 * only those listed there
136 */
137 bool ifaces_exclude;
138 };
139
140 METHOD(kernel_interface_t, get_features, kernel_feature_t,
141 private_kernel_interface_t *this)
142 {
143 kernel_feature_t features = 0;
144
145 if (this->ipsec && this->ipsec->get_features)
146 {
147 features |= this->ipsec->get_features(this->ipsec);
148 }
149 if (this->net && this->net->get_features)
150 {
151 features |= this->net->get_features(this->net);
152 }
153 return features;
154 }
155
156 METHOD(kernel_interface_t, get_spi, status_t,
157 private_kernel_interface_t *this, host_t *src, host_t *dst,
158 u_int8_t protocol, u_int32_t reqid, u_int32_t *spi)
159 {
160 if (!this->ipsec)
161 {
162 return NOT_SUPPORTED;
163 }
164 return this->ipsec->get_spi(this->ipsec, src, dst, protocol, reqid, spi);
165 }
166
167 METHOD(kernel_interface_t, get_cpi, status_t,
168 private_kernel_interface_t *this, host_t *src, host_t *dst,
169 u_int32_t reqid, u_int16_t *cpi)
170 {
171 if (!this->ipsec)
172 {
173 return NOT_SUPPORTED;
174 }
175 return this->ipsec->get_cpi(this->ipsec, src, dst, reqid, cpi);
176 }
177
178 METHOD(kernel_interface_t, add_sa, status_t,
179 private_kernel_interface_t *this, host_t *src, host_t *dst,
180 u_int32_t spi, u_int8_t protocol, u_int32_t reqid, mark_t mark,
181 u_int32_t tfc, lifetime_cfg_t *lifetime, u_int16_t enc_alg, chunk_t enc_key,
182 u_int16_t int_alg, chunk_t int_key, ipsec_mode_t mode, u_int16_t ipcomp,
183 u_int16_t cpi, bool encap, bool esn, bool inbound,
184 traffic_selector_t *src_ts, traffic_selector_t *dst_ts)
185 {
186 if (!this->ipsec)
187 {
188 return NOT_SUPPORTED;
189 }
190 return this->ipsec->add_sa(this->ipsec, src, dst, spi, protocol, reqid,
191 mark, tfc, lifetime, enc_alg, enc_key, int_alg, int_key, mode,
192 ipcomp, cpi, encap, esn, inbound, src_ts, dst_ts);
193 }
194
195 METHOD(kernel_interface_t, update_sa, status_t,
196 private_kernel_interface_t *this, u_int32_t spi, u_int8_t protocol,
197 u_int16_t cpi, host_t *src, host_t *dst, host_t *new_src, host_t *new_dst,
198 bool encap, bool new_encap, mark_t mark)
199 {
200 if (!this->ipsec)
201 {
202 return NOT_SUPPORTED;
203 }
204 return this->ipsec->update_sa(this->ipsec, spi, protocol, cpi, src, dst,
205 new_src, new_dst, encap, new_encap, mark);
206 }
207
208 METHOD(kernel_interface_t, query_sa, status_t,
209 private_kernel_interface_t *this, host_t *src, host_t *dst,
210 u_int32_t spi, u_int8_t protocol, mark_t mark,
211 u_int64_t *bytes, u_int64_t *packets)
212 {
213 if (!this->ipsec)
214 {
215 return NOT_SUPPORTED;
216 }
217 return this->ipsec->query_sa(this->ipsec, src, dst, spi, protocol, mark,
218 bytes, packets);
219 }
220
221 METHOD(kernel_interface_t, del_sa, status_t,
222 private_kernel_interface_t *this, host_t *src, host_t *dst, u_int32_t spi,
223 u_int8_t protocol, u_int16_t cpi, mark_t mark)
224 {
225 if (!this->ipsec)
226 {
227 return NOT_SUPPORTED;
228 }
229 return this->ipsec->del_sa(this->ipsec, src, dst, spi, protocol, cpi, mark);
230 }
231
232 METHOD(kernel_interface_t, flush_sas, status_t,
233 private_kernel_interface_t *this)
234 {
235 if (!this->ipsec)
236 {
237 return NOT_SUPPORTED;
238 }
239 return this->ipsec->flush_sas(this->ipsec);
240 }
241
242 METHOD(kernel_interface_t, add_policy, status_t,
243 private_kernel_interface_t *this, host_t *src, host_t *dst,
244 traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
245 policy_dir_t direction, policy_type_t type, ipsec_sa_cfg_t *sa,
246 mark_t mark, policy_priority_t priority)
247 {
248 if (!this->ipsec)
249 {
250 return NOT_SUPPORTED;
251 }
252 return this->ipsec->add_policy(this->ipsec, src, dst, src_ts, dst_ts,
253 direction, type, sa, mark, priority);
254 }
255
256 METHOD(kernel_interface_t, query_policy, status_t,
257 private_kernel_interface_t *this, traffic_selector_t *src_ts,
258 traffic_selector_t *dst_ts, policy_dir_t direction, mark_t mark,
259 u_int32_t *use_time)
260 {
261 if (!this->ipsec)
262 {
263 return NOT_SUPPORTED;
264 }
265 return this->ipsec->query_policy(this->ipsec, src_ts, dst_ts,
266 direction, mark, use_time);
267 }
268
269 METHOD(kernel_interface_t, del_policy, status_t,
270 private_kernel_interface_t *this, traffic_selector_t *src_ts,
271 traffic_selector_t *dst_ts, policy_dir_t direction, u_int32_t reqid,
272 mark_t mark, policy_priority_t priority)
273 {
274 if (!this->ipsec)
275 {
276 return NOT_SUPPORTED;
277 }
278 return this->ipsec->del_policy(this->ipsec, src_ts, dst_ts,
279 direction, reqid, mark, priority);
280 }
281
282 METHOD(kernel_interface_t, flush_policies, status_t,
283 private_kernel_interface_t *this)
284 {
285 if (!this->ipsec)
286 {
287 return NOT_SUPPORTED;
288 }
289 return this->ipsec->flush_policies(this->ipsec);
290 }
291
292 METHOD(kernel_interface_t, get_source_addr, host_t*,
293 private_kernel_interface_t *this, host_t *dest, host_t *src)
294 {
295 if (!this->net)
296 {
297 return NULL;
298 }
299 return this->net->get_source_addr(this->net, dest, src);
300 }
301
302 METHOD(kernel_interface_t, get_nexthop, host_t*,
303 private_kernel_interface_t *this, host_t *dest, host_t *src)
304 {
305 if (!this->net)
306 {
307 return NULL;
308 }
309 return this->net->get_nexthop(this->net, dest, src);
310 }
311
312 METHOD(kernel_interface_t, get_interface, bool,
313 private_kernel_interface_t *this, host_t *host, char **name)
314 {
315 if (!this->net)
316 {
317 return NULL;
318 }
319 return this->net->get_interface(this->net, host, name);
320 }
321
322 METHOD(kernel_interface_t, create_address_enumerator, enumerator_t*,
323 private_kernel_interface_t *this, kernel_address_type_t which)
324 {
325 if (!this->net)
326 {
327 return enumerator_create_empty();
328 }
329 return this->net->create_address_enumerator(this->net, which);
330 }
331
332 METHOD(kernel_interface_t, add_ip, status_t,
333 private_kernel_interface_t *this, host_t *virtual_ip, int prefix,
334 char *iface)
335 {
336 if (!this->net)
337 {
338 return NOT_SUPPORTED;
339 }
340 return this->net->add_ip(this->net, virtual_ip, prefix, iface);
341 }
342
343 METHOD(kernel_interface_t, del_ip, status_t,
344 private_kernel_interface_t *this, host_t *virtual_ip, int prefix, bool wait)
345 {
346 if (!this->net)
347 {
348 return NOT_SUPPORTED;
349 }
350 return this->net->del_ip(this->net, virtual_ip, prefix, wait);
351 }
352
353 METHOD(kernel_interface_t, add_route, status_t,
354 private_kernel_interface_t *this, chunk_t dst_net,
355 u_int8_t prefixlen, host_t *gateway, host_t *src_ip, char *if_name)
356 {
357 if (!this->net)
358 {
359 return NOT_SUPPORTED;
360 }
361 return this->net->add_route(this->net, dst_net, prefixlen, gateway,
362 src_ip, if_name);
363 }
364
365 METHOD(kernel_interface_t, del_route, status_t,
366 private_kernel_interface_t *this, chunk_t dst_net,
367 u_int8_t prefixlen, host_t *gateway, host_t *src_ip, char *if_name)
368 {
369 if (!this->net)
370 {
371 return NOT_SUPPORTED;
372 }
373 return this->net->del_route(this->net, dst_net, prefixlen, gateway,
374 src_ip, if_name);
375 }
376
377 METHOD(kernel_interface_t, bypass_socket, bool,
378 private_kernel_interface_t *this, int fd, int family)
379 {
380 if (!this->ipsec)
381 {
382 return FALSE;
383 }
384 return this->ipsec->bypass_socket(this->ipsec, fd, family);
385 }
386
387 METHOD(kernel_interface_t, enable_udp_decap, bool,
388 private_kernel_interface_t *this, int fd, int family, u_int16_t port)
389 {
390 if (!this->ipsec)
391 {
392 return FALSE;
393 }
394 return this->ipsec->enable_udp_decap(this->ipsec, fd, family, port);
395 }
396
397 METHOD(kernel_interface_t, is_interface_usable, bool,
398 private_kernel_interface_t *this, const char *iface)
399 {
400 status_t expected;
401
402 if (!this->ifaces_filter)
403 {
404 return TRUE;
405 }
406 expected = this->ifaces_exclude ? NOT_FOUND : SUCCESS;
407 return this->ifaces_filter->find_first(this->ifaces_filter, (void*)streq,
408 NULL, iface) == expected;
409 }
410
411 METHOD(kernel_interface_t, all_interfaces_usable, bool,
412 private_kernel_interface_t *this)
413 {
414 return this->ifaces_filter == NULL;
415 }
416
417 METHOD(kernel_interface_t, get_address_by_ts, status_t,
418 private_kernel_interface_t *this, traffic_selector_t *ts, host_t **ip)
419 {
420 enumerator_t *addrs;
421 host_t *host;
422 int family;
423 bool found = FALSE;
424
425 DBG2(DBG_KNL, "getting a local address in traffic selector %R", ts);
426
427 /* if we have a family which includes localhost, we do not
428 * search for an IP, we use the default */
429 family = ts->get_type(ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
430
431 if (family == AF_INET)
432 {
433 host = host_create_from_string("127.0.0.1", 0);
434 }
435 else
436 {
437 host = host_create_from_string("::1", 0);
438 }
439
440 if (ts->includes(ts, host))
441 {
442 *ip = host_create_any(family);
443 host->destroy(host);
444 DBG2(DBG_KNL, "using host %H", *ip);
445 return SUCCESS;
446 }
447 host->destroy(host);
448
449 addrs = create_address_enumerator(this, ADDR_TYPE_ALL);
450 while (addrs->enumerate(addrs, (void**)&host))
451 {
452 if (ts->includes(ts, host))
453 {
454 found = TRUE;
455 *ip = host->clone(host);
456 break;
457 }
458 }
459 addrs->destroy(addrs);
460
461 if (!found)
462 {
463 DBG2(DBG_KNL, "no local address found in traffic selector %R", ts);
464 return FAILED;
465 }
466
467 DBG2(DBG_KNL, "using host %H", *ip);
468 return SUCCESS;
469 }
470
471
472 METHOD(kernel_interface_t, add_ipsec_interface, void,
473 private_kernel_interface_t *this, kernel_ipsec_constructor_t constructor)
474 {
475 if (!this->ipsec)
476 {
477 this->ipsec_constructor = constructor;
478 this->ipsec = constructor();
479 }
480 }
481
482 METHOD(kernel_interface_t, remove_ipsec_interface, void,
483 private_kernel_interface_t *this, kernel_ipsec_constructor_t constructor)
484 {
485 if (constructor == this->ipsec_constructor && this->ipsec)
486 {
487 this->ipsec->destroy(this->ipsec);
488 this->ipsec = NULL;
489 }
490 }
491
492 METHOD(kernel_interface_t, add_net_interface, void,
493 private_kernel_interface_t *this, kernel_net_constructor_t constructor)
494 {
495 if (!this->net)
496 {
497 this->net_constructor = constructor;
498 this->net = constructor();
499 }
500 }
501
502 METHOD(kernel_interface_t, remove_net_interface, void,
503 private_kernel_interface_t *this, kernel_net_constructor_t constructor)
504 {
505 if (constructor == this->net_constructor && this->net)
506 {
507 this->net->destroy(this->net);
508 this->net = NULL;
509 }
510 }
511
512 METHOD(kernel_interface_t, add_listener, void,
513 private_kernel_interface_t *this, kernel_listener_t *listener)
514 {
515 this->mutex->lock(this->mutex);
516 this->listeners->insert_last(this->listeners, listener);
517 this->mutex->unlock(this->mutex);
518 }
519
520 METHOD(kernel_interface_t, remove_listener, void,
521 private_kernel_interface_t *this, kernel_listener_t *listener)
522 {
523 this->mutex->lock(this->mutex);
524 this->listeners->remove(this->listeners, listener, NULL);
525 this->mutex->unlock(this->mutex);
526 }
527
528 METHOD(kernel_interface_t, acquire, void,
529 private_kernel_interface_t *this, u_int32_t reqid,
530 traffic_selector_t *src_ts, traffic_selector_t *dst_ts)
531 {
532 kernel_listener_t *listener;
533 enumerator_t *enumerator;
534 this->mutex->lock(this->mutex);
535 enumerator = this->listeners->create_enumerator(this->listeners);
536 while (enumerator->enumerate(enumerator, &listener))
537 {
538 if (listener->acquire &&
539 !listener->acquire(listener, reqid, src_ts, dst_ts))
540 {
541 this->listeners->remove_at(this->listeners, enumerator);
542 }
543 }
544 enumerator->destroy(enumerator);
545 this->mutex->unlock(this->mutex);
546 }
547
548 METHOD(kernel_interface_t, expire, void,
549 private_kernel_interface_t *this, u_int32_t reqid, u_int8_t protocol,
550 u_int32_t spi, bool hard)
551 {
552 kernel_listener_t *listener;
553 enumerator_t *enumerator;
554 this->mutex->lock(this->mutex);
555 enumerator = this->listeners->create_enumerator(this->listeners);
556 while (enumerator->enumerate(enumerator, &listener))
557 {
558 if (listener->expire &&
559 !listener->expire(listener, reqid, protocol, spi, hard))
560 {
561 this->listeners->remove_at(this->listeners, enumerator);
562 }
563 }
564 enumerator->destroy(enumerator);
565 this->mutex->unlock(this->mutex);
566 }
567
568 METHOD(kernel_interface_t, mapping, void,
569 private_kernel_interface_t *this, u_int32_t reqid, u_int32_t spi,
570 host_t *remote)
571 {
572 kernel_listener_t *listener;
573 enumerator_t *enumerator;
574 this->mutex->lock(this->mutex);
575 enumerator = this->listeners->create_enumerator(this->listeners);
576 while (enumerator->enumerate(enumerator, &listener))
577 {
578 if (listener->mapping &&
579 !listener->mapping(listener, reqid, spi, remote))
580 {
581 this->listeners->remove_at(this->listeners, enumerator);
582 }
583 }
584 enumerator->destroy(enumerator);
585 this->mutex->unlock(this->mutex);
586 }
587
588 METHOD(kernel_interface_t, migrate, void,
589 private_kernel_interface_t *this, u_int32_t reqid,
590 traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
591 policy_dir_t direction, host_t *local, host_t *remote)
592 {
593 kernel_listener_t *listener;
594 enumerator_t *enumerator;
595 this->mutex->lock(this->mutex);
596 enumerator = this->listeners->create_enumerator(this->listeners);
597 while (enumerator->enumerate(enumerator, &listener))
598 {
599 if (listener->migrate &&
600 !listener->migrate(listener, reqid, src_ts, dst_ts, direction,
601 local, remote))
602 {
603 this->listeners->remove_at(this->listeners, enumerator);
604 }
605 }
606 enumerator->destroy(enumerator);
607 this->mutex->unlock(this->mutex);
608 }
609
610 static bool call_roam(kernel_listener_t *listener, bool *roam)
611 {
612 return listener->roam && !listener->roam(listener, *roam);
613 }
614
615 METHOD(kernel_interface_t, roam, void,
616 private_kernel_interface_t *this, bool address)
617 {
618 this->mutex->lock(this->mutex);
619 this->listeners->remove(this->listeners, &address, (void*)call_roam);
620 this->mutex->unlock(this->mutex);
621 }
622
623 METHOD(kernel_interface_t, register_algorithm, void,
624 private_kernel_interface_t *this, u_int16_t alg_id, transform_type_t type,
625 u_int16_t kernel_id, char *kernel_name)
626 {
627 kernel_algorithm_t *algorithm;
628
629 INIT(algorithm,
630 .type = type,
631 .ike = alg_id,
632 .kernel = kernel_id,
633 .name = strdup(kernel_name),
634 );
635
636 this->mutex_algs->lock(this->mutex_algs);
637 this->algorithms->insert_first(this->algorithms, algorithm);
638 this->mutex_algs->unlock(this->mutex_algs);
639 }
640
641 METHOD(kernel_interface_t, lookup_algorithm, bool,
642 private_kernel_interface_t *this, u_int16_t alg_id, transform_type_t type,
643 u_int16_t *kernel_id, char **kernel_name)
644 {
645 kernel_algorithm_t *algorithm;
646 enumerator_t *enumerator;
647 bool found = FALSE;
648
649 this->mutex_algs->lock(this->mutex_algs);
650 enumerator = this->algorithms->create_enumerator(this->algorithms);
651 while (enumerator->enumerate(enumerator, &algorithm))
652 {
653 if (algorithm->type == type && algorithm->ike == alg_id)
654 {
655 if (kernel_id)
656 {
657 *kernel_id = algorithm->kernel;
658 }
659 if (kernel_name)
660 {
661 *kernel_name = algorithm->name;
662 }
663 found = TRUE;
664 break;
665 }
666 }
667 enumerator->destroy(enumerator);
668 this->mutex_algs->unlock(this->mutex_algs);
669 return found;
670 }
671
672 METHOD(kernel_interface_t, destroy, void,
673 private_kernel_interface_t *this)
674 {
675 kernel_algorithm_t *algorithm;
676
677 while (this->algorithms->remove_first(this->algorithms,
678 (void**)&algorithm) == SUCCESS)
679 {
680 free(algorithm->name);
681 free(algorithm);
682 }
683 this->algorithms->destroy(this->algorithms);
684 this->mutex_algs->destroy(this->mutex_algs);
685 DESTROY_IF(this->ipsec);
686 DESTROY_IF(this->net);
687 DESTROY_FUNCTION_IF(this->ifaces_filter, (void*)free);
688 this->listeners->destroy(this->listeners);
689 this->mutex->destroy(this->mutex);
690 free(this);
691 }
692
693 /*
694 * Described in header-file
695 */
696 kernel_interface_t *kernel_interface_create()
697 {
698 private_kernel_interface_t *this;
699 char *ifaces;
700
701 INIT(this,
702 .public = {
703 .get_features = _get_features,
704 .get_spi = _get_spi,
705 .get_cpi = _get_cpi,
706 .add_sa = _add_sa,
707 .update_sa = _update_sa,
708 .query_sa = _query_sa,
709 .del_sa = _del_sa,
710 .flush_sas = _flush_sas,
711 .add_policy = _add_policy,
712 .query_policy = _query_policy,
713 .del_policy = _del_policy,
714 .flush_policies = _flush_policies,
715 .get_source_addr = _get_source_addr,
716 .get_nexthop = _get_nexthop,
717 .get_interface = _get_interface,
718 .create_address_enumerator = _create_address_enumerator,
719 .add_ip = _add_ip,
720 .del_ip = _del_ip,
721 .add_route = _add_route,
722 .del_route = _del_route,
723 .bypass_socket = _bypass_socket,
724 .enable_udp_decap = _enable_udp_decap,
725
726 .is_interface_usable = _is_interface_usable,
727 .all_interfaces_usable = _all_interfaces_usable,
728 .get_address_by_ts = _get_address_by_ts,
729 .add_ipsec_interface = _add_ipsec_interface,
730 .remove_ipsec_interface = _remove_ipsec_interface,
731 .add_net_interface = _add_net_interface,
732 .remove_net_interface = _remove_net_interface,
733
734 .add_listener = _add_listener,
735 .remove_listener = _remove_listener,
736 .register_algorithm = _register_algorithm,
737 .lookup_algorithm = _lookup_algorithm,
738 .acquire = _acquire,
739 .expire = _expire,
740 .mapping = _mapping,
741 .migrate = _migrate,
742 .roam = _roam,
743 .destroy = _destroy,
744 },
745 .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
746 .listeners = linked_list_create(),
747 .mutex_algs = mutex_create(MUTEX_TYPE_DEFAULT),
748 .algorithms = linked_list_create(),
749 );
750
751 ifaces = lib->settings->get_str(lib->settings,
752 "%s.interfaces_use", NULL, hydra->daemon);
753 if (!ifaces)
754 {
755 this->ifaces_exclude = TRUE;
756 ifaces = lib->settings->get_str(lib->settings,
757 "%s.interfaces_ignore", NULL, hydra->daemon);
758 }
759 if (ifaces)
760 {
761 enumerator_t *enumerator;
762 char *iface;
763
764 enumerator = enumerator_create_token(ifaces, ",", " ");
765 while (enumerator->enumerate(enumerator, &iface))
766 {
767 if (!this->ifaces_filter)
768 {
769 this->ifaces_filter = linked_list_create();
770 }
771 this->ifaces_filter->insert_last(this->ifaces_filter,
772 strdup(iface));
773 }
774 enumerator->destroy(enumerator);
775 }
776
777 return &this->public;
778 }