forked from opnsense/ports
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/asterisk13: partially sync with upstream
Taken from: FreeBSD
- Loading branch information
Showing
4 changed files
with
133 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
$OpenBSD: patch-res_res_rtp_asterisk_c,v 1.1 2016/07/30 21:12:15 sthen Exp $ | ||
|
||
Obtained from OpenBSD cvs | ||
|
||
--- res/res_rtp_asterisk.c.orig 2016-07-21 14:54:02 UTC | ||
--- res/res_rtp_asterisk.c.orig 2016-11-23 15:26:01 UTC | ||
+++ res/res_rtp_asterisk.c | ||
@@ -1357,7 +1357,7 @@ static int ast_rtp_dtls_set_configuratio | ||
return 0; | ||
@@ -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 | ||
} | ||
|
||
-#if OPENSSL_VERSION_NUMBER < 0x10002000L | ||
+#if OPENSSL_VERSION_NUMBER < 0x10002000L || defined(LIBRESSL_VERSION_NUMBER) | ||
rtp->ssl_ctx = SSL_CTX_new(DTLSv1_method()); | ||
#else | ||
rtp->ssl_ctx = SSL_CTX_new(DTLS_method()); | ||
/* 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; | ||
} |