[asterisk-bugs] [JIRA] (ASTERISK-29932) res_pjsip_sdp_rtp.c::create_rtp() binds to UDP6 for UDP4 peer on BSD
Justin T. Gibbs (JIRA)
noreply at issues.asterisk.org
Tue Feb 22 15:58:06 CST 2022
[ https://issues.asterisk.org/jira/browse/ASTERISK-29932?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=258127#comment-258127 ]
Justin T. Gibbs edited comment on ASTERISK-29932 at 2/22/22 3:57 PM:
---------------------------------------------------------------------
Patch for option 1:
{code}
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index d422f01794..215bc06afd 100644
--- res/res_pjsip_sdp_rtp.c.orig
+++ res/res_pjsip_sdp_rtp.c
@@ -62,8 +62,10 @@
/*! \brief Scheduler for RTCP purposes */
static struct ast_sched_context *sched;
-/*! \brief Address for RTP */
+/*! \brief Default local address for RTP (ipv4 or ipv6) */
static struct ast_sockaddr address_rtp;
+/*! \brief Default local address for ipv4 RTP endpoints */
+static struct ast_sockaddr address_rtp_ipv4;
static const char STR_AUDIO[] = "audio";
static const char STR_VIDEO[] = "video";
@@ -230,7 +232,12 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
{
struct ast_rtp_engine_ice *ice;
struct ast_sockaddr temp_media_address;
- struct ast_sockaddr *media_address = &address_rtp;
+ struct ast_sockaddr *media_address = &address_rtp;
+
+ /* If the endpoint does not support IPv6, default to binding to an IPv4 address for RTP data. */
+ if (!session->endpoint->media.rtp.ipv6) {
+ media_address = &address_rtp_ipv4;
+ }
if (session->endpoint->media.bind_rtp_to_media_address && !ast_strlen_zero(session->endpoint->media.address)) {
if (ast_sockaddr_parse(&temp_media_address, session->endpoint->media.address, 0)) {
@@ -2358,10 +2365,11 @@ static int unload_module(void)
*/
static int load_module(void)
{
+ ast_sockaddr_parse(&address_rtp_ipv4, "0.0.0.0", 0);
if (ast_check_ipv6()) {
ast_sockaddr_parse(&address_rtp, "::", 0);
} else {
- ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0);
+ ast_sockaddr_copy(&address_rtp, &address_rtp_ipv4);
}
if (!(sched = ast_sched_context_create())) {
{code}
was (Author: scsiguy):
Patch for option 1:
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index d422f01794..215bc06afd 100644
--- res/res_pjsip_sdp_rtp.c.orig
+++ res/res_pjsip_sdp_rtp.c
@@ -62,8 +62,10 @@
/*! \brief Scheduler for RTCP purposes */
static struct ast_sched_context *sched;
-/*! \brief Address for RTP */
+/*! \brief Default local address for RTP (ipv4 or ipv6) */
static struct ast_sockaddr address_rtp;
+/*! \brief Default local address for ipv4 RTP endpoints */
+static struct ast_sockaddr address_rtp_ipv4;
static const char STR_AUDIO[] = "audio";
static const char STR_VIDEO[] = "video";
@@ -230,7 +232,12 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
{
struct ast_rtp_engine_ice *ice;
struct ast_sockaddr temp_media_address;
- struct ast_sockaddr *media_address = &address_rtp;
+ struct ast_sockaddr *media_address = &address_rtp;
+
+ /* If the endpoint does not support IPv6, default to binding to an IPv4 address for RTP data. */
+ if (!session->endpoint->media.rtp.ipv6) {
+ media_address = &address_rtp_ipv4;
+ }
if (session->endpoint->media.bind_rtp_to_media_address && !ast_strlen_zero(session->endpoint->media.address)) {
if (ast_sockaddr_parse(&temp_media_address, session->endpoint->media.address, 0)) {
@@ -2358,10 +2365,11 @@ static int unload_module(void)
*/
static int load_module(void)
{
+ ast_sockaddr_parse(&address_rtp_ipv4, "0.0.0.0", 0);
if (ast_check_ipv6()) {
ast_sockaddr_parse(&address_rtp, "::", 0);
} else {
- ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0);
+ ast_sockaddr_copy(&address_rtp, &address_rtp_ipv4);
}
if (!(sched = ast_sched_context_create())) {
> res_pjsip_sdp_rtp.c::create_rtp() binds to UDP6 for UDP4 peer on BSD
> --------------------------------------------------------------------
>
> Key: ASTERISK-29932
> URL: https://issues.asterisk.org/jira/browse/ASTERISK-29932
> Project: Asterisk
> Issue Type: Bug
> Security Level: None
> Components: Channels/chan_pjsip
> Affects Versions: 18.9.0
> Environment: FreeBSD 13.0-STABLE + Asterisk 18.10 + pjsip 2.11
> IPv6 kernel support enabled, but no IPv6 configured interfaces
> Reporter: Justin T. Gibbs
> Severity: Major
>
> First reported here (https://community.asterisk.org/t/pjsip-create-rtp-udp6-vs-udp4/83315). Pandemic intervened. Now I'm hoping to get to an acceptable solution that can be upstreamed into Asterisk.
> On most BSD derived systems (iOS/MacOS, Free/Net/OpenBSD, etc.), IPv4 traffic is not routed to IPv6 sockets even when bound to the IPv6 wildcard address. Information about this policy is documented here (https://www.freebsd.org/cgi/man.cgi?query=inet6&sektion=4). This differs from the behavior of the Linux kernel.
> PJSIP support current assumes that a wildcard bind will work for both IPv4 and IPv6 peers. This is incompatible with BSD systems.
> There are two options to solving this:
> 1) Bind to the IPv4 wildcard address unless the media endpoint has an ipv6 address.
> 2) Bind and poll sockets for the wildcard address for both IPv4 and IPv6.
> The attached patch does 1 and works for me. From the discussion in the community forum, there was some concern that doing so would break ICE. It's not clear to me that this is the case. It seems strange that an end-point exporting an IPv4 address would be proxied via IPv6. However, if this is allowed, I'm happy to implement option 2.
> If the decision is to go with option 2, I'm looking for some guidance on the best/idiomatic way to do this in Asterisk. I don't believe there are any other cases where a single virtual channel binds multiple sockets. Adding this into the existing pjsip code looks like it will require a pretty extensive change. This is why I'd like to understand the preferred approach before I dig into implementing this.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
More information about the asterisk-bugs
mailing list