Merge pull request #244 from micmac1/asterisk_I-for-17.01
authorJiri Slachta <jiri.slachta@gmail.com>
Mon, 22 Jan 2018 18:53:24 +0000 (19:53 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Jan 2018 18:53:24 +0000 (19:53 +0100)
Asterisk part 1 for 17.01

18 files changed:
libs/pjproject/Makefile
libs/pjproject/patches/120-non-gnu-pthreads.patch
libs/pjproject/patches/150-config_site.patch [new file with mode: 0644]
net/asterisk-11.x/Makefile
net/asterisk-11.x/patches/054-AST-2016-007.patch [new file with mode: 0644]
net/asterisk-11.x/patches/055-AST-2016-009-11.diff [new file with mode: 0644]
net/asterisk-11.x/patches/056-AST-2017-005-11.diff [new file with mode: 0644]
net/asterisk-11.x/patches/057-AST-2017-006-11.diff [new file with mode: 0644]
net/asterisk-11.x/patches/058-AST-2017-008-11.diff [new file with mode: 0644]
net/asterisk-13.x/Config.in [new file with mode: 0644]
net/asterisk-13.x/Makefile
net/asterisk-13.x/files/asterisk.init
net/asterisk-13.x/patches/001-disable-semaphores-check.patch
net/asterisk-13.x/patches/002-undef-res-ninit.patch
net/asterisk-13.x/patches/004-ifdef-missing-execinfo.patch
net/asterisk-13.x/patches/040-fix-config-options.patch [deleted file]
net/asterisk-13.x/patches/051-musl-includes.patch [deleted file]
net/asterisk-13.x/patches/052-musl-libcap.patch

index 31cdb827d47da80dc29a36ae371aca1cb816fe32..c349657559d86513ad6d94b676d0f61e8c5bfc9d 100644 (file)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=pjproject
-PKG_VERSION:=2.4.5
+PKG_VERSION:=2.7.1
 PKG_RELEASE:=1
 
 PKG_SOURCE:=pjproject-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=http://www.pjsip.org/release/$(PKG_VERSION)/
-PKG_MD5SUM:=f58b3485977b3a700256203a554b3869
+PKG_MD5SUM:=99a64110fa5c2debff40e0e8d4676380
 PKG_INSTALL:=1
 PKG_FIXUP:=autoreconf
 
@@ -31,7 +31,7 @@ define Package/pjproject/Default
   CATEGORY:=Libraries
   SUBMENU:=Telephony
   URL:=http://www.pjsip.org/
-  DEPENDS:=+libuuid +libstdcpp +libpthread
+  DEPENDS:=+libopenssl +libuuid +libstdcpp +libpthread
 endef
 
 define Package/pjproject/install/lib
@@ -54,46 +54,47 @@ $(call Package/pjproject/install/lib,$$(1),$2)
 endef
 
 CONFIGURE_ARGS += \
-       --enable-shared \
-       --disable-floating-point \
-       --enable-g711-codec \
-       --disable-l16-codec \
+       $(if $(CONFIG_SOFT_FLOAT),--disable-floating-point) \
+       --disable-bcg729 \
+       --disable-ext-sound \
+       --disable-ffmpeg \
+       --disable-g711-codec \
        --disable-g722-codec \
        --disable-g7221-codec \
        --disable-gsm-codec \
-       --disable-ilbc-coder \
+       --disable-ilbc-codec \
        --disable-ipp \
-       --disable-ssl \
+       --disable-l16-codec \
+       --disable-libwebrtc \
+       --disable-libyuv \
+       --disable-opencore-amr \
+       --disable-openh264 \
+       --disable-opus \
        --disable-oss \
+       --disable-resample \
+       --disable-sdl \
+       --disable-silk \
        --disable-sound \
-       --with-external-srtp="$(STAGING_DIR)/usr" \
-       --without-external-gsm \
-       --disable-small-filter \
-       --disable-large-filter \
        --disable-speex-aec \
-       --disable-g711-codec \
-       --disable-l16-codec \
-       --disable-gsm-codec \
-       --disable-g722-codec \
-       --disable-g7221-codec \
        --disable-speex-codec \
-       --disable-ilbc-codec \
-       --disable-resample-dll \
-       --disable-sdl \
-       --disable-ffmpeg \
-       --disable-v4l2
+       --disable-v4l2 \
+       --disable-video \
+       --enable-shared \
+       --with-external-srtp="$(STAGING_DIR)/usr" \
+       --with-ssl="$(STAGING_DIR)/usr" \
+       --without-external-gsm \
+       --without-external-pa \
+       --without-external-webrtc
 
-TARGET_LDFLAGS+=-lc $(LIBGCC) -lm
-TARGET_CFLAGS+=$(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS)
+TARGET_CFLAGS+=$(TARGET_CPPFLAGS)
 
 define Build/Compile
        $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)
 endef
 
 PJPROJECT_LIBS = \
-       libpj libpjlib-util libpjmedia-audiodev libpjmedia-codec \
-       libpjmedia-videodev libpjmedia libpjnath libpjsip-simple \
-       libpjsip-ua libpjsip libpjsua libpjsua2 libresample
+       libpj libpjlib-util libpjmedia libpjnath libpjsip-simple \
+       libpjsip-ua libpjsip libpjsua libpjsua2
 
 define Build/InstallDev
        $(INSTALL_DIR) $(1)/usr/{include,lib}
@@ -102,16 +103,16 @@ define Build/InstallDev
 
        $(foreach m,$(PJPROJECT_LIBS),$(CP) $(PKG_INSTALL_DIR)/usr/lib/$(m)* $(1)/usr/lib/;)
        $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+       $(SED) 's|$(TARGET_CFLAGS)||g' $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libpjproject.pc
        $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libpjproject.pc $(1)/usr/lib/pkgconfig/
 endef
 
 $(eval $(call PJSIPpackage,libpj,libpj,+librt))
 $(eval $(call PJSIPpackage,libpjlib-util,libpjlib-util,+libpj +librt))
-$(eval $(call PJSIPpackage,libpjmedia,libpjmedia*,+libpj +libpjlib-util +libpjnath +libresample +librt +libspeex +libsrtp))
+$(eval $(call PJSIPpackage,libpjmedia,libpjmedia*,+libpj +libpjlib-util +libpjnath +librt +libsrtp))
 $(eval $(call PJSIPpackage,libpjnath,libpjnath,+libpj +libpjlib-util +librt))
-$(eval $(call PJSIPpackage,libpjsip-simple,libpjsip-simple,+libpj +libpjlib-util +libpjsip +libresample +librt +libspeex +libsrtp))
-$(eval $(call PJSIPpackage,libpjsip-ua,libpjsip-ua,+libpj +libpjlib-util +libpjmedia +libpjsip-simple +libpjsip +libresample +librt +libspeex +libsrtp))
-$(eval $(call PJSIPpackage,libpjsip,libpjsip,+libpj +libpjlib-util +libresample +librt +libspeex +libsrtp))
-$(eval $(call PJSIPpackage,libpjsua,libpjsua,+libpj +libpjlib-util +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsip +libresample +librt +libspeex +libsrtp))
-$(eval $(call PJSIPpackage,libpjsua2,libpjsua2,+libpj +libpjlib-util +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsip +libresample +librt +libspeex +libsrtp +libpjsua))
-$(eval $(call PJSIPpackage,libresample,libresample,))
+$(eval $(call PJSIPpackage,libpjsip-simple,libpjsip-simple,+libpj +libpjlib-util +libpjsip +librt))
+$(eval $(call PJSIPpackage,libpjsip-ua,libpjsip-ua,+libpj +libpjlib-util +libpjmedia +libpjsip-simple +libpjsip +librt))
+$(eval $(call PJSIPpackage,libpjsip,libpjsip,+libpj +libpjlib-util +librt +libsrtp))
+$(eval $(call PJSIPpackage,libpjsua,libpjsua,+libpj +libpjlib-util +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsip +librt))
+$(eval $(call PJSIPpackage,libpjsua2,libpjsua2,+libpj +libpjlib-util +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsip +librt +libpjsua))
index e01b542e8bfe26f83e9c88745de9655fe184efa8..23a9b3f481ac5918c6655211afc3942b23ede2a0 100644 (file)
@@ -1,7 +1,5 @@
-Index: pjproject-2.4/pjlib/src/pj/os_core_unix.c
-===================================================================
---- pjproject-2.4.orig/pjlib/src/pj/os_core_unix.c
-+++ pjproject-2.4/pjlib/src/pj/os_core_unix.c
+--- pjproject-2.6/pjlib/src/pj/os_core_unix.c  2016-04-13 08:24:48.000000000 +0200
++++ pjproject-new/pjlib/src/pj/os_core_unix.c  2017-05-08 09:51:49.980905420 +0200
 @@ -1123,7 +1123,7 @@ static pj_status_t init_mutex(pj_mutex_t
        return PJ_RETURN_OS_ERROR(rc);
  
@@ -9,7 +7,7 @@ Index: pjproject-2.4/pjlib/src/pj/os_core_unix.c
 -#if (defined(PJ_LINUX) && PJ_LINUX!=0) || \
 +#if (defined(PJ_LINUX) && PJ_LINUX!=0 && defined(__GLIBC__)) || \
      defined(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE)
-       rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP);
+       rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
  #elif (defined(PJ_RTEMS) && PJ_RTEMS!=0) || \
 @@ -1133,7 +1133,7 @@ static pj_status_t init_mutex(pj_mutex_t
        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
@@ -18,49 +16,5 @@ Index: pjproject-2.4/pjlib/src/pj/os_core_unix.c
 -#if (defined(PJ_LINUX) && PJ_LINUX!=0) || \
 +#if (defined(PJ_LINUX) && PJ_LINUX!=0 && defined(__GLIBC__)) || \
       defined(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE)
-       rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+       rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  #elif (defined(PJ_RTEMS) && PJ_RTEMS!=0) || \
-Index: pjproject-2.4/pjsip-apps/src/samples/siprtp.c
-===================================================================
---- pjproject-2.4.orig/pjsip-apps/src/samples/siprtp.c
-+++ pjproject-2.4/pjsip-apps/src/samples/siprtp.c
-@@ -1134,7 +1134,7 @@ static void boost_priority(void)
-                   PJ_RETURN_OS_ERROR(rc));
-       return;
-     }
--    tp.__sched_priority = max_prio;
-+    tp.sched_priority = max_prio;
-     rc = sched_setscheduler(0, POLICY, &tp);
-     if (rc != 0) {
-@@ -1143,7 +1143,7 @@ static void boost_priority(void)
-     }
-     PJ_LOG(4, (THIS_FILE, "New process policy=%d, priority=%d",
--            policy, tp.__sched_priority));
-+            policy, tp.sched_priority));
-     /*
-      * Adjust thread scheduling algorithm and priority
-@@ -1156,10 +1156,10 @@ static void boost_priority(void)
-     }
-     PJ_LOG(4, (THIS_FILE, "Old thread policy=%d, priority=%d",
--            policy, tp.__sched_priority));
-+            policy, tp.sched_priority));
-     policy = POLICY;
--    tp.__sched_priority = max_prio;
-+    tp.sched_priority = max_prio;
-     rc = pthread_setschedparam(pthread_self(), policy, &tp);
-     if (rc != 0) {
-@@ -1169,7 +1169,7 @@ static void boost_priority(void)
-     }
-     PJ_LOG(4, (THIS_FILE, "New thread policy=%d, priority=%d",
--            policy, tp.__sched_priority));
-+            policy, tp.sched_priority));
- }
- #else
diff --git a/libs/pjproject/patches/150-config_site.patch b/libs/pjproject/patches/150-config_site.patch
new file mode 100644 (file)
index 0000000..5805137
--- /dev/null
@@ -0,0 +1,95 @@
+--- /dev/null
++++ b/pjlib/include/pj/config_site.h
+@@ -0,0 +1,92 @@
++/*
++ * Asterisk config_site.h
++ */
++
++#include <sys/select.h>
++
++/*
++ * Since both pjproject and asterisk source files will include config_site.h,
++ * we need to make sure that only pjproject source files include asterisk_malloc_debug.h.
++ */
++
++/* #if defined(MALLOC_DEBUG) && !defined(_ASTERISK_ASTMM_H)
++ * #include "asterisk_malloc_debug.h"
++ * #endif
++ */
++
++/*
++ * Defining PJMEDIA_HAS_SRTP to 0 does NOT disable Asterisk's ability to use srtp.
++ * It only disables the pjmedia srtp transport which Asterisk doesn't use.
++ * The reason for the disable is that while Asterisk works fine with older libsrtp
++ * versions, newer versions of pjproject won't compile with them.
++ */
++
++/*
++ * This doesn't disable SRTP completely, so we have to keep using the external
++ * libsrtp, otherwise pjsip would just build the internal one.
++ */
++
++#define PJMEDIA_HAS_SRTP 0
++
++/*
++ * Defining PJMEDIA_HAS_WEBRTC_AEC to 0 does NOT disable Asterisk's ability to use
++ * webrtc.  It only disables the pjmedia webrtc transport which Asterisk doesn't use.
++ */
++#define PJMEDIA_HAS_WEBRTC_AEC 0
++
++#define PJ_HAS_IPV6 1
++#define NDEBUG 1
++#define PJ_MAX_HOSTNAME (256)
++#define PJSIP_MAX_URL_SIZE (512)
++#ifdef PJ_HAS_LINUX_EPOLL
++#define PJ_IOQUEUE_MAX_HANDLES        (5000)
++#else
++#define PJ_IOQUEUE_MAX_HANDLES        (FD_SETSIZE)
++#endif
++#define PJ_IOQUEUE_HAS_SAFE_UNREG 1
++#define PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL (16)
++
++#define PJ_SCANNER_USE_BITWISE        0
++#define PJ_OS_HAS_CHECK_STACK 0
++
++#ifndef PJ_LOG_MAX_LEVEL
++#define PJ_LOG_MAX_LEVEL              6
++#endif
++
++#define PJ_ENABLE_EXTRA_CHECK 1
++#define PJSIP_MAX_TSX_COUNT           ((64*1024)-1)
++#define PJSIP_MAX_DIALOG_COUNT        ((64*1024)-1)
++#define PJSIP_UDP_SO_SNDBUF_SIZE      (512*1024)
++#define PJSIP_UDP_SO_RCVBUF_SIZE      (512*1024)
++#define PJ_DEBUG                      0
++#define PJSIP_SAFE_MODULE             0
++#define PJ_HAS_STRICMP_ALNUM          0
++
++/*
++ * Do not ever enable PJ_HASH_USE_OWN_TOLOWER because the algorithm is
++ * inconsistently used when calculating the hash value and doesn't
++ * convert the same characters as pj_tolower()/tolower().  Thus you
++ * can get different hash values if the string hashed has certain
++ * characters in it.  (ASCII '@', '[', '\\', ']', '^', and '_')
++ */
++#undef PJ_HASH_USE_OWN_TOLOWER
++
++/*
++  It is imperative that PJSIP_UNESCAPE_IN_PLACE remain 0 or undefined.
++  Enabling it will result in SEGFAULTS when URIs containing escape sequences are encountered.
++*/
++#undef PJSIP_UNESCAPE_IN_PLACE
++#define PJSIP_MAX_PKT_LEN                     6000
++
++#undef PJ_TODO
++#define PJ_TODO(x)
++
++/* Defaults too low for WebRTC */
++#define PJ_ICE_MAX_CAND 32
++#define PJ_ICE_MAX_CHECKS (PJ_ICE_MAX_CAND * PJ_ICE_MAX_CAND)
++
++/* Increase limits to allow more formats */
++#define       PJMEDIA_MAX_SDP_FMT   64
++#define       PJMEDIA_MAX_SDP_BANDW   4
++#define       PJMEDIA_MAX_SDP_ATTR   (PJMEDIA_MAX_SDP_FMT*2 + 4)
++#define       PJMEDIA_MAX_SDP_MEDIA   16
index 064a47ab614cbbde87e28d43ab2f387df2fe1145..28220e91490dcc2da97a83cf94a0e589628a9ebe 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=asterisk11
 PKG_VERSION:=11.22.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://downloads.asterisk.org/pub/telephony/asterisk/releases/
