- rewrite of logger_manager, uses now one instance per context

- cleanups for logger here and there
- removed critical flag check in payload verification (conformance to IKEv2)
- so thats and theres everywere... ;-)
This commit is contained in:
Martin Willi
2006-03-23 15:25:43 +00:00
parent 3264ce50b9
commit dec598220b
59 changed files with 461 additions and 762 deletions
+1 -2
View File
@@ -1029,7 +1029,6 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
static status_t destroy(private_generator_t *this)
{
allocator_free(this->buffer);
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
allocator_free(this);
return SUCCESS;
}
@@ -1073,7 +1072,7 @@ generator_t *generator_create()
this->current_bit = 0;
this->last_payload_length_position_offset = 0;
this->header_length_position_offset = 0;
this->logger = charon->logger_manager->create_logger(charon->logger_manager,GENERATOR,NULL);
this->logger = charon->logger_manager->get_logger(charon->logger_manager, GENERATOR);
return &(this->public);
}
+7 -8
View File
@@ -746,7 +746,7 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
current_payload_type = this->first_payload;
this->logger->log(this->logger, CONTROL|LEVEL1, "Parsing body of message, first payload %s",
this->logger->log(this->logger, CONTROL|LEVEL1, "Parsing body of message, first payload is %s",
mapping_find(payload_type_m, current_payload_type));
/* parse payload for payload, while there are more available */
@@ -754,7 +754,7 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
{
payload_t *current_payload;
this->logger->log(this->logger, CONTROL|LEVEL2, "Start parsing payload of type %s",
this->logger->log(this->logger, CONTROL|LEVEL2, "Start parsing a %s payload",
mapping_find(payload_type_m, current_payload_type));
/* parse current payload */
@@ -774,21 +774,21 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
status = current_payload->verify(current_payload);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Payload type %s verification failed",
this->logger->log(this->logger, ERROR, "%s payload verification failed",
mapping_find(payload_type_m,current_payload_type));
current_payload->destroy(current_payload);
status = VERIFY_ERROR;
return status;
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Payload verified. Adding to payload list",
this->logger->log(this->logger, CONTROL|LEVEL2, "%s payload verified. Adding to payload list",
mapping_find(payload_type_m, current_payload_type));
this->payloads->insert_last(this->payloads,current_payload);
/* an encryption payload is the last one, so STOP here. decryption is done later */
if (current_payload_type == ENCRYPTED)
{
this->logger->log(this->logger, CONTROL|LEVEL2, "Payload of type encrypted found. Stop parsing",
this->logger->log(this->logger, CONTROL|LEVEL2, "%s payload found. Stop parsing",
mapping_find(payload_type_m, current_payload_type));
break;
}
@@ -1153,7 +1153,6 @@ static void destroy (private_message_t *this)
iterator->destroy(iterator);
this->payloads->destroy(this->payloads);
this->parser->destroy(this->parser);
charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -1218,7 +1217,7 @@ message_t *message_create_from_packet(packet_t *packet)
/* parser is created from data of packet */
this->parser = parser_create(this->packet->get_data(this->packet));
this->logger = charon->logger_manager->create_logger(charon->logger_manager, MESSAGE, NULL);
this->logger = charon->logger_manager->get_logger(charon->logger_manager, MESSAGE);
return (&this->public);
}
@@ -1246,7 +1245,7 @@ message_t *message_create_notify_reply(host_t *source, host_t *destination, exch
message->set_message_id(message,0);
message->set_ike_sa_id(message, ike_sa_id);
payload = notify_payload_create_from_protocol_and_type(IKE,notify_type);
payload = notify_payload_create_from_protocol_and_type(PROTO_IKE, notify_type);
message->add_payload(message,(payload_t *) payload);
return message;
+1 -2
View File
@@ -1027,7 +1027,6 @@ static void reset_context (private_parser_t *this)
*/
static void destroy(private_parser_t *this)
{
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
allocator_free(this);
}
@@ -1038,7 +1037,7 @@ parser_t *parser_create(chunk_t data)
{
private_parser_t *this = allocator_alloc_thing(private_parser_t);
this->logger = charon->logger_manager->create_logger(charon->logger_manager, PARSER, NULL);
this->logger = charon->logger_manager->get_logger(charon->logger_manager, PARSER);
this->public.parse_payload = (status_t(*)(parser_t*,payload_type_t,payload_t**)) parse_payload;
this->public.reset_context = (void(*)(parser_t*)) reset_context;
@@ -116,11 +116,6 @@ encoding_rule_t auth_payload_encodings[] = {
*/
static status_t verify(private_auth_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if ((this->auth_method == 0) ||
((this->auth_method >= 4) && (this->auth_method <= 200)))
{
@@ -129,11 +129,6 @@ encoding_rule_t cert_payload_encodings[] = {
*/
static status_t verify(private_cert_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if ((this->cert_encoding == 0) ||
((this->cert_encoding >= 14) && (this->cert_encoding <= 200)))
{
@@ -109,11 +109,6 @@ encoding_rule_t certreq_payload_encodings[] = {
*/
static status_t verify(private_certreq_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if ((this->cert_encoding == 0) ||
((this->cert_encoding >= 14) && (this->cert_encoding <= 200)))
{
@@ -139,12 +139,6 @@ static status_t verify(private_cp_payload_t *this)
{
status_t status = SUCCESS;
iterator_t *iterator;
if (this->critical)
{
/* critical bit set! */
return FAILED;
}
iterator = this->attributes->create_iterator(this->attributes,TRUE);
@@ -121,11 +121,6 @@ encoding_rule_t delete_payload_encodings[] = {
*/
static status_t verify(private_delete_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if ((this->protocol_id == 0) ||
(this->protocol_id > 3))
{
@@ -136,7 +131,7 @@ static status_t verify(private_delete_payload_t *this)
{
return FAILED;
}
if ((this->protocol_id == IKE) && (this->spis.len != 0))
if ((this->protocol_id == PROTO_IKE) && (this->spis.len != 0))
{
/* IKE deletion has no spi assigned! */
return FAILED;
@@ -318,7 +313,7 @@ delete_payload_t *delete_payload_create()
this->critical = FALSE;
this->next_payload = NO_PAYLOAD;
this->payload_length =DELETE_PAYLOAD_HEADER_LENGTH;
this->protocol_id = UNDEFINED_PROTOCOL_ID;
this->protocol_id = PROTO_NONE;
this->spi_size = 0;
this->spi_count = 0;
this->spis = CHUNK_INITIALIZER;
@@ -101,11 +101,6 @@ encoding_rule_t eap_payload_encodings[] = {
*/
static status_t verify(private_eap_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
return SUCCESS;
}
@@ -638,7 +638,6 @@ static void destroy(private_encryption_payload_t *this)
current_payload->destroy(current_payload);
}
this->payloads->destroy(this->payloads);
charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this->encrypted.ptr);
allocator_free(this->decrypted.ptr);
allocator_free(this);
@@ -677,10 +676,10 @@ encryption_payload_t *encryption_payload_create()
this->compute_length = compute_length;
this->generate = generate;
this->parse = parse;
this->logger = charon->logger_manager->create_logger(charon->logger_manager, ENCRYPTION_PAYLOAD, NULL);
this->logger = charon->logger_manager->get_logger(charon->logger_manager, ENCRYPTION_PAYLOAD);
/* set default values of the fields */
this->critical = TRUE;
this->critical = FALSE;
this->next_payload = NO_PAYLOAD;
this->payload_length = ENCRYPTION_PAYLOAD_HEADER_LENGTH;
this->encrypted = CHUNK_INITIALIZER;
@@ -119,11 +119,6 @@ encoding_rule_t id_payload_encodings[] = {
*/
static status_t verify(private_id_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if ((this->id_type == 0) ||
(this->id_type == 4) ||
((this->id_type >= 6) && (this->id_type <= 8)) ||
@@ -123,12 +123,6 @@ encoding_rule_t ke_payload_encodings[] = {
*/
static status_t verify(private_ke_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
/* dh group is not verified in here */
return SUCCESS;
}
@@ -111,11 +111,6 @@ encoding_rule_t nonce_payload_encodings[] = {
*/
static status_t verify(private_nonce_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if ((this->nonce.len < 16) || ((this->nonce.len > 256)))
{
/* nonce length is wrong */
@@ -25,6 +25,7 @@
#include "notify_payload.h"
#include <daemon.h>
#include <encoding/payloads/encodings.h>
#include <utils/allocator.h>
@@ -104,6 +105,11 @@ struct private_notify_payload_t {
*/
chunk_t notification_data;
/**
* Assigned logger
*/
logger_t *logger;
/**
* @brief Computes the length of this payload.
*
@@ -169,11 +175,6 @@ encoding_rule_t notify_payload_encodings[] = {
*/
static status_t verify(private_notify_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if (this->protocol_id > 3)
{
/* reserved for future use */
@@ -191,9 +192,20 @@ static status_t verify(private_notify_payload_t *this)
return FAILED;
}
dh_group = ntohs(*((u_int16_t*)this->notification_data.ptr));
if (dh_group < MODP_1024_BIT || dh_group > MODP_8192_BIT)
switch (dh_group)
{
return FAILED;
case MODP_768_BIT:
case MODP_1024_BIT:
case MODP_1536_BIT:
case MODP_2048_BIT:
case MODP_3072_BIT:
case MODP_4096_BIT:
case MODP_6144_BIT:
case MODP_8192_BIT:
break;
default:
this->logger->log(this->logger, ERROR, "Bad DH group (%d)", dh_group);
return FAILED;
}
}
return SUCCESS;
@@ -402,7 +414,7 @@ notify_payload_t *notify_payload_create()
this->compute_length = compute_length;
/* set default values of the fields */
this->critical = NOTIFY_PAYLOAD_CRITICAL_FLAG;
this->critical = FALSE;
this->next_payload = NO_PAYLOAD;
this->payload_length = NOTIFY_PAYLOAD_HEADER_LENGTH;
this->protocol_id = 0;
@@ -412,6 +424,7 @@ notify_payload_t *notify_payload_create()
this->spi_size = 0;
this->notification_data.ptr = NULL;
this->notification_data.len = 0;
this->logger = charon->logger_manager->get_logger(charon->logger_manager, PAYLOAD);
return (&(this->public));
}
@@ -29,13 +29,6 @@
#include <encoding/payloads/proposal_substructure.h>
#include <utils/linked_list.h>
/**
* Critical flag must not be set.
*
* @ingroup payloads
*/
#define NOTIFY_PAYLOAD_CRITICAL_FLAG FALSE;
/**
* Notify payload length in bytes without any spi and notification data.
*
@@ -620,7 +620,7 @@ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *
iterator->destroy(iterator);
/* take over general infos */
this->spi_size = proto == IKE ? 8 : 4;
this->spi_size = proto == PROTO_IKE ? 8 : 4;
this->spi.len = this->spi_size;
this->spi.ptr = allocator_alloc(this->spi_size);
*((u_int32_t*)this->spi.ptr) = proposal->get_spi(proposal, proto);
+2 -8
View File
@@ -118,12 +118,6 @@ static status_t verify(private_sa_payload_t *this)
status_t status = SUCCESS;
iterator_t *iterator;
bool first = TRUE;
if (this->critical)
{
/* critical bit set! */
return FAILED;
}
/* check proposal numbering */
iterator = this->proposals->create_iterator(this->proposals,TRUE);
@@ -269,7 +263,7 @@ static void add_proposal(private_sa_payload_t *this, proposal_t *proposal)
proposal->get_protocols(proposal, proto);
for (i = 0; i<2; i++)
{
if (proto[i] != UNDEFINED_PROTOCOL_ID)
if (proto[i] != PROTO_NONE)
{
substructure = proposal_substructure_create_from_proposal(proposal, proto[i]);
add_proposal_substructure(this, substructure);
@@ -356,7 +350,7 @@ sa_payload_t *sa_payload_create()
this->compute_length = compute_length;
/* set default values of the fields */
this->critical = SA_PAYLOAD_CRITICAL_FLAG;
this->critical = FALSE;
this->next_payload = NO_PAYLOAD;
this->payload_length = SA_PAYLOAD_HEADER_LENGTH;
@@ -28,13 +28,6 @@
#include <encoding/payloads/proposal_substructure.h>
#include <utils/linked_list.h>
/**
* Critical flag must not be set.
*
* @ingroup payloads
*/
#define SA_PAYLOAD_CRITICAL_FLAG FALSE;
/**
* SA_PAYLOAD length in bytes without any proposal substructure.
*
@@ -130,11 +130,6 @@ static status_t verify(private_ts_payload_t *this)
iterator_t *iterator;
status_t status = SUCCESS;
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
if (this->number_of_traffic_selectors != (this->traffic_selectors->get_count(this->traffic_selectors)))
{
/* must be the same */
@@ -102,12 +102,6 @@ encoding_rule_t vendor_id_payload_encodings[] = {
*/
static status_t verify(private_vendor_id_payload_t *this)
{
if (this->critical)
{
/* critical bit is set! */
return FAILED;
}
return SUCCESS;
}