Migrated dhcp plugin to moved attribute manager
[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 <hydra.h>
19 #include <daemon.h>
20
21 #include "dhcp_socket.h"
22 #include "dhcp_provider.h"
23
24 typedef struct private_dhcp_plugin_t private_dhcp_plugin_t;
25
26 /**
27 * private data of dhcp plugin
28 */
29 struct private_dhcp_plugin_t {
30
31 /**
32 * implements plugin interface
33 */
34 dhcp_plugin_t public;
35
36 /**
37 * DHCP communication socket
38 */
39 dhcp_socket_t *socket;
40
41 /**
42 * Attribute provider
43 */
44 dhcp_provider_t *provider;
45 };
46
47 METHOD(plugin_t, destroy, void,
48 private_dhcp_plugin_t *this)
49 {
50 hydra->attributes->remove_provider(hydra->attributes,
51 &this->provider->provider);
52 this->provider->destroy(this->provider);
53 this->socket->destroy(this->socket);
54 free(this);
55 }
56
57 /**
58 * Plugin constructor.
59 */
60 plugin_t *dhcp_plugin_create()
61 {
62 private_dhcp_plugin_t *this;
63
64 INIT(this,
65 .public.plugin.destroy = _destroy,
66 .socket = dhcp_socket_create(),
67 );
68
69 if (!this->socket)
70 {
71 free(this);
72 return NULL;
73 }
74
75 this->provider = dhcp_provider_create(this->socket);
76 hydra->attributes->add_provider(hydra->attributes,
77 &this->provider->provider);
78
79 return &this->public.plugin;
80 }
81