@@ -146,6 +146,20 @@ $(foreach m,$(AST_EMB_MODULES),$(call Package/asterisk11/install/module,$(1),$(m
        $(INSTALL_BIN) ./files/asterisk.init $(1)/etc/init.d/asterisk
 endef
 
+define Package/$(PKG_NAME)/postinst
+#!/bin/sh
+if [ -z "$${IPKG_INSTROOT}" ]; then
+  echo
+  echo "o-------------------------------------------------------------------o"
+  echo "| Asterisk 11 WARNING                                               |"
+  echo "o-------------------------------------------------------------------o"
+  echo "| Asterisk 11 is end-of-life. You should upgrade to Asterisk 13.    |"
+  echo "o-------------------------------------------------------------=^_^=-o"
+  echo
+fi
+exit 0
+endef
+
 define Package/asterisk11-sounds
 $(call Package/asterisk11/Default)
   TITLE:=Sounds support
diff --git a/net/asterisk-11.x/patches/054-AST-2016-007.patch b/net/asterisk-11.x/patches/054-AST-2016-007.patch
new file mode 100644 (file)
index 0000000..ae61d9d
--- /dev/null
@@ -0,0 +1,117 @@
+From a503e4879cab7e35069e5481e0864b64b55e223d Mon Sep 17 00:00:00 2001
+From: Corey Farrell <git@cfware.com>
+Date: Mon, 8 Aug 2016 08:47:12 -0400
+Subject: [PATCH] Prevent leak of dialog RTP/SRTP instances.
+
+In some scenarios dialog_initialize_rtp can be called multiple times on
+the same dialog.  This can cause RTP instances to be leaked along with
+multiple file descriptors for each instance.
+
+ASTERISK-26272 #close
+
+Change-Id: Id716c2b87762d890c062b42538524a95067018a8
+---
+ channels/chan_sip.c | 61 ++++++++++++++++++++++++++++++++++-------------------
+ 1 file changed, 39 insertions(+), 22 deletions(-)
+
+diff --git a/channels/chan_sip.c b/channels/chan_sip.c
+index 9eaed58..2c29c9e 100644
+--- a/channels/chan_sip.c
++++ b/channels/chan_sip.c
+@@ -5697,6 +5697,38 @@ static void copy_socket_data(struct sip_socket *to_sock, const struct sip_socket
+       *to_sock = *from_sock;
+ }
++/*! Cleanup the RTP and SRTP portions of a dialog
++ *
++ * \note This procedure excludes vsrtp as it is initialized differently.
++ */
++static void dialog_clean_rtp(struct sip_pvt *p)
++{
++      if (p->rtp) {
++              ast_rtp_instance_destroy(p->rtp);
++              p->rtp = NULL;
++      }
++
++      if (p->vrtp) {
++              ast_rtp_instance_destroy(p->vrtp);
++              p->vrtp = NULL;
++      }
++
++      if (p->trtp) {
++              ast_rtp_instance_destroy(p->trtp);
++              p->trtp = NULL;
++      }
++
++      if (p->srtp) {
++              sip_srtp_destroy(p->srtp);
++              p->srtp = NULL;
++      }
++
++      if (p->tsrtp) {
++              sip_srtp_destroy(p->tsrtp);
++              p->tsrtp = NULL;
++      }
++}
++
+ /*! \brief Initialize DTLS-SRTP support on an RTP instance */
+ static int dialog_initialize_dtls_srtp(const struct sip_pvt *dialog, struct ast_rtp_instance *rtp, struct sip_srtp **srtp)
+ {
+@@ -5744,6 +5776,9 @@ static int dialog_initialize_rtp(struct sip_pvt *dialog)
+               return 0;
+       }
++      /* Make sure previous RTP instances/FD's do not leak */
++      dialog_clean_rtp(dialog);
++
+       ast_sockaddr_copy(&bindaddr_tmp, &bindaddr);
+       if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) {
+               return -1;
+@@ -6408,18 +6443,10 @@ static void sip_pvt_dtor(void *vdoomed)
+               ast_free(p->notify);
+               p->notify = NULL;
+       }
+-      if (p->rtp) {
+-              ast_rtp_instance_destroy(p->rtp);
+-              p->rtp = NULL;
+-      }
+-      if (p->vrtp) {
+-              ast_rtp_instance_destroy(p->vrtp);
+-              p->vrtp = NULL;
+-      }
+-      if (p->trtp) {
+-              ast_rtp_instance_destroy(p->trtp);
+-              p->trtp = NULL;
+-      }
++
++      /* Free RTP and SRTP instances */
++      dialog_clean_rtp(p);
++
+       if (p->udptl) {
+               ast_udptl_destroy(p->udptl);
+               p->udptl = NULL;
+@@ -6455,21 +6482,11 @@ static void sip_pvt_dtor(void *vdoomed)
+       destroy_msg_headers(p);
+-      if (p->srtp) {
+-              sip_srtp_destroy(p->srtp);
+-              p->srtp = NULL;
+-      }
+-
+       if (p->vsrtp) {
+               sip_srtp_destroy(p->vsrtp);
+               p->vsrtp = NULL;
+       }
+-      if (p->tsrtp) {
+-              sip_srtp_destroy(p->tsrtp);
+-              p->tsrtp = NULL;
+-      }
+-
+       if (p->directmediaacl) {
+               p->directmediaacl = ast_free_acl_list(p->directmediaacl);
+       }
+-- 
+2.5.5
+
diff --git a/net/asterisk-11.x/patches/055-AST-2016-009-11.diff b/net/asterisk-11.x/patches/055-AST-2016-009-11.diff
new file mode 100644 (file)
index 0000000..421da37
--- /dev/null
@@ -0,0 +1,27 @@
+diff --git a/channels/chan_sip.c b/channels/chan_sip.c
+index 556db57..9c74acb 100644
+--- a/channels/chan_sip.c
++++ b/channels/chan_sip.c
+@@ -8132,8 +8132,6 @@ static const char *__get_header(const struct sip_request *req, const char *name,
+        * one afterwards.  If you shouldn't do it, what absolute idiot decided it was
+        * a good idea to say you can do it, and if you can do it, why in the hell would.
+        * you say you shouldn't.
+-       * Anyways, pedanticsipchecking controls whether we allow spaces before ':',
+-       * and we always allow spaces after that for compatibility.
+        */
+       const char *sname = find_alias(name, NULL);
+       int x, len = strlen(name), slen = (sname ? 1 : 0);
+@@ -8146,10 +8144,10 @@ static const char *__get_header(const struct sip_request *req, const char *name,
+               if (match || smatch) {
+                       /* skip name */
+                       const char *r = header + (match ? len : slen );
+-                      if (sip_cfg.pedanticsipchecking) {
+-                              r = ast_skip_blanks(r);
++                      /* HCOLON has optional SP/HTAB; skip past those */
++                      while (*r == ' ' || *r == '\t') {
++                              ++r;
+                       }
+-
+                       if (*r == ':') {
+                               *start = x+1;
+                               return ast_skip_blanks(r+1);
diff --git a/net/asterisk-11.x/patches/056-AST-2017-005-11.diff b/net/asterisk-11.x/patches/056-AST-2017-005-11.diff
new file mode 100644 (file)
index 0000000..c263efd
--- /dev/null
@@ -0,0 +1,195 @@
+From dc4c130439f053592b86f0b35c1fb219a0dc6587 Mon Sep 17 00:00:00 2001
+From: Joshua Colp <jcolp@digium.com>
+Date: Mon, 22 May 2017 15:36:38 +0000
+Subject: [PATCH] res_rtp_asterisk: Only learn a new source in learn state.
+
+This change moves the logic which learns a new source address
+for RTP so it only occurs in the learning state. The learning
+state is entered on initial allocation of RTP or if we are
+told that the remote address for the media has changed. While
+in the learning state if we continue to receive media from
+the original source we restart the learning process. It is
+only once we receive a sufficient number of RTP packets from
+the new source that we will switch to it. Once this is done
+the closed state is entered where all packets that do not
+originate from the expected source are dropped.
+
+The learning process has also been improved to take into
+account the time between received packets so a flood of them
+while in the learning state does not cause media to be switched.
+
+Finally RTCP now drops packets which are not for the learned
+SSRC if strict RTP is enabled.
+
+ASTERISK-27013
+
+Change-Id: I56a96e993700906355e79bc880ad9d4ad3ab129c
+---
+
+diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
+index 4cdc750..4881171 100644
+--- a/res/res_rtp_asterisk.c
++++ b/res/res_rtp_asterisk.c
+@@ -201,6 +201,7 @@
+ struct rtp_learning_info {
+       int max_seq;    /*!< The highest sequence number received */
+       int packets;    /*!< The number of remaining packets before the source is accepted */
++      struct timeval received; /*!< The time of the last received packet */
+ };
+ #ifdef HAVE_OPENSSL_SRTP
+@@ -286,7 +287,6 @@
+        * but these are in place to keep learning mode sequence values sealed from their normal counterparts.
+        */
+       struct rtp_learning_info rtp_source_learn;      /* Learning mode track for the expected RTP source */
+-      struct rtp_learning_info alt_source_learn;      /* Learning mode tracking for a new RTP source after one has been chosen */
+       struct rtp_red *red;
+@@ -2357,6 +2357,7 @@
+ {
+       info->max_seq = seq - 1;
+       info->packets = learning_min_sequential;
++      memset(&info->received, 0, sizeof(info->received));
+ }
+ /*!
+@@ -2371,6 +2372,13 @@
+  */
+ static int rtp_learning_rtp_seq_update(struct rtp_learning_info *info, uint16_t seq)
+ {
++      if (!ast_tvzero(info->received) && ast_tvdiff_ms(ast_tvnow(), info->received) < 5) {
++              /* During the probation period the minimum amount of media we'll accept is
++               * 10ms so give a reasonable 5ms buffer just in case we get it sporadically.
++               */
++              return 1;
++      }
++
+       if (seq == info->max_seq + 1) {
+               /* packet is in sequence */
+               info->packets--;
+@@ -2379,6 +2387,7 @@
+               info->packets = learning_min_sequential - 1;
+       }
+       info->max_seq = seq;
++      info->received = ast_tvnow();
+       return (info->packets == 0);
+ }
+@@ -2540,7 +2549,6 @@
+       rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN);
+       if (strictrtp) {
+               rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno);
+-              rtp_learning_seq_init(&rtp->alt_source_learn, (uint16_t)rtp->seqno);
+       }
+       /* Create a new socket for us to listen on and use */
+@@ -3910,16 +3918,6 @@
+       packetwords = res / 4;
+-      if (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
+-              /* Send to whoever sent to us */
+-              if (ast_sockaddr_cmp(&rtp->rtcp->them, &addr)) {
+-                      ast_sockaddr_copy(&rtp->rtcp->them, &addr);
+-                      if (rtpdebug)
+-                              ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
+-                                        ast_sockaddr_stringify(&rtp->rtcp->them));
+-              }
+-      }
+-
+       ast_debug(1, "Got RTCP report of %d bytes\n", res);
+       while (position < packetwords) {
+@@ -3939,6 +3937,24 @@
+                       if (rtpdebug)
+                               ast_debug(1, "RTCP Read too short\n");
+                       return &ast_null_frame;
++              }
++
++              if ((rtp->strict_rtp_state != STRICT_RTP_OPEN) && (ntohl(rtcpheader[i + 1]) != rtp->themssrc)) {
++                      /* Skip over this RTCP record as it does not contain the correct SSRC */
++                      position += (length + 1);
++                      ast_debug(1, "%p -- Received RTCP report from %s, dropping due to strict RTP protection. Received SSRC '%u' but expected '%u'\n",
++                              rtp, ast_sockaddr_stringify(&addr), ntohl(rtcpheader[i + 1]), rtp->themssrc);
++                      continue;
++              }
++
++              if (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
++                      /* Send to whoever sent to us */
++                      if (ast_sockaddr_cmp(&rtp->rtcp->them, &addr)) {
++                              ast_sockaddr_copy(&rtp->rtcp->them, &addr);
++                              if (rtpdebug)
++                                      ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
++                                              ast_sockaddr_stringify(&rtp->rtcp->them));
++                      }
+               }
+               if (rtcp_debug_test_addr(&addr)) {
+@@ -4330,24 +4346,11 @@
+       /* If strict RTP protection is enabled see if we need to learn the remote address or if we need to drop the packet */
+       if (rtp->strict_rtp_state == STRICT_RTP_LEARN) {
+-              ast_debug(1, "%p -- Probation learning mode pass with source address %s\n", rtp, ast_sockaddr_stringify(&addr));
+-              /* For now, we always copy the address. */
+-              ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
+-
+-              /* Send the rtp and the seqno from header to rtp_learning_rtp_seq_update to see whether we can exit or not*/
+-              if (rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
+-                      ast_debug(1, "%p -- Probation at seq %d with %d to go; discarding frame\n",
+-                              rtp, rtp->rtp_source_learn.max_seq, rtp->rtp_source_learn.packets);
+-                      return &ast_null_frame;
+-              }
+-
+-              ast_verb(4, "%p -- Probation passed - setting RTP source address to %s\n", rtp, ast_sockaddr_stringify(&addr));
+-              rtp->strict_rtp_state = STRICT_RTP_CLOSED;
+-      }
+-      if (rtp->strict_rtp_state == STRICT_RTP_CLOSED) {
+               if (!ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
+-                      /* Always reset the alternate learning source */
+-                      rtp_learning_seq_init(&rtp->alt_source_learn, seqno);
++                      /* We are learning a new address but have received traffic from the existing address,
++                       * accept it but reset the current learning for the new source so it only takes over
++                       * once sufficient traffic has been received. */
++                      rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
+               } else {
+                       /* Hmm, not the strict address. Perhaps we're getting audio from the alternate? */
+                       if (!ast_sockaddr_cmp(&rtp->alt_rtp_address, &addr)) {
+@@ -4359,15 +4362,21 @@
+                                * it, that means we've stopped getting RTP from the original source and we should
+                                * switch to it.
+                                */
+-                              if (rtp_learning_rtp_seq_update(&rtp->alt_source_learn, seqno)) {
++                              if (rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
+                                       ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Will switch to it in %d packets\n",
+-                                                      rtp, ast_sockaddr_stringify(&addr), rtp->alt_source_learn.packets);
++                                                      rtp, ast_sockaddr_stringify(&addr), rtp->rtp_source_learn.packets);
+                                       return &ast_null_frame;
+                               }
+-                              ast_verb(4, "%p -- Switching RTP source address to %s\n", rtp, ast_sockaddr_stringify(&addr));
+                               ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
+                       }
++
++                      ast_verb(4, "%p -- Probation passed - setting RTP source address to %s\n", rtp, ast_sockaddr_stringify(&addr));
++                      rtp->strict_rtp_state = STRICT_RTP_CLOSED;
+               }
++      } else if (rtp->strict_rtp_state == STRICT_RTP_CLOSED && ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
++              ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection.\n",
++                      rtp, ast_sockaddr_stringify(&addr));
++              return &ast_null_frame;
+       }
+       /* If symmetric RTP is enabled see if the remote side is not what we expected and change where we are sending audio */
+@@ -4762,7 +4771,11 @@
+       rtp->rxseqno = 0;
+-      if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN) {
++      if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN && !ast_sockaddr_isnull(addr) &&
++              ast_sockaddr_cmp(addr, &rtp->strict_rtp_address)) {
++              /* We only need to learn a new strict source address if we've been told the source is
++               * changing to something different.
++               */
+               rtp->strict_rtp_state = STRICT_RTP_LEARN;
+               rtp_learning_seq_init(&rtp->rtp_source_learn, rtp->seqno);
+       }
diff --git a/net/asterisk-11.x/patches/057-AST-2017-006-11.diff b/net/asterisk-11.x/patches/057-AST-2017-006-11.diff
new file mode 100644 (file)
index 0000000..ce8ed7a
--- /dev/null
@@ -0,0 +1,397 @@
+From 31676ce058596b57e10fbf83ff1817ca7907c3b1 Mon Sep 17 00:00:00 2001
+From: Corey Farrell <git@cfware.com>
+Date: Sat, 01 Jul 2017 20:24:27 -0400
+Subject: [PATCH] AST-2017-006: Fix app_minivm application MinivmNotify command injection
+
+An admin can configure app_minivm with an externnotify program to be run
+when a voicemail is received.  The app_minivm application MinivmNotify
+uses ast_safe_system() for this purpose which is vulnerable to command
+injection since the Caller-ID name and number values given to externnotify
+can come from an external untrusted source.
+
+* Add ast_safe_execvp() function.  This gives modules the ability to run
+external commands with greater safety compared to ast_safe_system().
+Specifically when some parameters are filled by untrusted sources the new
+function does not allow malicious input to break argument encoding.  This
+may be of particular concern where CALLERID(name) or CALLERID(num) may be
+used as a parameter to a script run by ast_safe_system() which could
+potentially allow arbitrary command execution.
+
+* Changed app_minivm.c:run_externnotify() to use the new ast_safe_execvp()
+instead of ast_safe_system() to avoid command injection.
+
+* Document code injection potential from untrusted data sources for other
+shell commands that are under user control.
+
+ASTERISK-27103
+
+Change-Id: I7552472247a84cde24e1358aaf64af160107aef1
+---
+
+diff --git a/README-SERIOUSLY.bestpractices.txt b/README-SERIOUSLY.bestpractices.txt
+index 281d0d3..d63f1df 100644
+--- a/README-SERIOUSLY.bestpractices.txt
++++ b/README-SERIOUSLY.bestpractices.txt
+@@ -94,6 +94,13 @@
+ ways in which you can mitigate this impact: stricter pattern matching, or using
+ the FILTER() dialplan function.
++The CALLERID(num) and CALLERID(name) values are other commonly used values that
++are sources of data potentially supplied by outside sources.  If you use these
++values as parameters to the System(), MixMonitor(), or Monitor() applications
++or the SHELL() dialplan function, you can allow injection of arbitrary operating
++system command execution.  The FILTER() dialplan function is available to remove
++dangerous characters from untrusted strings to block the command injection.
++
+ Strict Pattern Matching
+ -----------------------
+diff --git a/apps/app_minivm.c b/apps/app_minivm.c
+index ecdf9c6..8edc132 100644
+--- a/apps/app_minivm.c
++++ b/apps/app_minivm.c
+@@ -1741,21 +1741,35 @@
+ /*! \brief Run external notification for voicemail message */
+ static void run_externnotify(struct ast_channel *chan, struct minivm_account *vmu)
+ {
+-      char arguments[BUFSIZ];
++      char fquser[AST_MAX_CONTEXT * 2];
++      char *argv[5] = { NULL };
++      struct ast_party_caller *caller;
++      char *cid;
++      int idx;
+-      if (ast_strlen_zero(vmu->externnotify) && ast_strlen_zero(global_externnotify))
++      if (ast_strlen_zero(vmu->externnotify) && ast_strlen_zero(global_externnotify)) {
+               return;
++      }
+-      snprintf(arguments, sizeof(arguments), "%s %s@%s %s %s&", 
+-              ast_strlen_zero(vmu->externnotify) ? global_externnotify : vmu->externnotify, 
+-              vmu->username, vmu->domain,
+-              (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str)
+-                      ? ast_channel_caller(chan)->id.name.str : "",
+-              (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str)
+-                      ? ast_channel_caller(chan)->id.number.str : "");
++      snprintf(fquser, sizeof(fquser), "%s@%s", vmu->username, vmu->domain);
+-      ast_debug(1, "Executing: %s\n", arguments);
+-      ast_safe_system(arguments);
++      caller = ast_channel_caller(chan);
++      idx = 0;
++      argv[idx++] = ast_strlen_zero(vmu->externnotify) ? global_externnotify : vmu->externnotify;
++      argv[idx++] = fquser;
++      cid = S_COR(caller->id.name.valid, caller->id.name.str, NULL);
++      if (cid) {
++              argv[idx++] = cid;
++      }
++      cid = S_COR(caller->id.number.valid, caller->id.number.str, NULL);
++      if (cid) {
++              argv[idx++] = cid;
++      }
++      argv[idx] = NULL;
++
++      ast_debug(1, "Executing: %s %s %s %s\n",
++              argv[0], argv[1], argv[2] ?: "", argv[3] ?: "");
++      ast_safe_execvp(1, argv[0], argv);
+ }
+ /*!\internal
+diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
+index 89a1d8c..96adb9a 100644
+--- a/apps/app_mixmonitor.c
++++ b/apps/app_mixmonitor.c
+@@ -127,6 +127,11 @@
+                               <para>Will be executed when the recording is over.</para>
+                               <para>Any strings matching <literal>^{X}</literal> will be unescaped to <variable>X</variable>.</para>
+                               <para>All variables will be evaluated at the time MixMonitor is called.</para>
++                              <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
++                              or <variable>CALLERID(name)</variable> as part of the command parameters.  You
++                              risk a command injection attack executing arbitrary commands if the untrusted
++                              strings aren't filtered to remove dangerous characters.  See function
++                              <variable>FILTER()</variable>.</para></warning>
+                       </parameter>
+               </syntax>
+               <description>
+@@ -143,6 +148,11 @@
+                                       <para>Will contain the filename used to record.</para>
+                               </variable>
+                       </variablelist>
++                      <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
++                      or <variable>CALLERID(name)</variable> as part of ANY of the application's
++                      parameters.  You risk a command injection attack executing arbitrary commands
++                      if the untrusted strings aren't filtered to remove dangerous characters.  See
++                      function <variable>FILTER()</variable>.</para></warning>
+               </description>
+               <see-also>
+                       <ref type="application">Monitor</ref>
+diff --git a/apps/app_system.c b/apps/app_system.c
+index 7fe453d..e868a07 100644
+--- a/apps/app_system.c
++++ b/apps/app_system.c
+@@ -48,6 +48,11 @@
+               <syntax>
+                       <parameter name="command" required="true">
+                               <para>Command to execute</para>
++                              <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
++                              or <variable>CALLERID(name)</variable> as part of the command parameters.  You
++                              risk a command injection attack executing arbitrary commands if the untrusted
++                              strings aren't filtered to remove dangerous characters.  See function
++                              <variable>FILTER()</variable>.</para></warning>
+                       </parameter>
+               </syntax>
+               <description>
+@@ -73,6 +78,11 @@
+               <syntax>
+                       <parameter name="command" required="true">
+                               <para>Command to execute</para>
++                              <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
++                              or <variable>CALLERID(name)</variable> as part of the command parameters.  You
++                              risk a command injection attack executing arbitrary commands if the untrusted
++                              strings aren't filtered to remove dangerous characters.  See function
++                              <variable>FILTER()</variable>.</para></warning>
+                       </parameter>
+               </syntax>
+               <description>
+diff --git a/configs/minivm.conf.sample b/configs/minivm.conf.sample
+index 55a39c8..3dcd59d 100644
+--- a/configs/minivm.conf.sample
++++ b/configs/minivm.conf.sample
+@@ -51,7 +51,7 @@
+ ; If you need to have an external program, i.e. /usr/bin/myapp called when a
+ ; voicemail is received by the server. The arguments are
+ ;
+-;     <app> <username@domain> <callerid-number> <callerid-name>
++;     <app> <username@domain> <callerid-name> <callerid-number>
+ ;
+ ;externnotify=/usr/bin/myapp
+ ; The character set for voicemail messages can be specified here
+diff --git a/funcs/func_shell.c b/funcs/func_shell.c
+index e403efc..79b7f99 100644
+--- a/funcs/func_shell.c
++++ b/funcs/func_shell.c
+@@ -84,6 +84,11 @@
+               <syntax>
+                       <parameter name="command" required="true">
+                               <para>The command that the shell should execute.</para>
++                              <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
++                              or <variable>CALLERID(name)</variable> as part of the command parameters.  You
++                              risk a command injection attack executing arbitrary commands if the untrusted
++                              strings aren't filtered to remove dangerous characters.  See function
++                              <variable>FILTER()</variable>.</para></warning>
+                       </parameter>
+               </syntax>
+               <description>
+diff --git a/include/asterisk/app.h b/include/asterisk/app.h
+index d10a0a6..8cdaea1 100644
+--- a/include/asterisk/app.h
++++ b/include/asterisk/app.h
+@@ -577,9 +577,34 @@
+ int ast_vm_test_create_user(const char *context, const char *mailbox);
+ #endif
+-/*! \brief Safely spawn an external program while closing file descriptors
+-      \note This replaces the \b system call in all Asterisk modules
+-*/
++/*!
++ * \brief Safely spawn an external program while closing file descriptors
++ *
++ * \note This replaces the \b execvp call in all Asterisk modules
++ *
++ * \param dualfork Non-zero to simulate running the program in the
++ * background by forking twice.  The option provides similar
++ * functionality to the '&' in the OS shell command "cmd &".  The
++ * option allows Asterisk to run a reaper loop to watch the first fork
++ * which immediately exits after spaning the second fork.  The actual
++ * program is run in the second fork.
++ * \param file execvp(file, argv) file parameter
++ * \param argv execvp(file, argv) argv parameter
++ */
++int ast_safe_execvp(int dualfork, const char *file, char *const argv[]);
++
++/*!
++ * \brief Safely spawn an OS shell command while closing file descriptors
++ *
++ * \note This replaces the \b system call in all Asterisk modules
++ *
++ * \param s - OS shell command string to execute.
++ *
++ * \warning Command injection can happen using this call if the passed
++ * in string is created using untrusted data from an external source.
++ * It is best not to use untrusted data.  However, the caller could
++ * filter out dangerous characters to avoid command injection.
++ */
+ int ast_safe_system(const char *s);
+ /*!
+diff --git a/main/asterisk.c b/main/asterisk.c
+index ce1d153..92256bd 100644
+--- a/main/asterisk.c
++++ b/main/asterisk.c
+@@ -1102,12 +1102,10 @@
+       ast_mutex_unlock(&safe_system_lock);
+ }
+-int ast_safe_system(const char *s)
++/*! \brief fork and perform other preparations for spawning applications */
++static pid_t safe_exec_prep(int dualfork)
+ {
+       pid_t pid;
+-      int res;
+-      struct rusage rusage;
+-      int status;
+ #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
+       ast_replace_sigchld();
+@@ -1129,35 +1127,102 @@
+               cap_free(cap);
+ #endif
+ #ifdef HAVE_WORKING_FORK
+-              if (ast_opt_high_priority)
++              if (ast_opt_high_priority) {
+                       ast_set_priority(0);
++              }
+               /* Close file descriptors and launch system command */
+               ast_close_fds_above_n(STDERR_FILENO);
+ #endif
+-              execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
+-              _exit(1);
+-      } else if (pid > 0) {
++              if (dualfork) {
++#ifdef HAVE_WORKING_FORK
++                      pid = fork();
++#else
++                      pid = vfork();
++#endif
++                      if (pid < 0) {
++                              /* Second fork failed. */
++                              /* No logger available. */
++                              _exit(1);
++                      }
++
++                      if (pid > 0) {
++                              /* This is the first fork, exit so the reaper finishes right away. */
++                              _exit(0);
++                      }
++
++                      /* This is the second fork.  The first fork will exit immediately so
++                       * Asterisk doesn't have to wait for completion.
++                       * ast_safe_system("cmd &") would run in the background, but the '&'
++                       * cannot be added with ast_safe_execvp, so we have to double fork.
++                       */
++              }
++      }
++
++      if (pid < 0) {
++              ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
++      }
++#else
++      ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(ENOTSUP));
++      pid = -1;
++#endif
++
++      return pid;
++}
++
++/*! \brief wait for spawned application to complete and unreplace sigchld */
++static int safe_exec_wait(pid_t pid)
++{
++      int res = -1;
++
++#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
++      if (pid > 0) {
+               for (;;) {
++                      struct rusage rusage;
++                      int status;
++
+                       res = wait4(pid, &status, 0, &rusage);
+                       if (res > -1) {
+                               res = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
+                               break;
+-                      } else if (errno != EINTR)
++                      }
++                      if (errno != EINTR) {
+                               break;
++                      }
+               }
+-      } else {
+-              ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
+-              res = -1;
+       }
+       ast_unreplace_sigchld();
+-#else /* !defined(HAVE_WORKING_FORK) && !defined(HAVE_WORKING_VFORK) */
+-      res = -1;
+ #endif
+       return res;
+ }
++int ast_safe_execvp(int dualfork, const char *file, char *const argv[])
++{
++      pid_t pid = safe_exec_prep(dualfork);
++
++      if (pid == 0) {
++              execvp(file, argv);
++              _exit(1);
++              /* noreturn from _exit */
++      }
++
++      return safe_exec_wait(pid);
++}
++
++int ast_safe_system(const char *s)
++{
++      pid_t pid = safe_exec_prep(0);
++
++      if (pid == 0) {
++              execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
++              _exit(1);
++              /* noreturn from _exit */
++      }
++
++      return safe_exec_wait(pid);
++}
++
+ /*!
+  * \brief enable or disable a logging level to a specified console
+  */
+diff --git a/res/res_monitor.c b/res/res_monitor.c
+index 76c43e1..12f478a 100644
+--- a/res/res_monitor.c
++++ b/res/res_monitor.c
+@@ -57,17 +57,17 @@
+               <syntax>
+                       <parameter name="file_format" argsep=":">
+                               <argument name="file_format" required="true">
+-                                      <para>optional, if not set, defaults to <literal>wav</literal></para>
++                                      <para>Optional.  If not set, defaults to <literal>wav</literal></para>
+                               </argument>
+                               <argument name="urlbase" />
+                       </parameter>
+                       <parameter name="fname_base">
+-                              <para>if set, changes the filename used to the one specified.</para>
++                              <para>If set, changes the filename used to the one specified.</para>
+                       </parameter>
+                       <parameter name="options">
+                               <optionlist>
+                                       <option name="m">
+-                                              <para>when the recording ends mix the two leg files into one and
++                                              <para>When the recording ends mix the two leg files into one and
+                                               delete the two leg files. If the variable <variable>MONITOR_EXEC</variable>
+                                               is set, the application referenced in it will be executed instead of
+                                               soxmix/sox and the raw leg files will NOT be deleted automatically.
+@@ -78,6 +78,13 @@
+                                               will be passed on as additional arguments to <variable>MONITOR_EXEC</variable>.
+                                               Both <variable>MONITOR_EXEC</variable> and the Mix flag can be set from the
+                                               administrator interface.</para>
++                                              <warning><para>Do not use untrusted strings such as
++                                              <variable>CALLERID(num)</variable> or <variable>CALLERID(name)</variable>
++                                              as part of <variable>MONITOR_EXEC</variable> or
++                                              <variable>MONITOR_EXEC_ARGS</variable>.  You risk a command injection
++                                              attack executing arbitrary commands if the untrusted strings aren't
++                                              filtered to remove dangerous characters.  See function
++                                              <variable>FILTER()</variable>.</para></warning>
+                                       </option>
+                                       <option name="b">
+                                               <para>Don't begin recording unless a call is bridged to another channel.</para>
diff --git a/net/asterisk-11.x/patches/058-AST-2017-008-11.diff b/net/asterisk-11.x/patches/058-AST-2017-008-11.diff
new file mode 100644 (file)
index 0000000..7f77bf7
--- /dev/null
@@ -0,0 +1,778 @@
+From fe2ba2f3ca60d33bc789c6ae8e03ee26dc1b637c Mon Sep 17 00:00:00 2001
+From: Richard Mudgett <rmudgett@digium.com>
+Date: Wed, 13 Sep 2017 12:07:42 -0500
+Subject: [PATCH] AST-2017-008: Improve RTP and RTCP packet processing.
+
+Validate RTCP packets before processing them.
+
+* Validate that the received packet is of a minimum length and apply the
+RFC3550 RTCP packet validation checks.
+
+* Fixed potentially reading garbage beyond the received RTCP record data.
+
+* Fixed rtp->themssrc only being set once when the remote could change
+the SSRC.  We would effectively stop handling the RTCP statistic records.
+
+* Fixed rtp->themssrc to not treat a zero value as special by adding
+rtp->themssrc_valid to indicate if rtp->themssrc is available.
+
+ASTERISK-27274
+
+Make strict RTP learning more flexible.
+
+Direct media can cause strict RTP to attempt to learn a remote address
+again before it has had a chance to learn the remote address the first
+time.  Because of the rapid relearn requests, strict RTP could latch onto
+the first remote address and fail to latch onto the direct media remote
+address.  As a result, you have one way audio until the call is placed on
+and off hold.
+
+The new algorithm learns remote addresses for a set time (1.5 seconds)
+before locking the remote address.  In addition, we must see a configured
+number of remote packets from the same address in a row before switching.
+
+* Fixed strict RTP learning from always accepting the first new address
+packet as the new stream.
+
+* Fixed strict RTP to initialize the expected sequence number with the
+last received sequence number instead of the last transmitted sequence
+number.
+
+* Fixed the predicted next sequence number calculation in
+rtp_learning_rtp_seq_update() to handle overflow.
+
+ASTERISK-27252
+
+Change-Id: Ia2d3aa6e0f22906c25971e74f10027d96525f31c
+---
+
+diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
+index 4881171..7393d57 100644
+--- a/res/res_rtp_asterisk.c
++++ b/res/res_rtp_asterisk.c
+@@ -115,7 +115,9 @@
+       STRICT_RTP_CLOSED,   /*! Drop all RTP packets not coming from source that was learned */
+ };
+-#define DEFAULT_STRICT_RTP STRICT_RTP_CLOSED
++#define STRICT_RTP_LEARN_TIMEOUT      1500    /*!< milliseconds */
++
++#define DEFAULT_STRICT_RTP -1 /*!< Enabled */
+ #define DEFAULT_ICESUPPORT 1
+ extern struct ast_srtp_res *res_srtp;
+@@ -199,9 +201,11 @@
+ /*! \brief RTP learning mode tracking information */
+ struct rtp_learning_info {
++      struct ast_sockaddr proposed_address;   /*!< Proposed remote address for strict RTP */
++      struct timeval start;   /*!< The time learning mode was started */
++      struct timeval received; /*!< The time of the last received packet */
+       int max_seq;    /*!< The highest sequence number received */
+       int packets;    /*!< The number of remaining packets before the source is accepted */
+-      struct timeval received; /*!< The time of the last received packet */
+ };
+ #ifdef HAVE_OPENSSL_SRTP
+@@ -223,7 +227,7 @@
+       unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
+       unsigned int ssrc;              /*!< Synchronization source, RFC 3550, page 10. */
+       unsigned int themssrc;          /*!< Their SSRC */
+-      unsigned int rxssrc;
++      unsigned int themssrc_valid;    /*!< True if their SSRC is available. */
+       unsigned int lastts;
+       unsigned int lastrxts;
+       unsigned int lastividtimestamp;
+@@ -1655,8 +1659,6 @@
+ #endif
+ };
+-static void rtp_learning_seq_init(struct rtp_learning_info *info, uint16_t seq);
+-
+ #ifdef HAVE_OPENSSL_SRTP
+ static void dtls_perform_handshake(struct ast_rtp_instance *instance, struct dtls_details *dtls, int rtcp)
+ {
+@@ -1685,6 +1687,8 @@
+ #endif
+ #ifdef USE_PJPROJECT
++static void rtp_learning_start(struct ast_rtp *rtp);
++
+ static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
+ {
+       struct ast_rtp_instance *instance = ice->user_data;
+@@ -1721,8 +1725,8 @@
+               return;
+       }
+-      rtp->strict_rtp_state = STRICT_RTP_LEARN;
+-      rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno);
++      ast_verb(4, "%p -- Strict RTP learning after ICE completion\n", rtp);
++      rtp_learning_start(rtp);
+ }
+ static void ast_rtp_on_ice_rx_data(pj_ice_sess *ice, unsigned comp_id, unsigned transport_id, void *pkt, pj_size_t size, const pj_sockaddr_t *src_addr, unsigned src_addr_len)
+@@ -2355,7 +2359,7 @@
+  */
+ static void rtp_learning_seq_init(struct rtp_learning_info *info, uint16_t seq)
+ {
+-      info->max_seq = seq - 1;
++      info->max_seq = seq;
+       info->packets = learning_min_sequential;
+       memset(&info->received, 0, sizeof(info->received));
+ }
+@@ -2372,14 +2376,17 @@
+  */
+ static int rtp_learning_rtp_seq_update(struct rtp_learning_info *info, uint16_t seq)
+ {
++      /*
++       * During the learning mode the minimum amount of media we'll accept is
++       * 10ms so give a reasonable 5ms buffer just in case we get it sporadically.
++       */
+       if (!ast_tvzero(info->received) && ast_tvdiff_ms(ast_tvnow(), info->received) < 5) {
+-              /* During the probation period the minimum amount of media we'll accept is
+-               * 10ms so give a reasonable 5ms buffer just in case we get it sporadically.
++              /*
++               * Reject a flood of packets as acceptable for learning.
++               * Reset the needed packets.
+                */
+-              return 1;
+-      }
+-
+-      if (seq == info->max_seq + 1) {
++              info->packets = learning_min_sequential - 1;
++      } else if (seq == (uint16_t) (info->max_seq + 1)) {
+               /* packet is in sequence */
+               info->packets--;
+       } else {
+@@ -2389,7 +2396,23 @@
+       info->max_seq = seq;
+       info->received = ast_tvnow();
+-      return (info->packets == 0);
++      return info->packets;
++}
++
++/*!
++ * \brief Start the strictrtp learning mode.
++ *
++ * \param rtp RTP session description
++ *
++ * \return Nothing
++ */
++static void rtp_learning_start(struct ast_rtp *rtp)
++{
++      rtp->strict_rtp_state = STRICT_RTP_LEARN;
++      memset(&rtp->rtp_source_learn.proposed_address, 0,
++              sizeof(rtp->rtp_source_learn.proposed_address));
++      rtp->rtp_source_learn.start = ast_tvnow();
++      rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t) rtp->lastrxseqno);
+ }
+ #ifdef USE_PJPROJECT
+@@ -2546,10 +2569,7 @@
+       /* Set default parameters on the newly created RTP structure */
+       rtp->ssrc = ast_random();
+       rtp->seqno = ast_random() & 0xffff;
+-      rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN);
+-      if (strictrtp) {
+-              rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno);
+-      }
++      rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_CLOSED : STRICT_RTP_OPEN);
+       /* Create a new socket for us to listen on and use */
+       if ((rtp->s =
+@@ -3867,13 +3887,86 @@
+       return &rtp->f;
+ }
++static const char *rtcp_payload_type2str(unsigned int pt)
++{
++      const char *str;
++
++      switch (pt) {
++      case RTCP_PT_SR:
++              str = "Sender Report";
++              break;
++      case RTCP_PT_RR:
++              str = "Receiver Report";
++              break;
++      case RTCP_PT_FUR:
++              /* Full INTRA-frame Request / Fast Update Request */
++              str = "H.261 FUR";
++              break;
++      case RTCP_PT_SDES:
++              str = "Source Description";
++              break;
++      case RTCP_PT_BYE:
++              str = "BYE";
++              break;
++      default:
++              str = "Unknown";
++              break;
++      }
++      return str;
++}
++
++/*
++ * Unshifted RTCP header bit field masks
++ */
++#define RTCP_LENGTH_MASK                      0xFFFF
++#define RTCP_PAYLOAD_TYPE_MASK                0xFF
++#define RTCP_REPORT_COUNT_MASK                0x1F
++#define RTCP_PADDING_MASK                     0x01
++#define RTCP_VERSION_MASK                     0x03
++
++/*
++ * RTCP header bit field shift offsets
++ */
++#define RTCP_LENGTH_SHIFT                     0
++#define RTCP_PAYLOAD_TYPE_SHIFT               16
++#define RTCP_REPORT_COUNT_SHIFT               24
++#define RTCP_PADDING_SHIFT                    29
++#define RTCP_VERSION_SHIFT                    30
++
++#define RTCP_VERSION                          2U
++#define RTCP_VERSION_SHIFTED          (RTCP_VERSION << RTCP_VERSION_SHIFT)
++#define RTCP_VERSION_MASK_SHIFTED     (RTCP_VERSION_MASK << RTCP_VERSION_SHIFT)
++
++/*
++ * RTCP first packet record validity header mask and value.
++ *
++ * RFC3550 intentionally defines the encoding of RTCP_PT_SR and RTCP_PT_RR
++ * such that they differ in the least significant bit.  Either of these two
++ * payload types MUST be the first RTCP packet record in a compound packet.
++ *
++ * RFC3550 checks the padding bit in the algorithm they use to check the
++ * RTCP packet for validity.  However, we aren't masking the padding bit
++ * to check since we don't know if it is a compound RTCP packet or not.
++ */
++#define RTCP_VALID_MASK (RTCP_VERSION_MASK_SHIFTED | (((RTCP_PAYLOAD_TYPE_MASK & ~0x1)) << RTCP_PAYLOAD_TYPE_SHIFT))
++#define RTCP_VALID_VALUE (RTCP_VERSION_SHIFTED | (RTCP_PT_SR << RTCP_PAYLOAD_TYPE_SHIFT))
++
++#define RTCP_SR_BLOCK_WORD_LENGTH 5
++#define RTCP_RR_BLOCK_WORD_LENGTH 6
++#define RTCP_HEADER_SSRC_LENGTH   2
++
+ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
+ {
+       struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+       struct ast_sockaddr addr;
+       unsigned char rtcpdata[8192 + AST_FRIENDLY_OFFSET];
+       unsigned int *rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET);
+-      int res, packetwords, position = 0;
++      int res;
++      unsigned int packetwords;
++      unsigned int position;
++      unsigned int first_word;
++      /*! True if we have seen an acceptable SSRC to learn the remote RTCP address */
++      unsigned int ssrc_seen;
+       struct ast_frame *f = &ast_null_frame;
+       /* Read in RTCP data from the socket */
+@@ -3918,56 +4011,170 @@
+       packetwords = res / 4;
+-      ast_debug(1, "Got RTCP report of %d bytes\n", res);
++      ast_debug(1, "Got RTCP report of %d bytes from %s\n",
++              res, ast_sockaddr_stringify(&addr));
++      /*
++       * Validate the RTCP packet according to an adapted and slightly
++       * modified RFC3550 validation algorithm.
++       */
++      if (packetwords < RTCP_HEADER_SSRC_LENGTH) {
++              ast_debug(1, "%p -- RTCP from %s: Frame size (%u words) is too short\n",
++                      rtp, ast_sockaddr_stringify(&addr), packetwords);
++              return &ast_null_frame;
++      }
++      position = 0;
++      first_word = ntohl(rtcpheader[position]);
++      if ((first_word & RTCP_VALID_MASK) != RTCP_VALID_VALUE) {
++              ast_debug(1, "%p -- RTCP from %s: Failed first packet validity check\n",
++                      rtp, ast_sockaddr_stringify(&addr));
++              return &ast_null_frame;
++      }
++      do {
++              position += ((first_word >> RTCP_LENGTH_SHIFT) & RTCP_LENGTH_MASK) + 1;
++              if (packetwords <= position) {
++                      break;
++              }
++              first_word = ntohl(rtcpheader[position]);
++      } while ((first_word & RTCP_VERSION_MASK_SHIFTED) == RTCP_VERSION_SHIFTED);
++      if (position != packetwords) {
++              ast_debug(1, "%p -- RTCP from %s: Failed packet version or length check\n",
++                      rtp, ast_sockaddr_stringify(&addr));
++              return &ast_null_frame;
++      }
++
++      /*
++       * Note: RFC3605 points out that true NAT (vs NAPT) can cause RTCP
++       * to have a different IP address and port than RTP.  Otherwise, when
++       * strictrtp is enabled we could reject RTCP packets not coming from
++       * the learned RTP IP address if it is available.
++       */
++
++      /*
++       * strictrtp safety needs SSRC to match before we use the
++       * sender's address for symmetrical RTP to send our RTCP
++       * reports.
++       *
++       * If strictrtp is not enabled then claim to have already seen
++       * a matching SSRC so we'll accept this packet's address for
++       * symmetrical RTP.
++       */
++      ssrc_seen = rtp->strict_rtp_state == STRICT_RTP_OPEN;
++
++      position = 0;
+       while (position < packetwords) {
+-              int i, pt, rc;
+-              unsigned int length, dlsr, lsr, msw, lsw, comp;
++              unsigned int i;
++              unsigned int pt;
++              unsigned int rc;
++              unsigned int ssrc;
++              /*! True if the ssrc value we have is valid and not garbage because it doesn't exist. */
++              unsigned int ssrc_valid;
++              unsigned int length;
++              unsigned int min_length;
++              unsigned int dlsr, lsr, msw, lsw, comp;
+               struct timeval now;
+               double rttsec, reported_jitter, reported_normdev_jitter_current, normdevrtt_current, reported_lost, reported_normdev_lost_current;
+               uint64_t rtt = 0;
+               i = position;
+-              length = ntohl(rtcpheader[i]);
+-              pt = (length & 0xff0000) >> 16;
+-              rc = (length & 0x1f000000) >> 24;
+-              length &= 0xffff;
++              first_word = ntohl(rtcpheader[i]);
++              pt = (first_word >> RTCP_PAYLOAD_TYPE_SHIFT) & RTCP_PAYLOAD_TYPE_MASK;
++              rc = (first_word >> RTCP_REPORT_COUNT_SHIFT) & RTCP_REPORT_COUNT_MASK;
++              /* RFC3550 says 'length' is the number of words in the packet - 1 */
++              length = ((first_word >> RTCP_LENGTH_SHIFT) & RTCP_LENGTH_MASK) + 1;
+-              if ((i + length) > packetwords) {
+-                      if (rtpdebug)
+-                              ast_debug(1, "RTCP Read too short\n");
++              /* Check expected RTCP packet record length */
++              min_length = RTCP_HEADER_SSRC_LENGTH;
++              switch (pt) {
++              case RTCP_PT_SR:
++                      min_length += RTCP_SR_BLOCK_WORD_LENGTH;
++                      /* fall through */
++              case RTCP_PT_RR:
++                      min_length += (rc * RTCP_RR_BLOCK_WORD_LENGTH);
++                      break;
++              case RTCP_PT_FUR:
++                      break;
++              case RTCP_PT_SDES:
++              case RTCP_PT_BYE:
++                      /*
++                       * There may not be a SSRC/CSRC present.  The packet is
++                       * useless but still valid if it isn't present.
++                       *
++                       * We don't know what min_length should be so disable the check
++                       */
++                      min_length = length;
++                      break;
++              default:
++                      ast_debug(1, "%p -- RTCP from %s: %u(%s) skipping record\n",
++                              rtp, ast_sockaddr_stringify(&addr), pt, rtcp_payload_type2str(pt));
++                      if (rtcp_debug_test_addr(&addr)) {
++                              ast_verbose("\n");
++                              ast_verbose("RTCP from %s: %u(%s) skipping record\n",
++                                      ast_sockaddr_stringify(&addr), pt, rtcp_payload_type2str(pt));
++                      }
++                      position += length;
++                      continue;
++              }
++              if (length < min_length) {
++                      ast_debug(1, "%p -- RTCP from %s: %u(%s) length field less than expected minimum.  Min:%u Got:%u\n",
++                              rtp, ast_sockaddr_stringify(&addr), pt, rtcp_payload_type2str(pt),
++                              min_length - 1, length - 1);
+                       return &ast_null_frame;
+               }
+-              if ((rtp->strict_rtp_state != STRICT_RTP_OPEN) && (ntohl(rtcpheader[i + 1]) != rtp->themssrc)) {
+-                      /* Skip over this RTCP record as it does not contain the correct SSRC */
+-                      position += (length + 1);
+-                      ast_debug(1, "%p -- Received RTCP report from %s, dropping due to strict RTP protection. Received SSRC '%u' but expected '%u'\n",
+-                              rtp, ast_sockaddr_stringify(&addr), ntohl(rtcpheader[i + 1]), rtp->themssrc);
+-                      continue;
+-              }
+-
+-              if (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
+-                      /* Send to whoever sent to us */
+-                      if (ast_sockaddr_cmp(&rtp->rtcp->them, &addr)) {
+-                              ast_sockaddr_copy(&rtp->rtcp->them, &addr);
+-                              if (rtpdebug)
+-                                      ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
+-                                              ast_sockaddr_stringify(&rtp->rtcp->them));
+-                      }
++              /* Get the RTCP record SSRC if defined for the record */
++              ssrc_valid = 1;
++              switch (pt) {
++              case RTCP_PT_SR:
++              case RTCP_PT_RR:
++              case RTCP_PT_FUR:
++                      ssrc = ntohl(rtcpheader[i + 1]);
++                      break;
++              case RTCP_PT_SDES:
++              case RTCP_PT_BYE:
++              default:
++                      ssrc = 0;
++                      ssrc_valid = 0;
++                      break;
+               }
+               if (rtcp_debug_test_addr(&addr)) {
+-                      ast_verbose("\n\nGot RTCP from %s\n",
+-                                  ast_sockaddr_stringify(&addr));
+-                      ast_verbose("PT: %d(%s)\n", pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown");
+-                      ast_verbose("Reception reports: %d\n", rc);
+-                      ast_verbose("SSRC of sender: %u\n", rtcpheader[i + 1]);
++                      ast_verbose("\n");
++                      ast_verbose("RTCP from %s\n", ast_sockaddr_stringify(&addr));
++                      ast_verbose("PT: %u(%s)\n", pt, rtcp_payload_type2str(pt));
++                      ast_verbose("Reception reports: %u\n", rc);
++                      ast_verbose("SSRC of sender: %u\n", ssrc);
+               }
+-              i += 2; /* Advance past header and ssrc */
++              if (ssrc_valid && rtp->themssrc_valid) {
++                      if (ssrc != rtp->themssrc) {
++                              /*
++                               * Skip over this RTCP record as it does not contain the
++                               * correct SSRC.  We should not act upon RTCP records
++                               * for a different stream.
++                               */
++                              position += length;
++                              ast_debug(1, "%p -- RTCP from %s: Skipping record, received SSRC '%u' != expected '%u'\n",
++                                      rtp, ast_sockaddr_stringify(&addr), ssrc, rtp->themssrc);
++                              continue;
++                      }
++                      ssrc_seen = 1;
++              }
++
++              if (ssrc_seen && ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
++                      /* Send to whoever sent to us */
++                      if (ast_sockaddr_cmp(&rtp->rtcp->them, &addr)) {
++                              ast_sockaddr_copy(&rtp->rtcp->them, &addr);
++                              if (rtpdebug) {
++                                      ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
++                                              ast_sockaddr_stringify(&addr));
++                              }
++                      }
++              }
++
++              i += RTCP_HEADER_SSRC_LENGTH; /* Advance past header and ssrc */
+               if (rc == 0 && pt == RTCP_PT_RR) {      /* We're receiving a receiver report with no reports, which is ok */
+-                      position += (length + 1);
++                      position += length;
+                       continue;
+               }
+@@ -3983,7 +4190,7 @@
+                               ast_verbose("RTP timestamp: %lu\n", (unsigned long) ntohl(rtcpheader[i + 2]));
+                               ast_verbose("SPC: %lu\tSOC: %lu\n", (unsigned long) ntohl(rtcpheader[i + 3]), (unsigned long) ntohl(rtcpheader[i + 4]));
+                       }
+-                      i += 5;
++                      i += RTCP_SR_BLOCK_WORD_LENGTH;
+                       if (rc < 1)
+                               break;
+                       /* Intentional fall through */
+@@ -4153,21 +4360,18 @@
+               case RTCP_PT_SDES:
+                       if (rtcp_debug_test_addr(&addr))
+                               ast_verbose("Received an SDES from %s\n",
+-                                          ast_sockaddr_stringify(&rtp->rtcp->them));
++                                      ast_sockaddr_stringify(&addr));
+                       break;
+               case RTCP_PT_BYE:
+                       if (rtcp_debug_test_addr(&addr))
+                               ast_verbose("Received a BYE from %s\n",
+-                                          ast_sockaddr_stringify(&rtp->rtcp->them));
++                                      ast_sockaddr_stringify(&addr));
+                       break;
+               default:
+-                      ast_debug(1, "Unknown RTCP packet (pt=%d) received from %s\n",
+-                                pt, ast_sockaddr_stringify(&rtp->rtcp->them));
+                       break;
+               }
+-              position += (length + 1);
++              position += length;
+       }
+-
+       rtp->rtcp->rtcp_info = 1;
+       return f;
+@@ -4344,39 +4548,156 @@
+               return &ast_null_frame;
+       }
++      /* If the version is not what we expected by this point then just drop the packet */
++      if (version != 2) {
++              return &ast_null_frame;
++      }
++
+       /* If strict RTP protection is enabled see if we need to learn the remote address or if we need to drop the packet */
+-      if (rtp->strict_rtp_state == STRICT_RTP_LEARN) {
+-              if (!ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
+-                      /* We are learning a new address but have received traffic from the existing address,
+-                       * accept it but reset the current learning for the new source so it only takes over
+-                       * once sufficient traffic has been received. */
+-                      rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
++      switch (rtp->strict_rtp_state) {
++      case STRICT_RTP_LEARN:
++              /*
++               * Scenario setup:
++               * PartyA -- Ast1 -- Ast2 -- PartyB
++               *
++               * The learning timeout is necessary for Ast1 to handle the above
++               * setup where PartyA calls PartyB and Ast2 initiates direct media
++               * between Ast1 and PartyB.  Ast1 may lock onto the Ast2 stream and
++               * never learn the PartyB stream when it starts.  The timeout makes
++               * Ast1 stay in the learning state long enough to see and learn the
++               * RTP stream from PartyB.
++               *
++               * To mitigate against attack, the learning state cannot switch
++               * streams while there are competing streams.  The competing streams
++               * interfere with each other's qualification.  Once we accept a
++               * stream and reach the timeout, an attacker cannot interfere
++               * anymore.
++               *
++               * Here are a few scenarios and each one assumes that the streams
++               * are continuous:
++               *
++               * 1) We already have a known stream source address and the known
++               * stream wants to change to a new source address.  An attacking
++               * stream will block learning the new stream source.  After the
++               * timeout we re-lock onto the original stream source address which
++               * likely went away.  The result is one way audio.
++               *
++               * 2) We already have a known stream source address and the known
++               * stream doesn't want to change source addresses.  An attacking
++               * stream will not be able to replace the known stream.  After the
++               * timeout we re-lock onto the known stream.  The call is not
++               * affected.
++               *
++               * 3) We don't have a known stream source address.  This presumably
++               * is the start of a call.  Competing streams will result in staying
++               * in learning mode until a stream becomes the victor and we reach
++               * the timeout.  We cannot exit learning if we have no known stream
++               * to lock onto.  The result is one way audio until there is a victor.
++               *
++               * If we learn a stream source address before the timeout we will be
++               * in scenario 1) or 2) when a competing stream starts.
++               */
++              if (!ast_sockaddr_isnull(&rtp->strict_rtp_address)
++                      && STRICT_RTP_LEARN_TIMEOUT < ast_tvdiff_ms(ast_tvnow(), rtp->rtp_source_learn.start)) {
++                      ast_verb(4, "%p -- Strict RTP learning complete - Locking on source address %s\n",
++                              rtp, ast_sockaddr_stringify(&rtp->strict_rtp_address));
++                      rtp->strict_rtp_state = STRICT_RTP_CLOSED;
++
++                      /*
++                       * Clear the alternate remote address after learning.
++                       *
++                       * We should not leave this address laying around.
++                       * It gets set only on a chan_sip reINVITE glare.
++                       * We don't want a stale address interfering with
++                       * the next learning time.
++                       */
++                      ast_sockaddr_setnull(&rtp->alt_rtp_address);
+               } else {
+-                      /* Hmm, not the strict address. Perhaps we're getting audio from the alternate? */
+-                      if (!ast_sockaddr_cmp(&rtp->alt_rtp_address, &addr)) {
+-                              /* ooh, we did! You're now the new expected address, son! */
+-                              ast_sockaddr_copy(&rtp->strict_rtp_address,
+-                                                &addr);
+-                      } else {
+-                              /* Start trying to learn from the new address. If we pass a probationary period with
+-                               * it, that means we've stopped getting RTP from the original source and we should
+-                               * switch to it.
++                      if (!ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
++                              /*
++                               * We are open to learning a new address but have received
++                               * traffic from the current address, accept it and reset
++                               * the learning counts for a new source.  When no more
++                               * current source packets arrive a new source can take over
++                               * once sufficient traffic is received.
+                                */
+-                              if (rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
+-                                      ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Will switch to it in %d packets\n",
+-                                                      rtp, ast_sockaddr_stringify(&addr), rtp->rtp_source_learn.packets);
+-                                      return &ast_null_frame;
+-                              }
+-                              ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
++                              rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
++                              break;
+                       }
+-                      ast_verb(4, "%p -- Probation passed - setting RTP source address to %s\n", rtp, ast_sockaddr_stringify(&addr));
+-                      rtp->strict_rtp_state = STRICT_RTP_CLOSED;
++                      /*
++                       * We give preferential treatment to the requested remote address
++                       * (negotiated SDP address) where we are to send our RTP.  However,
++                       * the other end has no obligation to send from that address even
++                       * though it is practically a requirement when NAT is involved.
++                       */
++                      if (!ast_sockaddr_cmp(&remote_address, &addr)) {
++                              /* Accept the negotiated remote RTP stream as the source */
++                              ast_verb(4, "%p -- Strict RTP switching to RTP remote address %s as source\n",
++                                      rtp, ast_sockaddr_stringify(&addr));
++                              ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
++                              rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
++                              break;
++                      }
++                      /* Treat the alternate remote address as another negotiated SDP address. */
++                      if (!ast_sockaddr_isnull(&rtp->alt_rtp_address)
++                              && !ast_sockaddr_cmp(&rtp->alt_rtp_address, &addr)) {
++                              /* ooh, we did! You're now the new expected address, son! */
++                              ast_verb(4, "%p -- Strict RTP switching to RTP alt remote address %s as source\n",
++                                      rtp, ast_sockaddr_stringify(&addr));
++                              ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
++                              rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
++                              break;
++                      }
++
++                      /*
++                       * Trying to learn a new address.  If we pass a probationary period
++                       * with it, that means we've stopped getting RTP from the original
++                       * source and we should switch to it.
++                       */
++                      if (!ast_sockaddr_cmp(&rtp->rtp_source_learn.proposed_address, &addr)) {
++                              if (!rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
++                                      /* Accept the new RTP stream */
++                                      ast_verb(4, "%p -- Strict RTP switching source address to %s\n",
++                                              rtp, ast_sockaddr_stringify(&addr));
++                                      ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
++                                      rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
++                                      break;
++                              }
++                              /* Not ready to accept the RTP stream candidate */
++                              ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Will switch to it in %d packets.\n",
++                                      rtp, ast_sockaddr_stringify(&addr), rtp->rtp_source_learn.packets);
++                      } else {
++                              /*
++                               * This is either an attacking stream or
++                               * the start of the expected new stream.
++                               */
++                              ast_sockaddr_copy(&rtp->rtp_source_learn.proposed_address, &addr);
++                              rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
++                              ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Qualifying new stream.\n",
++                                      rtp, ast_sockaddr_stringify(&addr));
++                      }
++                      return &ast_null_frame;
+               }
+-      } else if (rtp->strict_rtp_state == STRICT_RTP_CLOSED && ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
++              /* Fall through */
++      case STRICT_RTP_CLOSED:
++              /*
++               * We should not allow a stream address change if the SSRC matches
++               * once strictrtp learning is closed.  Any kind of address change
++               * like this should have happened while we were in the learning
++               * state.  We do not want to allow the possibility of an attacker
++               * interfering with the RTP stream after the learning period.
++               * An attacker could manage to get an RTCP packet redirected to
++               * them which can contain the SSRC value.
++               */
++              if (!ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
++                      break;
++              }
+               ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection.\n",
+                       rtp, ast_sockaddr_stringify(&addr));
+               return &ast_null_frame;
++      case STRICT_RTP_OPEN:
++              break;
+       }
+       /* If symmetric RTP is enabled see if the remote side is not what we expected and change where we are sending audio */
+@@ -4401,11 +4722,6 @@
+               return &ast_null_frame;
+       }
+-      /* If the version is not what we expected by this point then just drop the packet */
+-      if (version != 2) {
+-              return &ast_null_frame;
+-      }
+-
+       /* Pull out the various other fields we will need */
+       payloadtype = (seqno & 0x7f0000) >> 16;
+       padding = seqno & (1 << 29);
+@@ -4418,7 +4734,7 @@
+       AST_LIST_HEAD_INIT_NOLOCK(&frames);
+       /* Force a marker bit and change SSRC if the SSRC changes */
+-      if (rtp->rxssrc && rtp->rxssrc != ssrc) {
++      if (rtp->themssrc_valid && rtp->themssrc != ssrc) {
+               struct ast_frame *f, srcupdate = {
+                       AST_FRAME_CONTROL,
+                       .subclass.integer = AST_CONTROL_SRCCHANGE,
+@@ -4445,8 +4761,8 @@
+                       rtp->rtcp->received_prior = 0;
+               }
+       }
+-
+-      rtp->rxssrc = ssrc;
++      rtp->themssrc = ssrc; /* Record their SSRC to put in future RR */
++      rtp->themssrc_valid = 1;
+       /* Remove any padding bytes that may be present */
+       if (padding) {
+@@ -4498,10 +4814,6 @@
+       prev_seqno = rtp->lastrxseqno;
+       rtp->lastrxseqno = seqno;
+-
+-      if (!rtp->themssrc) {
+-              rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */
+-      }
+       if (rtp_debug_test_addr(&addr)) {
+               ast_verbose("Got  RTP packet from    %s (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6d)\n",
+@@ -4771,13 +5083,14 @@
+       rtp->rxseqno = 0;
+-      if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN && !ast_sockaddr_isnull(addr) &&
+-              ast_sockaddr_cmp(addr, &rtp->strict_rtp_address)) {
++      if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN
++              && !ast_sockaddr_isnull(addr) && ast_sockaddr_cmp(addr, &rtp->strict_rtp_address)) {
+               /* We only need to learn a new strict source address if we've been told the source is
+                * changing to something different.
+                */
+-              rtp->strict_rtp_state = STRICT_RTP_LEARN;
+-              rtp_learning_seq_init(&rtp->rtp_source_learn, rtp->seqno);
++              ast_verb(4, "%p -- Strict RTP learning after remote address set to: %s\n",
++                      rtp, ast_sockaddr_stringify(addr));
++              rtp_learning_start(rtp);
+       }
+       return;
+@@ -4805,7 +5118,23 @@
+        */
+       ast_sockaddr_copy(&rtp->alt_rtp_address, addr);
+-      return;
++      if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN
++              && !ast_sockaddr_isnull(addr) && ast_sockaddr_cmp(addr, &rtp->strict_rtp_address)) {
++              /*
++               * We only need to learn a new strict source address if we've been told the
++               * source may be changing to something different.
++               *
++               * XXX NOTE: The alternate source address is only set because of a reINVITE
++               * glare in chan_sip.  A reINVITE glare is supposed to be retried after a
++               * backoff delay so it shouldn't be needed at all.  However, I found this
++               * as the best description of why it was added:
++               * http://lists.digium.com/pipermail/asterisk-dev/2009-May/038348.html
++               * https://reviewboard.asterisk.org/r/252/
++               */
++              ast_verb(4, "%p -- Strict RTP learning after alternate remote address set to: %s\n",
++                      rtp, ast_sockaddr_stringify(addr));
++              rtp_learning_start(rtp);
++      }
+ }
+ /*! \brief Write t140 redundacy frame
diff --git a/net/asterisk-13.x/Config.in b/net/asterisk-13.x/Config.in
new file mode 100644 (file)
index 0000000..fd38585
--- /dev/null
@@ -0,0 +1,11 @@
+menu "Advanced configuration"
+       depends on PACKAGE_asterisk13
+
+config ASTERISK13_LOW_MEMORY
+       bool "Optimize Asterisk 13 for low memory usage"
+       default n
+       help
+         Warning: this feature is known to cause problems with some modules.
+         Disable it if you experience problems like segmentation faults.
+
+endmenu
index 5cf80cf6f227dedea1b132d6561358a7dd704e35..8f730bc2d677f864908e9d4c5fbd74655e186826 100644 (file)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=asterisk13
-PKG_VERSION:=13.9.1
+PKG_VERSION:=13.18.5
 PKG_RELEASE:=1
 
 PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=http://downloads.asterisk.org/pub/telephony/asterisk/releases/
-PKG_MD5SUM:=76c42992a79f41ec467ed20500e8b249
+PKG_SOURCE_URL:=https://downloads.asterisk.org/pub/telephony/asterisk/releases/
+PKG_MD5SUM:=4ad2a5ab1dd12cba5f37fca52961aa2a
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/asterisk-$(PKG_VERSION)
 PKG_BUILD_DEPENDS:=libxml2/host
@@ -46,8 +46,12 @@ define Package/asterisk13/install/sbin
 endef
 
 define Package/asterisk13/install/sounds
-       $(INSTALL_DIR) $(1)/usr/lib/asterisk/sounds/
-       $(CP) $(PKG_INSTALL_DIR)/usr/lib/asterisk/sounds/en/$(2) $(1)/usr/lib/asterisk/sounds/
+       $(INSTALL_DIR) $(1)/usr/share/asterisk/sounds/
+       $(CP) $(PKG_INSTALL_DIR)/usr/share/asterisk/sounds/en/$(2) $(1)/usr/share/asterisk/sounds/
+endef
+
+define Package/$(PKG_NAME)/config
+       source "$(SOURCE)/Config.in"
 endef
 
 define BuildAsterisk13Module
@@ -58,7 +62,7 @@ define BuildAsterisk13Module
   endef
 
   define Package/asterisk13-$(1)/conffiles
-$(foreach c,$(5),/etc/asterisk/$(c))
+$(subst $(space),$(newline),$(foreach c,$(5),/etc/asterisk/$(c)))
   endef
 
   define Package/asterisk13-$(1)/description
@@ -105,7 +109,11 @@ define Package/asterisk13/conffiles
 /etc/asterisk/acl.conf
 /etc/asterisk/cel.conf
 /etc/asterisk/ccss.conf
-/etc/asterisk/modules.conf
+/etc/asterisk/cli.conf
+/etc/asterisk/cli_permissions.conf
+/etc/asterisk/codecs.conf
+/etc/asterisk/dnsmgr.conf
+/etc/asterisk/dsp.conf
 /etc/asterisk/extconfig.conf
 /etc/asterisk/extensions.conf
 /etc/asterisk/features.conf
@@ -115,7 +123,7 @@ define Package/asterisk13/conffiles
 /etc/asterisk/manager.conf
 /etc/asterisk/modules.conf
 /etc/asterisk/res_config_sqlite3.conf
-/etc/asterisk/rtp.conf
+/etc/asterisk/stasis.conf
 /etc/asterisk/udptl.conf
 /etc/asterisk/users.conf
 /etc/default/asterisk
@@ -123,9 +131,10 @@ define Package/asterisk13/conffiles
 endef
 
 AST_CFG_FILES:= \
-       asterisk.conf acl.conf cel.conf ccss.conf extconfig.conf \
+       asterisk.conf acl.conf cel.conf ccss.conf cli.conf \
+       cli_permissions.conf codecs.conf dnsmgr.conf dsp.conf extconfig.conf \
        extensions.conf features.conf http.conf indications.conf \
-       logger.conf manager.conf modules.conf udptl.conf \
+       logger.conf manager.conf modules.conf stasis.conf udptl.conf \
        users.conf res_config_sqlite3.conf
 
 AST_EMB_MODULES:=\
@@ -140,7 +149,7 @@ $(call Package/asterisk13/install/sbin,$(1),safe_asterisk)
 $(call Package/asterisk13/install/sbin,$(1),astgenkey)
 $(foreach m,$(AST_CFG_FILES),$(call Package/asterisk13/install/conffile,$(1),$(m));)
 $(foreach m,$(AST_EMB_MODULES),$(call Package/asterisk13/install/module,$(1),$(m));)
-       $(INSTALL_DIR) $(1)/usr/lib/asterisk/sounds/
+       $(INSTALL_DIR) $(1)/usr/share/asterisk/sounds/
        $(INSTALL_DIR) $(1)/etc/default
        $(INSTALL_DATA) ./files/asterisk.default $(1)/etc/default/asterisk
        $(INSTALL_DIR) $(1)/etc/init.d
@@ -158,12 +167,12 @@ This package provides the sound-files for Asterisk-13.
 endef
 
 define Package/asterisk13-sounds/install
-       $(INSTALL_DIR) $(1)/usr/lib/asterisk/sounds/
-       $(CP) $(PKG_INSTALL_DIR)/usr/lib/asterisk/sounds/en/* $(1)/usr/lib/asterisk/sounds/
-       rm -f $(1)/usr/lib/asterisk/sounds/vm-*
+       $(INSTALL_DIR) $(1)/usr/share/asterisk/sounds/
+       $(CP) $(PKG_INSTALL_DIR)/usr/share/asterisk/sounds/en/* $(1)/usr/share/asterisk/sounds/
+       rm -f $(1)/usr/share/asterisk/sounds/vm-*
 endef
 
-ifneq ($(SDK)$(CONFIG_PACKAGE_asterisk13-chan-dahdi),)
+ifneq ($(CONFIG_PACKAGE_asterisk13-chan-dahdi),)
   CONFIGURE_ARGS+= \
        --with-dahdi="$(STAGING_DIR)/usr" \
        --with-pri="$(STAGING_DIR)/usr" \
@@ -175,13 +184,12 @@ else
        --without-tonezone
 endif
 
-TARGET_LDFLAGS+= \
-       $(if $(CONFIG_PACKAGE_$(PKG_NAME)-pbx-lua),-ldl -lcrypt)
-
-EXTRA_CFLAGS+=$(TARGET_CPPFLAGS)
-EXTRA_LDFLAGS+=$(TARGET_LDFLAGS) -Wl,-rpath-link,$(STAGING_DIR)/usr/lib
+# Pass CPPFLAGS in the CFLAGS as otherwise the build system will
+# ignore them.
+TARGET_CFLAGS+=$(TARGET_CPPFLAGS)
 
 CONFIGURE_ARGS+= \
+       $(if $(CONFIG_PACKAGE_$(PKG_NAME)-chan-alsa),--with-asound="$(STAGING_DIR)/usr",--without-asound) \
        --without-execinfo \
        --without-bluetooth \
        --without-cap \
@@ -203,30 +211,57 @@ CONFIGURE_ARGS+= \
        --without-osptk \
        $(if $(CONFIG_PACKAGE_$(PKG_NAME)-pbx-lua),--with-lua="$(STAGING_DIR)/usr",--without-lua) \
        $(if $(CONFIG_PACKAGE_$(PKG_NAME)-pgsql),--with-postgres="$(STAGING_DIR)/usr",--without-postgres) \
-       $(if $(CONFIG_PACKAGE_$(PKG_NAME)-pjsip),--with-pjproject,--without-pjproject) \
        --with-popt="$(STAGING_DIR)/usr" \
        --without-pwlib \
        --without-radius \
-       --without-spandsp \
+       $(if $(CONFIG_PACKAGE_$(PKG_NAME)-res-fax-spandsp),--with-spandsp="$(STAGING_DIR)/usr",--without-spandsp) \
        $(if $(CONFIG_PACKAGE_$(PKG_NAME)-res-xmpp),--with-iksemel="$(STAGING_DIR)/usr",--without-iksemel) \
        --without-sdl \
        --without-sqlite \
        --with-sqlite3="$(STAGING_DIR)/usr" \
-       $(if $(CONFIG_PACKAGE_$(PKG_NAME)-res-srtp),--with-srtp="$(STAGING_DIR)/usr",--without-srtp) \
        --without-suppserv \
        --without-tds \
        --without-termcap \
        --without-tinfo \
-       --with-uuid="$(STAGING_DIR)/usr" \
        --without-vorbis \
        --without-vpb \
        --with-z="$(STAGING_DIR)/usr" \
        --with-sounds-cache="$(DL_DIR)" \
        --enable-xmldoc
 
+ifeq ($(CONFIG_PACKAGE_$(PKG_NAME)-res-pjproject)$(CONFIG_PACKAGE_$(PKG_NAME)-res-srtp),)
+CONFIGURE_ARGS+= \
+       --without-srtp
+else
+CONFIGURE_ARGS+= \
+       --with-srtp="$(STAGING_DIR)/usr"
+endif
+
+ifeq ($(CONFIG_PACKAGE_$(PKG_NAME)-pjsip)$(CONFIG_PACKAGE_$(PKG_NAME)-res-pjproject)$(CONFIG_PACKAGE_$(PKG_NAME)-res-rtp-asterisk),)
+CONFIGURE_ARGS+= \
+       --without-pjproject
+else
+CONFIGURE_ARGS+= \
+       --with-pjproject="$(STAGING_DIR)/usr"
+endif
+
 CONFIGURE_VARS += \
        ac_cv_path_ac_pt_CONFIG_LIBXML2=$(STAGING_DIR)/host/bin/xml2-config
 
+MAKE_FLAGS+= \
+       ASTDATADIR="/usr/share/asterisk" \
+       DESTDIR="$(PKG_INSTALL_DIR)"
+
+# show full gcc arguments instead of [CC] and [LD]
+MAKE_FLAGS+= \
+       NOISY_BUILD="yes"
+
+# don't let asterisk mess with build flags
+MAKE_FLAGS+= \
+       AST_FORTIFY_SOURCE="" \
+       DEBUG="" \
+       OPTIMIZE=""
+
 AST_MENUSELECT_OPTS = \
        --without-newt \
        --without-curses \
@@ -237,7 +272,7 @@ define Build/Configure
        (cd $(PKG_BUILD_DIR); \
                ./bootstrap.sh; \
        );
-       $(call Build/Configure/Default,,$(SITE_VARS))
+       $(call Build/Configure/Default)
        (cd $(PKG_BUILD_DIR)/menuselect; \
                ./bootstrap.sh; \
                ./configure \
@@ -252,22 +287,20 @@ define Build/Compile
        $(MAKE) -C "$(PKG_BUILD_DIR)/menuselect" \
                CFLAGS="$(HOST_CFLAGS) -I$(STAGING_DIR)/host/include/libxml2" \
                LDFLAGS="$(HOST_LDFLAGS) -lxml2"
-       $(MAKE) -C "$(PKG_BUILD_DIR)" \
-               include/asterisk/version.h \
-               include/asterisk/buildopts.h defaults.h \
-               makeopts.embed_rules
-       ASTCFLAGS="$(EXTRA_CFLAGS) -DLOW_MEMORY"
-       ASTLDFLAGS="$(EXTRA_LDFLAGS)"
-       $(MAKE) -C "$(PKG_BUILD_DIR)" \
-               ASTVARLIBDIR="/usr/lib/asterisk" \
-               ASTDATADIR="/usr/lib/asterisk" \
-               ASTKEYDIR="/usr/lib/asterisk" \
-               ASTDBDIR="/usr/lib/asterisk" \
-               NOISY_BUILD="yes" \
-               DEBUG="" \
-               OPTIMIZE="" \
-               DESTDIR="$(PKG_INSTALL_DIR)" \
-               all install samples
+       $(MAKE) -C "$(PKG_BUILD_DIR)" menuselect-tree
+       cd "$(PKG_BUILD_DIR)" && \
+               ./menuselect/menuselect \
+                       --disable BUILD_NATIVE \
+                       $(if $(CONFIG_ASTERISK13_LOW_MEMORY),--enable LOW_MEMORY) \
+                       menuselect.makeopts
+       # Hack:
+       # When changing anything in MENUSELECT_CFLAGS the file ".lastclean"
+       # gets deleted. E.g. when compiling on x86 for x86 "--disable
+       # BUILD_NATIVE" changes MENUSELECT_CFLAGS and the file gets removed.
+       # But that will result in a rebuild attempt of menuselect which will
+       # likely fail. Prevent that by recreating ".lastclean".
+       $(CP) "$(PKG_BUILD_DIR)/.cleancount" "$(PKG_BUILD_DIR)/.lastclean"
+       $(call Build/Compile/Default,all install samples)
 endef
 
 define Build/InstallDev
@@ -329,7 +362,7 @@ $(eval $(call BuildAsterisk13Module,cdr,Provides CDR,Call Detail Record,,cdr.con
 $(eval $(call BuildAsterisk13Module,cdr-csv,Provides CDR CSV,Call Detail Record with CSV support,,,cdr_csv,,))
 $(eval $(call BuildAsterisk13Module,cdr-sqlite3,Provides CDR SQLITE3,Call Detail Record with SQLITE3 support,libsqlite3,,cdr_sqlite3_custom,,))
 $(eval $(call BuildAsterisk13Module,chan-alsa,ALSA channel,the channel chan_alsa,+alsa-lib,alsa.conf,chan_alsa,,))
-$(eval $(call BuildAsterisk13Module,chan-dahdi,DAHDI channel,DAHDI channel support,+dahdi-tools-libtonezone +kmod-dahdi +libpri,chan_dahdi.conf,chan_dahdi,,))
+$(eval $(call BuildAsterisk13Module,chan-dahdi,DAHDI channel,DAHDI channel support,+dahdi-tools-libtonezone +kmod-dahdi +libpri @!aarch64,chan_dahdi.conf,chan_dahdi,,))
 $(eval $(call BuildAsterisk13Module,chan-iax2,IAX2 channel,IAX support,+asterisk13-res-timing-timerfd,iax.conf iaxprov.conf,chan_iax2,,))
 $(eval $(call BuildAsterisk13Module,chan-oss,OSS channel,the channel chan_oss,,oss.conf,chan_oss,,))
 $(eval $(call BuildAsterisk13Module,chan-sip,SIP channel,the channel chan_sip,+asterisk13-app-confbridge,sip.conf sip_notify.conf,chan_sip,,))
@@ -346,7 +379,7 @@ $(eval $(call BuildAsterisk13Module,codec-ilbc,linear to ILBC translation,transl
 $(eval $(call BuildAsterisk13Module,codec-lpc10,Linear to LPC10 translation,translate between signed linear and LPC10,,,codec_lpc10,,))
 $(eval $(call BuildAsterisk13Module,codec-resample,resample sLinear audio,resample sLinear audio,,,codec_resample,,))
 $(eval $(call BuildAsterisk13Module,codec-ulaw,Signed linear to ulaw translation,translation between signed linear and ulaw codecs,,,codec_ulaw,,))
-$(eval $(call BuildAsterisk13Module,curl,CURL,CURL support,+libcurl,,func_curl res_curl,,))
+$(eval $(call BuildAsterisk13Module,curl,CURL,CURL support,+libcurl,,func_curl res_config_curl res_curl,,))
 $(eval $(call BuildAsterisk13Module,format-g726,G.726,support for headerless G.726 16/24/32/40kbps data format,,,format_g726,,))
 $(eval $(call BuildAsterisk13Module,format-g729,G.729,support for raw headerless G729 data,,,format_g729,,))
 $(eval $(call BuildAsterisk13Module,format-gsm,GSM format,support for GSM format,,,format_gsm,,))
@@ -372,38 +405,44 @@ $(eval $(call BuildAsterisk13Module,func-groupcount,Group count,for counting num
 $(eval $(call BuildAsterisk13Module,func-math,Math functions,Math functions,,,func_math,))
 $(eval $(call BuildAsterisk13Module,func-module,Simple module check function,Simple module check function,,,func_module,))
 $(eval $(call BuildAsterisk13Module,func-presencestate,Hinted presence state,Gets or sets a presence state in the dialplan,,,func_presencestate,,))
+$(eval $(call BuildAsterisk13Module,func-periodic-hook,Periodic dialplan hooks,Execute a periodic dialplan hook into the audio of a call,+$(PKG_NAME)-app-chanspy +$(PKG_NAME)-func-cut +$(PKG_NAME)-func-groupcount +$(PKG_NAME)-func-uri,,func_periodic_hook,,))
 $(eval $(call BuildAsterisk13Module,func-realtime,realtime,the realtime dialplan function,,,func_realtime,,))
 $(eval $(call BuildAsterisk13Module,func-shell,Shell,support for shell execution,,,func_shell,,))
 $(eval $(call BuildAsterisk13Module,func-uri,URI encoding and decoding,Encodes and decodes URI-safe strings,,,func_uri,,))
 $(eval $(call BuildAsterisk13Module,func-vmcount,vmcount dialplan,a vmcount dialplan function,,,func_vmcount,,))
-$(eval $(call BuildAsterisk13Module,odbc,ODBC,ODBC support,+libpthread +libc +unixodbc,cdr_adaptive_odbc.conf cdr_odbc.conf cel_odbc.conf func_odbc.conf res_odbc.conf,cdr_adaptive_odbc cdr_odbc cel_odbc func_odbc res_config_odbc res_odbc,,))
-$(eval $(call BuildAsterisk13Module,pbx-ael,Asterisk Extension Logic,support for symbolic Asterisk Extension Logic,,extensions.ael,pbx_ael,,))
+$(eval $(call BuildAsterisk13Module,odbc,ODBC,ODBC support,+libpthread +libc +unixodbc,cdr_adaptive_odbc.conf cdr_odbc.conf cel_odbc.conf func_odbc.conf res_odbc.conf,cdr_adaptive_odbc cdr_odbc cel_odbc func_odbc res_config_odbc res_odbc res_odbc_transaction,,))
+$(eval $(call BuildAsterisk13Module,pbx-ael,Asterisk Extension Logic,support for symbolic Asterisk Extension Logic,+$(PKG_NAME)-res-ael-share,extensions.ael,pbx_ael,,))
 $(eval $(call BuildAsterisk13Module,pbx-dundi,Dundi,provides Dundi Lookup service for Asterisk,,dundi.conf,pbx_dundi,,))
 $(eval $(call BuildAsterisk13Module,pbx-realtime,Realtime Switch,realtime switch support,,,pbx_realtime,,))
 $(eval $(call BuildAsterisk13Module,pbx-spool,Call Spool,outgoing call spool support,,,pbx_spool,,))
-$(eval $(call BuildAsterisk13Module,pgsql,PostgreSQL,PostgreSQL support,+libpq,cel_pgsql.conf cdr_pgsql.conf res_pgsql.conf,cel_pgsql cdr_pgsql res_config_pgsql,,))
-$(eval $(call BuildAsterisk13Module,pjsip,pjsip channel,the channel pjsip,+asterisk13-res-sorcery +libpjsip +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsua +libpjsua2,pjsip.conf pjsip_notify.conf,func_pjsip_endpoint chan_pjsip res_pjsip_acl res_pjsip_authenticator_digest res_pjsip_caller_id res_pjsip_dialog_info_body_generator res_pjsip_diversion res_pjsip_dtmf_info res_pjsip_endpoint_identifier_anonymous res_pjsip_endpoint_identifier_ip res_pjsip_endpoint_identifier_user res_pjsip_exten_state res_pjsip_header_funcs res_pjsip_log_forwarder res_pjsip_logger res_pjsip_messaging res_pjsip_multihomed res_pjsip_mwi_body_generator res_pjsip_mwi res_pjsip_nat res_pjsip_notify res_pjsip_one_touch_record_info res_pjsip_outbound_authenticator_digest res_pjsip_outbound_publish res_pjsip_outbound_registration res_pjsip_path res_pjsip_pidf_body_generator res_pjsip_pidf_digium_body_supplement res_pjsip_pidf_eyebeam_body_supplement res_pjsip_publish_asterisk res_pjsip_pubsub res_pjsip_refer res_pjsip_registrar_expire res_pjsip_registrar res_pjsip_rfc3326 res_pjsip_sdp_rtp res_pjsip_send_to_voicemail res_pjsip_session res_pjsip res_pjsip_transport_websocket res_pjsip_t38 res_pjsip_xpidf_body_generator,,))
+$(eval $(call BuildAsterisk13Module,pgsql,PostgreSQL,PostgreSQL support,+libpq @!arc,cel_pgsql.conf cdr_pgsql.conf res_pgsql.conf,cel_pgsql cdr_pgsql res_config_pgsql,,))
+$(eval $(call BuildAsterisk13Module,pjsip,pjsip channel,the channel pjsip,+asterisk13-res-sorcery +asterisk13-res-pjproject +libpjsip +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsua +libpjsua2,pjsip.conf pjsip_notify.conf pjsip_wizard.conf,chan_pjsip func_pjsip_aor func_pjsip_contact func_pjsip_endpoint res_pjsip res_pjsip_acl res_pjsip_authenticator_digest res_pjsip_caller_id res_pjsip_config_wizard res_pjsip_dialog_info_body_generator res_pjsip_diversion res_pjsip_dlg_options res_pjsip_dtmf_info res_pjsip_empty_info res_pjsip_endpoint_identifier_anonymous res_pjsip_endpoint_identifier_ip res_pjsip_endpoint_identifier_user res_pjsip_exten_state res_pjsip_header_funcs res_pjsip_history res_pjsip_logger res_pjsip_messaging res_pjsip_mwi res_pjsip_mwi_body_generator res_pjsip_nat res_pjsip_notify res_pjsip_one_touch_record_info res_pjsip_outbound_authenticator_digest res_pjsip_outbound_publish res_pjsip_outbound_registration res_pjsip_path res_pjsip_pidf_body_generator res_pjsip_pidf_digium_body_supplement res_pjsip_pidf_eyebeam_body_supplement res_pjsip_publish_asterisk res_pjsip_pubsub res_pjsip_refer res_pjsip_registrar res_pjsip_registrar_expire res_pjsip_rfc3326 res_pjsip_sdp_rtp res_pjsip_send_to_voicemail res_pjsip_session res_pjsip_sips_contact res_pjsip_t38 res_pjsip_transport_management res_pjsip_transport_websocket res_pjsip_xpidf_body_generator,,))
 $(eval $(call BuildAsterisk13Module,res-adsi,Provide ADSI,Analog Display Services Interface capability,,,res_adsi,,))
 $(eval $(call BuildAsterisk13Module,res-ael-share,Shareable AEL code,support for shareable AEL code mainly between internal and external modules,,,res_ael_share,,))
-$(eval $(call BuildAsterisk13Module,res-agi,Asterisk Gateway Interface,Support for the Asterisk Gateway Interface extension,,,res_agi,,))
+$(eval $(call BuildAsterisk13Module,res-agi,Asterisk Gateway Interface,Support for the Asterisk Gateway Interface extension,+asterisk13-res-speech,,res_agi,,))
 $(eval $(call BuildAsterisk13Module,res-calendar,Calendaring API,Calendaring support (ICal and Google Calendar),,calendar.conf,res_calendar,,))
 $(eval $(call BuildAsterisk13Module,res-clioriginate,Calls via CLI,Originate calls via the CLI,,,res_clioriginate,,))
-$(eval $(call BuildAsterisk13Module,res-hep,HEPv3 API,,,,res_hep,,))
-$(eval $(call BuildAsterisk13Module,res-hep-pjsip,PJSIP HEPv3 Logger,,+asterisk13-res-hep +asterisk13-pjsip,,res_hep,,))
-$(eval $(call BuildAsterisk13Module,res-hep-rtcp,RTCP HEPv3 Logger,,+asterisk13-res-hep,,res_hep,,))
-$(eval $(call BuildAsterisk13Module,res-http-websocket,HTTP websocket support,,,,res_http_websocket,,))
-$(eval $(call BuildAsterisk13Module,res-monitor,Provide Monitor,Cryptographic Signature capability,,,res_monitor,,))
+$(eval $(call BuildAsterisk13Module,res-fax,FAX modules,Generic FAX resource for FAX technology resource modules,+asterisk13-res-timing-pthread,res_fax.conf,res_fax,,))
+$(eval $(call BuildAsterisk13Module,res-fax-spandsp,Spandsp T.38 and G.711,Spandsp T.38 and G.711 FAX Resource,+asterisk13-res-fax +libspandsp +libtiff,,res_fax_spandsp,,))
+$(eval $(call BuildAsterisk13Module,res-hep,HEPv3 API,Routines for integration with Homer using HEPv3,,hep.conf,res_hep,,))
+$(eval $(call BuildAsterisk13Module,res-hep-pjsip,PJSIP HEPv3 Logger,PJSIP logging with Homer,+asterisk13-res-hep +asterisk13-pjsip,,res_hep_pjsip,,))
+$(eval $(call BuildAsterisk13Module,res-hep-rtcp,RTCP HEPv3 Logger,RTCP logging with Homer,+asterisk13-res-hep,,res_hep_rtcp,,))
+$(eval $(call BuildAsterisk13Module,res-http-websocket,HTTP websocket support,WebSocket support for the Asterisk internal HTTP server,,,res_http_websocket,,))
+$(eval $(call BuildAsterisk13Module,res-monitor,PBX channel monitoring,call monitoring resource,+$(PKG_NAME)-func-periodic-hook,,res_monitor,,))
 $(eval $(call BuildAsterisk13Module,res-musiconhold,MOH,Music On Hold support,,musiconhold.conf,res_musiconhold,,))
-$(eval $(call BuildAsterisk13Module,res-parking,Phone Parking,Phone Parking application,,res_parking.conf,res_parking,,))
+$(eval $(call BuildAsterisk13Module,res-parking,Phone Parking,Phone Parking application,+$(PKG_NAME)-bridge-holding,res_parking.conf,res_parking,,))
 $(eval $(call BuildAsterisk13Module,res-phoneprov,Phone Provisioning,Phone provisioning application for the asterisk internal http server,,phoneprov.conf,res_phoneprov,,))
+$(eval $(call BuildAsterisk13Module,res-pjproject,Bridge PJPROJECT to Asterisk logging,,+libpj +libpjlib-util +libpjmedia +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsip +libpjsua +libpjsua2 +libsrtp,pjproject.conf,res_pjproject,,))
 $(eval $(call BuildAsterisk13Module,res-realtime,Realtime,Realtime Interface,,,res_realtime,,))
-$(eval $(call BuildAsterisk13Module,res-rtp-asterisk,RTP stack,,+libpjsip +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsua +libpjsua2,rtp.conf,res_rtp_asterisk,,))
-$(eval $(call BuildAsterisk13Module,res-rtp-multicast,RTP multicast engine,,,,res_rtp_multicast,,))
+$(eval $(call BuildAsterisk13Module,res-rtp-asterisk,RTP stack,Supports RTP and RTCP with Symmetric RTP support for NAT traversal,+libpjsip +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsua +libpjsua2,rtp.conf,res_rtp_asterisk,,))
+$(eval $(call BuildAsterisk13Module,res-rtp-multicast,RTP multicast engine,Multicast RTP Engine,,,res_rtp_multicast,,))
 $(eval $(call BuildAsterisk13Module,res-smdi,Provide SMDI,Simple Message Desk Interface capability,,smdi.conf,res_smdi,,))
-$(eval $(call BuildAsterisk13Module,res-sorcery,Sorcery data layer,,,,res_sorcery_astdb res_sorcery_config res_sorcery_memory res_sorcery_realtime,,))
+$(eval $(call BuildAsterisk13Module,res-sorcery,Sorcery data layer,Sorcery backend modules for data access intended for using realtime as backend,,sorcery.conf,res_sorcery_astdb res_sorcery_config res_sorcery_memory res_sorcery_realtime,,))
+$(eval $(call BuildAsterisk13Module,res-speech,Speech Recognition API,Support for the Asterisk Generic Speech Recognition API,,,res_speech,,))
 $(eval $(call BuildAsterisk13Module,res-srtp,SRTP Support,Secure RTP connection,+libsrtp,,res_srtp,,))
-$(eval $(call BuildAsterisk13Module,res-timing-dahdi,DAHDI Timing Interface,,+asterisk13-chan-dahdi,,res_timing_dahdi,,))
-$(eval $(call BuildAsterisk13Module,res-timing-pthread,pthread Timing Interface,,,,res_timing_pthread,,))
-$(eval $(call BuildAsterisk13Module,res-timing-timerfd,Timerfd Timing Interface,,,,res_timing_timerfd,,))
+$(eval $(call BuildAsterisk13Module,res-timing-dahdi,DAHDI Timing Interface,DAHDI timing interface,+asterisk13-chan-dahdi,,res_timing_dahdi,,))
+$(eval $(call BuildAsterisk13Module,res-timing-pthread,pthread Timing Interface,POSIX pthreads Timing Interface,,,res_timing_pthread,,))
+$(eval $(call BuildAsterisk13Module,res-timing-timerfd,Timerfd Timing Interface,Timing interface provided by Linux kernel,,,res_timing_timerfd,,))
+$(eval $(call BuildAsterisk13Module,res-xmpp,XMPP client and component module,reference module for interfacting Asterisk directly as a client or component with XMPP server,+libiksemel +libopenssl,xmpp.conf,res_xmpp,,))
 $(eval $(call BuildAsterisk13Module,voicemail,Voicemail,voicemail related modules,+asterisk13-res-adsi +asterisk13-res-smdi,voicemail.conf,app_voicemail,vm-*,))
 
index 78e891383c2ae9073cd1b17a13b8ecac72137570..aa413fc350217e3333e4edc16edef90d0fd8d441 100644 (file)
@@ -14,8 +14,7 @@ start() {
        [ -d $DEST/var/run/asterisk ] || mkdir -p $DEST/var/run/asterisk
        [ -d $DEST/var/log/asterisk ] || mkdir -p $DEST/var/log/asterisk
        [ -d $DEST/var/spool/asterisk ] || mkdir -p $DEST/var/spool/asterisk
-       [ -d $DEST/var/lib ] || mkdir -p $DEST/var/lib
-       [ -h $DEST/var/lib/asterisk ] || ln -s /usr/lib/asterisk /var/lib/asterisk
+       [ -d $DEST/var/lib/asterisk ] || mkdir -p $DEST/var/lib/asterisk
        [ -d $DEST/var/lib/asterisk/keys ] || mkdir -p $DEST/var/lib/asterisk/keys
        [ -d $DEST/var/log/asterisk/cdr-csv ] || mkdir -p $DEST/var/log/asterisk/cdr-csv
 
index 6256fd8c575f67e86f30abc82208016acc5f2e9a..ba36dc7505b136e42e46c74544d50fb9a50084ce 100644 (file)
@@ -1,6 +1,6 @@
 --- a/configure.ac
 +++ b/configure.ac
-@@ -927,19 +927,6 @@ AC_LINK_IFELSE(
+@@ -963,19 +963,6 @@ AC_LINK_IFELSE(
    ]
  )
  
index 1d01bb8297d310fe15ff776a138e2da3641066d5..110c07e6425355a331e54014f7b102ae18d6a488 100644 (file)
@@ -1,6 +1,6 @@
 --- a/configure.ac
 +++ b/configure.ac
-@@ -1261,7 +1261,6 @@ AC_LINK_IFELSE(
+@@ -1290,7 +1290,6 @@ AC_LINK_IFELSE(
                        #include <resolv.h>],
                        [int foo = res_ninit(NULL);])],
        AC_MSG_RESULT(yes)
index 264eb41a7b406c380c19cb76b28b39b2491c9406..0a03b3874551ab31543c2a6c16395c895f080045 100644 (file)
@@ -31,7 +31,7 @@
 @@ -114,9 +120,11 @@ struct ast_lock_track {
        int reentrancy;
        const char *func[AST_MAX_REENTRANCY];
-       pthread_t thread[AST_MAX_REENTRANCY];
+       pthread_t thread_id[AST_MAX_REENTRANCY];
 +#ifndef __UCLIBC__
  #ifdef HAVE_BKTR
        struct ast_bt backtrace[AST_MAX_REENTRANCY];
diff --git a/net/asterisk-13.x/patches/040-fix-config-options.patch b/net/asterisk-13.x/patches/040-fix-config-options.patch
deleted file mode 100644 (file)
index e3ed33a..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
---- a/main/config_options.c
-+++ b/main/config_options.c
-@@ -198,8 +198,8 @@ static int link_option_to_types(struct a
- #ifdef AST_DEVMODE
-                       opt->doc_unavailable = 1;
- #endif
--#endif
-               }
-+#endif
-       }
-       /* The container(s) should hold the only ref to opt */
-       ao2_ref(opt, -1);
diff --git a/net/asterisk-13.x/patches/051-musl-includes.patch b/net/asterisk-13.x/patches/051-musl-includes.patch
deleted file mode 100644 (file)
index 6bee31c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
---- a/include/asterisk/compat.h
-+++ b/include/asterisk/compat.h
-@@ -68,7 +68,7 @@
- #endif
- #ifndef AST_POLL_COMPAT
--#include <sys/poll.h>
-+#include <poll.h>
- #else
- #include "asterisk/poll-compat.h"
- #endif
---- a/include/asterisk/poll-compat.h
-+++ b/include/asterisk/poll-compat.h
-@@ -83,7 +83,7 @@
- #ifndef AST_POLL_COMPAT
--#include <sys/poll.h>
-+#include <poll.h>
- #define ast_poll(a, b, c) poll(a, b, c)
---- a/main/ast_expr2.c
-+++ b/main/ast_expr2.c
-@@ -93,6 +93,7 @@
- #include "asterisk.h"
-+#include <sys/cdefs.h>
- #include <sys/types.h>
- #include <stdio.h>
---- a/main/ast_expr2.y
-+++ b/main/ast_expr2.y
-@@ -14,6 +14,7 @@
- #include "asterisk.h"
-+#include <sys/cdefs.h>
- #include <sys/types.h>
- #include <stdio.h>
index 41981ca17fc655b352b1641b46066e67e2a3ac6d..c50d24ede6c83e917e35fee131ec43bd1850a3c9 100644 (file)
@@ -1,7 +1,7 @@
 --- a/configure.ac
 +++ b/configure.ac
 @@ -181,6 +181,9 @@ case "${host_os}" in
-      linux-gnueabi* |  linux-gnuspe)
+      linux-gnu*)
       OSARCH=linux-gnu
       ;;
 +     linux-musl*)
