summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/uci
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcharon/plugins/uci')
-rw-r--r--src/libcharon/plugins/uci/Makefile.in7
-rw-r--r--src/libcharon/plugins/uci/uci_config.c112
-rw-r--r--src/libcharon/plugins/uci/uci_control.c37
-rw-r--r--src/libcharon/plugins/uci/uci_creds.c70
-rw-r--r--src/libcharon/plugins/uci/uci_parser.c43
-rw-r--r--src/libcharon/plugins/uci/uci_plugin.c4
6 files changed, 135 insertions, 138 deletions
diff --git a/src/libcharon/plugins/uci/Makefile.in b/src/libcharon/plugins/uci/Makefile.in
index 013ceb7da..dd001e0bd 100644
--- a/src/libcharon/plugins/uci/Makefile.in
+++ b/src/libcharon/plugins/uci/Makefile.in
@@ -192,6 +192,9 @@ am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
+attest_plugins = @attest_plugins@
+axis2c_CFLAGS = @axis2c_CFLAGS@
+axis2c_LIBS = @axis2c_LIBS@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
@@ -200,6 +203,7 @@ build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
c_plugins = @c_plugins@
+clearsilver_LIBS = @clearsilver_LIBS@
datadir = @datadir@
datarootdir = @datarootdir@
dbusservicedir = @dbusservicedir@
@@ -216,11 +220,13 @@ host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
+imcvdir = @imcvdir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
ipsecdir = @ipsecdir@
ipsecgroup = @ipsecgroup@
+ipseclibdir = @ipseclibdir@
ipsecuser = @ipsecuser@
libcharon_plugins = @libcharon_plugins@
libdir = @libdir@
@@ -264,6 +270,7 @@ sharedstatedir = @sharedstatedir@
soup_CFLAGS = @soup_CFLAGS@
soup_LIBS = @soup_LIBS@
srcdir = @srcdir@
+starter_plugins = @starter_plugins@
strongswan_conf = @strongswan_conf@
sysconfdir = @sysconfdir@
systemdsystemunitdir = @systemdsystemunitdir@
diff --git a/src/libcharon/plugins/uci/uci_config.c b/src/libcharon/plugins/uci/uci_config.c
index 4e43388ec..2f5e59b89 100644
--- a/src/libcharon/plugins/uci/uci_config.c
+++ b/src/libcharon/plugins/uci/uci_config.c
@@ -133,10 +133,8 @@ static u_int create_rekey(char *string)
return 12 * 3600;
}
-/**
- * Implementation of peer_enumerator_t.public.enumerate
- */
-static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
+METHOD(enumerator_t, peer_enumerator_enumerate, bool,
+ peer_enumerator_t *this, peer_cfg_t **cfg)
{
char *name, *ike_proposal, *esp_proposal, *ike_rekey, *esp_rekey;
char *local_id, *local_addr, *local_net;
@@ -177,9 +175,9 @@ static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
name, 2, ike_cfg, CERT_SEND_IF_ASKED, UNIQUE_NO,
1, create_rekey(ike_rekey), 0, /* keytries, rekey, reauth */
1800, 900, /* jitter, overtime */
- TRUE, 60, /* mobike, dpddelay */
- NULL, NULL, /* vip, pool */
- FALSE, NULL, NULL); /* mediation, med by, peer id */
+ TRUE, 60, /* mobike, dpddelay */
+ NULL, NULL, /* vip, pool */
+ FALSE, NULL, NULL); /* mediation, med by, peer id */
auth = auth_cfg_create();
auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PSK);
auth->add(auth, AUTH_RULE_IDENTITY,
@@ -208,32 +206,30 @@ static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
return FALSE;
}
-/**
- * Implementation of peer_enumerator_t.public.destroy
- */
-static void peer_enumerator_destroy(peer_enumerator_t *this)
+
+METHOD(enumerator_t, peer_enumerator_destroy, void,
+ peer_enumerator_t *this)
{
DESTROY_IF(this->peer_cfg);
this->inner->destroy(this->inner);
free(this);
}
-/**
- * Implementation of backend_t.create_peer_cfg_enumerator.
- */
-static enumerator_t* create_peer_cfg_enumerator(private_uci_config_t *this,
- identification_t *me,
- identification_t *other)
+METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
+ private_uci_config_t *this, identification_t *me, identification_t *other)
{
- peer_enumerator_t *e = malloc_thing(peer_enumerator_t);
-
- e->public.enumerate = (void*)peer_enumerator_enumerate;
- e->public.destroy = (void*)peer_enumerator_destroy;
- e->peer_cfg = NULL;
- e->inner = this->parser->create_section_enumerator(this->parser,
+ peer_enumerator_t *e;
+
+ INIT(e,
+ .public = {
+ .enumerate = (void*)_peer_enumerator_enumerate,
+ .destroy = _peer_enumerator_destroy,
+ },
+ .inner = this->parser->create_section_enumerator(this->parser,
"local_id", "remote_id", "local_addr", "remote_addr",
"local_net", "remote_net", "ike_proposal", "esp_proposal",
- "ike_rekey", "esp_rekey", NULL);
+ "ike_rekey", "esp_rekey", NULL),
+ );
if (!e->inner)
{
free(e);
@@ -254,10 +250,8 @@ typedef struct {
enumerator_t *inner;
} ike_enumerator_t;
-/**
- * Implementation of peer_enumerator_t.public.enumerate
- */
-static bool ike_enumerator_enumerate(ike_enumerator_t *this, ike_cfg_t **cfg)
+METHOD(enumerator_t, ike_enumerator_enumerate, bool,
+ ike_enumerator_t *this, ike_cfg_t **cfg)
{
char *local_addr, *remote_addr, *ike_proposal;
@@ -281,29 +275,27 @@ static bool ike_enumerator_enumerate(ike_enumerator_t *this, ike_cfg_t **cfg)
return FALSE;
}
-/**
- * Implementation of ike_enumerator_t.public.destroy
- */
-static void ike_enumerator_destroy(ike_enumerator_t *this)
+METHOD(enumerator_t, ike_enumerator_destroy, void,
+ ike_enumerator_t *this)
{
DESTROY_IF(this->ike_cfg);
this->inner->destroy(this->inner);
free(this);
}
-/**
- * Implementation of backend_t.create_ike_cfg_enumerator.
- */
-static enumerator_t* create_ike_cfg_enumerator(private_uci_config_t *this,
- host_t *me, host_t *other)
+METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
+ private_uci_config_t *this, host_t *me, host_t *other)
{
- ike_enumerator_t *e = malloc_thing(ike_enumerator_t);
-
- e->public.enumerate = (void*)ike_enumerator_enumerate;
- e->public.destroy = (void*)ike_enumerator_destroy;
- e->ike_cfg = NULL;
- e->inner = this->parser->create_section_enumerator(this->parser,
- "local_addr", "remote_addr", "ike_proposal", NULL);
+ ike_enumerator_t *e;
+
+ INIT(e,
+ .public = {
+ .enumerate = (void*)_ike_enumerator_enumerate,
+ .destroy = _ike_enumerator_destroy,
+ },
+ .inner = this->parser->create_section_enumerator(this->parser,
+ "local_addr", "remote_addr", "ike_proposal", NULL),
+ );
if (!e->inner)
{
free(e);
@@ -312,10 +304,8 @@ static enumerator_t* create_ike_cfg_enumerator(private_uci_config_t *this,
return &e->public;
}
-/**
- * implements backend_t.get_peer_cfg_by_name.
- */
-static peer_cfg_t *get_peer_cfg_by_name(private_uci_config_t *this, char *name)
+METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
+ private_uci_config_t *this, char *name)
{
enumerator_t *enumerator;
peer_cfg_t *current, *found = NULL;
@@ -336,10 +326,8 @@ static peer_cfg_t *get_peer_cfg_by_name(private_uci_config_t *this, char *name)
return found;
}
-/**
- * Implementation of uci_config_t.destroy.
- */
-static void destroy(private_uci_config_t *this)
+METHOD(uci_config_t, destroy, void,
+ private_uci_config_t *this)
{
free(this);
}
@@ -349,13 +337,19 @@ static void destroy(private_uci_config_t *this)
*/
uci_config_t *uci_config_create(uci_parser_t *parser)
{
- private_uci_config_t *this = malloc_thing(private_uci_config_t);
-
- this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
- this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
- this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
- this->public.destroy = (void(*)(uci_config_t*))destroy;
- this->parser = parser;
+ private_uci_config_t *this;
+
+ INIT(this,
+ .public = {
+ .backend = {
+ .create_peer_cfg_enumerator = _create_peer_cfg_enumerator,
+ .create_ike_cfg_enumerator = _create_ike_cfg_enumerator,
+ .get_peer_cfg_by_name = _get_peer_cfg_by_name,
+ },
+ .destroy = _destroy,
+ },
+ .parser = parser,
+ );
return &this->public;
}
diff --git a/src/libcharon/plugins/uci/uci_control.c b/src/libcharon/plugins/uci/uci_control.c
index aee2505e3..af4a6a711 100644
--- a/src/libcharon/plugins/uci/uci_control.c
+++ b/src/libcharon/plugins/uci/uci_control.c
@@ -76,8 +76,7 @@ static void write_fifo(private_uci_control_t *this, char *format, ...)
*/
static void status(private_uci_control_t *this, char *name)
{
- enumerator_t *configs, *sas;
- iterator_t *children;
+ enumerator_t *configs, *sas, *children;
ike_sa_t *ike_sa;
child_sa_t *child_sa;
peer_cfg_t *peer_cfg;
@@ -92,7 +91,8 @@ static void status(private_uci_control_t *this, char *name)
{
continue;
}
- sas = charon->controller->create_ike_sa_enumerator(charon->controller);
+ sas = charon->controller->create_ike_sa_enumerator(
+ charon->controller, TRUE);
while (sas->enumerate(sas, &ike_sa))
{
if (!streq(ike_sa->get_name(ike_sa), peer_cfg->get_name(peer_cfg)))
@@ -110,8 +110,8 @@ static void status(private_uci_control_t *this, char *name)
fprintf(out, "%-8s %-20D %-16H ", ike_sa->get_name(ike_sa),
ike_sa->get_other_id(ike_sa), ike_sa->get_other_host(ike_sa));
- children = ike_sa->create_child_sa_iterator(ike_sa);
- while (children->iterate(children, (void**)&child_sa))
+ children = ike_sa->create_child_sa_enumerator(ike_sa);
+ while (children->enumerate(children, (void**)&child_sa))
{
fprintf(out, "%#R",
child_sa->get_traffic_selectors(child_sa, FALSE));
@@ -148,8 +148,8 @@ static void initiate(private_uci_control_t *this, char *name)
enumerator = peer_cfg->create_child_cfg_enumerator(peer_cfg);
if (enumerator->enumerate(enumerator, &child_cfg) &&
charon->controller->initiate(charon->controller, peer_cfg,
- child_cfg->get_ref(child_cfg),
- controller_cb_empty, NULL) == SUCCESS)
+ child_cfg->get_ref(child_cfg),
+ controller_cb_empty, NULL, 0) == SUCCESS)
{
write_fifo(this, "connection '%s' established\n", name);
}
@@ -174,7 +174,8 @@ static void terminate(private_uci_control_t *this, char *name)
ike_sa_t *ike_sa;
u_int id;
- enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
+ enumerator = charon->controller->create_ike_sa_enumerator(
+ charon->controller, TRUE);
while (enumerator->enumerate(enumerator, &ike_sa))
{
if (streq(name, ike_sa->get_name(ike_sa)))
@@ -182,7 +183,7 @@ static void terminate(private_uci_control_t *this, char *name)
id = ike_sa->get_unique_id(ike_sa);
enumerator->destroy(enumerator);
charon->controller->terminate_ike(charon->controller, id,
- controller_cb_empty, NULL);
+ controller_cb_empty, NULL, 0);
write_fifo(this, "connection '%s' terminated\n", name);
return;
}
@@ -265,10 +266,8 @@ static job_requeue_t receive(private_uci_control_t *this)
return JOB_REQUEUE_FAIR;
}
-/**
- * Implementation of uci_control_t.destroy
- */
-static void destroy(private_uci_control_t *this)
+METHOD(uci_control_t, destroy, void,
+ private_uci_control_t *this)
{
this->job->cancel(this->job);
unlink(FIFO_FILE);
@@ -280,9 +279,13 @@ static void destroy(private_uci_control_t *this)
*/
uci_control_t *uci_control_create()
{
- private_uci_control_t *this = malloc_thing(private_uci_control_t);
+ private_uci_control_t *this;
- this->public.destroy = (void(*)(uci_control_t*))destroy;
+ INIT(this,
+ .public = {
+ .destroy = _destroy,
+ },
+ );
unlink(FIFO_FILE);
if (mkfifo(FIFO_FILE, S_IRUSR|S_IWUSR) != 0)
@@ -292,8 +295,8 @@ uci_control_t *uci_control_create()
}
else
{
- this->job = callback_job_create((callback_job_cb_t)receive,
- this, NULL, NULL);
+ this->job = callback_job_create_with_prio((callback_job_cb_t)receive,
+ this, NULL, NULL, JOB_PRIO_CRITICAL);
lib->processor->queue_job(lib->processor, (job_t*)this->job);
}
return &this->public;
diff --git a/src/libcharon/plugins/uci/uci_creds.c b/src/libcharon/plugins/uci/uci_creds.c
index 4d664feb2..f5d5ace70 100644
--- a/src/libcharon/plugins/uci/uci_creds.c
+++ b/src/libcharon/plugins/uci/uci_creds.c
@@ -51,11 +51,9 @@ typedef struct {
identification_t *other;
} shared_enumerator_t;
-/**
- * Implementation of shared_enumerator_t.public.enumerate
- */
-static bool shared_enumerator_enumerate(shared_enumerator_t *this,
- shared_key_t **key, id_match_t *me, id_match_t *other)
+METHOD(enumerator_t, shared_enumerator_enumerate, bool,
+ shared_enumerator_t *this, shared_key_t **key, id_match_t *me,
+ id_match_t *other)
{
char *local_id, *remote_id, *psk;
identification_t *local, *remote;
@@ -107,23 +105,17 @@ static bool shared_enumerator_enumerate(shared_enumerator_t *this,
return TRUE;
}
-/**
- * Implementation of shared_enumerator_t.public.destroy
- */
-static void shared_enumerator_destroy(shared_enumerator_t *this)
+METHOD(enumerator_t, shared_enumerator_destroy, void,
+ shared_enumerator_t *this)
{
this->inner->destroy(this->inner);
DESTROY_IF(this->current);
free(this);
}
-/**
- * Implementation of backend_t.create_shared_cfg_enumerator.
- */
-static enumerator_t* create_shared_enumerator(private_uci_creds_t *this,
- shared_key_type_t type,
- identification_t *me,
- identification_t *other)
+METHOD(credential_set_t, create_shared_enumerator, enumerator_t*,
+ private_uci_creds_t *this, shared_key_type_t type,
+ identification_t *me, identification_t *other)
{
shared_enumerator_t *e;
@@ -132,14 +124,16 @@ static enumerator_t* create_shared_enumerator(private_uci_creds_t *this,
return NULL;
}
- e = malloc_thing(shared_enumerator_t);
- e->current = NULL;
- e->public.enumerate = (void*)shared_enumerator_enumerate;
- e->public.destroy = (void*)shared_enumerator_destroy;
- e->me = me;
- e->other = other;
- e->inner = this->parser->create_section_enumerator(this->parser,
- "local_id", "remote_id", "psk", NULL);
+ INIT(e,
+ .public = {
+ .enumerate = (void*)_shared_enumerator_enumerate,
+ .destroy = _shared_enumerator_destroy,
+ },
+ .me = me,
+ .other = other,
+ .inner = this->parser->create_section_enumerator(this->parser,
+ "local_id", "remote_id", "psk", NULL),
+ );
if (!e->inner)
{
free(e);
@@ -148,24 +142,28 @@ static enumerator_t* create_shared_enumerator(private_uci_creds_t *this,
return &e->public;
}
-/**
- * Implementation of uci_creds_t.destroy
- */
-static void destroy(private_uci_creds_t *this)
+METHOD(uci_creds_t, destroy, void,
+ private_uci_creds_t *this)
{
free(this);
}
uci_creds_t *uci_creds_create(uci_parser_t *parser)
{
- private_uci_creds_t *this = malloc_thing(private_uci_creds_t);
-
- this->public.credential_set.create_shared_enumerator = (enumerator_t*(*)(credential_set_t*, shared_key_type_t, identification_t*, identification_t*))create_shared_enumerator;
- this->public.credential_set.create_private_enumerator = (enumerator_t*(*) (credential_set_t*, key_type_t, identification_t*))return_null;
- this->public.credential_set.create_cert_enumerator = (enumerator_t*(*) (credential_set_t*, certificate_type_t, key_type_t,identification_t *, bool))return_null;
- this->public.credential_set.create_cdp_enumerator = (enumerator_t*(*) (credential_set_t *,certificate_type_t, identification_t *))return_null;
- this->public.credential_set.cache_cert = (void (*)(credential_set_t *, certificate_t *))nop;
- this->public.destroy = (void(*) (uci_creds_t*))destroy;
+ private_uci_creds_t *this;
+
+ INIT(this,
+ .public = {
+ .credential_set = {
+ .create_shared_enumerator = _create_shared_enumerator,
+ .create_private_enumerator = (void*)return_null,
+ .create_cert_enumerator = (void*)return_null,
+ .create_cdp_enumerator = (void*)return_null,
+ .cache_cert = (void*)nop,
+ },
+ .destroy = _destroy,
+ },
+ );
this->parser = parser;
diff --git a/src/libcharon/plugins/uci/uci_parser.c b/src/libcharon/plugins/uci/uci_parser.c
index 6de55d218..2429e9e44 100644
--- a/src/libcharon/plugins/uci/uci_parser.c
+++ b/src/libcharon/plugins/uci/uci_parser.c
@@ -57,10 +57,8 @@ typedef struct {
char *keywords[];
} section_enumerator_t;
-/**
- * Implementation of section_enumerator_t.enumerate
- */
-static bool section_enumerator_enumerate(section_enumerator_t *this, ...)
+METHOD(enumerator_t, section_enumerator_enumerate, bool,
+ section_enumerator_t *this, ...)
{
struct uci_element *element;
char **value;
@@ -104,19 +102,15 @@ static bool section_enumerator_enumerate(section_enumerator_t *this, ...)
return TRUE;
}
-/**
- * Implementation of section_enumerator_t.public.destroy
- */
-static void section_enumerator_destroy(section_enumerator_t *this)
+METHOD(enumerator_t, section_enumerator_destroy, void,
+ section_enumerator_t *this)
{
uci_free_context(this->ctx);
free(this);
}
-/**
- * Implementation of backend_t.create_section_enumerator.
- */
-static enumerator_t* create_section_enumerator(private_uci_parser_t *this, ...)
+METHOD(uci_parser_t, create_section_enumerator, enumerator_t*,
+ private_uci_parser_t *this, ...)
{
section_enumerator_t *e;
va_list args;
@@ -140,8 +134,8 @@ static enumerator_t* create_section_enumerator(private_uci_parser_t *this, ...)
while (e->keywords[i++]);
va_end(args);
- e->public.enumerate = (void*)section_enumerator_enumerate;
- e->public.destroy = (void*)section_enumerator_destroy;
+ e->public.enumerate = (void*)_section_enumerator_enumerate;
+ e->public.destroy = _section_enumerator_destroy;
/* load uci context */
e->ctx = uci_alloc_context();
@@ -160,10 +154,8 @@ static enumerator_t* create_section_enumerator(private_uci_parser_t *this, ...)
return &e->public;
}
-/**
- * Implementation of uci_parser_t.destroy.
- */
-static void destroy(private_uci_parser_t *this)
+METHOD(uci_parser_t, destroy, void,
+ private_uci_parser_t *this)
{
free(this->package);
free(this);
@@ -174,12 +166,15 @@ static void destroy(private_uci_parser_t *this)
*/
uci_parser_t *uci_parser_create(char *package)
{
- private_uci_parser_t *this = malloc_thing(private_uci_parser_t);
-
- this->public.create_section_enumerator = (enumerator_t*(*)(uci_parser_t*, ...))create_section_enumerator;
- this->public.destroy = (void(*)(uci_parser_t*))destroy;
-
- this->package = strdup(package);
+ private_uci_parser_t *this;
+
+ INIT(this,
+ .public = {
+ .create_section_enumerator = _create_section_enumerator,
+ .destroy = _destroy,
+ },
+ .package = strdup(package),
+ );
return &this->public;
}
diff --git a/src/libcharon/plugins/uci/uci_plugin.c b/src/libcharon/plugins/uci/uci_plugin.c
index a6d24c32b..497c473a4 100644
--- a/src/libcharon/plugins/uci/uci_plugin.c
+++ b/src/libcharon/plugins/uci/uci_plugin.c
@@ -92,10 +92,10 @@ plugin_t *uci_plugin_create()
},
},
.parser = uci_parser_create(UCI_PACKAGE),
- .config = uci_config_create(this->parser),
- .creds = uci_creds_create(this->parser),
.control = uci_control_create(),
);
+ this->config = uci_config_create(this->parser);
+ this->creds = uci_creds_create(this->parser);
charon->backends->add_backend(charon->backends, &this->config->backend);
lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);