proposal: Extract proposal selection code in ike/child_cfg_t

Also invert the PREFER_CONFIGURED flag (i.e. make it PREFER_SUPPLIED)
so the default, without flags, is what we preferred so far.
This commit is contained in:
Tobias Brunner
2019-10-24 17:36:33 +02:00
parent a406bc60c5
commit c9599d4101
10 changed files with 184 additions and 133 deletions
+62 -6
View File
@@ -485,16 +485,16 @@ METHOD(proposal_t, select_proposal, proposal_t*,
return NULL;
}
if (flags & PROPOSAL_PREFER_CONFIGURED)
{
selected = proposal_create(this->protocol, other->get_number(other));
selected->set_spi(selected, other->get_spi(other));
}
else
if (flags & PROPOSAL_PREFER_SUPPLIED)
{
selected = proposal_create(this->protocol, this->number);
selected->set_spi(selected, this->spi);
}
else
{
selected = proposal_create(this->protocol, other->get_number(other));
selected->set_spi(selected, other->get_spi(other));
}
if (!select_algos(this, other, selected, flags))
{
@@ -1346,3 +1346,59 @@ proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs
return &this->public;
}
/*
* Described in header
*/
proposal_t *proposal_select(linked_list_t *configured, linked_list_t *supplied,
proposal_selection_flag_t flags)
{
enumerator_t *prefer_enum, *match_enum;
proposal_t *proposal, *match, *selected = NULL;
if (flags & PROPOSAL_PREFER_SUPPLIED)
{
prefer_enum = supplied->create_enumerator(supplied);
match_enum = configured->create_enumerator(configured);
}
else
{
prefer_enum = configured->create_enumerator(configured);
match_enum = supplied->create_enumerator(supplied);
}
while (prefer_enum->enumerate(prefer_enum, &proposal))
{
if (flags & PROPOSAL_PREFER_SUPPLIED)
{
configured->reset_enumerator(configured, match_enum);
}
else
{
supplied->reset_enumerator(supplied, match_enum);
}
while (match_enum->enumerate(match_enum, &match))
{
selected = proposal->select(proposal, match, flags);
if (selected)
{
DBG2(DBG_CFG, "received proposals: %#P", supplied);
DBG2(DBG_CFG, "configured proposals: %#P", configured);
DBG1(DBG_CFG, "selected proposal: %P", selected);
break;
}
}
if (selected)
{
break;
}
}
prefer_enum->destroy(prefer_enum);
match_enum->destroy(match_enum);
if (!selected)
{
DBG1(DBG_CFG, "received proposals: %#P", supplied);
DBG1(DBG_CFG, "configured proposals: %#P", configured);
}
return selected;
}