2 * Copyright (C) 2013 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
5 * Copyright (C) 2010 Martin Willi
6 * Copyright (C) 2010 revosec AG
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include "dhcp_plugin.h"
22 #include <plugins/plugin_feature.h>
24 #include "dhcp_socket.h"
25 #include "dhcp_provider.h"
27 typedef struct private_dhcp_plugin_t private_dhcp_plugin_t
;
30 * private data of dhcp plugin
32 struct private_dhcp_plugin_t
{
35 * implements plugin interface
40 * DHCP communication socket
42 dhcp_socket_t
*socket
;
47 dhcp_provider_t
*provider
;
50 METHOD(plugin_t
, get_name
, char*,
51 private_dhcp_plugin_t
*this)
59 static bool plugin_cb(private_dhcp_plugin_t
*this,
60 plugin_feature_t
*feature
, bool reg
, void *cb_data
)
64 this->socket
= dhcp_socket_create();
70 this->provider
= dhcp_provider_create(this->socket
);
71 charon
->attributes
->add_provider(charon
->attributes
,
72 &this->provider
->provider
);
76 charon
->attributes
->remove_provider(charon
->attributes
,
77 &this->provider
->provider
);
78 this->provider
->destroy(this->provider
);
79 this->socket
->destroy(this->socket
);
84 METHOD(plugin_t
, get_features
, int,
85 private_dhcp_plugin_t
*this, plugin_feature_t
*features
[])
87 static plugin_feature_t f
[] = {
88 PLUGIN_CALLBACK((plugin_feature_callback_t
)plugin_cb
, NULL
),
89 PLUGIN_PROVIDE(CUSTOM
, "dhcp"),
90 PLUGIN_DEPENDS(RNG
, RNG_WEAK
),
96 METHOD(plugin_t
, destroy
, void,
97 private_dhcp_plugin_t
*this)
103 * Plugin constructor.
105 plugin_t
*dhcp_plugin_create()
107 private_dhcp_plugin_t
*this;
109 if (!lib
->caps
->check(lib
->caps
, CAP_NET_BIND_SERVICE
))
110 { /* required to bind DHCP socket (port 68) */
111 DBG1(DBG_NET
, "dhcp plugin requires CAP_NET_BIND_SERVICE capability");
114 else if (!lib
->caps
->keep(lib
->caps
, CAP_NET_RAW
))
115 { /* required to open DHCP receive socket (AF_PACKET). according to
116 * capabilities(7) it is also required to use the socket */
117 DBG1(DBG_NET
, "dhcp plugin requires CAP_NET_RAW capability");
124 .get_name
= _get_name
,
125 .get_features
= _get_features
,
131 return &this->public.plugin
;