Introduce "features" for the kernel backends returning kernel capabilities
[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, u_int64_t *bytes)
211 {
212 if (!this->ipsec)
213 {
214 return NOT_SUPPORTED;
215 }
216 return this->ipsec->query_sa(this->ipsec, src, dst, spi, protocol, mark, bytes);
217 }
218
219 METHOD(kernel_interface_t, del_sa, status_t,
220 private_kernel_interface_t *this, host_t *src, host_t *dst, u_int32_t spi,
221 u_int8_t protocol, u_int16_t cpi, mark_t mark)
222 {
223 if (!this->ipsec)
224 {
225 return NOT_SUPPORTED;
226 }
227 return this->ipsec->del_sa(this->ipsec, src, dst, spi, protocol, cpi, mark);
228 }
229
230 METHOD(kernel_interface_t, flush_sas, status_t,
231 private_kernel_interface_t *this)
232 {
233 if (!this->ipsec)
234 {
235 return NOT_SUPPORTED;
236 }
237 return this->ipsec->flush_sas(this->ipsec);
238 }
239
240 METHOD(kernel_interface_t, add_policy, status_t,
241 private_kernel_interface_t *this, host_t *src, host_t *dst,
242 traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
243 policy_dir_t direction, policy_type_t type, ipsec_sa_cfg_t *sa,
244 mark_t mark, policy_priority_t priority)
245 {
246 if (!this->ipsec)
247 {
248 return NOT_SUPPORTED;
249 }
250 return this->ipsec->add_policy(this->ipsec, src, dst, src_ts, dst_ts,
251 direction, type, sa, mark, priority);
252 }
253
254 METHOD(kernel_interface_t, query_policy, status_t,
255 private_kernel_interface_t *this, traffic_selector_t *src_ts,
256 traffic_selector_t *dst_ts, policy_dir_t direction, mark_t mark,
257 u_int32_t *use_time)
258 {
259 if (!this->ipsec)
260 {
261 return NOT_SUPPORTED;
262 }
263 return this->ipsec->query_policy(this->ipsec, src_ts, dst_ts,
264 direction, mark, use_time);
265 }
266
267 METHOD(kernel_interface_t, del_policy, status_t,
268 private_kernel_interface_t *this, traffic_selector_t *src_ts,
269 traffic_selector_t *dst_ts, policy_dir_t direction, u_int32_t reqid,
270 mark_t mark, policy_priority_t priority)
271 {
272 if (!this->ipsec)
273 {
274 return NOT_SUPPORTED;
275 }
276 return this->ipsec->del_policy(this->ipsec, src_ts, dst_ts,
277 direction, reqid, mark, priority);
278 }
279
280 METHOD(kernel_interface_t, flush_policies, status_t,
281 private_kernel_interface_t *this)
282 {
283 if (!this->ipsec)
284 {
285 return NOT_SUPPORTED;
286 }
287 return this->ipsec->flush_policies(this->ipsec);
288 }
289
290 METHOD(kernel_interface_t, get_source_addr, host_t*,
291 private_kernel_interface_t *this, host_t *dest, host_t *src)
292 {
293 if (!this->net)
294 {
295 return NULL;
296 }
297 return this->net->get_source_addr(this->net, dest, src);
298 }
299
300 METHOD(kernel_interface_t, get_nexthop, host_t*,
301 private_kernel_interface_t *this, host_t *dest, host_t *src)
302 {
303 if (!this->net)
304 {
305 return NULL;
306 }
307 return this->net->get_nexthop(this->net, dest, src);
308 }
309
310 METHOD(kernel_interface_t, get_interface, bool,
311 private_kernel_interface_t *this, host_t *host, char **name)
312 {
313 if (!this->net)
314 {
315 return NULL;
316 }
317 return this->net->get_interface(this->net, host, name);
318 }
319
320 METHOD(kernel_interface_t, create_address_enumerator, enumerator_t*,
321 private_kernel_interface_t *this, kernel_address_type_t which)
322 {
323 if (!this->net)
324 {
325 return enumerator_create_empty();
326 }
327 return this->net->create_address_enumerator(this->net, which);
328 }
329
330 METHOD(kernel_interface_t, add_ip, status_t,
331 private_kernel_interface_t *this, host_t *virtual_ip, int prefix,
332 char *iface)
333 {
334 if (!this->net)
335 {
336 return NOT_SUPPORTED;
337 }
338 return this->net->add_ip(this->net, virtual_ip, prefix, iface);
339 }
340
341 METHOD(kernel_interface_t, del_ip, status_t,
342 private_kernel_interface_t *this, host_t *virtual_ip, int prefix, bool wait)
343 {
344 if (!this->net)
345 {
346 return NOT_SUPPORTED;
347 }
348 return this->net->del_ip(this->net, virtual_ip, prefix, wait);
349 }
350
351 METHOD(kernel_interface_t, add_route, status_t,
352 private_kernel_interface_t *this, chunk_t dst_net,
353 u_int8_t prefixlen, host_t *gateway, host_t *src_ip, char *if_name)
354 {
355 if (!this->net)
356 {
357 return NOT_SUPPORTED;
358 }
359 return this->net->add_route(this->net, dst_net, prefixlen, gateway,
360 src_ip, if_name);
361 }
362
363 METHOD(kernel_interface_t, del_route, status_t,
364 private_kernel_interface_t *this, chunk_t dst_net,
365 u_int8_t prefixlen, host_t *gateway, host_t *src_ip, char *if_name)
366 {
367 if (!this->net)
368 {
369 return NOT_SUPPORTED;
370 }
371 return this->net->del_route(this->net, dst_net, prefixlen, gateway,
372 src_ip, if_name);
373 }
374
375 METHOD(kernel_interface_t, bypass_socket, bool,
376 private_kernel_interface_t *this, int fd, int family)
377 {
378 if (!this->ipsec)
379 {
380 return FALSE;
381 }
382 return this->ipsec->bypass_socket(this->ipsec, fd, family);
383 }
384
385 METHOD(kernel_interface_t, enable_udp_decap, bool,
386 private_kernel_interface_t *this, int fd, int family, u_int16_t port)
387 {
388 if (!this->ipsec)
389 {
390 return FALSE;
391 }
392 return this->ipsec->enable_udp_decap(this->ipsec, fd, family, port);
393 }
394
395 METHOD(kernel_interface_t, is_interface_usable, bool,
396 private_kernel_interface_t *this, const char *iface)
397 {
398 status_t expected;
399
400 if (!this->ifaces_filter)
401 {
402 return TRUE;
403 }
404 expected = this->ifaces_exclude ? NOT_FOUND : SUCCESS;
405 return this->ifaces_filter->find_first(this->ifaces_filter, (void*)streq,
406 NULL, iface) == expected;
407 }
408
409 METHOD(kernel_interface_t, all_interfaces_usable, bool,
410 private_kernel_interface_t *this)
411 {
412 return this->ifaces_filter == NULL;
413 }
414
415 METHOD(kernel_interface_t, get_address_by_ts, status_t,
416 private_kernel_interface_t *this, traffic_selector_t *ts, host_t **ip)
417 {
418 enumerator_t *addrs;
419 host_t *host;
420 int family;
421 bool found = FALSE;
422
423 DBG2(DBG_KNL, "getting a local address in traffic selector %R", ts);
424
425 /* if we have a family which includes localhost, we do not
426 * search for an IP, we use the default */
427 family = ts->get_type(ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
428
429 if (family == AF_INET)
430 {
431 host = host_create_from_string("127.0.0.1", 0);
432 }
433 else
434 {
435 host = host_create_from_string("::1", 0);
436 }
437
438 if (ts->includes(ts, host))
439 {
440 *ip = host_create_any(family);
441 host->destroy(host);
442 DBG2(DBG_KNL, "using host %H", *ip);
443 return SUCCESS;
444 }
445 host->destroy(host);
446
447 addrs = create_address_enumerator(this, ADDR_TYPE_ALL);
448 while (addrs->enumerate(addrs, (void**)&host))
449 {
450 if (ts->includes(ts, host))
451 {
452 found = TRUE;
453 *ip = host->clone(host);
454 break;
455 }
456 }
457 addrs->destroy(addrs);
458
459 if (!found)
460 {
461 DBG2(DBG_KNL, "no local address found in traffic selector %R", ts);
462 return FAILED;
463 }
464
465 DBG2(DBG_KNL, "using host %H", *ip);
466 return SUCCESS;
467 }
468
469
470 METHOD(kernel_interface_t, add_ipsec_interface, void,
471 private_kernel_interface_t *this, kernel_ipsec_constructor_t constructor)
472 {
473 if (!this->ipsec)
474 {
475 this->ipsec_constructor = constructor;
476 this->ipsec = constructor();
477 }
478 }
479
480 METHOD(kernel_interface_t, remove_ipsec_interface, void,
481 private_kernel_interface_t *this, kernel_ipsec_constructor_t constructor)
482 {
483 if (constructor == this->ipsec_constructor && this->ipsec)
484 {
485 this->ipsec->destroy(this->ipsec);
486 this->ipsec = NULL;
487 }
488 }
489
490 METHOD(kernel_interface_t, add_net_interface, void,
491 private_kernel_interface_t *this, kernel_net_constructor_t constructor)
492 {
493 if (!this->net)
494 {
495 this->net_constructor = constructor;
496 this->net = constructor();
497 }
498 }
499
500 METHOD(kernel_interface_t, remove_net_interface, void,
501 private_kernel_interface_t *this, kernel_net_constructor_t constructor)
502 {
503 if (constructor == this->net_constructor && this->net)
504 {
505 this->net->destroy(this->net);
506 this->net = NULL;
507 }
508 }
509
510 METHOD(kernel_interface_t, add_listener, void,
511 private_kernel_interface_t *this, kernel_listener_t *listener)
512 {
513 this->mutex->lock(this->mutex);
514 this->listeners->insert_last(this->listeners, listener);
515 this->mutex->unlock(this->mutex);
516 }
517
518 METHOD(kernel_interface_t, remove_listener, void,
519 private_kernel_interface_t *this, kernel_listener_t *listener)
520 {
521 this->mutex->lock(this->mutex);
522 this->listeners->remove(this->listeners, listener, NULL);
523 this->mutex->unlock(this->mutex);
524 }
525
526 METHOD(kernel_interface_t, acquire, void,
527 private_kernel_interface_t *this, u_int32_t reqid,
528 traffic_selector_t *src_ts, traffic_selector_t *dst_ts)
529 {
530 kernel_listener_t *listener;
531 enumerator_t *enumerator;
532 this->mutex->lock(this->mutex);
533 enumerator = this->listeners->create_enumerator(this->listeners);
534 while (enumerator->enumerate(enumerator, &listener))
535 {
536 if (listener->acquire &&
537 !listener->acquire(listener, reqid, src_ts, dst_ts))
538 {
539 this->listeners->remove_at(this->listeners, enumerator);
540 }
541 }
542 enumerator->destroy(enumerator);
543 this->mutex->unlock(this->mutex);
544 }
545
546 METHOD(kernel_interface_t, expire, void,
547 private_kernel_interface_t *this, u_int32_t reqid, u_int8_t protocol,
548 u_int32_t spi, bool hard)
549 {
550 kernel_listener_t *listener;
551 enumerator_t *enumerator;
552 this->mutex->lock(this->mutex);
553 enumerator = this->listeners->create_enumerator(this->listeners);
554 while (enumerator->enumerate(enumerator, &listener))
555 {
556 if (listener->expire &&
557 !listener->expire(listener, reqid, protocol, spi, hard))
558 {
559 this->listeners->remove_at(this->listeners, enumerator);
560 }
561 }
562 enumerator->destroy(enumerator);
563 this->mutex->unlock(this->mutex);
564 }
565
566 METHOD(kernel_interface_t, mapping, void,
567 private_kernel_interface_t *this, u_int32_t reqid, u_int32_t spi,
568 host_t *remote)
569 {
570 kernel_listener_t *listener;
571 enumerator_t *enumerator;
572 this->mutex->lock(this->mutex);
573 enumerator = this->listeners->create_enumerator(this->listeners);
574 while (enumerator->enumerate(enumerator, &listener))
575 {
576 if (listener->mapping &&
577 !listener->mapping(listener, reqid, spi, remote))
578 {
579 this->listeners->remove_at(this->listeners, enumerator);
580 }
581 }
582 enumerator->destroy(enumerator);
583 this->mutex->unlock(this->mutex);
584 }
585
586 METHOD(kernel_interface_t, migrate, void,
587 private_kernel_interface_t *this, u_int32_t reqid,
588 traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
589 policy_dir_t direction, host_t *local, host_t *remote)
590 {
591 kernel_listener_t *listener;
592 enumerator_t *enumerator;
593 this->mutex->lock(this->mutex);
594 enumerator = this->listeners->create_enumerator(this->listeners);
595 while (enumerator->enumerate(enumerator, &listener))
596 {
597 if (listener->migrate &&
598 !listener->migrate(listener, reqid, src_ts, dst_ts, direction,
599 local, remote))
600 {
601 this->listeners->remove_at(this->listeners, enumerator);
602 }
603 }
604 enumerator->destroy(enumerator);
605 this->mutex->unlock(this->mutex);
606 }
607
608 static bool call_roam(kernel_listener_t *listener, bool *roam)
609 {
610 return listener->roam && !listener->roam(listener, *roam);
611 }
612
613 METHOD(kernel_interface_t, roam, void,
614 private_kernel_interface_t *this, bool address)
615 {
616 this->mutex->lock(this->mutex);
617 this->listeners->remove(this->listeners, &address, (void*)call_roam);
618 this->mutex->unlock(this->mutex);
619 }
620
621 METHOD(kernel_interface_t, register_algorithm, void,
622 private_kernel_interface_t *this, u_int16_t alg_id, transform_type_t type,
623 u_int16_t kernel_id, char *kernel_name)
624 {
625 kernel_algorithm_t *algorithm;
626
627 INIT(algorithm,
628 .type = type,
629 .ike = alg_id,
630 .kernel = kernel_id,
631 .name = strdup(kernel_name),
632 );
633
634 this->mutex_algs->lock(this->mutex_algs);
635 this->algorithms->insert_first(this->algorithms, algorithm);
636 this->mutex_algs->unlock(this->mutex_algs);
637 }
638
639 METHOD(kernel_interface_t, lookup_algorithm, bool,
640 private_kernel_interface_t *this, u_int16_t alg_id, transform_type_t type,
641 u_int16_t *kernel_id, char **kernel_name)
642 {
643 kernel_algorithm_t *algorithm;
644 enumerator_t *enumerator;
645 bool found = FALSE;
646
647 this->mutex_algs->lock(this->mutex_algs);
648 enumerator = this->algorithms->create_enumerator(this->algorithms);
649 while (enumerator->enumerate(enumerator, &algorithm))
650 {
651 if (algorithm->type == type && algorithm->ike == alg_id)
652 {
653 if (kernel_id)
654 {
655 *kernel_id = algorithm->kernel;
656 }
657 if (kernel_name)
658 {
659 *kernel_name = algorithm->name;
660 }
661 found = TRUE;
662 break;
663 }
664 }
665 enumerator->destroy(enumerator);
666 this->mutex_algs->unlock(this->mutex_algs);
667 return found;
668 }
669
670 METHOD(kernel_interface_t, destroy, void,
671 private_kernel_interface_t *this)
672 {
673 kernel_algorithm_t *algorithm;
674
675 while (this->algorithms->remove_first(this->algorithms,
676 (void**)&algorithm) == SUCCESS)
677 {
678 free(algorithm->name);
679 free(algorithm);
680 }
681 this->algorithms->destroy(this->algorithms);
682 this->mutex_algs->destroy(this->mutex_algs);
683 DESTROY_IF(this->ipsec);
684 DESTROY_IF(this->net);
685 DESTROY_FUNCTION_IF(this->ifaces_filter, (void*)free);
686 this->listeners->destroy(this->listeners);
687 this->mutex->destroy(this->mutex);
688 free(this);
689 }
690
691 /*
692 * Described in header-file
693 */
694 kernel_interface_t *kernel_interface_create()
695 {
696 private_kernel_interface_t *this;
697 char *ifaces;
698
699 INIT(this,
700 .public = {
701 .get_features = _get_features,
702 .get_spi = _get_spi,
703 .get_cpi = _get_cpi,
704 .add_sa = _add_sa,
705 .update_sa = _update_sa,
706 .query_sa = _query_sa,
707 .del_sa = _del_sa,
708 .flush_sas = _flush_sas,
709 .add_policy = _add_policy,
710 .query_policy = _query_policy,
711 .del_policy = _del_policy,
712 .flush_policies = _flush_policies,
713 .get_source_addr = _get_source_addr,
714 .get_nexthop = _get_nexthop,
715 .get_interface = _get_interface,
716 .create_address_enumerator = _create_address_enumerator,
717 .add_ip = _add_ip,
718 .del_ip = _del_ip,
719 .add_route = _add_route,
720 .del_route = _del_route,
721 .bypass_socket = _bypass_socket,
722 .enable_udp_decap = _enable_udp_decap,
723
724 .is_interface_usable = _is_interface_usable,
725 .all_interfaces_usable = _all_interfaces_usable,
726 .get_address_by_ts = _get_address_by_ts,
727 .add_ipsec_interface = _add_ipsec_interface,
728 .remove_ipsec_interface = _remove_ipsec_interface,
729 .add_net_interface = _add_net_interface,
730 .remove_net_interface = _remove_net_interface,
731
732 .add_listener = _add_listener,
733 .remove_listener = _remove_listener,
734 .register_algorithm = _register_algorithm,
735 .lookup_algorithm = _lookup_algorithm,
736 .acquire = _acquire,
737 .expire = _expire,
738 .mapping = _mapping,
739 .migrate = _migrate,
740 .roam = _roam,
741 .destroy = _destroy,
742 },
743 .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
744 .listeners = linked_list_create(),
745 .mutex_algs = mutex_create(MUTEX_TYPE_DEFAULT),
746 .algorithms = linked_list_create(),
747 );
748
749 ifaces = lib->settings->get_str(lib->settings,
750 "%s.interfaces_use", NULL, hydra->daemon);
751 if (!ifaces)
752 {
753 this->ifaces_exclude = TRUE;
754 ifaces = lib->settings->get_str(lib->settings,
755 "%s.interfaces_ignore", NULL, hydra->daemon);
756 }
757 if (ifaces)
758 {
759 enumerator_t *enumerator;
760 char *iface;
761
762 enumerator = enumerator_create_token(ifaces, ",", " ");
763 while (enumerator->enumerate(enumerator, &iface))
764 {
765 if (!this->ifaces_filter)
766 {
767 this->ifaces_filter = linked_list_create();
768 }
769 this->ifaces_filter->insert_last(this->ifaces_filter,
770 strdup(iface));
771 }
772 enumerator->destroy(enumerator);
773 }
774
775 return &this->public;
776 }