res_rtp_asterisk: Fix regression issues with DTLS client check

* Since ICE candidates are used for the check and pjproject is
  required to use ICE, res_rtp_asterisk was failing to compile
  when pjproject wasn't available.  The check is now wrapped
  with an #ifdef HAVE_PJPROJECT.

* The rtp->ice_active_remote_candidates container was being
  used to check the address on incoming packets but that
  container doesn't contain peer reflexive candidates discovered
  during negotiation. This was causing the check to fail
  where it shouldn't.  We now check against pjproject's
  real_ice->rcand array which will contain those candidates.

* Also fixed a bug in ast_sockaddr_from_pj_sockaddr() where
  we weren't zeroing out sin->sin_zero before returning.  This
  was causing ast_sockaddr_cmp() to always return false when
  one of the inputs was converted from a pj_sockaddr, even
  if both inputs had the same address and port.

Resolves: #500
Resolves: #503
Resolves: #505
This commit is contained in:
George Joseph
2023-12-15 09:37:54 -07:00
parent 85fc4ce712
commit a4f9d885a7
3 changed files with 45 additions and 12 deletions

View File

@@ -522,6 +522,7 @@ int ast_sockaddr_from_pj_sockaddr(struct ast_sockaddr *addr, const pj_sockaddr *
sin->sin_addr.s_addr = pjaddr->ipv4.sin_addr.s_addr;
#endif
sin->sin_port = pjaddr->ipv4.sin_port;
memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
addr->len = sizeof(struct sockaddr_in);
} else if (pjaddr->addr.sa_family == pj_AF_INET6()) {
struct sockaddr_in6 *sin = (struct sockaddr_in6 *) &addr->ss;
@@ -538,6 +539,27 @@ int ast_sockaddr_from_pj_sockaddr(struct ast_sockaddr *addr, const pj_sockaddr *
return 0;
}
int ast_sockaddr_pj_sockaddr_cmp(const struct ast_sockaddr *addr,
const pj_sockaddr *pjaddr)
{
struct ast_sockaddr temp_pjaddr;
int rc = 0;
rc = ast_sockaddr_from_pj_sockaddr(&temp_pjaddr, pjaddr);
if (rc != 0) {
return -1;
}
rc = ast_sockaddr_cmp(addr, &temp_pjaddr);
if (DEBUG_ATLEAST(4)) {
char *a_str = ast_strdupa(ast_sockaddr_stringify(addr));
char *pj_str = ast_strdupa(ast_sockaddr_stringify(&temp_pjaddr));
ast_debug(4, "Comparing %s -> %s rc: %d\n", a_str, pj_str, rc);
}
return rc;
}
#ifdef TEST_FRAMEWORK
static void fill_with_garbage(void *x, ssize_t len)
{