summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2012-07-22 17:03:24 +0000
committerJoshua Colp <jcolp@digium.com>2012-07-22 17:03:24 +0000
commit4d6b524b61833147fdaeee1cda6f02c1f8c6d509 (patch)
treec9472898cd864dcd89b4feeda7dae03f0e1b6006 /res
parent13427db64c2c2f3cf15501c998bc982e91f8bf58 (diff)
Prevent multiple local candidates from being added with the same information and add support for disabling ICE on a per-peer basis.
(closes issue ASTERISK-20088) Reported by: wimpy Review: https://reviewboard.asterisk.org/r/2044/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370347 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/res_rtp_asterisk.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index d18729ddf..97e63b48f 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -547,18 +547,32 @@ static void ast_rtp_ice_lite(struct ast_rtp_instance *instance)
pj_ice_sess_change_role(rtp->ice, PJ_ICE_SESS_ROLE_CONTROLLING);
}
+static int ice_candidate_cmp(void *obj, void *arg, int flags)
+{
+ struct ast_rtp_engine_ice_candidate *candidate1 = obj, *candidate2 = arg;
+
+ if ((strcmp(candidate1->foundation, candidate2->foundation)) ||
+ (candidate1->id != candidate2->id) ||
+ (ast_sockaddr_cmp(&candidate1->address, &candidate2->address)) ||
+ (candidate1->type != candidate1->type)) {
+ return 0;
+ }
+
+ return CMP_MATCH | CMP_STOP;
+}
+
static void ast_rtp_ice_add_cand(struct ast_rtp *rtp, unsigned comp_id, unsigned transport_id, pj_ice_cand_type type, pj_uint16_t local_pref,
const pj_sockaddr_t *addr, const pj_sockaddr_t *base_addr, const pj_sockaddr_t *rel_addr, int addr_len)
{
pj_str_t foundation;
- struct ast_rtp_engine_ice_candidate *candidate;
+ struct ast_rtp_engine_ice_candidate *candidate, *existing;
char address[PJ_INET6_ADDRSTRLEN];
pj_thread_register_check();
pj_ice_calc_foundation(rtp->ice->pool, &foundation, type, addr);
- if (!rtp->local_candidates && !(rtp->local_candidates = ao2_container_alloc(1, NULL, NULL))) {
+ if (!rtp->local_candidates && !(rtp->local_candidates = ao2_container_alloc(1, NULL, ice_candidate_cmp))) {
return;
}
@@ -586,6 +600,12 @@ static void ast_rtp_ice_add_cand(struct ast_rtp *rtp, unsigned comp_id, unsigned
candidate->type = AST_RTP_ICE_CANDIDATE_TYPE_RELAYED;
}
+ if ((existing = ao2_find(rtp->local_candidates, candidate, OBJ_POINTER))) {
+ ao2_ref(existing, -1);
+ ao2_ref(candidate, -1);
+ return;
+ }
+
if (pj_ice_sess_add_cand(rtp->ice, comp_id, transport_id, type, local_pref, &foundation, addr, addr, rel_addr, addr_len, NULL) != PJ_SUCCESS) {
ao2_ref(candidate, -1);
return;