[Asterisk-code-review] res pjsip transport websocket: Add support for IPv6. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Tue Mar 7 11:02:12 CST 2017


Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/5136 )

Change subject: res_pjsip_transport_websocket: Add support for IPv6.
......................................................................

res_pjsip_transport_websocket: Add support for IPv6.

This change adds a PJSIP patch (which has been contributed upstream)
to allow the registration of IPv6 transport types.

Using this the res_pjsip_transport_websocket module now registers
an IPv6 Websocket transport and uses it for the corresponding
traffic.

ASTERISK-26685

Change-Id: Id1f9126f995b31dc38db8fdb58afd289b4ad1647
---
M res/res_pjsip_transport_websocket.c
A third-party/pjproject/patches/0014-Add-pjsip-transport-register-type-ipv6.patch
2 files changed, 80 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/36/5136/1

diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index a52b42d..b3e63fc 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -39,6 +39,7 @@
 #include "asterisk/taskprocessor.h"
 
 static int transport_type_wss;
+static int transport_type_wss_ipv6;
 
 /*!
  * \brief Wrapper for pjsip_transport, for storing the WebSocket session
@@ -198,15 +199,20 @@
 		newtransport->transport.type_name, ws_addr_str);
 
 	pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, ws_addr_str), &newtransport->transport.key.rem_addr);
-	newtransport->transport.key.rem_addr.addr.sa_family = pj_AF_INET();
-	newtransport->transport.key.type = transport_type_wss;
+	if (newtransport->transport.key.rem_addr.addr.sa_family == pj_AF_INET6()) {
+		newtransport->transport.key.type = transport_type_wss_ipv6;
+		newtransport->transport.local_name.host.ptr = (char *)pj_pool_alloc(pool, PJ_INET6_ADDRSTRLEN);
+		pj_sockaddr_print(&newtransport->transport.key.rem_addr, newtransport->transport.local_name.host.ptr, PJ_INET6_ADDRSTRLEN, 0);
+	} else {
+		newtransport->transport.key.type = transport_type_wss;
+		newtransport->transport.local_name.host.ptr = (char *)pj_pool_alloc(pool, PJ_INET_ADDRSTRLEN);
+		pj_sockaddr_print(&newtransport->transport.key.rem_addr, newtransport->transport.local_name.host.ptr, PJ_INET_ADDRSTRLEN, 0);
+	}
 
 	newtransport->transport.addr_len = pj_sockaddr_get_len(&newtransport->transport.key.rem_addr);
 
 	pj_sockaddr_cp(&newtransport->transport.local_addr, &newtransport->transport.key.rem_addr);
 
-	newtransport->transport.local_name.host.ptr = (char *)pj_pool_alloc(pool, newtransport->transport.addr_len+4);
-	pj_sockaddr_print(&newtransport->transport.key.rem_addr, newtransport->transport.local_name.host.ptr, newtransport->transport.addr_len+4, 0);
 	newtransport->transport.local_name.host.slen = pj_ansi_strlen(newtransport->transport.local_name.host.ptr);
 	newtransport->transport.local_name.port = pj_sockaddr_get_port(&newtransport->transport.key.rem_addr);
 
@@ -271,8 +277,6 @@
 	rdata->pkt_info.zero = 0;
 
 	pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, ast_sockaddr_stringify(ast_websocket_remote_address(session))), &rdata->pkt_info.src_addr);
-	rdata->pkt_info.src_addr.addr.sa_family = pj_AF_INET();
-
 	rdata->pkt_info.src_addr_len = sizeof(rdata->pkt_info.src_addr);
 
 	pj_ansi_strcpy(rdata->pkt_info.src_name, ast_sockaddr_stringify_host(ast_websocket_remote_address(session)));
@@ -395,7 +399,7 @@
 
 	long type = rdata->tp_info.transport->key.type;
 
-	if (type != (long) transport_type_wss) {
+	if (type != (long) transport_type_wss && type != (long) transport_type_wss_ipv6) {
 		return PJ_FALSE;
 	}
 
@@ -451,15 +455,17 @@
 	CHECK_PJSIP_MODULE_LOADED();
 
 	/*
-	 * We only need one transport type defined.  Firefox and Chrome
-	 * do not support anything other than secure websockets anymore.
+	 * We only need one transport type name (ws) defined.  Firefox
+	 * and Chrome do not support anything other than secure websockets
+	 * anymore.
 	 *
 	 * Also we really cannot have two transports with the same name
-	 * because it would be ambiguous.  Outgoing requests may try to
-	 * find the transport by name and pjproject only finds the first
-	 * one registered.
+	 * and address family because it would be ambiguous.  Outgoing
+	 * requests may try to find the transport by name and pjproject
+	 * only finds the first one registered.
 	 */
 	pjsip_transport_register_type(PJSIP_TRANSPORT_RELIABLE | PJSIP_TRANSPORT_SECURE, "ws", 5060, &transport_type_wss);
