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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ extern enum_name_t *protocol_id_names;
|
||||
enum proposal_selection_flag_t {
|
||||
/** Accept algorithms from a private range. */
|
||||
PROPOSAL_ALLOW_PRIVATE = (1<<0),
|
||||
/** Whether to prefer configured or supplied proposals. */
|
||||
PROPOSAL_PREFER_CONFIGURED = (1<<1),
|
||||
/** Whether to prefer configured (default) or supplied proposals. */
|
||||
PROPOSAL_PREFER_SUPPLIED = (1<<1),
|
||||
/** Whether to skip and ignore diffie hellman groups. */
|
||||
PROPOSAL_SKIP_DH = (1<<2),
|
||||
};
|
||||
@@ -145,7 +145,7 @@ struct proposal_t {
|
||||
* compared. If they have at least one algorithm of each type
|
||||
* in common, a resulting proposal of this kind is created.
|
||||
*
|
||||
* If the flag PROPOSAL_PREFER_CONFIGURED is set, other is expected to be
|
||||
* Unless the flag PROPOSAL_PREFER_SUPPLIED is set, other is expected to be
|
||||
* the remote proposal from which to copy SPI and proposal number to the
|
||||
* result, otherwise copy from this proposal.
|
||||
*
|
||||
@@ -255,7 +255,19 @@ proposal_t *proposal_create_default_aead(protocol_id_t protocol);
|
||||
* @param algs algorithms as string
|
||||
* @return proposal_t object
|
||||
*/
|
||||
proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs);
|
||||
proposal_t *proposal_create_from_string(protocol_id_t protocol,
|
||||
const char *algs);
|
||||
|
||||
/**
|
||||
* Select a common proposal from the given lists of proposals.
|
||||
*
|
||||
* @param configured list of configured/local proposals
|
||||
* @param supplied list of supplied/remote proposals
|
||||
* @param flags flags to consider during proposal selection
|
||||
* @return selected proposal, or NULL (allocated)
|
||||
*/
|
||||
proposal_t *proposal_select(linked_list_t *configured, linked_list_t *supplied,
|
||||
proposal_selection_flag_t flags);
|
||||
|
||||
/**
|
||||
* printf hook function for proposal_t.
|
||||
|
||||
Reference in New Issue
Block a user