res_pjsip: Add external PJSIP resolver implementation using core DNS API.

This change adds the following:

1. A query set implementation. This is an API that allows queries to be executed in parallel and once all have completed a callback is invoked.
2. Unit tests for the query set implementation.
3. An external PJSIP resolver which uses the DNS core API to do NAPTR, SRV, AAAA, and A lookups.

For the resolver it will do NAPTR, SRV, and AAAA/A lookups in parallel. If NAPTR or SRV
are available it will then do more queries. And so on. Preference is NAPTR > SRV > AAAA/A,
with IPv6 preferred over IPv4. For transport it will prefer TLS > TCP > UDP if no explicit
transport has been provided. Configured transports on the system are taken into account to
eliminate resolved addresses which have no hope of completing.

ASTERISK-24947 #close
Reported by: Joshua Colp

Change-Id: I56cb03ce4f9d3d600776f36928e0b3e379b5d71e
This commit is contained in:
Joshua Colp
2015-04-13 10:47:01 -03:00
parent 60d1911482
commit a3cec44a0a
13 changed files with 1479 additions and 55 deletions

122
configure vendored
View File

@@ -1,5 +1,5 @@
#! /bin/sh
# From configure.ac Revision: 432815 .
# From configure.ac Revision.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for asterisk trunk.
#
@@ -908,6 +908,10 @@ PBX_PORTAUDIO
PORTAUDIO_DIR
PORTAUDIO_INCLUDE
PORTAUDIO_LIB
PBX_PJSIP_EXTERNAL_RESOLVER
PJSIP_EXTERNAL_RESOLVER_DIR
PJSIP_EXTERNAL_RESOLVER_INCLUDE
PJSIP_EXTERNAL_RESOLVER_LIB
PBX_PJ_SSL_CERT_LOAD_FROM_FILES2
PJ_SSL_CERT_LOAD_FROM_FILES2_DIR
PJ_SSL_CERT_LOAD_FROM_FILES2_INCLUDE
@@ -10310,6 +10314,18 @@ PBX_PJ_SSL_CERT_LOAD_FROM_FILES2=0
PJSIP_EXTERNAL_RESOLVER_DESCRIP="PJSIP External Resolver Support"
PJSIP_EXTERNAL_RESOLVER_OPTION=pjsip
PJSIP_EXTERNAL_RESOLVER_DIR=${PJPROJECT_DIR}
PBX_PJSIP_EXTERNAL_RESOLVER=0
PORTAUDIO_DESCRIP="PortAudio"
PORTAUDIO_OPTION="portaudio"
PBX_PORTAUDIO=0
@@ -24470,6 +24486,110 @@ fi
if test "x${PBX_PJSIP_EXTERNAL_RESOLVER}" != "x1" -a "${USE_PJSIP_EXTERNAL_RESOLVER}" != "no"; then
pbxlibdir=""
# if --with-PJSIP_EXTERNAL_RESOLVER=DIR has been specified, use it.
if test "x${PJSIP_EXTERNAL_RESOLVER_DIR}" != "x"; then
if test -d ${PJSIP_EXTERNAL_RESOLVER_DIR}/lib; then
pbxlibdir="-L${PJSIP_EXTERNAL_RESOLVER_DIR}/lib"
else
pbxlibdir="-L${PJSIP_EXTERNAL_RESOLVER_DIR}"
fi
fi
pbxfuncname="pjsip_endpt_set_ext_resolver"
if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
AST_PJSIP_EXTERNAL_RESOLVER_FOUND=yes
else
ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
CFLAGS="${CFLAGS} $PJPROJECT_CFLAGS"
as_ac_Lib=`$as_echo "ac_cv_lib_pjsip_${pbxfuncname}" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lpjsip" >&5
$as_echo_n "checking for ${pbxfuncname} in -lpjsip... " >&6; }
if eval \${$as_ac_Lib+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpjsip ${pbxlibdir} $PJPROJECT_LIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char ${pbxfuncname} ();
int
main ()
{
return ${pbxfuncname} ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "$as_ac_Lib=yes"
else
eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
eval ac_res=\$$as_ac_Lib
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
AST_PJSIP_EXTERNAL_RESOLVER_FOUND=yes
else
AST_PJSIP_EXTERNAL_RESOLVER_FOUND=no
fi
CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
fi
# now check for the header.
if test "${AST_PJSIP_EXTERNAL_RESOLVER_FOUND}" = "yes"; then
PJSIP_EXTERNAL_RESOLVER_LIB="${pbxlibdir} -lpjsip $PJPROJECT_LIBS"
# if --with-PJSIP_EXTERNAL_RESOLVER=DIR has been specified, use it.
if test "x${PJSIP_EXTERNAL_RESOLVER_DIR}" != "x"; then
PJSIP_EXTERNAL_RESOLVER_INCLUDE="-I${PJSIP_EXTERNAL_RESOLVER_DIR}/include"
fi
PJSIP_EXTERNAL_RESOLVER_INCLUDE="${PJSIP_EXTERNAL_RESOLVER_INCLUDE} $PJPROJECT_CFLAGS"
if test "xpjsip.h" = "x" ; then # no header, assume found
PJSIP_EXTERNAL_RESOLVER_HEADER_FOUND="1"
else # check for the header
ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
CPPFLAGS="${CPPFLAGS} ${PJSIP_EXTERNAL_RESOLVER_INCLUDE}"
ac_fn_c_check_header_mongrel "$LINENO" "pjsip.h" "ac_cv_header_pjsip_h" "$ac_includes_default"
if test "x$ac_cv_header_pjsip_h" = xyes; then :
PJSIP_EXTERNAL_RESOLVER_HEADER_FOUND=1
else
PJSIP_EXTERNAL_RESOLVER_HEADER_FOUND=0
fi
CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
fi
if test "x${PJSIP_EXTERNAL_RESOLVER_HEADER_FOUND}" = "x0" ; then
PJSIP_EXTERNAL_RESOLVER_LIB=""
PJSIP_EXTERNAL_RESOLVER_INCLUDE=""
else
if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
PJSIP_EXTERNAL_RESOLVER_LIB=""
fi
PBX_PJSIP_EXTERNAL_RESOLVER=1
cat >>confdefs.h <<_ACEOF
#define HAVE_PJSIP_EXTERNAL_RESOLVER 1
_ACEOF
fi
fi
fi
if test "x${PBX_POPT}" != "x1" -a "${USE_POPT}" != "no"; then
pbxlibdir=""