diff --git a/net/asterisk13/Makefile b/net/asterisk13/Makefile index eeb0f2c8e6fc..b30d732f825b 100644 --- a/net/asterisk13/Makefile +++ b/net/asterisk13/Makefile @@ -2,6 +2,7 @@ PORTNAME= asterisk PORTVERSION= 13.13.0 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= http://downloads.asterisk.org/pub/telephony/%SUBDIR%/:DEFAULT,g729 MASTER_SITE_SUBDIR= asterisk/ \ diff --git a/net/asterisk13/files/patch-include_asterisk_utils.h b/net/asterisk13/files/patch-include_asterisk_utils.h new file mode 100644 index 000000000000..ea372d7f2425 --- /dev/null +++ b/net/asterisk13/files/patch-include_asterisk_utils.h @@ -0,0 +1,16 @@ +--- include/asterisk/utils.h.orig 2016-11-23 15:26:01 UTC ++++ include/asterisk/utils.h +@@ -1127,4 +1127,13 @@ int ast_file_is_readable(const char *fil + */ + 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/net/asterisk13/files/patch-main_udptl.c b/net/asterisk13/files/patch-main_udptl.c deleted file mode 100644 index aa904afea110..000000000000 --- a/net/asterisk13/files/patch-main_udptl.c +++ /dev/null @@ -1,65 +0,0 @@ ---- main/udptl.c.orig 2016-11-23 15:26:01 UTC -+++ main/udptl.c -@@ -1016,6 +1016,9 @@ struct ast_udptl *ast_udptl_new_with_bin - int i; - long int flags; - RAII_VAR(struct udptl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); -+#if defined(__FreeBSD__) -+ int portretryipv4 = 1; -+#endif - - if (!cfg || !cfg->general) { - ast_log(LOG_ERROR, "Could not access global udptl options!\n"); -@@ -1039,8 +1042,18 @@ struct ast_udptl *ast_udptl_new_with_bin - udptl->tx[i].buf_len = -1; - } - -- if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ? -- AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) { -+#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); -+ portretryipv4 = 0; -+ } -+#else -+ udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ? -+ AF_INET6 : AF_INET, SOCK_DGRAM, 0); -+#endif -+ if (udptl->fd < 0) { - ast_free(udptl); - ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno)); - return NULL; -@@ -1079,8 +1092,30 @@ struct ast_udptl *ast_udptl_new_with_bin - if (x > cfg->general->end) - x = cfg->general->start; - if (x == startplace) { -+#if defined(__FreeBSD__) -+ /* Try again with IPv4 if not IPv6 port could be found */ -+ if (portretryipv4 == 1) { -+ close(udptl->fd); -+ ast_sockaddr_parse(addr, "0.0.0.0", 0); -+ udptl->fd = socket(AF_INET, SOCK_DGRAM, 0); -+ if (udptl->fd >= 0) { -+ flags = fcntl(udptl->fd, F_GETFL); -+ fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK); -+ /* Reset the RTP port search parameters */ -+ x = (cfg->general->start == cfg->general->end) ? cfg->general->start : (ast_random() % (cfg->general->end - cfg->general->start)) + cfg->general->start; -+ if (cfg->general->use_even_ports && (x & 1)) { -+ ++x; -+ } -+ startplace = x; -+ portretryipv4 = 0; -+ continue; -+ } -+ } -+#endif - ast_log(LOG_WARNING, "No UDPTL ports remaining\n"); -- close(udptl->fd); -+ if (udptl->fd >= 0) { -+ close(udptl->fd); -+ } - ast_free(udptl); - return NULL; - } diff --git a/net/asterisk13/files/patch-main_utils.c b/net/asterisk13/files/patch-main_utils.c new file mode 100644 index 000000000000..0be8c40bff87 --- /dev/null +++ b/net/asterisk13/files/patch-main_utils.c @@ -0,0 +1,21 @@ +--- main/utils.c.orig 2016-11-23 15:26:01 UTC ++++ main/utils.c +@@ -2425,6 +2425,18 @@ char *ast_utils_which(const char *binary + 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/net/asterisk13/files/patch-res_res__pjsip__sdp__rtp.c b/net/asterisk13/files/patch-res_res__pjsip__sdp__rtp.c new file mode 100644 index 000000000000..88ee0dac606e --- /dev/null +++ b/net/asterisk13/files/patch-res_res__pjsip__sdp__rtp.c @@ -0,0 +1,23 @@ +--- res/res_pjsip_sdp_rtp.c.orig 2016-11-23 15:26:01 UTC ++++ res/res_pjsip_sdp_rtp.c +@@ -51,6 +51,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revisi + #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"); diff --git a/net/asterisk13/files/patch-res_res__pjsip__t38.c b/net/asterisk13/files/patch-res_res__pjsip__t38.c new file mode 100644 index 000000000000..543337212377 --- /dev/null +++ b/net/asterisk13/files/patch-res_res__pjsip__t38.c @@ -0,0 +1,23 @@ +--- res/res_pjsip_t38.c.orig 2016-11-23 15:26:01 UTC ++++ res/res_pjsip_t38.c +@@ -44,6 +44,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revisi + #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"); diff --git a/net/asterisk13/files/patch-res_res__rtp__asterisk.c b/net/asterisk13/files/patch-res_res__rtp__asterisk.c deleted file mode 100644 index cbc432f27217..000000000000 --- a/net/asterisk13/files/patch-res_res__rtp__asterisk.c +++ /dev/null @@ -1,65 +0,0 @@ ---- res/res_rtp_asterisk.c.orig 2016-11-23 15:26:01 UTC -+++ res/res_rtp_asterisk.c -@@ -2638,6 +2638,9 @@ static int ast_rtp_new(struct ast_rtp_in - { - struct ast_rtp *rtp = NULL; - int x, startplace; -+#if defined(__FreeBSD__) -+ int portretryipv4 = 1; -+#endif - - /* Create a new RTP structure to hold all of our data */ - if (!(rtp = ast_calloc(1, sizeof(*rtp)))) { -@@ -2658,10 +2661,20 @@ static int ast_rtp_new(struct ast_rtp_in - } - - /* Create a new socket for us to listen on and use */ -- if ((rtp->s = -- create_new_socket("RTP", -- ast_sockaddr_is_ipv4(addr) ? AF_INET : -- ast_sockaddr_is_ipv6(addr) ? AF_INET6 : -1)) < 0) { -+#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); -+ portretryipv4 = 0; -+ } -+#else -+ rtp->s = create_new_socket("RTP", -+ ast_sockaddr_is_ipv4(addr) ? AF_INET : -+ ast_sockaddr_is_ipv6(addr) ? AF_INET6 : -1); -+#endif -+ if (rtp->s < 0) { - ast_log(LOG_WARNING, "Failed to create a new socket for RTP instance '%p'\n", instance); - ast_free(rtp); - return -1; -@@ -2688,8 +2701,26 @@ static int ast_rtp_new(struct ast_rtp_in - - /* See if we ran out of ports or if the bind actually failed because of something other than the address being in use */ - if (x == startplace || (errno != EADDRINUSE && errno != EACCES)) { -+#if defined(__FreeBSD__) -+ /* Try again with IPv4 if not IPv6 port could be found */ -+ if (portretryipv4 == 1) { -+ close(rtp->s); -+ ast_sockaddr_parse(addr, "0.0.0.0", 0); -+ rtp->s = create_new_socket("RTP", AF_INET); -+ if (rtp->s >= 0) { -+ /* Reset the RTP port search parameters */ -+ x = (rtpend == rtpstart) ? rtpstart : (ast_random() % (rtpend - rtpstart)) + rtpstart; -+ x = x & ~1; -+ startplace = x; -+ portretryipv4 = 0; -+ continue; -+ } -+ } -+#endif - ast_log(LOG_ERROR, "Oh dear... we couldn't allocate a port for RTP instance '%p'\n", instance); -- close(rtp->s); -+ if (rtp->s >= 0) { -+ close(rtp->s); -+ } - ast_free(rtp); - return -1; - }