[Asterisk-code-review] res rtp: Fix regression when IPv6 is not available. (asterisk[14])
Joshua Colp
asteriskteam at digium.com
Thu Dec 1 17:13:10 CST 2016
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/4539 )
Change subject: res_rtp: Fix regression when IPv6 is not available.
......................................................................
res_rtp: Fix regression when IPv6 is not available.
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
---
M include/asterisk/utils.h
M main/utils.c
M res/res_pjsip_sdp_rtp.c
M res/res_pjsip_t38.c
4 files changed, 33 insertions(+), 2 deletions(-)
Approvals:
Anonymous Coward #1000019: Verified
Joshua Colp: Looks good to me, approved
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index a504a5d..4a5dbf2 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -1127,4 +1127,13 @@
*/
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 */
diff --git a/main/utils.c b/main/utils.c
index 3dfc02c..1ca77ce 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2420,6 +2420,18 @@
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)
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 24d852c..8afa75d 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -52,6 +52,7 @@
#include "asterisk/sdp_srtp.h"
#include "asterisk/dsp.h"
#include "asterisk/linkedlists.h" /* for AST_LIST_NEXT */
+#include "asterisk/utils.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
@@ -1511,7 +1512,11 @@
{
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");
diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c
index b052cc4..f60f0ef 100644
--- a/res/res_pjsip_t38.c
+++ b/res/res_pjsip_t38.c
@@ -44,6 +44,7 @@
#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 @@
{
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");
--
To view, visit https://gerrit.asterisk.org/4539
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I627a4e91795e821111e1cda523f083a40d0e0c3e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Guido Falsi <madpilot at freebsd.org>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
More information about the asterisk-code-review
mailing list