[Asterisk-code-review] res rtp: Fix regression observed in FreeBSD when IPv6 is not... (asterisk[master])

Guido Falsi asteriskteam at digium.com
Tue Nov 22 11:28:23 CST 2016


Guido Falsi has uploaded a new change for review. ( https://gerrit.asterisk.org/4487 )

Change subject: res_rtp: Fix regression observed in FreeBSD when IPv6 is not available
......................................................................

res_rtp: Fix regression observed in FreeBSD when IPv6 is not available

As reported in ASTERISK-26617 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, at least on FreeBSD. This patch add some code (wrapped
in @ifdefs) to reallocate the ast_sockaddr structure on the fly
with an AF_INET family, allowing it to work correctly when creating
the cosket with the passed structure fails.

Change-Id: I627a4e91795e821111e1cda523f083a40d0e0c3e
---
M main/udptl.c
M res/res_rtp_asterisk.c
2 files changed, 19 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/87/4487/1

diff --git a/main/udptl.c b/main/udptl.c
index 853e43c..ff8781a 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -1037,8 +1037,17 @@
 		udptl->tx[i].buf_len = -1;
 	}
 
+#if defined(__FreeBSD__)
+	udptl->fd = socket(AF_INET6, SOCK_DGRAM, 0);
+	if(udptl->fd < 0) {
+		ast_sockaddr_parse(addr, "0.0.0.0", 0);
+		udptl->fd = socket(AF_INET, SOCK_DGRAM, 0);
+	}
+	if(udptl->fd < 0) {
+#else
 	if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ?
 					AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
+#endif
 		ast_free(udptl);
 		ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
 		return NULL;
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index a882033..a534b65 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -2656,10 +2656,20 @@
 	}
 
 	/* Create a new socket for us to listen on and use */
+#if defined(__FreeBSD__)
+	rtp->s = create_new_socket("RTP", AF_INET6);
+	if(rtp->s < 0) {
+		/* create correct addr structure for AF_INET */
+		ast_sockaddr_parse(addr, "0.0.0.0", 0);
+		rtp->s = create_new_socket("RTP", AF_INET);
+	}
+	if(rtp->s < 0) {
+#else
 	if ((rtp->s =
 	     create_new_socket("RTP",
 			       ast_sockaddr_is_ipv4(addr) ? AF_INET  :
 			       ast_sockaddr_is_ipv6(addr) ? AF_INET6 : -1)) < 0) {
+#endif
 		ast_log(LOG_WARNING, "Failed to create a new socket for RTP instance '%p'\n", instance);
 		ast_free(rtp);
 		return -1;

-- 
To view, visit https://gerrit.asterisk.org/4487
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I627a4e91795e821111e1cda523f083a40d0e0c3e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Guido Falsi <madpilot at freebsd.org>



More information about the asterisk-code-review mailing list