@@ -10,7 +10,7 @@
       kfreebsd*-gnu)
       OSARCH=kfreebsd-gnu
       ;;
-@@ -1373,9 +1376,11 @@ if test "${PBX_BFD}" = "0"; then
+@@ -1414,9 +1417,11 @@ if test "${PBX_BFD}" = "0"; then
    AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_check_format], [bfd.h], [-ldl -liberty -lz])
  fi
  
  AST_C_DEFINE_CHECK([DAHDI], [DAHDI_DEFAULT_MTU_MRU], [dahdi/user.h], [220])
 --- a/main/Makefile
 +++ b/main/Makefile
-@@ -45,7 +45,7 @@ AST_LIBS+=$(UUID_LIB)
- AST_LIBS+=$(CRYPT_LIB)
- AST_LIBS+=$(AST_CLANG_BLOCKS_LIBS)
+@@ -47,7 +47,7 @@ AST_LIBS+=$(AST_CLANG_BLOCKS_LIBS)
+ AST_LIBS+=$(RT_LIB)
+ AST_LIBS+=$(SYSTEMD_LIB)
  
 -ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc kfreebsd-gnu),)
 +ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-musl kfreebsd-gnu),)
-   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
    AST_LIBS+=-ldl
-   endif
+   ifneq (x$(CAP_LIB),x)
+     AST_LIBS+=$(CAP_LIB)