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:
@@ -237,54 +237,7 @@ METHOD(child_cfg_t, select_proposal, proposal_t*,
|
||||
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 (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
prefer_enum = this->proposals->create_enumerator(this->proposals);
|
||||
match_enum = proposals->create_enumerator(proposals);
|
||||
}
|
||||
else
|
||||
{
|
||||
prefer_enum = proposals->create_enumerator(proposals);
|
||||
match_enum = this->proposals->create_enumerator(this->proposals);
|
||||
}
|
||||
|
||||
while (prefer_enum->enumerate(prefer_enum, &proposal))
|
||||
{
|
||||
if (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
proposals->reset_enumerator(proposals, match_enum);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->proposals->reset_enumerator(this->proposals, match_enum);
|
||||
}
|
||||
while (match_enum->enumerate(match_enum, &match))
|
||||
{
|
||||
selected = proposal->select(proposal, match, flags);
|
||||
if (selected)
|
||||
{
|
||||
DBG2(DBG_CFG, "received proposals: %#P", proposals);
|
||||
DBG2(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||
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", proposals);
|
||||
DBG1(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||
}
|
||||
return selected;
|
||||
return proposal_select(this->proposals, proposals, flags);
|
||||
}
|
||||
|
||||
METHOD(child_cfg_t, add_traffic_selector, void,
|
||||
|
||||
@@ -344,54 +344,7 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
||||
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 (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
prefer_enum = this->proposals->create_enumerator(this->proposals);
|
||||
match_enum = proposals->create_enumerator(proposals);
|
||||
}
|
||||
else
|
||||
{
|
||||
prefer_enum = proposals->create_enumerator(proposals);
|
||||
match_enum = this->proposals->create_enumerator(this->proposals);
|
||||
}
|
||||
|
||||
while (prefer_enum->enumerate(prefer_enum, (void**)&proposal))
|
||||
{
|
||||
if (flags & PROPOSAL_PREFER_CONFIGURED)
|
||||
{
|
||||
proposals->reset_enumerator(proposals, match_enum);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->proposals->reset_enumerator(this->proposals, match_enum);
|
||||
}
|
||||
while (match_enum->enumerate(match_enum, (void**)&match))
|
||||
{
|
||||
selected = proposal->select(proposal, match, flags);
|
||||
if (selected)
|
||||
{
|
||||
DBG2(DBG_CFG, "received proposals: %#P", proposals);
|
||||
DBG2(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||
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", proposals);
|
||||
DBG1(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||
}
|
||||
return selected;
|
||||
return proposal_select(this->proposals, proposals, flags);
|
||||
}
|
||||
|
||||
METHOD(ike_cfg_t, get_dh_group, diffie_hellman_group_t,
|
||||
|
||||
@@ -399,10 +399,10 @@ METHOD(task_t, process_r, status_t,
|
||||
}
|
||||
|
||||
list = sa_payload->get_proposals(sa_payload);
|
||||
if (lib->settings->get_bool(lib->settings,
|
||||
if (!lib->settings->get_bool(lib->settings,
|
||||
"%s.prefer_configured_proposals", TRUE, lib->ns))
|
||||
{
|
||||
flags = PROPOSAL_PREFER_CONFIGURED;
|
||||
flags = PROPOSAL_PREFER_SUPPLIED;
|
||||
}
|
||||
this->proposal = this->ike_cfg->select_proposal(this->ike_cfg, list,
|
||||
flags);
|
||||
@@ -644,8 +644,7 @@ METHOD(task_t, process_i, status_t,
|
||||
return send_notify(this, INVALID_PAYLOAD_TYPE);
|
||||
}
|
||||
list = sa_payload->get_proposals(sa_payload);
|
||||
this->proposal = this->ike_cfg->select_proposal(this->ike_cfg, list,
|
||||
PROPOSAL_PREFER_CONFIGURED);
|
||||
this->proposal = this->ike_cfg->select_proposal(this->ike_cfg, list, 0);
|
||||
list->destroy_offset(list, offsetof(proposal_t, destroy));
|
||||
if (!this->proposal)
|
||||
{
|
||||
|
||||
@@ -390,10 +390,10 @@ METHOD(task_t, process_r, status_t,
|
||||
{
|
||||
flags |= PROPOSAL_ALLOW_PRIVATE;
|
||||
}
|
||||
if (lib->settings->get_bool(lib->settings,
|
||||
if (!lib->settings->get_bool(lib->settings,
|
||||
"%s.prefer_configured_proposals", TRUE, lib->ns))
|
||||
{
|
||||
flags |= PROPOSAL_PREFER_CONFIGURED;
|
||||
flags |= PROPOSAL_PREFER_SUPPLIED;
|
||||
}
|
||||
this->proposal = this->ike_cfg->select_proposal(this->ike_cfg,
|
||||
list, flags);
|
||||
@@ -629,7 +629,7 @@ METHOD(task_t, process_i, status_t,
|
||||
linked_list_t *list;
|
||||
sa_payload_t *sa_payload;
|
||||
auth_method_t method;
|
||||
proposal_selection_flag_t flags = PROPOSAL_PREFER_CONFIGURED;
|
||||
proposal_selection_flag_t flags = 0;
|
||||
uint32_t lifetime;
|
||||
|
||||
sa_payload = (sa_payload_t*)message->get_payload(message,
|
||||
|
||||
@@ -1136,10 +1136,10 @@ METHOD(task_t, process_r, status_t,
|
||||
{
|
||||
flags |= PROPOSAL_ALLOW_PRIVATE;
|
||||
}
|
||||
if (lib->settings->get_bool(lib->settings,
|
||||
if (!lib->settings->get_bool(lib->settings,
|
||||
"%s.prefer_configured_proposals", TRUE, lib->ns))
|
||||
{
|
||||
flags |= PROPOSAL_PREFER_CONFIGURED;
|
||||
flags |= PROPOSAL_PREFER_SUPPLIED;
|
||||
}
|
||||
this->proposal = this->config->select_proposal(this->config, list,
|
||||
flags);
|
||||
@@ -1345,7 +1345,7 @@ METHOD(task_t, process_i, status_t,
|
||||
{
|
||||
sa_payload_t *sa_payload;
|
||||
linked_list_t *list = NULL;
|
||||
proposal_selection_flag_t flags = PROPOSAL_PREFER_CONFIGURED;
|
||||
proposal_selection_flag_t flags = 0;
|
||||
|
||||
sa_payload = (sa_payload_t*)message->get_payload(message,
|
||||
PLV1_SECURITY_ASSOCIATION);
|
||||
|
||||
@@ -568,10 +568,10 @@ static status_t select_and_install(private_child_create_t *this,
|
||||
{
|
||||
flags |= PROPOSAL_ALLOW_PRIVATE;
|
||||
}
|
||||
if (lib->settings->get_bool(lib->settings, "%s.prefer_configured_proposals",
|
||||
TRUE, lib->ns))
|
||||
if (!lib->settings->get_bool(lib->settings,
|
||||
"%s.prefer_configured_proposals", TRUE, lib->ns))
|
||||
{
|
||||
flags |= PROPOSAL_PREFER_CONFIGURED;
|
||||
flags |= PROPOSAL_PREFER_SUPPLIED;
|
||||
}
|
||||
this->proposal = this->config->select_proposal(this->config,
|
||||
this->proposals, flags);
|
||||
|
||||
@@ -462,10 +462,10 @@ static void process_sa_payload(private_ike_init_t *this, message_t *message,
|
||||
{
|
||||
flags |= PROPOSAL_ALLOW_PRIVATE;
|
||||
}
|
||||
if (lib->settings->get_bool(lib->settings, "%s.prefer_configured_proposals",
|
||||
TRUE, lib->ns))
|
||||
if (!lib->settings->get_bool(lib->settings,
|
||||
"%s.prefer_configured_proposals", TRUE, lib->ns))
|
||||
{
|
||||
flags |= PROPOSAL_PREFER_CONFIGURED;
|
||||
flags |= PROPOSAL_PREFER_SUPPLIED;
|
||||
}
|
||||
this->proposal = ike_cfg->select_proposal(ike_cfg, proposal_list, flags);
|
||||
if (!this->proposal)
|
||||
|
||||
Reference in New Issue
Block a user