]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libcharon/plugins/updown/updown_plugin.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libcharon / plugins / updown / updown_plugin.c
CommitLineData
ad3af574
MW
1/*
2 * Copyright (C) 2008 Martin Willi
19ef2aec
TB
3 *
4 * Copyright (C) secunet Security Networks AG
ad3af574
MW
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
ad3af574
MW
15 */
16
17#include "updown_plugin.h"
49653b6b 18#include "updown_listener.h"
e0d3014a 19#include "updown_handler.h"
ad3af574
MW
20
21#include <daemon.h>
ad3af574
MW
22
23typedef struct private_updown_plugin_t private_updown_plugin_t;
24
25/**
26 * private data of updown plugin
27 */
28struct private_updown_plugin_t {
29
30 /**
31 * implements plugin interface
32 */
33 updown_plugin_t public;
7daf5226 34
ad3af574
MW
35 /**
36 * Listener interface, listens to CHILD_SA state changes
37 */
49653b6b 38 updown_listener_t *listener;
e0d3014a
MW
39
40 /**
41 * Attribute handler, to pass DNS servers to updown
42 */
43 updown_handler_t *handler;
ad3af574
MW
44};
45
787b5884
MW
46METHOD(plugin_t, get_name, char*,
47 private_updown_plugin_t *this)
48{
49 return "updown";
50}
51
49d333ac
TB
52/**
53 * Register listener
54 */
55static bool plugin_cb(private_updown_plugin_t *this,
56 plugin_feature_t *feature, bool reg, void *cb_data)
ad3af574 57{
49d333ac 58 if (reg)
e0d3014a 59 {
49d333ac 60 if (lib->settings->get_bool(lib->settings,
d223fe80 61 "%s.plugins.updown.dns_handler", FALSE, lib->ns))
49d333ac
TB
62 {
63 this->handler = updown_handler_create();
75136327
MW
64 charon->attributes->add_handler(charon->attributes,
65 &this->handler->handler);
49d333ac
TB
66 }
67 this->listener = updown_listener_create(this->handler);
68 charon->bus->add_listener(charon->bus, &this->listener->listener);
e0d3014a 69 }
49d333ac
TB
70 else
71 {
72 charon->bus->remove_listener(charon->bus, &this->listener->listener);
73 this->listener->destroy(this->listener);
74 if (this->handler)
75 {
76 this->handler->destroy(this->handler);
75136327
MW
77 charon->attributes->remove_handler(charon->attributes,
78 &this->handler->handler);
49d333ac
TB
79 }
80 }
81 return TRUE;
82}
83
84METHOD(plugin_t, get_features, int,
85 private_updown_plugin_t *this, plugin_feature_t *features[])
86{
87 static plugin_feature_t f[] = {
88 PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
89 PLUGIN_PROVIDE(CUSTOM, "updown"),
90 };
91 *features = f;
92 return countof(f);
93}
94
95METHOD(plugin_t, destroy, void,
96 private_updown_plugin_t *this)
97{
ad3af574
MW
98 free(this);
99}
100
101/*
102 * see header file
103 */
9ce567f8 104plugin_t *updown_plugin_create()
ad3af574 105{
6e279171 106 private_updown_plugin_t *this;
7daf5226 107
6e279171
MW
108 INIT(this,
109 .public = {
110 .plugin = {
787b5884 111 .get_name = _get_name,
49d333ac 112 .get_features = _get_features,
6e279171
MW
113 .destroy = _destroy,
114 },
115 },
6e279171 116 );
7daf5226 117
ad3af574
MW
118 return &this->public.plugin;
119}