proposal: Use flags to select/match proposals
During proposal selection with ike/child_cfgs a couple of boolean variables can be set (e.g. private, prefer_self, strip_dh). To simplify the addition of new parameters, these functions now use a set of flags instead of indiviual boolean values. Signed-off-by: Thomas Egerer <[email protected]>
This commit is contained in:
committed by
Tobias Brunner
parent
8346db09dd
commit
f930b732c4
@@ -234,13 +234,13 @@ METHOD(child_cfg_t, get_proposals, linked_list_t*,
|
||||
}
|
||||
|
||||
METHOD(child_cfg_t, select_proposal, proposal_t*,
|
||||
private_child_cfg_t*this, linked_list_t *proposals, bool strip_dh,
|
||||
bool private, bool prefer_self)
|
||||
private_child_cfg_t*this, linked_list_t *proposals,
|
||||
proposal_selection_flag_t flags)
|
||||
{
|
||||
enumerator_t *prefer_enum, *match_enum;
|
||||
proposal_t *proposal, *match, *selected = NULL;
|
||||
|
||||
if (prefer_self)
|
||||
if (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
prefer_enum = this->proposals->create_enumerator(this->proposals);
|
||||
match_enum = proposals->create_enumerator(proposals);
|
||||
@@ -254,11 +254,11 @@ METHOD(child_cfg_t, select_proposal, proposal_t*,
|
||||
while (prefer_enum->enumerate(prefer_enum, &proposal))
|
||||
{
|
||||
proposal = proposal->clone(proposal);
|
||||
if (strip_dh)
|
||||
if (flags & PROPOSAL_STRIP_DH)
|
||||
{
|
||||
proposal->strip_dh(proposal, MODP_NONE);
|
||||
}
|
||||
if (prefer_self)
|
||||
if (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
proposals->reset_enumerator(proposals, match_enum);
|
||||
}
|
||||
@@ -269,11 +269,11 @@ METHOD(child_cfg_t, select_proposal, proposal_t*,
|
||||
while (match_enum->enumerate(match_enum, &match))
|
||||
{
|
||||
match = match->clone(match);
|
||||
if (strip_dh)
|
||||
if (flags & PROPOSAL_STRIP_DH)
|
||||
{
|
||||
match->strip_dh(match, MODP_NONE);
|
||||
}
|
||||
selected = proposal->select(proposal, match, prefer_self, private);
|
||||
selected = proposal->select(proposal, match, flags);
|
||||
match->destroy(match);
|
||||
if (selected)
|
||||
{
|
||||
|
||||
@@ -99,14 +99,11 @@ struct child_cfg_t {
|
||||
* Returned propsal is newly created and must be destroyed after usage.
|
||||
*
|
||||
* @param proposals list from which proposals are selected
|
||||
* @param strip_dh TRUE strip out diffie hellman groups
|
||||
* @param private accept algorithms from a private range
|
||||
* @param prefer_self whether to prefer configured or supplied proposals
|
||||
* @param flags flags to consider during proposal selection
|
||||
* @return selected proposal, or NULL if nothing matches
|
||||
*/
|
||||
proposal_t* (*select_proposal)(child_cfg_t*this, linked_list_t *proposals,
|
||||
bool strip_dh, bool private,
|
||||
bool prefer_self);
|
||||
proposal_selection_flag_t flags);
|
||||
|
||||
/**
|
||||
* Add a traffic selector to the config.
|
||||
|
||||
@@ -329,7 +329,8 @@ METHOD(ike_cfg_t, has_proposal, bool,
|
||||
enumerator = this->proposals->create_enumerator(this->proposals);
|
||||
while (enumerator->enumerate(enumerator, &proposal))
|
||||
{
|
||||
if (proposal->matches(proposal, match, private))
|
||||
if (proposal->matches(proposal, match,
|
||||
private ? PROPOSAL_ALLOW_PRIVATE : 0))
|
||||
{
|
||||
enumerator->destroy(enumerator);
|
||||
return TRUE;
|
||||
@@ -340,13 +341,13 @@ METHOD(ike_cfg_t, has_proposal, bool,
|
||||
}
|
||||
|
||||
METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
||||
private_ike_cfg_t *this, linked_list_t *proposals, bool private,
|
||||
bool prefer_self)
|
||||
private_ike_cfg_t *this, linked_list_t *proposals,
|
||||
proposal_selection_flag_t flags)
|
||||
{
|
||||
enumerator_t *prefer_enum, *match_enum;
|
||||
proposal_t *proposal, *match, *selected = NULL;
|
||||
|
||||
if (prefer_self)
|
||||
if (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
prefer_enum = this->proposals->create_enumerator(this->proposals);
|
||||
match_enum = proposals->create_enumerator(proposals);
|
||||
@@ -359,7 +360,7 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
||||
|
||||
while (prefer_enum->enumerate(prefer_enum, (void**)&proposal))
|
||||
{
|
||||
if (prefer_self)
|
||||
if (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
proposals->reset_enumerator(proposals, match_enum);
|
||||
}
|
||||
@@ -369,7 +370,7 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
||||
}
|
||||
while (match_enum->enumerate(match_enum, (void**)&match))
|
||||
{
|
||||
selected = proposal->select(proposal, match, prefer_self, private);
|
||||
selected = proposal->select(proposal, match, flags);
|
||||
if (selected)
|
||||
{
|
||||
DBG2(DBG_CFG, "received proposals: %#P", proposals);
|
||||
|
||||
@@ -186,12 +186,11 @@ struct ike_cfg_t {
|
||||
* Returned proposal must be destroyed after use.
|
||||
*
|
||||
* @param proposals list of proposals to select from
|
||||
* @param private accept algorithms from a private range
|
||||
* @param prefer_self whether to prefer configured or supplied proposals
|
||||
* @param flags flags to consider during proposal selection
|
||||
* @return selected proposal, or NULL if none matches.
|
||||
*/
|
||||
proposal_t *(*select_proposal) (ike_cfg_t *this, linked_list_t *proposals,
|
||||
bool private, bool prefer_self);
|
||||
proposal_selection_flag_t flags);
|
||||
|
||||
/**
|
||||
* Check if the config has a matching proposal.
|
||||
|
||||
Reference in New Issue
Block a user