summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice Bellet <fabrice@bellet.info>2020-04-16 20:01:25 +0200
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>2020-05-06 23:38:40 +0000
commitc4993988067a2bf5056fa3146314992c06bfe51d (patch)
treeffdeec45a0bede6230acf06add3c25ec72f6bc6e
parent25ad2c7a32d6621e23500437d5abd525af592d4b (diff)
downloadlibnice-c4993988067a2bf5056fa3146314992c06bfe51d.tar.gz
discovery: ensure port number uniqueness agent-wide
The port number must be different for all local host candidates, not just in the same component, but across all components and all streams. A candidate ambiguity between a host local host and an identical server reflexive candidate have more unwanted consequences when it concerns two different components, because an inbound stun request may be associated to a wrong component.
-rw-r--r--agent/discovery.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/agent/discovery.c b/agent/discovery.c
index c757031..f562bba 100644
--- a/agent/discovery.c
+++ b/agent/discovery.c
@@ -607,23 +607,31 @@ void priv_generate_candidate_credentials (NiceAgent *agent,
}
static gboolean
-priv_local_host_candidate_duplicate_port (NiceComponent *component,
+priv_local_host_candidate_duplicate_port (NiceAgent *agent,
NiceCandidate *candidate)
{
- GSList *i;
+ GSList *i, *j, *k;
if (candidate->transport == NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE)
return FALSE;
- for (i = component->local_candidates; i; i = i->next) {
- NiceCandidate *c = i->data;
+ for (i = agent->streams; i; i = i->next) {
+ NiceStream *stream = i->data;
- if (candidate->transport == c->transport &&
- nice_address_ip_version (&candidate->addr) ==
- nice_address_ip_version (&c->addr) &&
- nice_address_get_port (&candidate->addr) ==
- nice_address_get_port (&c->addr))
- return TRUE;
+ for (j = stream->components; j; j = j->next) {
+ NiceComponent *component = j->data;
+
+ for (k = component->local_candidates; k; k = k->next) {
+ NiceCandidate *c = k->data;
+
+ if (candidate->transport == c->transport &&
+ nice_address_ip_version (&candidate->addr) ==
+ nice_address_ip_version (&c->addr) &&
+ nice_address_get_port (&candidate->addr) ==
+ nice_address_get_port (&c->addr))
+ return TRUE;
+ }
+ }
}
return FALSE;
}
@@ -693,7 +701,7 @@ HostCandidateResult discovery_add_local_host_candidate (
candidate->addr = nicesock->addr;
candidate->base_addr = nicesock->addr;
- if (priv_local_host_candidate_duplicate_port (component, candidate)) {
+ if (priv_local_host_candidate_duplicate_port (agent, candidate)) {
res = HOST_CANDIDATE_DUPLICATE_PORT;
goto errors;
}