aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins/dhcp/dhcp_transaction.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-03-23 17:18:18 +0100
committerMartin Willi <martin@revosec.ch>2010-03-25 14:28:28 +0100
commitddc93db612b51179d8b62da931c2080708c8bd68 (patch)
treeb616eabcd864e2acc97b1ffa8bb8016e59aacc41 /src/libcharon/plugins/dhcp/dhcp_transaction.c
parentbeaa048eed92d00aa23547e55be7e6dc8a450206 (diff)
downloadstrongswan-ddc93db612b51179d8b62da931c2080708c8bd68.tar.bz2
strongswan-ddc93db612b51179d8b62da931c2080708c8bd68.tar.xz
DHCP plugin framework, send DHCP Discover upon IP request
Diffstat (limited to 'src/libcharon/plugins/dhcp/dhcp_transaction.c')
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_transaction.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/libcharon/plugins/dhcp/dhcp_transaction.c b/src/libcharon/plugins/dhcp/dhcp_transaction.c
new file mode 100644
index 000000000..14e65409f
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_transaction.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "dhcp_transaction.h"
+
+typedef struct private_dhcp_transaction_t private_dhcp_transaction_t;
+
+/**
+ * Private data of an dhcp_transaction_t object.
+ */
+struct private_dhcp_transaction_t {
+
+ /**
+ * Public dhcp_transaction_t interface.
+ */
+ dhcp_transaction_t public;
+
+ /**
+ * DHCP transaction ID
+ */
+ u_int32_t id;
+
+ /**
+ * Peer identity
+ */
+ identification_t *identity;
+
+ /**
+ * received DHCP address
+ */
+ host_t *address;
+};
+
+METHOD(dhcp_transaction_t, get_id, u_int32_t,
+ private_dhcp_transaction_t *this)
+{
+ return this->id;
+}
+
+METHOD(dhcp_transaction_t, get_identity, identification_t*,
+ private_dhcp_transaction_t *this)
+{
+ return this->identity;
+}
+
+METHOD(dhcp_transaction_t, set_address, void,
+ private_dhcp_transaction_t *this, host_t *address)
+{
+ DESTROY_IF(this->address);
+ this->address = address;
+}
+
+METHOD(dhcp_transaction_t, get_address, host_t*,
+ private_dhcp_transaction_t *this)
+{
+ return this->address;
+}
+
+METHOD(dhcp_transaction_t, destroy, void,
+ private_dhcp_transaction_t *this)
+{
+ this->identity->destroy(this->identity);
+ DESTROY_IF(this->address);
+ free(this);
+}
+
+/**
+ * See header
+ */
+dhcp_transaction_t *dhcp_transaction_create(u_int32_t id,
+ identification_t *identity)
+{
+ private_dhcp_transaction_t *this;
+
+ INIT(this,
+ .public = {
+ .get_id = _get_id,
+ .get_identity = _get_identity,
+ .set_address = _set_address,
+ .get_address = _get_address,
+ .destroy = _destroy,
+ },
+ .id = id,
+ .identity = identity->clone(identity),
+ );
+
+ return &this->public;
+}
+