]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_rtp: Fix regression when IPv6 is not available. 40/4540/1
authorGuido Falsi <mad@madpilot.net>
Tue, 22 Nov 2016 17:20:06 +0000 (18:20 +0100)
committerJoshua Colp <jcolp@digium.com>
Wed, 30 Nov 2016 20:04:31 +0000 (20:04 +0000)
The latest Release candidate fails to create RTP streams when IPv6
is not available. Due to the changes made in September the ast_sockaddr
structure passed around to create these streams is always of AF_INET6
type, causing failure when used for IPv4. This patch adds a utility
function to check for availability of IPv6 and applies such check
at startup to determine how to create the ast_sockaddr structures.

ASTERISK-26617 #close

Change-Id: I627a4e91795e821111e1cda523f083a40d0e0c3e

include/asterisk/utils.h
main/utils.c
res/res_pjsip_sdp_rtp.c
res/res_pjsip_t38.c

index a504a5da13e72ebfc321f85b0c227f3410a90c8e..4a5dbf282c5b2ce4a808fd74a909b0bf7978c02d 100644 (file)
@@ -1127,4 +1127,13 @@ int ast_file_is_readable(const char *filename);
  */
 int ast_compare_versions(const char *version1, const char *version2);
 
+/*
+ * \brief Test that an OS supports IPv6 Networking.
+ * \since 13.14.0
+ *
+ * \return True (non-zero) if the IPv6 supported.
+ * \return False (zero) if the OS doesn't support IPv6.
+ */
+int ast_check_ipv6(void);
+
 #endif /* _ASTERISK_UTILS_H */
index 03bead273f186192269013d171cafd5230a917c1..253df8d039715a7c63d2c3421c8c2f2e265545f8 100644 (file)
@@ -2425,6 +2425,18 @@ char *ast_utils_which(const char *binary, char *fullpath, size_t fullpath_size)
        return NULL;
 }
 
+int ast_check_ipv6(void)
+{
+       int udp6_socket = socket(AF_INET6, SOCK_DGRAM, 0);
+
+       if (udp6_socket < 0) {
+               return 0;
+       }
+
+       close(udp6_socket);
+       return 1;
+}
+
 void DO_CRASH_NORETURN ast_do_crash(void)
 {
 #if defined(DO_CRASH)
index 66550a2fde31ef442ae72ccf3a4649c84b0dad3b..b27050ed86f7d81f991174b94e76c80447a0e5bb 100644 (file)
@@ -51,6 +51,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/acl.h"
 #include "asterisk/sdp_srtp.h"
 #include "asterisk/dsp.h"
+#include "asterisk/utils.h"
 
 #include "asterisk/res_pjsip.h"
 #include "asterisk/res_pjsip_session.h"
@@ -1493,7 +1494,11 @@ static int load_module(void)
 {
        CHECK_PJSIP_SESSION_MODULE_LOADED();
 
-       ast_sockaddr_parse(&address_rtp, "::", 0);
+       if (ast_check_ipv6()) {
+               ast_sockaddr_parse(&address_rtp, "::", 0);
+       } else {
+               ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0);
+       }
 
        if (!(sched = ast_sched_context_create())) {
                ast_log(LOG_ERROR, "Unable to create scheduler context.\n");
index cf12111779a982aa66f39f50727ddac5ce71942b..0787f07635ed3c42246b49da2a085969247926fb 100644 (file)
@@ -44,6 +44,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/netsock2.h"
 #include "asterisk/channel.h"
 #include "asterisk/acl.h"
+#include "asterisk/utils.h"
 
 #include "asterisk/res_pjsip.h"
 #include "asterisk/res_pjsip_session.h"
@@ -918,7 +919,11 @@ static int load_module(void)
 {
        CHECK_PJSIP_SESSION_MODULE_LOADED();
 
-       ast_sockaddr_parse(&address, "::", 0);
+       if (ast_check_ipv6()) {
+               ast_sockaddr_parse(&address, "::", 0);
+       } else {
+               ast_sockaddr_parse(&address, "0.0.0.0", 0);
+       }
 
        if (ast_sip_session_register_supplement(&t38_supplement)) {
                ast_log(LOG_ERROR, "Unable to register T.38 session supplement\n");