DHCP plugin framework, send DHCP Discover upon IP request
[strongswan.git] / src / libcharon / plugins / dhcp / dhcp_plugin.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 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 "dhcp_plugin.h"
17
18 #include <daemon.h>
19
20 #include "dhcp_socket.h"
21 #include "dhcp_provider.h"
22
23 typedef struct private_dhcp_plugin_t private_dhcp_plugin_t;
24
25 /**
26 * private data of dhcp plugin
27 */
28 struct private_dhcp_plugin_t {
29
30 /**
31 * implements plugin interface
32 */
33 dhcp_plugin_t public;
34
35 /**
36 * DHCP communication socket
37 */
38 dhcp_socket_t *socket;
39
40 /**
41 * Attribute provider
42 */
43 dhcp_provider_t *provider;
44 };
45
46 METHOD(plugin_t, destroy, void,
47 private_dhcp_plugin_t *this)
48 {
49 lib->attributes->remove_provider(lib->attributes, &this->provider->provider);
50 this->provider->destroy(this->provider);
51 this->socket->destroy(this->socket);
52 free(this);
53 }
54
55 /**
56 * Plugin constructor.
57 */
58 plugin_t *dhcp_plugin_create()
59 {
60 private_dhcp_plugin_t *this;
61
62 INIT(this,
63 .public.plugin.destroy = _destroy,
64 .socket = dhcp_socket_create(),
65 );
66
67 if (!this->socket)
68 {
69 free(this);
70 return NULL;
71 }
72
73 this->provider = dhcp_provider_create(this->socket);
74 lib->attributes->add_provider(lib->attributes, &this->provider->provider);
75
76 return &this->public.plugin;
77 }
78