diff options
Diffstat (limited to 'src/libcharon/plugins/dhcp/dhcp_plugin.c')
-rw-r--r-- | src/libcharon/plugins/dhcp/dhcp_plugin.c | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/src/libcharon/plugins/dhcp/dhcp_plugin.c b/src/libcharon/plugins/dhcp/dhcp_plugin.c index f8782c2a4..c36c60d28 100644 --- a/src/libcharon/plugins/dhcp/dhcp_plugin.c +++ b/src/libcharon/plugins/dhcp/dhcp_plugin.c @@ -1,4 +1,7 @@ /* + * Copyright (C) 2013 Tobias Brunner + * Hochschule fuer Technik Rapperswil + * * Copyright (C) 2010 Martin Willi * Copyright (C) 2010 revosec AG * @@ -17,6 +20,7 @@ #include <hydra.h> #include <daemon.h> +#include <plugins/plugin_feature.h> #include "dhcp_socket.h" #include "dhcp_provider.h" @@ -50,13 +54,49 @@ METHOD(plugin_t, get_name, char*, return "dhcp"; } +/** + * Register listener + */ +static bool plugin_cb(private_dhcp_plugin_t *this, + plugin_feature_t *feature, bool reg, void *cb_data) +{ + if (reg) + { + this->socket = dhcp_socket_create(); + + if (!this->socket) + { + return FALSE; + } + this->provider = dhcp_provider_create(this->socket); + hydra->attributes->add_provider(hydra->attributes, + &this->provider->provider); + } + else + { + hydra->attributes->remove_provider(hydra->attributes, + &this->provider->provider); + this->provider->destroy(this->provider); + this->socket->destroy(this->socket); + } + return TRUE; +} + +METHOD(plugin_t, get_features, int, + private_dhcp_plugin_t *this, plugin_feature_t *features[]) +{ + static plugin_feature_t f[] = { + PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL), + PLUGIN_PROVIDE(CUSTOM, "dhcp"), + PLUGIN_DEPENDS(RNG, RNG_WEAK), + }; + *features = f; + return countof(f); +} + METHOD(plugin_t, destroy, void, private_dhcp_plugin_t *this) { - hydra->attributes->remove_provider(hydra->attributes, - &this->provider->provider); - this->provider->destroy(this->provider); - this->socket->destroy(this->socket); free(this); } @@ -67,27 +107,27 @@ plugin_t *dhcp_plugin_create() { private_dhcp_plugin_t *this; + if (!lib->caps->check(lib->caps, CAP_NET_BIND_SERVICE)) + { /* required to bind DHCP socket (port 68) */ + DBG1(DBG_NET, "dhcp plugin requires CAP_NET_BIND_SERVICE capability"); + return NULL; + } + else if (!lib->caps->keep(lib->caps, CAP_NET_RAW)) + { /* required to open DHCP receive socket (AF_PACKET). according to + * capabilities(7) it is also required to use the socket */ + DBG1(DBG_NET, "dhcp plugin requires CAP_NET_RAW capability"); + return NULL; + } + INIT(this, .public = { .plugin = { .get_name = _get_name, - .reload = (void*)return_false, + .get_features = _get_features, .destroy = _destroy, }, }, - .socket = dhcp_socket_create(), ); - if (!this->socket) - { - free(this); - return NULL; - } - - this->provider = dhcp_provider_create(this->socket); - hydra->attributes->add_provider(hydra->attributes, - &this->provider->provider); - return &this->public.plugin; } - |