ike-cfg: Consider port information in IKE config match

Signed-off-by: Thomas Egerer <[email protected]>
This commit is contained in:
Thomas Egerer
2024-05-17 13:53:00 +02:00
committed by Tobias Brunner
parent 287ef047a9
commit 9228a5109b
+10 -4
View File
@@ -209,7 +209,8 @@ METHOD(ike_cfg_t, resolve_other, host_t*,
/** /**
* Common function for match_me/other * Common function for match_me/other
*/ */
static u_int match(linked_list_t *hosts, linked_list_t *ranges, host_t *cand) static u_int match(linked_list_t *hosts, linked_list_t *ranges, uint16_t port,
host_t *cand)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
traffic_selector_t *ts; traffic_selector_t *ts;
@@ -229,7 +230,7 @@ static u_int match(linked_list_t *hosts, linked_list_t *ranges, host_t *cand)
{ {
quality = max(quality, 128 + 1); quality = max(quality, 128 + 1);
} }
if (host->is_anyaddr(host)) else if (host->is_anyaddr(host))
{ {
quality = max(quality, 1); quality = max(quality, 1);
} }
@@ -257,19 +258,24 @@ static u_int match(linked_list_t *hosts, linked_list_t *ranges, host_t *cand)
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
/* honor if port matches exactly */
if (port == cand->get_port(cand))
{
quality += 1;
}
return quality; return quality;
} }
METHOD(ike_cfg_t, match_me, u_int, METHOD(ike_cfg_t, match_me, u_int,
private_ike_cfg_t *this, host_t *host) private_ike_cfg_t *this, host_t *host)
{ {
return match(this->my_hosts, this->my_ranges, host); return match(this->my_hosts, this->my_ranges, this->my_port, host);
} }
METHOD(ike_cfg_t, match_other, u_int, METHOD(ike_cfg_t, match_other, u_int,
private_ike_cfg_t *this, host_t *host) private_ike_cfg_t *this, host_t *host)
{ {
return match(this->other_hosts, this->other_ranges, host); return match(this->other_hosts, this->other_ranges, this->other_port, host);
} }
METHOD(ike_cfg_t, get_my_addr, char*, METHOD(ike_cfg_t, get_my_addr, char*,