27235ffb93739547f728e461b9dfad321c13c56e
[strongswan.git] / src / libcharon / plugins / dhcp / dhcp_transaction.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_transaction.h"
17
18 typedef struct private_dhcp_transaction_t private_dhcp_transaction_t;
19
20 /**
21 * Private data of an dhcp_transaction_t object.
22 */
23 struct private_dhcp_transaction_t {
24
25 /**
26 * Public dhcp_transaction_t interface.
27 */
28 dhcp_transaction_t public;
29
30 /**
31 * DHCP transaction ID
32 */
33 u_int32_t id;
34
35 /**
36 * Peer identity
37 */
38 identification_t *identity;
39
40 /**
41 * received DHCP address
42 */
43 host_t *address;
44
45 /**
46 * discovered DHCP server address
47 */
48 host_t *server;
49 };
50
51 METHOD(dhcp_transaction_t, get_id, u_int32_t,
52 private_dhcp_transaction_t *this)
53 {
54 return this->id;
55 }
56
57 METHOD(dhcp_transaction_t, get_identity, identification_t*,
58 private_dhcp_transaction_t *this)
59 {
60 return this->identity;
61 }
62
63 METHOD(dhcp_transaction_t, set_address, void,
64 private_dhcp_transaction_t *this, host_t *address)
65 {
66 DESTROY_IF(this->address);
67 this->address = address;
68 }
69
70 METHOD(dhcp_transaction_t, get_address, host_t*,
71 private_dhcp_transaction_t *this)
72 {
73 return this->address;
74 }
75
76 METHOD(dhcp_transaction_t, set_server, void,
77 private_dhcp_transaction_t *this, host_t *server)
78 {
79 DESTROY_IF(this->server);
80 this->server = server;
81 }
82
83 METHOD(dhcp_transaction_t, get_server, host_t*,
84 private_dhcp_transaction_t *this)
85 {
86 return this->server;
87 }
88
89 METHOD(dhcp_transaction_t, destroy, void,
90 private_dhcp_transaction_t *this)
91 {
92 this->identity->destroy(this->identity);
93 DESTROY_IF(this->address);
94 DESTROY_IF(this->server);
95 free(this);
96 }
97
98 /**
99 * See header
100 */
101 dhcp_transaction_t *dhcp_transaction_create(u_int32_t id,
102 identification_t *identity)
103 {
104 private_dhcp_transaction_t *this;
105
106 INIT(this,
107 .public = {
108 .get_id = _get_id,
109 .get_identity = _get_identity,
110 .set_address = _set_address,
111 .get_address = _get_address,
112 .set_server = _set_server,
113 .get_server = _get_server,
114 .destroy = _destroy,
115 },
116 .id = id,
117 .identity = identity->clone(identity),
118 );
119
120 return &this->public;
121 }
122