diff options
Diffstat (limited to 'src/libimcv/ietf')
-rw-r--r-- | src/libimcv/ietf/ietf_attr.c | 12 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_assess_result.c | 209 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_assess_result.h | 63 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_attr_request.c | 270 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_attr_request.h | 71 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_pa_tnc_error.c | 82 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_pa_tnc_error.h | 18 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_port_filter.c | 29 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_product_info.c | 29 |
9 files changed, 672 insertions, 111 deletions
diff --git a/src/libimcv/ietf/ietf_attr.c b/src/libimcv/ietf/ietf_attr.c index 89c6fc8db..fc89c5716 100644 --- a/src/libimcv/ietf/ietf_attr.c +++ b/src/libimcv/ietf/ietf_attr.c @@ -16,6 +16,8 @@ #include "ietf/ietf_attr_pa_tnc_error.h" #include "ietf/ietf_attr_port_filter.h" #include "ietf/ietf_attr_product_info.h" +#include "ietf/ietf_attr_attr_request.h" +#include "ietf/ietf_attr_assess_result.h" ENUM(ietf_attr_names, IETF_ATTR_TESTING, IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED, "Testing", @@ -40,19 +42,21 @@ pa_tnc_attr_t* ietf_attr_create_from_data(u_int32_t type, chunk_t value) { switch (type) { + case IETF_ATTR_ATTRIBUTE_REQUEST: + return ietf_attr_attr_request_create_from_data(value); + case IETF_ATTR_PRODUCT_INFORMATION: + return ietf_attr_product_info_create_from_data(value); case IETF_ATTR_PORT_FILTER: return ietf_attr_port_filter_create_from_data(value); case IETF_ATTR_PA_TNC_ERROR: return ietf_attr_pa_tnc_error_create_from_data(value); - case IETF_ATTR_PRODUCT_INFORMATION: - return ietf_attr_product_info_create_from_data(value); + case IETF_ATTR_ASSESSMENT_RESULT: + return ietf_attr_assess_result_create_from_data(value); case IETF_ATTR_TESTING: - case IETF_ATTR_ATTRIBUTE_REQUEST: case IETF_ATTR_NUMERIC_VERSION: case IETF_ATTR_STRING_VERSION: case IETF_ATTR_OPERATIONAL_STATUS: case IETF_ATTR_INSTALLED_PACKAGES: - case IETF_ATTR_ASSESSMENT_RESULT: case IETF_ATTR_REMEDIATION_INSTRUCTIONS: case IETF_ATTR_FORWARDING_ENABLED: case IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED: diff --git a/src/libimcv/ietf/ietf_attr_assess_result.c b/src/libimcv/ietf/ietf_attr_assess_result.c new file mode 100644 index 000000000..6893730bf --- /dev/null +++ b/src/libimcv/ietf/ietf_attr_assess_result.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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 "ietf_attr_assess_result.h" + +#include <pa_tnc/pa_tnc_msg.h> +#include <bio/bio_writer.h> +#include <bio/bio_reader.h> +#include <debug.h> + +typedef struct private_ietf_attr_assess_result_t private_ietf_attr_assess_result_t; + +/** + * PA-TNC Product Information type (see section 4.2.2 of RFC 5792) + * + * 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Assessment Result | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define ASSESS_RESULT_SIZE 4 + +/** + * Private data of an ietf_attr_assess_result_t object. + */ +struct private_ietf_attr_assess_result_t { + + /** + * Public members of ietf_attr_assess_result_t + */ + ietf_attr_assess_result_t public; + + /** + * Vendor-specific attribute type + */ + pen_type_t type; + + /** + * Attribute value + */ + chunk_t value; + + /** + * Noskip flag + */ + bool noskip_flag; + + /** + * Assessment Result + */ + u_int32_t result; + + /** + * Reference count + */ + refcount_t ref; +}; + +METHOD(pa_tnc_attr_t, get_type, pen_type_t, + private_ietf_attr_assess_result_t *this) +{ + return this->type; +} + +METHOD(pa_tnc_attr_t, get_value, chunk_t, + private_ietf_attr_assess_result_t *this) +{ + return this->value; +} + +METHOD(pa_tnc_attr_t, get_noskip_flag, bool, + private_ietf_attr_assess_result_t *this) +{ + return this->noskip_flag; +} + +METHOD(pa_tnc_attr_t, set_noskip_flag,void, + private_ietf_attr_assess_result_t *this, bool noskip) +{ + this->noskip_flag = noskip; +} + +METHOD(pa_tnc_attr_t, build, void, + private_ietf_attr_assess_result_t *this) +{ + bio_writer_t *writer; + + if (this->value.ptr) + { + return; + } + + writer = bio_writer_create(ASSESS_RESULT_SIZE); + writer->write_uint32(writer, this->result); + this->value = chunk_clone(writer->get_buf(writer)); + writer->destroy(writer); +} + +METHOD(pa_tnc_attr_t, process, status_t, + private_ietf_attr_assess_result_t *this, u_int32_t *offset) +{ + bio_reader_t *reader; + + if (this->value.len < ASSESS_RESULT_SIZE) + { + DBG1(DBG_TNC, "insufficient data for IETF assessment result"); + *offset = 0; + return FAILED; + } + reader = bio_reader_create(this->value); + reader->read_uint32(reader, &this->result); + reader->destroy(reader); + + return SUCCESS; +} + +METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, + private_ietf_attr_assess_result_t *this) +{ + ref_get(&this->ref); + return &this->public.pa_tnc_attribute; +} + +METHOD(pa_tnc_attr_t, destroy, void, + private_ietf_attr_assess_result_t *this) +{ + if (ref_put(&this->ref)) + { + free(this->value.ptr); + free(this); + } +} + +METHOD(ietf_attr_assess_result_t, get_result, u_int32_t, + private_ietf_attr_assess_result_t *this) +{ + return this->result; +} + +/** + * Described in header. + */ +pa_tnc_attr_t *ietf_attr_assess_result_create(u_int32_t result) +{ + private_ietf_attr_assess_result_t *this; + + INIT(this, + .public = { + .pa_tnc_attribute = { + .get_type = _get_type, + .get_value = _get_value, + .get_noskip_flag = _get_noskip_flag, + .set_noskip_flag = _set_noskip_flag, + .build = _build, + .process = _process, + .get_ref = _get_ref, + .destroy = _destroy, + }, + .get_result = _get_result, + }, + .type = { PEN_IETF, IETF_ATTR_ASSESSMENT_RESULT }, + .result = result, + .ref = 1, + ); + + return &this->public.pa_tnc_attribute; +} + +/** + * Described in header. + */ +pa_tnc_attr_t *ietf_attr_assess_result_create_from_data(chunk_t data) +{ + private_ietf_attr_assess_result_t *this; + + INIT(this, + .public = { + .pa_tnc_attribute = { + .get_type = _get_type, + .get_value = _get_value, + .build = _build, + .process = _process, + .get_ref = _get_ref, + .destroy = _destroy, + }, + .get_result = _get_result, + }, + .type = { PEN_IETF, IETF_ATTR_ASSESSMENT_RESULT }, + .value = chunk_clone(data), + .ref = 1, + ); + + return &this->public.pa_tnc_attribute; +} + diff --git a/src/libimcv/ietf/ietf_attr_assess_result.h b/src/libimcv/ietf/ietf_attr_assess_result.h new file mode 100644 index 000000000..fab8bc3f0 --- /dev/null +++ b/src/libimcv/ietf/ietf_attr_assess_result.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. + */ + +/** + * @defgroup ietf_attr_assess_resultt ietf_attr_assess_result + * @{ @ingroup ietf + */ + +#ifndef IETF_ATTR_ASSESS_RESULT_H_ +#define IETF_ATTR_ASSESS_RESULT_H_ + +typedef struct ietf_attr_assess_result_t ietf_attr_assess_result_t; + +#include "ietf_attr.h" +#include "pa_tnc/pa_tnc_attr.h" + + +/** + * Class implementing the IETF PA-TNC Assessment Result attribute. + * + */ +struct ietf_attr_assess_result_t { + + /** + * Public PA-TNC attribute interface + */ + pa_tnc_attr_t pa_tnc_attribute; + + /** + * Get the assessment result + * + * @return Assessment Result + */ + u_int32_t (*get_result)(ietf_attr_assess_result_t *this); + +}; + +/** + * Creates an ietf_attr_assess_result_t object + * + */ +pa_tnc_attr_t* ietf_attr_assess_result_create(u_int32_t result); + +/** + * Creates an ietf_attr_assess_result_t object from received data + * + * @param value unparsed attribute value + */ +pa_tnc_attr_t* ietf_attr_assess_result_create_from_data(chunk_t value); + +#endif /** IETF_ATTR_ASSESS_RESULT_H_ @}*/ diff --git a/src/libimcv/ietf/ietf_attr_attr_request.c b/src/libimcv/ietf/ietf_attr_attr_request.c new file mode 100644 index 000000000..c0dcd0983 --- /dev/null +++ b/src/libimcv/ietf/ietf_attr_attr_request.c @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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 "imcv.h" +#include "ietf_attr_attr_request.h" + +#include <pa_tnc/pa_tnc_msg.h> +#include <bio/bio_writer.h> +#include <bio/bio_reader.h> +#include <utils/linked_list.h> + +#include <debug.h> + +typedef struct private_ietf_attr_attr_request_t private_ietf_attr_attr_request_t; + +/** + * PA-TNC Attribute Request type (see section 4.2.1 of RFC 5792) + * + * 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Reserved | PA-TNC Attribute Vendor ID | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | PA-TNC Attribute Type | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Reserved | PA-TNC Attribute Vendor ID | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | PA-TNC Attribute Type | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define ATTR_REQUEST_ENTRY_SIZE 8 + +/** + * Private data of an ietf_attr_attr_request_t object. + */ +struct private_ietf_attr_attr_request_t { + + /** + * Public members of ietf_attr_attr_request_t + */ + ietf_attr_attr_request_t public; + + /** + * Vendor-specific attribute type + */ + pen_type_t type; + + /** + * Attribute value + */ + chunk_t value; + + /** + * Noskip flag + */ + bool noskip_flag; + + /** + * List of requested attribute types + */ + linked_list_t *list; + + /** + * Reference count + */ + refcount_t ref; +}; + +METHOD(pa_tnc_attr_t, get_type, pen_type_t, + private_ietf_attr_attr_request_t *this) +{ + return this->type; +} + +METHOD(pa_tnc_attr_t, get_value, chunk_t, + private_ietf_attr_attr_request_t *this) +{ + return this->value; +} + +METHOD(pa_tnc_attr_t, get_noskip_flag, bool, + private_ietf_attr_attr_request_t *this) +{ + return this->noskip_flag; +} + +METHOD(pa_tnc_attr_t, set_noskip_flag,void, + private_ietf_attr_attr_request_t *this, bool noskip) +{ + this->noskip_flag = noskip; +} + +METHOD(pa_tnc_attr_t, build, void, + private_ietf_attr_attr_request_t *this) +{ + bio_writer_t *writer; + enumerator_t *enumerator; + pen_type_t *entry; + + if (this->value.ptr) + { + return; + } + writer = bio_writer_create(ATTR_REQUEST_ENTRY_SIZE * + this->list->get_count(this->list)); + + enumerator = this->list->create_enumerator(this->list); + while (enumerator->enumerate(enumerator, &entry)) + { + writer->write_uint32(writer, entry->vendor_id); + writer->write_uint32(writer, entry->type); + } + enumerator->destroy(enumerator); + + this->value = chunk_clone(writer->get_buf(writer)); + writer->destroy(writer); +} + +METHOD(ietf_attr_attr_request_t, add, void, + private_ietf_attr_attr_request_t *this, pen_t vendor_id, u_int32_t type) +{ + pen_type_t *entry; + + entry = malloc_thing(pen_type_t); + entry->vendor_id = vendor_id; + entry->type = type; + this->list->insert_last(this->list, entry); +} + +METHOD(pa_tnc_attr_t, process, status_t, + private_ietf_attr_attr_request_t *this, u_int32_t *offset) +{ + bio_reader_t *reader; + enum_name_t *pa_attr_names; + pen_t vendor_id; + u_int32_t type; + u_int8_t reserved; + int count; + + count = this->value.len / ATTR_REQUEST_ENTRY_SIZE; + if (this->value.len != ATTR_REQUEST_ENTRY_SIZE * count) + { + DBG1(DBG_TNC, "incorrect attribute length for IETF attribute request"); + *offset = 0; + return FAILED; + } + + reader = bio_reader_create(this->value); + while (count--) + { + reader->read_uint8 (reader, &reserved); + reader->read_uint24(reader, &vendor_id); + reader->read_uint32(reader, &type); + + pa_attr_names = imcv_pa_tnc_attributes->get_names(imcv_pa_tnc_attributes, + vendor_id); + if (pa_attr_names) + { + DBG2(DBG_TNC, " 0x%06x/0x%08x '%N/%N'", vendor_id, type, + pen_names, vendor_id, pa_attr_names, type); + } + else + { + DBG2(DBG_TNC, " 0x%06x/0x%08x '%N'", vendor_id, type, + pen_names, vendor_id); + } + add(this, vendor_id, type); + } + reader->destroy(reader); + + return SUCCESS; +} + +METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, + private_ietf_attr_attr_request_t *this) +{ + ref_get(&this->ref); + return &this->public.pa_tnc_attribute; +} + +METHOD(pa_tnc_attr_t, destroy, void, + private_ietf_attr_attr_request_t *this) +{ + if (ref_put(&this->ref)) + { + this->list->destroy_function(this->list, free); + free(this->value.ptr); + free(this); + } +} + +METHOD(ietf_attr_attr_request_t, create_enumerator, enumerator_t*, + private_ietf_attr_attr_request_t *this) +{ + return this->list->create_enumerator(this->list); +} + +/** + * Described in header. + */ +pa_tnc_attr_t *ietf_attr_attr_request_create(pen_t vendor_id, u_int32_t type) +{ + private_ietf_attr_attr_request_t *this; + + INIT(this, + .public = { + .pa_tnc_attribute = { + .get_type = _get_type, + .get_value = _get_value, + .get_noskip_flag = _get_noskip_flag, + .set_noskip_flag = _set_noskip_flag, + .build = _build, + .process = _process, + .get_ref = _get_ref, + .destroy = _destroy, + }, + .add = _add, + .create_enumerator = _create_enumerator, + }, + .type = { PEN_IETF, IETF_ATTR_ATTRIBUTE_REQUEST }, + .list = linked_list_create(), + .ref = 1, + ); + add(this, vendor_id, type); + + return &this->public.pa_tnc_attribute; +} + +/** + * Described in header. + */ +pa_tnc_attr_t *ietf_attr_attr_request_create_from_data(chunk_t data) +{ + private_ietf_attr_attr_request_t *this; + + INIT(this, + .public = { + .pa_tnc_attribute = { + .get_type = _get_type, + .get_value = _get_value, + .build = _build, + .process = _process, + .get_ref = _get_ref, + .destroy = _destroy, + }, + .add = _add, + .create_enumerator = _create_enumerator, + }, + .type = { PEN_IETF,IETF_ATTR_ATTRIBUTE_REQUEST }, + .value = chunk_clone(data), + .list = linked_list_create(), + .ref = 1, + ); + + return &this->public.pa_tnc_attribute; +} + diff --git a/src/libimcv/ietf/ietf_attr_attr_request.h b/src/libimcv/ietf/ietf_attr_attr_request.h new file mode 100644 index 000000000..22c5be0a0 --- /dev/null +++ b/src/libimcv/ietf/ietf_attr_attr_request.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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. + */ + +/** + * @defgroup ietf_attr_attr_requestt ietf_attr_attr_request + * @{ @ingroup ietf + */ + +#ifndef IETF_ATTR_ATTR_REQUEST_H_ +#define IETF_ATTR_ATTR_REQUEST_H_ + +typedef struct ietf_attr_attr_request_t ietf_attr_attr_request_t; + +#include "ietf_attr.h" +#include "pa_tnc/pa_tnc_attr.h" + + +/** + * Class implementing the IETF PA-TNC Attribute Request attribute. + * + */ +struct ietf_attr_attr_request_t { + + /** + * Public PA-TNC attribute interface + */ + pa_tnc_attr_t pa_tnc_attribute; + + /** + * Adds another attribute type to the attribute request + * + * @param vendor_id Attribute Vendor ID + * @param type Attribute Type + */ + void (*add)(ietf_attr_attr_request_t *this, pen_t vendor_id, u_int32_t type); + + /** + * Creates an enumerator over all attribute types contained + * in the attribute request + * + * @return Attribute Type enumerator returns (vendor ID, type) + */ + enumerator_t* (*create_enumerator)(ietf_attr_attr_request_t *this); +}; + +/** + * Creates an ietf_attr_attr_request_t object + * + */ +pa_tnc_attr_t* ietf_attr_attr_request_create(pen_t vendor_id, u_int32_t type); + +/** + * Creates an ietf_attr_attr_request_t object from received data + * + * @param value unparsed attribute value + */ +pa_tnc_attr_t* ietf_attr_attr_request_create_from_data(chunk_t value); + +#endif /** IETF_ATTR_ATTR_REQUEST_H_ @}*/ diff --git a/src/libimcv/ietf/ietf_attr_pa_tnc_error.c b/src/libimcv/ietf/ietf_attr_pa_tnc_error.c index 6daee1a77..46f5d6716 100644 --- a/src/libimcv/ietf/ietf_attr_pa_tnc_error.c +++ b/src/libimcv/ietf/ietf_attr_pa_tnc_error.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil + * Copyright (C) 2011-2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil * * 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 @@ -107,14 +108,9 @@ struct private_ietf_attr_pa_tnc_error_t { ietf_attr_pa_tnc_error_t public; /** - * Attribute vendor ID + * Vendor-specific attribute type */ - pen_t vendor_id; - - /** - * Attribute type - */ - u_int32_t type; + pen_type_t type; /** * Attribute value @@ -127,14 +123,9 @@ struct private_ietf_attr_pa_tnc_error_t { bool noskip_flag; /** - * Error code vendor ID - */ - pen_t error_vendor_id; - - /** - * Error code + * Vendor-specific error code */ - u_int32_t error_code; + pen_type_t error_code; /** * First 8 bytes of erroneous PA-TNC message @@ -157,13 +148,7 @@ struct private_ietf_attr_pa_tnc_error_t { refcount_t ref; }; -METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, - private_ietf_attr_pa_tnc_error_t *this) -{ - return this->vendor_id; -} - -METHOD(pa_tnc_attr_t, get_type, u_int32_t, +METHOD(pa_tnc_attr_t, get_type, pen_type_t, private_ietf_attr_pa_tnc_error_t *this) { return this->type; @@ -192,15 +177,19 @@ METHOD(pa_tnc_attr_t, build, void, { bio_writer_t *writer; + if (this->value.ptr) + { + return; + } writer = bio_writer_create(PA_ERROR_HEADER_SIZE + PA_ERROR_MSG_INFO_SIZE); writer->write_uint8 (writer, PA_ERROR_RESERVED); - writer->write_uint24(writer, this->error_vendor_id); - writer->write_uint32(writer, this->error_code); + writer->write_uint24(writer, this->error_code.vendor_id); + writer->write_uint32(writer, this->error_code.type); writer->write_data (writer, this->msg_info); - if (this->error_vendor_id == PEN_IETF) + if (this->error_code.vendor_id == PEN_IETF) { - switch (this->error_code) + switch (this->error_code.type) { case PA_ERROR_INVALID_PARAMETER: writer->write_uint32(writer, this->error_offset); @@ -235,10 +224,10 @@ METHOD(pa_tnc_attr_t, process, status_t, } reader = bio_reader_create(this->value); reader->read_uint8 (reader, &reserved); - reader->read_uint24(reader, &this->error_vendor_id); - reader->read_uint32(reader, &this->error_code); + reader->read_uint24(reader, &this->error_code.vendor_id); + reader->read_uint32(reader, &this->error_code.type); - if (this->error_vendor_id == PEN_IETF) + if (this->error_code.vendor_id == PEN_IETF) { if (!reader->read_data(reader, PA_ERROR_MSG_INFO_SIZE, &this->msg_info)) { @@ -249,7 +238,7 @@ METHOD(pa_tnc_attr_t, process, status_t, } this->msg_info = chunk_clone(this->msg_info); - switch (this->error_code) + switch (this->error_code.type) { case PA_ERROR_INVALID_PARAMETER: if (!reader->read_uint32(reader, &this->error_offset)) @@ -305,13 +294,7 @@ METHOD(pa_tnc_attr_t, destroy, void, } } -METHOD(ietf_attr_pa_tnc_error_t, get_error_vendor_id, pen_t, - private_ietf_attr_pa_tnc_error_t *this) -{ - return this->error_vendor_id; -} - -METHOD(ietf_attr_pa_tnc_error_t, get_error_code, u_int32_t, +METHOD(ietf_attr_pa_tnc_error_t, get_error_code, pen_type_t, private_ietf_attr_pa_tnc_error_t *this) { return this->error_code; @@ -344,13 +327,12 @@ METHOD(ietf_attr_pa_tnc_error_t, get_offset, u_int32_t, /** * Described in header. */ -pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id, - u_int32_t error_code, +pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_type_t error_code, chunk_t msg_info) { private_ietf_attr_pa_tnc_error_t *this; - if (vendor_id == PEN_IETF) + if (error_code.vendor_id == PEN_IETF) { msg_info.len = PA_ERROR_MSG_INFO_SIZE; } @@ -362,7 +344,6 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id, INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .get_noskip_flag = _get_noskip_flag, @@ -372,16 +353,13 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id, .get_ref = _get_ref, .destroy = _destroy, }, - .get_vendor_id = _get_error_vendor_id, .get_error_code = _get_error_code, .get_msg_info = _get_msg_info, .get_attr_info = _get_attr_info, .set_attr_info = _set_attr_info, .get_offset = _get_offset, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PA_TNC_ERROR, - .error_vendor_id = vendor_id, + .type = { PEN_IETF, IETF_ATTR_PA_TNC_ERROR }, .error_code = error_code, .msg_info = chunk_clone(msg_info), .ref = 1, @@ -393,8 +371,7 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id, /** * Described in header. */ -pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_with_offset(pen_t vendor_id, - u_int32_t error_code, +pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_with_offset(pen_type_t error_code, chunk_t msg_info, u_int32_t error_offset) { @@ -406,7 +383,6 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_with_offset(pen_t vendor_id, INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .get_noskip_flag = _get_noskip_flag, @@ -416,16 +392,13 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_with_offset(pen_t vendor_id, .get_ref = _get_ref, .destroy = _destroy, }, - .get_vendor_id = _get_error_vendor_id, .get_error_code = _get_error_code, .get_msg_info = _get_msg_info, .get_attr_info = _get_attr_info, .set_attr_info = _set_attr_info, .get_offset = _get_offset, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PA_TNC_ERROR, - .error_vendor_id = vendor_id, + .type = { PEN_IETF, IETF_ATTR_PA_TNC_ERROR }, .error_code = error_code, .msg_info = chunk_clone(msg_info), .error_offset = error_offset, @@ -445,7 +418,6 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_from_data(chunk_t data) INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .build = _build, @@ -453,15 +425,13 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_from_data(chunk_t data) .get_ref = _get_ref, .destroy = _destroy, }, - .get_vendor_id = _get_error_vendor_id, .get_error_code = _get_error_code, .get_msg_info = _get_msg_info, .get_attr_info = _get_attr_info, .set_attr_info = _set_attr_info, .get_offset = _get_offset, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PA_TNC_ERROR, + .type = { PEN_IETF, IETF_ATTR_PA_TNC_ERROR }, .value = chunk_clone(data), .ref = 1, ); diff --git a/src/libimcv/ietf/ietf_attr_pa_tnc_error.h b/src/libimcv/ietf/ietf_attr_pa_tnc_error.h index 945e06c62..d28c524aa 100644 --- a/src/libimcv/ietf/ietf_attr_pa_tnc_error.h +++ b/src/libimcv/ietf/ietf_attr_pa_tnc_error.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Andreas Steffen + * Copyright (C) 2011-2012 Andreas Steffen * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it @@ -62,11 +62,11 @@ struct ietf_attr_pa_tnc_error_t { pen_t (*get_vendor_id)(ietf_attr_pa_tnc_error_t *this); /** - * Get PA-TNC error code + * Get Vendor-specific PA-TNC error code * * @return error code */ - pa_tnc_error_code_t (*get_error_code)(ietf_attr_pa_tnc_error_t *this); + pen_type_t (*get_error_code)(ietf_attr_pa_tnc_error_t *this); /** * Get first 8 bytes of erroneous PA-TNC message @@ -101,26 +101,22 @@ struct ietf_attr_pa_tnc_error_t { /** * Creates an ietf_attr_pa_tnc_error_t object from an error code * - * @param vendor_id PA-TNC error code vendor ID - * @param error_code PA-TNC error code + * @param error_code Vendor-specific PA-TNC error code * @param header PA-TNC message header (first 8 bytes) * */ -pa_tnc_attr_t* ietf_attr_pa_tnc_error_create(pen_t vendor_id, - u_int32_t error_code, +pa_tnc_attr_t* ietf_attr_pa_tnc_error_create(pen_type_t error_code, chunk_t header); /** * Creates an ietf_attr_pa_tnc_error_t object from an error code with offset * - * @param vendor_id PA-TNC error code vendor ID - * @param error_code PA-TNC error code + * @param error_code Vendor-specifica PA-TNC error code * @param header PA-TNC message header (first 8 bytes) * @param error_offset PA-TNC error offset in bytes * */ -pa_tnc_attr_t* ietf_attr_pa_tnc_error_create_with_offset(pen_t vendor_id, - u_int32_t error_code, +pa_tnc_attr_t* ietf_attr_pa_tnc_error_create_with_offset(pen_type_t error_code, chunk_t header, u_int32_t error_offset); diff --git a/src/libimcv/ietf/ietf_attr_port_filter.c b/src/libimcv/ietf/ietf_attr_port_filter.c index b53019657..5ea52256b 100644 --- a/src/libimcv/ietf/ietf_attr_port_filter.c +++ b/src/libimcv/ietf/ietf_attr_port_filter.c @@ -58,14 +58,9 @@ struct private_ietf_attr_port_filter_t { ietf_attr_port_filter_t public; /** - * Attribute vendor ID + * Vendor-specific attribute type */ - pen_t vendor_id; - - /** - * Attribute type - */ - u_int32_t type; + pen_type_t type; /** * Attribute value @@ -88,13 +83,7 @@ struct private_ietf_attr_port_filter_t { refcount_t ref; }; -METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, - private_ietf_attr_port_filter_t *this) -{ - return this->vendor_id; -} - -METHOD(pa_tnc_attr_t, get_type, u_int32_t, +METHOD(pa_tnc_attr_t, get_type, pen_type_t, private_ietf_attr_port_filter_t *this) { return this->type; @@ -125,6 +114,10 @@ METHOD(pa_tnc_attr_t, build, void, enumerator_t *enumerator; port_entry_t *entry; + if (this->value.ptr) + { + return; + } writer = bio_writer_create(this->ports->get_count(this->ports) * PORT_FILTER_ENTRY_SIZE); @@ -232,7 +225,6 @@ pa_tnc_attr_t *ietf_attr_port_filter_create(void) INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .get_noskip_flag = _get_noskip_flag, @@ -245,8 +237,7 @@ pa_tnc_attr_t *ietf_attr_port_filter_create(void) .add_port = _add_port, .create_port_enumerator = _create_port_enumerator, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PORT_FILTER, + .type = { PEN_IETF, IETF_ATTR_PORT_FILTER }, .ports = linked_list_create(), .ref = 1, ); @@ -264,7 +255,6 @@ pa_tnc_attr_t *ietf_attr_port_filter_create_from_data(chunk_t data) INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .build = _build, @@ -275,8 +265,7 @@ pa_tnc_attr_t *ietf_attr_port_filter_create_from_data(chunk_t data) .add_port = _add_port, .create_port_enumerator = _create_port_enumerator, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PORT_FILTER, + .type = {PEN_IETF, IETF_ATTR_PORT_FILTER }, .value = chunk_clone(data), .ports = linked_list_create(), .ref = 1, diff --git a/src/libimcv/ietf/ietf_attr_product_info.c b/src/libimcv/ietf/ietf_attr_product_info.c index 548793547..dcc0e0294 100644 --- a/src/libimcv/ietf/ietf_attr_product_info.c +++ b/src/libimcv/ietf/ietf_attr_product_info.c @@ -46,14 +46,9 @@ struct private_ietf_attr_product_info_t { ietf_attr_product_info_t public; /** - * Attribute vendor ID + * Vendor-specific attribute type */ - pen_t vendor_id; - - /** - * Attribute type - */ - u_int32_t type; + pen_type_t type; /** * Attribute value @@ -86,13 +81,7 @@ struct private_ietf_attr_product_info_t { refcount_t ref; }; -METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, - private_ietf_attr_product_info_t *this) -{ - return this->vendor_id; -} - -METHOD(pa_tnc_attr_t, get_type, u_int32_t, +METHOD(pa_tnc_attr_t, get_type, pen_type_t, private_ietf_attr_product_info_t *this) { return this->type; @@ -122,6 +111,10 @@ METHOD(pa_tnc_attr_t, build, void, bio_writer_t *writer; chunk_t product_name; + if (this->value.ptr) + { + return; + } product_name = chunk_create(this->product_name, strlen(this->product_name)); writer = bio_writer_create(PRODUCT_INFO_MIN_SIZE); @@ -201,7 +194,6 @@ pa_tnc_attr_t *ietf_attr_product_info_create(pen_t vendor_id, u_int16_t id, INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .get_noskip_flag = _get_noskip_flag, @@ -213,8 +205,7 @@ pa_tnc_attr_t *ietf_attr_product_info_create(pen_t vendor_id, u_int16_t id, }, .get_info = _get_info, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PRODUCT_INFORMATION, + .type = { PEN_IETF, IETF_ATTR_PRODUCT_INFORMATION }, .product_vendor_id = vendor_id, .product_id = id, .product_name = strdup(name), @@ -234,7 +225,6 @@ pa_tnc_attr_t *ietf_attr_product_info_create_from_data(chunk_t data) INIT(this, .public = { .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, .get_type = _get_type, .get_value = _get_value, .build = _build, @@ -244,8 +234,7 @@ pa_tnc_attr_t *ietf_attr_product_info_create_from_data(chunk_t data) }, .get_info = _get_info, }, - .vendor_id = PEN_IETF, - .type = IETF_ATTR_PRODUCT_INFORMATION, + .type = { PEN_IETF, IETF_ATTR_PRODUCT_INFORMATION }, .value = chunk_clone(data), .ref = 1, ); |