From 6df2837a8ce54887e142082f48a64f879b28c092 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 21 Oct 2008 10:57:40 +0000 Subject: [PATCH] fixed enumeration of CHILD_SA traffic selectors --- src/charon/sa/child_sa.c | 49 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/charon/sa/child_sa.c b/src/charon/sa/child_sa.c index d0df5454b..445d9b99b 100644 --- a/src/charon/sa/child_sa.c +++ b/src/charon/sa/child_sa.c @@ -277,6 +277,8 @@ struct policy_enumerator_t { enumerator_t *other; /** list of others TS, to recreate enumerator */ linked_list_t *list; + /** currently enumerating TS for "me" side */ + traffic_selector_t *ts; }; /** @@ -285,32 +287,30 @@ struct policy_enumerator_t { static bool policy_enumerate(policy_enumerator_t *this, traffic_selector_t **my_out, traffic_selector_t **other_out) { - traffic_selector_t *my_ts, *other_ts; - - while (this->mine->enumerate(this->mine, &my_ts)) + traffic_selector_t *other_ts; + + while (this->ts || this->mine->enumerate(this->mine, &this->ts)) { - while (TRUE) - { - if (!this->other->enumerate(this->other, &other_ts)) - { /* end of others list, restart with new of mine */ - this->other->destroy(this->other); - this->other = this->list->create_enumerator(this->list); - break; - } - if (my_ts->get_type(my_ts) != other_ts->get_type(other_ts)) - { /* family mismatch */ - continue; - } - if (my_ts->get_protocol(my_ts) && - other_ts->get_protocol(other_ts) && - my_ts->get_protocol(my_ts) != other_ts->get_protocol(other_ts)) - { /* protocol mismatch */ - continue; - } - *my_out = my_ts; - *other_out = other_ts; - return TRUE; + if (!this->other->enumerate(this->other, &other_ts)) + { /* end of others list, restart with new of mine */ + this->other->destroy(this->other); + this->other = this->list->create_enumerator(this->list); + this->ts = NULL; + continue; } + if (this->ts->get_type(this->ts) != other_ts->get_type(other_ts)) + { /* family mismatch */ + continue; + } + if (this->ts->get_protocol(this->ts) && + other_ts->get_protocol(other_ts) && + this->ts->get_protocol(this->ts) != other_ts->get_protocol(other_ts)) + { /* protocol mismatch */ + continue; + } + *my_out = this->ts; + *other_out = other_ts; + return TRUE; } return FALSE; } @@ -337,6 +337,7 @@ static enumerator_t* create_policy_enumerator(private_child_sa_t *this) e->mine = this->my_ts->create_enumerator(this->my_ts); e->other = this->other_ts->create_enumerator(this->other_ts); e->list = this->other_ts; + e->ts = NULL; return &e->public; }