unity: Send all traffic selectors in a single UNITY_SPLIT_INCLUDE attribute
[strongswan.git] / src / libcharon / plugins / unity / unity_plugin.c
1 /*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
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
16 #include "unity_plugin.h"
17 #include "unity_handler.h"
18 #include "unity_narrow.h"
19 #include "unity_provider.h"
20
21 #include <daemon.h>
22 #include <hydra.h>
23
24 typedef struct private_unity_plugin_t private_unity_plugin_t;
25
26 /**
27 * private data of unity_plugin
28 */
29 struct private_unity_plugin_t {
30
31 /**
32 * public functions
33 */
34 unity_plugin_t public;
35
36 /**
37 * Handler for UNITY configuration attributes
38 */
39 unity_handler_t *handler;
40
41 /**
42 * Responder Unity configuration attribute provider
43 */
44 unity_provider_t *provider;
45
46 /**
47 * Traffic selector narrower, for Unity Split-Includes
48 */
49 unity_narrow_t *narrower;
50 };
51
52 METHOD(plugin_t, get_name, char*,
53 private_unity_plugin_t *this)
54 {
55 return "unity";
56 }
57
58 /**
59 * Register listener
60 */
61 static bool plugin_cb(private_unity_plugin_t *this,
62 plugin_feature_t *feature, bool reg, void *cb_data)
63 {
64 if (reg)
65 {
66 hydra->attributes->add_handler(hydra->attributes,
67 &this->handler->handler);
68 hydra->attributes->add_provider(hydra->attributes,
69 &this->provider->provider);
70 charon->bus->add_listener(charon->bus, &this->narrower->listener);
71 }
72 else
73 {
74 charon->bus->remove_listener(charon->bus, &this->narrower->listener);
75 hydra->attributes->remove_handler(hydra->attributes,
76 &this->handler->handler);
77 hydra->attributes->remove_provider(hydra->attributes,
78 &this->provider->provider);
79
80 }
81 return TRUE;
82 }
83
84 METHOD(plugin_t, get_features, int,
85 private_unity_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, "unity"),
90 };
91 *features = f;
92 return countof(f);
93 }
94
95 METHOD(plugin_t, destroy, void,
96 private_unity_plugin_t *this)
97 {
98 this->narrower->destroy(this->narrower);
99 this->handler->destroy(this->handler);
100 this->provider->destroy(this->provider);
101 free(this);
102 }
103
104 /*
105 * see header file
106 */
107 plugin_t *unity_plugin_create()
108 {
109 private_unity_plugin_t *this;
110
111 INIT(this,
112 .public = {
113 .plugin = {
114 .get_name = _get_name,
115 .get_features = _get_features,
116 .destroy = _destroy,
117 },
118 },
119 .handler = unity_handler_create(),
120 .provider = unity_provider_create(),
121 );
122 this->narrower = unity_narrow_create(this->handler);
123
124 return &this->public.plugin;
125 }