diff options
Diffstat (limited to 'Source/charon')
-rw-r--r-- | Source/charon/config/child_proposal.c | 3 | ||||
-rw-r--r-- | Source/charon/config/sa_config.c | 9 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/sa_payload.c | 1 | ||||
-rw-r--r-- | Source/charon/sa/states/ike_auth_requested.c | 25 | ||||
-rw-r--r-- | Source/charon/sa/states/ike_sa_init_requested.c | 3 | ||||
-rw-r--r-- | Source/charon/sa/states/ike_sa_init_responded.c | 12 | ||||
-rw-r--r-- | Source/charon/utils/iterator.h | 13 | ||||
-rw-r--r-- | Source/charon/utils/linked_list.c | 38 |
8 files changed, 87 insertions, 17 deletions
diff --git a/Source/charon/config/child_proposal.c b/Source/charon/config/child_proposal.c index 5a68f4f9b..729102ebf 100644 --- a/Source/charon/config/child_proposal.c +++ b/Source/charon/config/child_proposal.c @@ -473,9 +473,10 @@ static void get_protocols(private_child_proposal_t *this, protocol_id_t ids[2]) if (i>1) { /* should not happen, but who knows */ - return; + break; } } + iterator->destroy(iterator); } /** diff --git a/Source/charon/config/sa_config.c b/Source/charon/config/sa_config.c index f098d176f..ca29b0294 100644 --- a/Source/charon/config/sa_config.c +++ b/Source/charon/config/sa_config.c @@ -287,25 +287,22 @@ static status_t destroy(private_sa_config_t *this) /* delete proposals */ - while(this->proposals->get_count(this->proposals) > 0) + while(this->proposals->remove_last(this->proposals, (void**)&proposal) == SUCCESS) { - this->proposals->remove_last(this->proposals, (void**)&proposal); proposal->destroy(proposal); } this->proposals->destroy(this->proposals); /* delete traffic selectors */ - while(this->ts_initiator->get_count(this->ts_initiator) > 0) + while(this->ts_initiator->remove_last(this->ts_initiator, (void**)&traffic_selector) == SUCCESS) { - this->ts_initiator->remove_last(this->ts_initiator, (void**)&traffic_selector); traffic_selector->destroy(traffic_selector); } this->ts_initiator->destroy(this->ts_initiator); /* delete traffic selectors */ - while(this->ts_responder->get_count(this->ts_responder) > 0) + while(this->ts_responder->remove_last(this->ts_responder, (void**)&traffic_selector) == SUCCESS) { - this->ts_responder->remove_last(this->ts_responder, (void**)&traffic_selector); traffic_selector->destroy(traffic_selector); } this->ts_responder->destroy(this->ts_responder); diff --git a/Source/charon/encoding/payloads/sa_payload.c b/Source/charon/encoding/payloads/sa_payload.c index 54b34568b..90f8698f8 100644 --- a/Source/charon/encoding/payloads/sa_payload.c +++ b/Source/charon/encoding/payloads/sa_payload.c @@ -558,6 +558,7 @@ sa_payload_t *sa_payload_create_from_child_proposal_list(linked_list_t *proposal iterator->current(iterator, (void**)&proposal); add_child_proposal((private_sa_payload_t*)sa_payload, proposal); } + iterator->destroy(iterator); return sa_payload; } diff --git a/Source/charon/sa/states/ike_auth_requested.c b/Source/charon/sa/states/ike_auth_requested.c index 00c691d03..743166ddb 100644 --- a/Source/charon/sa/states/ike_auth_requested.c +++ b/Source/charon/sa/states/ike_auth_requested.c @@ -325,32 +325,42 @@ static status_t process_idr_payload(private_ike_auth_requested_t *this, id_paylo */ static status_t process_sa_payload(private_ike_auth_requested_t *this, sa_payload_t *sa_payload) { - child_proposal_t *proposal; + child_proposal_t *proposal, *proposal_tmp; linked_list_t *proposal_list; protocol_id_t proto; - /* TODO fix mem allocation */ - /* TODO child sa stuff */ - - /* get selected proposal */ + /* get his selected proposal */ proposal_list = sa_payload->get_child_proposals(sa_payload); /* check count of proposals */ if (proposal_list->get_count(proposal_list) == 0) { - /* no proposal? we accept this, no child sa is built */ + /* no proposal? we accept this, but no child sa is built */ this->logger->log(this->logger, AUDIT, "IKE_AUTH reply's SA_PAYLOAD didn't contain any proposals. No CHILD_SA created", proposal_list->get_count(proposal_list)); + proposal_list->destroy(proposal_list); return SUCCESS; } if (proposal_list->get_count(proposal_list) > 1) { this->logger->log(this->logger, AUDIT, "IKE_AUTH reply's SA_PAYLOAD contained %d proposal. Deleting IKE_SA", proposal_list->get_count(proposal_list)); + while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS) + { + proposal->destroy(proposal); + } + proposal_list->destroy(proposal_list); return DELETE_ME; } /* we have to re-check here if other's selection is valid */ proposal = this->sa_config->select_proposal(this->sa_config, proposal_list); + /* list not needed anymore */ + while (proposal_list->remove_last(proposal_list, (void**)&proposal_tmp) == SUCCESS) + { + proposal_tmp->destroy(proposal_tmp); + } + proposal_list->destroy(proposal_list); + /* got a match? */ if (proposal == NULL) { this->logger->log(this->logger, AUDIT, "IKE_AUTH reply contained a not offered proposal. Deleting IKE_SA"); @@ -376,6 +386,9 @@ static status_t process_sa_payload(private_ike_auth_requested_t *this, sa_payloa } } + /* TODO: Proposal? child_sa */ + proposal->destroy(proposal); + return SUCCESS; } diff --git a/Source/charon/sa/states/ike_sa_init_requested.c b/Source/charon/sa/states/ike_sa_init_requested.c index d7fa1f127..7636ecbbe 100644 --- a/Source/charon/sa/states/ike_sa_init_requested.c +++ b/Source/charon/sa/states/ike_sa_init_requested.c @@ -525,10 +525,11 @@ static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message sa_payload_t *sa_payload; sa_config_t *sa_config; + /* get proposals form config, add to payload */ sa_config = this->ike_sa->get_sa_config(this->ike_sa); proposal_list = sa_config->get_proposals(sa_config); sa_payload = sa_payload_create_from_child_proposal_list(proposal_list); - /* TODO: fix mem allocation */ + /* TODO child sa stuff */ this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message"); diff --git a/Source/charon/sa/states/ike_sa_init_responded.c b/Source/charon/sa/states/ike_sa_init_responded.c index c89458e89..cb4c42559 100644 --- a/Source/charon/sa/states/ike_sa_init_responded.c +++ b/Source/charon/sa/states/ike_sa_init_responded.c @@ -386,12 +386,11 @@ static status_t build_idr_payload(private_ike_sa_init_responded_t *this, id_payl */ static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_payload_t *request, message_t *response) { - child_proposal_t *proposal; + child_proposal_t *proposal, *proposal_tmp; linked_list_t *proposal_list; sa_payload_t *sa_response; protocol_id_t proto; - /* TODO: fix mem */ /* TODO: child sa stuff */ /* get proposals from request */ @@ -402,12 +401,20 @@ static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_paylo this->logger->log(this->logger, AUDIT, "IKE_AUH request did not contain any proposals. No CHILD_SA created"); sa_response = sa_payload_create(); response->add_payload(response, (payload_t*)sa_response); + proposal_list->destroy(proposal_list); return SUCCESS; } /* now select a proposal */ this->logger->log(this->logger, CONTROL|LEVEL1, "Selecting proposals:"); proposal = this->sa_config->select_proposal(this->sa_config, proposal_list); + /* list is not needed anymore */ + while (proposal_list->remove_last(proposal_list, (void**)&proposal_tmp) == SUCCESS) + { + proposal_tmp->destroy(proposal_tmp); + } + proposal_list->destroy(proposal_list); + /* do we have a proposal */ if (proposal == NULL) { this->logger->log(this->logger, AUDIT, "IKE_AUTH request did not contain any proposals we accept. Deleting IKE_SA"); @@ -436,6 +443,7 @@ static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_paylo /* create payload with selected propsal */ sa_response = sa_payload_create_from_child_proposal(proposal); response->add_payload(response, (payload_t*)sa_response); + proposal->destroy(proposal); return SUCCESS; } diff --git a/Source/charon/utils/iterator.h b/Source/charon/utils/iterator.h index 69ee828f4..de81db8e9 100644 --- a/Source/charon/utils/iterator.h +++ b/Source/charon/utils/iterator.h @@ -44,6 +44,19 @@ typedef struct iterator_t iterator_t; struct iterator_t { /** + * @brief Iterate over all items. + * + * The easy way to iterate over items. + * + * @param this calling object + * @param[out] value item + * @return + * - TRUE, if more elements are avaiable, + * - FALSE otherwise + */ + bool (*iterate) (iterator_t *this, void** value); + + /** * @brief Moves to the next element, if available. * * A newly created iterator_t object doesn't point to any item. diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c index f3e686a5a..7ad07dbdd 100644 --- a/Source/charon/utils/linked_list.c +++ b/Source/charon/utils/linked_list.c @@ -156,7 +156,42 @@ struct private_iterator_t { /** * Implementation of iterator_t.has_next. */ -bool iterator_has_next(private_iterator_t *this) +static bool iterate(private_iterator_t *this, void** value) +{ + if (this->list->count == 0) + { + return FALSE; + } + if (this->current == NULL) + { + this->current = (this->forward) ? this->list->first : this->list->last; + *value = this->current->value; + return TRUE; + } + if (this->forward) + { + if (this->current->next == NULL) + { + return FALSE; + } + this->current = this->current->next; + *value = this->current->value; + return TRUE; + } + /* backward */ + if (this->current->previous == NULL) + { + return FALSE; + } + this->current = this->current->previous; + *value = this->current->value; + return TRUE; +} + +/** + * Implementation of iterator_t.has_next. + */ +static bool iterator_has_next(private_iterator_t *this) { if (this->list->count == 0) { @@ -632,6 +667,7 @@ static iterator_t *create_iterator (private_linked_list_t *linked_list,bool forw { private_iterator_t *this = allocator_alloc_thing(private_iterator_t); + this->public.iterate = (bool (*) (iterator_t *this, void **value)) iterate; this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next; this->public.current = (status_t (*) (iterator_t *this, void **value)) iterator_current; this->public.insert_before = (void (*) (iterator_t *this, void *item)) insert_before; |