X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=blobdiff_plain;f=src%2Flibcharon%2Fplugins%2Fdhcp%2Fdhcp_transaction.c;h=83f822dd8fa4e67480a281bd8c1efe5fc0ac58b0;hp=27235ffb93739547f728e461b9dfad321c13c56e;hb=19d49af53946999661209e0f915177b499a83585;hpb=4f0932ecfeb7400e39b990ac2a7716657d4bbe09 diff --git a/src/libcharon/plugins/dhcp/dhcp_transaction.c b/src/libcharon/plugins/dhcp/dhcp_transaction.c index 27235ff..83f822d 100644 --- a/src/libcharon/plugins/dhcp/dhcp_transaction.c +++ b/src/libcharon/plugins/dhcp/dhcp_transaction.c @@ -15,6 +15,8 @@ #include "dhcp_transaction.h" +#include + typedef struct private_dhcp_transaction_t private_dhcp_transaction_t; /** @@ -46,8 +48,21 @@ struct private_dhcp_transaction_t { * discovered DHCP server address */ host_t *server; + + /** + * List of added attributes, as attribute_entry_t + */ + linked_list_t *attributes; }; +/** + * Entry for an added attribute + */ +typedef struct { + configuration_attribute_type_t type; + chunk_t data; +} attribute_entry_t; + METHOD(dhcp_transaction_t, get_id, u_int32_t, private_dhcp_transaction_t *this) { @@ -86,12 +101,56 @@ METHOD(dhcp_transaction_t, get_server, host_t*, return this->server; } +METHOD(dhcp_transaction_t, add_attribute, void, + private_dhcp_transaction_t *this, configuration_attribute_type_t type, + chunk_t data) +{ + attribute_entry_t *entry; + + INIT(entry, + .type = type, + .data = chunk_clone(data), + ); + this->attributes->insert_last(this->attributes, entry); +} + +/** + * Filter function to map entries to type/data + */ +static bool attribute_filter(void *null, attribute_entry_t **entry, + configuration_attribute_type_t *type, + void **dummy, chunk_t *data) +{ + *type = (*entry)->type; + *data = (*entry)->data; + return TRUE; +} + +METHOD(dhcp_transaction_t, create_attribute_enumerator, enumerator_t*, + private_dhcp_transaction_t *this) +{ + return enumerator_create_filter( + this->attributes->create_enumerator(this->attributes), + (void*)attribute_filter, NULL, NULL); +} + +/** + * Clean up an attribute entry + */ +static void attribute_entry_destroy(attribute_entry_t *entry) +{ + free(entry->data.ptr); + free(entry); +} + METHOD(dhcp_transaction_t, destroy, void, private_dhcp_transaction_t *this) { this->identity->destroy(this->identity); DESTROY_IF(this->address); DESTROY_IF(this->server); + this->attributes->destroy_function(this->attributes, + (void*)attribute_entry_destroy); free(this); } @@ -111,10 +170,13 @@ dhcp_transaction_t *dhcp_transaction_create(u_int32_t id, .get_address = _get_address, .set_server = _set_server, .get_server = _get_server, + .add_attribute = _add_attribute, + .create_attribute_enumerator = _create_attribute_enumerator, .destroy = _destroy, }, .id = id, .identity = identity->clone(identity), + .attributes = linked_list_create(), ); return &this->public;