+	pjsip_transport_register_type(PJSIP_TRANSPORT_RELIABLE | PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_IPV6, "ws", 5060, &transport_type_wss_ipv6);
 
 	if (ast_sip_register_service(&websocket_module) != PJ_SUCCESS) {
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/third-party/pjproject/patches/0014-Add-pjsip-transport-register-type-ipv6.patch b/third-party/pjproject/patches/0014-Add-pjsip-transport-register-type-ipv6.patch
new file mode 100644
index 0000000..880331e
--- /dev/null
+++ b/third-party/pjproject/patches/0014-Add-pjsip-transport-register-type-ipv6.patch
@@ -0,0 +1,62 @@
+From 35e4cc04a5cbed4aa7657bf482052ac437b79ad1 Mon Sep 17 00:00:00 2001
+From: Joshua Colp <jcolp at digium.com>
+Date: Tue, 7 Mar 2017 12:32:49 +0000
+Subject: [PATCH] Add support for registering IPv6 transport type.
+
+This change allows an IPv6 transport type to be registered
+and used. This does require that the IPv4 transport immediately
+preceed the IPv6 transport, but
+
+The IPv4 transport is found (if available) and the
+IPv4 flag added to its type to match how the finding of
+IPv6 transport types works.
+---
+ pjsip/src/pjsip/sip_transport.c | 12 ++++++++++--
+ 1 file changed, 10 insertions(+), 2 deletions(-)
+
+diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
+index 7df6138..0211509 100644
+--- a/pjsip/src/pjsip/sip_transport.c
++++ b/pjsip/src/pjsip/sip_transport.c
+@@ -236,6 +236,7 @@ PJ_DEF(pj_status_t) pjsip_transport_register_type( unsigned tp_flag,
+ 						   int *p_tp_type)
+ {
+     unsigned i;
++    pjsip_transport_type_e parent = 0;
+ 
+     PJ_ASSERT_RETURN(tp_flag && tp_name && def_port, PJ_EINVAL);
+     PJ_ASSERT_RETURN(pj_ansi_strlen(tp_name) <
+@@ -243,6 +244,8 @@ PJ_DEF(pj_status_t) pjsip_transport_register_type( unsigned tp_flag,
+ 		     PJ_ENAMETOOLONG);
+ 
+     for (i=1; i<PJ_ARRAY_SIZE(transport_names); ++i) {
++        if (tp_flag & PJSIP_TRANSPORT_IPV6 && pj_stricmp2(&transport_names[i].name, tp_name) == 0)
++	    parent = transport_names[i].type;
+ 	if (transport_names[i].type == 0)
+ 	    break;
+     }
+@@ -250,14 +253,19 @@ PJ_DEF(pj_status_t) pjsip_transport_register_type( unsigned tp_flag,
+     if (i == PJ_ARRAY_SIZE(transport_names))
+ 	return PJ_ETOOMANY;
+ 
+-    transport_names[i].type = (pjsip_transport_type_e)i;
++    if (tp_flag & PJSIP_TRANSPORT_IPV6 && parent) {
++        transport_names[i].type = parent | PJSIP_TRANSPORT_IPV6;
++    } else {
++        transport_names[i].type = (pjsip_transport_type_e)i;
++    }
++
+     transport_names[i].port = (pj_uint16_t)def_port;
+     pj_ansi_strcpy(transport_names[i].name_buf, tp_name);
+     transport_names[i].name = pj_str(transport_names[i].name_buf);
+     transport_names[i].flag = tp_flag;
+ 
+     if (p_tp_type)
+-	*p_tp_type = i;
++	*p_tp_type = transport_names[i].type;
+ 
+     return PJ_SUCCESS;
+ }
+-- 
+2.7.4
+

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1f9126f995b31dc38db8fdb58afd289b4ad1647
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list