diff options
Diffstat (limited to 'Source/charon')
-rw-r--r-- | Source/charon/ike_sa_id.c | 23 | ||||
-rw-r--r-- | Source/charon/ike_sa_id.h | 9 | ||||
-rw-r--r-- | Source/charon/ike_sa_manager.c | 10 | ||||
-rw-r--r-- | Source/charon/jobs/incoming_packet_job.c | 4 | ||||
-rw-r--r-- | Source/charon/jobs/incoming_packet_job.h | 6 | ||||
-rw-r--r-- | Source/charon/message.c | 47 | ||||
-rw-r--r-- | Source/charon/message.h | 12 | ||||
-rw-r--r-- | Source/charon/parser.c | 11 | ||||
-rw-r--r-- | Source/charon/parser.h | 9 | ||||
-rw-r--r-- | Source/charon/testcases/ike_sa_id_test.c | 2 | ||||
-rw-r--r-- | Source/charon/testcases/ike_sa_manager_test.c | 2 | ||||
-rw-r--r-- | Source/charon/testcases/ike_sa_test.c | 2 | ||||
-rw-r--r-- | Source/charon/thread_pool.c | 43 | ||||
-rw-r--r-- | Source/charon/types.h | 5 |
14 files changed, 145 insertions, 40 deletions
diff --git a/Source/charon/ike_sa_id.c b/Source/charon/ike_sa_id.c index c498492fa..9f4acb9b4 100644 --- a/Source/charon/ike_sa_id.c +++ b/Source/charon/ike_sa_id.c @@ -45,12 +45,12 @@ struct private_ike_sa_id_s { /** * SPI of Initiator */ - spi_t initiator_spi; + u_int64_t initiator_spi; /** * SPI of Responder */ - spi_t responder_spi; + u_int64_t responder_spi; /** * Role for specific IKE_SA @@ -63,13 +63,13 @@ struct private_ike_sa_id_s { /** * @brief implements function set_responder_spi of ike_sa_id_t */ -static status_t set_responder_spi (private_ike_sa_id_t *this, spi_t responder_spi) +static status_t set_responder_spi (private_ike_sa_id_t *this, u_int64_t responder_spi) { this->responder_spi = responder_spi; return SUCCESS; } -static status_t set_initiator_spi(private_ike_sa_id_t *this, spi_t initiator_spi) +static status_t set_initiator_spi(private_ike_sa_id_t *this, u_int64_t initiator_spi) { this->initiator_spi = initiator_spi; return SUCCESS; @@ -80,7 +80,7 @@ static status_t set_initiator_spi(private_ike_sa_id_t *this, spi_t initiator_spi */ static bool initiator_spi_is_set (private_ike_sa_id_t *this) { - return (!(this->initiator_spi == 0)); + return (this->initiator_spi != 0); } /** @@ -88,7 +88,7 @@ static bool initiator_spi_is_set (private_ike_sa_id_t *this) */ static bool responder_spi_is_set (private_ike_sa_id_t *this) { - return (!(this->responder_spi == 0)); + return (this->responder_spi != 0); } /** @@ -103,6 +103,7 @@ static status_t equals (private_ike_sa_id_t *this,private_ike_sa_id_t *other, bo if ((this->is_initiator == other->is_initiator) && (this->initiator_spi == other->initiator_spi) && (this->responder_spi == other->responder_spi)) + { /* private_ike_sa_id's are equal */ *are_equal = TRUE; @@ -136,7 +137,7 @@ status_t replace_values (private_ike_sa_id_t *this, private_ike_sa_id_t *other) /** * @brief implements function ike_sa_id_t.get_values */ -static status_t get_values(private_ike_sa_id_t *this, spi_t *initiator, spi_t *responder, bool *is_initiator) +static status_t get_values(private_ike_sa_id_t *this, u_int64_t *initiator, u_int64_t *responder, bool *is_initiator) { memcpy(initiator, &(this->initiator_spi), sizeof(initiator)); memcpy(responder, &(this->responder_spi), sizeof(responder)); @@ -168,7 +169,7 @@ static status_t destroy (private_ike_sa_id_t *this) /* * Described in Header-File */ -ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, bool is_initiator) +ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiator) { private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t); if (this == NULL) @@ -177,13 +178,13 @@ ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, bool is } /* Public functions */ - this->public.set_responder_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_responder_spi; - this->public.set_initiator_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_initiator_spi; + this->public.set_responder_spi = (status_t(*)(ike_sa_id_t*,u_int64_t)) set_responder_spi; + this->public.set_initiator_spi = (status_t(*)(ike_sa_id_t*,u_int64_t)) set_initiator_spi; this->public.responder_spi_is_set = (bool(*)(ike_sa_id_t*)) responder_spi_is_set; this->public.initiator_spi_is_set = (bool(*)(ike_sa_id_t*)) initiator_spi_is_set; this->public.equals = (status_t(*)(ike_sa_id_t*,ike_sa_id_t*,bool*)) equals; this->public.replace_values = (status_t(*)(ike_sa_id_t*,ike_sa_id_t*)) replace_values; - this->public.get_values = (status_t(*)(ike_sa_id_t*,spi_t*,spi_t*,bool*)) get_values; + this->public.get_values = (status_t(*)(ike_sa_id_t*,u_int64_t*,u_int64_t*,bool*)) get_values; this->public.clone = (status_t(*)(ike_sa_id_t*,ike_sa_id_t**)) clone; this->public.destroy = (status_t(*)(ike_sa_id_t*))destroy; diff --git a/Source/charon/ike_sa_id.h b/Source/charon/ike_sa_id.h index 403c506b7..9c3ef4e90 100644 --- a/Source/charon/ike_sa_id.h +++ b/Source/charon/ike_sa_id.h @@ -46,7 +46,7 @@ struct ike_sa_id_s { * @param responder_spi SPI of responder to set * @return SUCCESSFUL in any case */ - status_t (*set_responder_spi) (ike_sa_id_t *this, spi_t responder_spi); + status_t (*set_responder_spi) (ike_sa_id_t *this, u_int64_t responder_spi); /** * @brief Sets the SPI of the initiator. @@ -56,7 +56,7 @@ struct ike_sa_id_s { * @param initiator_spi SPI to set * @return SUCCESSFUL in any case */ - status_t (*set_initiator_spi) (ike_sa_id_t *this, spi_t initiator_spi); + status_t (*set_initiator_spi) (ike_sa_id_t *this, u_int64_t initiator_spi); /** * @brief Returns TRUE if the initiator spi is set (not zero) @@ -103,7 +103,7 @@ struct ike_sa_id_s { * @param is_initiator address to write role * @return SUCCESSFUL if succeeded, FAILED otherwise */ - status_t (*get_values) (ike_sa_id_t *this, spi_t *initiator, spi_t *responder, bool *is_initiator); + status_t (*get_values) (ike_sa_id_t *this, u_int64_t *initiator, u_int64_t *responder,bool *is_initiator); /** * @brief Clones a given ike_sa_id_t object @@ -128,6 +128,7 @@ struct ike_sa_id_s { * * @warning The initiator SPI and role is not changeable after initiating a ike_sa_id object */ -ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, bool is_initiaor); + +ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiaor); #endif /*IKE_SA_ID_H_*/ diff --git a/Source/charon/ike_sa_manager.c b/Source/charon/ike_sa_manager.c index 8e88282e4..aaeb29583 100644 --- a/Source/charon/ike_sa_manager.c +++ b/Source/charon/ike_sa_manager.c @@ -131,7 +131,7 @@ struct private_ike_sa_manager_s { * @return SUCCESS or, * OUT_OF_RES when we already served 2^64 SPIs ;-) */ - status_t (*get_next_spi) (private_ike_sa_manager_t *this, spi_t *spi); + status_t (*get_next_spi) (private_ike_sa_manager_t *this, u_int64_t *spi); /** * @brief find the ike_sa_entry in the list by SPIs @@ -193,7 +193,7 @@ struct private_ike_sa_manager_s { /** * Next SPI, needed for incremental creation of SPIs */ - spi_t next_spi; + u_int64_t next_spi; }; @@ -293,7 +293,7 @@ static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *ent /** * @see private_ike_sa_manager_t.get_next_spi */ -static status_t get_next_spi(private_ike_sa_manager_t *this, spi_t *spi) +static status_t get_next_spi(private_ike_sa_manager_t *this, u_int64_t *spi) { this->next_spi++; if (this->next_spi == 0) { @@ -383,7 +383,7 @@ static status_t checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, * Request (even a retransmitted one) will result in a * IKE_SA. This could be improved... */ - spi_t responder_spi; + u_int64_t responder_spi; ike_sa_entry_t *new_ike_sa_entry; /* set SPIs, we are the responder */ @@ -431,7 +431,7 @@ static status_t checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, /* creation of an IKE_SA from local site, * we are the initiator! */ - spi_t initiator_spi; + u_int64_t initiator_spi; ike_sa_entry_t *new_ike_sa_entry; retval = this->get_next_spi(this, &initiator_spi); diff --git a/Source/charon/jobs/incoming_packet_job.c b/Source/charon/jobs/incoming_packet_job.c index 93508b7fe..c7758faed 100644 --- a/Source/charon/jobs/incoming_packet_job.c +++ b/Source/charon/jobs/incoming_packet_job.c @@ -59,6 +59,10 @@ static job_type_t get_type(private_incoming_packet_job_t *this) */ static status_t get_packet(private_incoming_packet_job_t *this,packet_t **packet) { + if (this->packet == NULL) + { + return FAILED; + } *packet = this->packet; return SUCCESS; } diff --git a/Source/charon/jobs/incoming_packet_job.h b/Source/charon/jobs/incoming_packet_job.h index a984c6011..10a35e6ff 100644 --- a/Source/charon/jobs/incoming_packet_job.h +++ b/Source/charon/jobs/incoming_packet_job.h @@ -42,11 +42,13 @@ struct incoming_packet_job_s { /** * @brief Returns the assigned packet_t object * - * @warning Returned packet is not cloned and has to get destroyed by the caller + * @warning Returned packet is not cloned and has to get destroyed by the caller. * * @param this calling incoming_packet_job_t object * @param[out] packet assigned packet will be written into this location - * @return SUCCESS + * @return + * - SUCCESS + * - FAILED if no packet is assigned */ status_t (*get_packet) (incoming_packet_job_t *this, packet_t **packet); diff --git a/Source/charon/message.c b/Source/charon/message.c index 1710a909f..5e7d7c1ee 100644 --- a/Source/charon/message.c +++ b/Source/charon/message.c @@ -33,6 +33,7 @@ #include "utils/logger_manager.h" #include "payloads/encodings.h" #include "payloads/payload.h" +#include "parser.h" /** * Entry for a payload in the internal used linked list @@ -103,15 +104,16 @@ struct private_message_s { */ linked_list_t *payloads; + /** + * Assigned parser to parse Header and Body of this message + */ + parser_t *parser; + /** * logger for this message */ logger_t *logger; - /** - * destination of this message - */ - }; @@ -273,7 +275,7 @@ static status_t generate(private_message_t *this, packet_t **packet) ike_header_t *ike_header; payload_t *payload, *next_payload; linked_list_iterator_t *iterator; - spi_t initiator_spi, responder_spi; + u_int64_t initiator_spi, responder_spi; bool is_initiator; status_t status; @@ -361,6 +363,27 @@ static status_t generate(private_message_t *this, packet_t **packet) } /** + * Implements message_t's parse_header function. + * See #message_s.parse_header. + */ +static status_t parse_header (private_message_t *this) +{ + ike_header_t *ike_header; + status_t status; + + this->parser->reset_context(this->parser); + status = this->parser->parse_payload(this->parser,HEADER,(payload_t **) &ike_header); + if (status != SUCCESS) + { + return status; + + } + ike_header->destroy(ike_header); + return SUCCESS; +} + + +/** * Implements message_t's destroy function. * See #message_s.destroy. */ @@ -420,6 +443,7 @@ message_t *message_create_from_packet(packet_t *packet) this->public.get_source = (status_t (*) (message_t*,host_t**)) get_source; this->public.set_destination = (status_t (*) (message_t*,host_t*)) set_destination; this->public.get_destination = (status_t (*) (message_t*,host_t**)) get_destination; + this->public.parse_header = (status_t (*) (message_t *)) parse_header; this->public.destroy = (status_t(*)(message_t*))destroy; /* public values */ @@ -446,12 +470,23 @@ message_t *message_create_from_packet(packet_t *packet) allocator_free(this); return NULL; } + + /* parser is created from data of packet */ + this->parser = parser_create(this->packet->data); + if (this->parser == NULL) + { + this->payloads->destroy(this->payloads); + allocator_free(this); + return NULL; + } this->logger = global_logger_manager->create_logger(global_logger_manager, MESSAGE, NULL); if (this->logger == NULL) { + this->parser->destroy(this->parser); this->payloads->destroy(this->payloads); - allocator_free(this); + allocator_free(this); + return NULL; } return (&this->public); diff --git a/Source/charon/message.h b/Source/charon/message.h index 7fbeb2e7a..f08076284 100644 --- a/Source/charon/message.h +++ b/Source/charon/message.h @@ -158,6 +158,18 @@ struct message_s { * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set * .... */ + + /** + * @brief Parses header of message + * + * @param this message_t object + * @return + * - SUCCESS if header could be parsed + * - NOT_SUPPORTED if payload_type is not supported + * - OUT_OF_RES if out of ressources + * - PARSE_ERROR if corrupted/invalid data found + */ + status_t (*parse_header) (message_t *this); status_t (*generate) (message_t *this, packet_t **packet); status_t (*get_source) (message_t *this, host_t **host); diff --git a/Source/charon/parser.c b/Source/charon/parser.c index a1be3a833..c30092302 100644 --- a/Source/charon/parser.c +++ b/Source/charon/parser.c @@ -778,6 +778,16 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ } /** + * implementation of parser_t.reset_context + */ +static status_t reset_context (private_parser_t *this) +{ + this->byte_pos = this->input; + this->bit_pos = 0; + return SUCCESS; +} + +/** * implementation of parser_t.destroy */ static status_t destroy(private_parser_t *this) @@ -811,6 +821,7 @@ parser_t *parser_create(chunk_t data) } this->public.parse_payload = (status_t(*)(parser_t*,payload_type_t,payload_t**)) parse_payload; + this->public.reset_context = (status_t(*)(parser_t*)) reset_context; this->public.destroy = (status_t(*)(parser_t*)) destroy; diff --git a/Source/charon/parser.h b/Source/charon/parser.h index 758e3db3d..65910139f 100644 --- a/Source/charon/parser.h +++ b/Source/charon/parser.h @@ -58,6 +58,15 @@ struct parser_s { status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, payload_t **payload); /** + * @brief Resets the current parser context + * + * @param parser parser object + * @return + * - SUCCESSFUL in any case + */ + status_t (*reset_context) (parser_t *this); + + /** * @brief Destroys a parser object * * @param parser parser object diff --git a/Source/charon/testcases/ike_sa_id_test.c b/Source/charon/testcases/ike_sa_id_test.c index 5523ab0af..19c19d88f 100644 --- a/Source/charon/testcases/ike_sa_id_test.c +++ b/Source/charon/testcases/ike_sa_id_test.c @@ -30,7 +30,7 @@ void test_ike_sa_id(tester_t *tester) { ike_sa_id_t *ike_sa_id, *clone, *equal, *other1, *other2, *other3, *other4; - spi_t initiator, initiator2, responder, responder2; + u_int64_t initiator, initiator2, responder, responder2; bool is_initiator; bool are_equal = FALSE; diff --git a/Source/charon/testcases/ike_sa_manager_test.c b/Source/charon/testcases/ike_sa_manager_test.c index 5bb8c75a0..d91685d7e 100644 --- a/Source/charon/testcases/ike_sa_manager_test.c +++ b/Source/charon/testcases/ike_sa_manager_test.c @@ -74,7 +74,7 @@ static void test3_thread(ike_sa_id_t *ike_sa_id) void test_ike_sa_manager(tester_t *tester) { status_t status; - spi_t initiator, responder; + u_int64_t initiator, responder; ike_sa_id_t *ike_sa_id, *sa_id; ike_sa_t *ike_sa; int thread_count = 200; diff --git a/Source/charon/testcases/ike_sa_test.c b/Source/charon/testcases/ike_sa_test.c index 8a704c272..81ea21057 100644 --- a/Source/charon/testcases/ike_sa_test.c +++ b/Source/charon/testcases/ike_sa_test.c @@ -31,7 +31,7 @@ void test_ike_sa(tester_t *tester) { ike_sa_t *ike_sa; ike_sa_id_t *ike_sa_id; - spi_t initiator, responder; + u_int64_t initiator, responder; bool is_initiator; diff --git a/Source/charon/thread_pool.c b/Source/charon/thread_pool.c index c4bd5479a..fdac81c92 100644 --- a/Source/charon/thread_pool.c +++ b/Source/charon/thread_pool.c @@ -69,19 +69,54 @@ struct private_thread_pool_s { */ static void job_processing(private_thread_pool_t *this) { + /* cancellation disabled by default */ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - this->logger->log(this->logger, CONTROL_MORE, "thread %u started working", pthread_self()); for (;;) { job_t *job; - + job_type_t job_type; + global_job_queue->get(global_job_queue, &job); - this->logger->log(this->logger, CONTROL_MORE, "thread %u got a job", pthread_self()); + job_type = job->get_type(job); + this->logger->log(this->logger, CONTROL_MORE, "thread %u got a job of type %s", pthread_self(),mapping_find(job_type_m,job_type)); /* process them here */ - + switch (job_type) + { + case INCOMING_PACKET: + { + packet_t *packet; + message_t *message; + incoming_packet_job_t *incoming_packet_job = (incoming_packet_job_t *)job; + + if (incoming_packet_job->get_packet(incoming_packet_job,&packet) != SUCCESS) + { + this->logger->log(this->logger, CONTROL_MORE, "thread %u: Packet in job of type %s could not be retrieved!", pthread_self(),mapping_find(job_type_m,job_type)); + break; + } + message = message_create_from_packet(packet); + if (message == NULL) + { + this->logger->log(this->logger, CONTROL_MORE, "thread %u: Message could not be created from packet!", pthread_self(),mapping_find(job_type_m,job_type)); + packet->destroy(packet); + break; + } + + //global_ike_sa_manager->checkout + break; + } + case INITIATE_IKE_SA: + { + break; + } + case RETRANSMIT_REQUEST: + { + this->logger->log(this->logger, CONTROL_MORE, "thread %u: Job of type %s not supported!", pthread_self(),mapping_find(job_type_m,job_type)); + break; + } + } job->destroy(job); } diff --git a/Source/charon/types.h b/Source/charon/types.h index 381861a36..506d73e26 100644 --- a/Source/charon/types.h +++ b/Source/charon/types.h @@ -47,11 +47,6 @@ typedef struct timespec timespec_t; typedef struct sockaddr sockaddr_t; /** - * Representates a IKE_SA spi - */ -typedef u_int64_t spi_t; - -/** * General purpose pointer/length abstraction */ typedef struct chunk_s chunk_t; |