Change in osmo-mgw[master]: mgcp_client: Allow submitting and parsing IPv6 addr in SDP

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Fri Aug 28 18:50:27 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/19888 )


Change subject: mgcp_client: Allow submitting and parsing IPv6 addr in SDP
......................................................................

mgcp_client: Allow submitting and parsing IPv6 addr in SDP

Existing mgcp_client_test code required the '.' to trigger the same code
path, since with this commit we do extra checks and without a dot the
address is not accepted as IPv4 by osmo_ip_str_type().

Change-Id: I936bf57d37f5f0607dfe7fc66c37e424c3793f9b
---
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
2 files changed, 33 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/88/19888/1

diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 146a59d..ae07e92 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -25,6 +25,7 @@
 #include <osmocom/core/logging.h>
 #include <osmocom/core/byteswap.h>
 #include <osmocom/core/socket.h>
+#include <osmocom/core/sockaddr_str.h>
 
 #include <osmocom/mgcp_client/mgcp_client.h>
 #include <osmocom/mgcp_client/mgcp_client_internal.h>
@@ -370,20 +371,27 @@
 /* Parse a line like "c=IN IP4 10.11.12.13" */
 static int mgcp_parse_audio_ip(struct mgcp_response *r, const char *line)
 {
-	struct in_addr ip_test;
+	struct in6_addr ip_test;
+	int family;
 
-	if (strlen(line) < 16)
+	if (strncmp("c=IN IP", line, 7) != 0)
 		goto response_parse_failure;
-
-	/* The current implementation strictly supports IPV4 only ! */
-	if (memcmp("c=IN IP4 ", line, 9) != 0)
+	line += 7;
+	if (*line != '4' && *line != '6')
 		goto response_parse_failure;
+	line++;
+	if (*line != ' ')
+		goto response_parse_failure;
+	line++;
 
 	/* Extract IP-Address */
-	osmo_strlcpy(r->audio_ip, line + 9, sizeof(r->audio_ip));
+	osmo_strlcpy(r->audio_ip, line, sizeof(r->audio_ip));
 
 	/* Check IP-Address */
-	if (inet_aton(r->audio_ip, &ip_test) == 0)
+	family = osmo_ip_str_type(r->audio_ip);
+	if (family == AF_UNSPEC)
+		goto response_parse_failure;
+	if (inet_pton(family, r->audio_ip, &ip_test) != 1)
 		goto response_parse_failure;
 
 	return 0;
@@ -1122,6 +1130,7 @@
 	unsigned int i;
 	int rc = 0;
 	char local_ip[INET6_ADDRSTRLEN];
+	int local_ip_family, audio_ip_family;
 	const char *codec;
 	unsigned int pt;
 
@@ -1138,10 +1147,21 @@
 		msgb_free(msg);
 		return -2;
 	}
+	local_ip_family = osmo_ip_str_type(local_ip);
+	if (local_ip_family == AF_UNSPEC) {
+		msgb_free(msg);
+		return -2;
+	}
+	audio_ip_family = osmo_ip_str_type(mgcp_msg->audio_ip);
+	if (audio_ip_family == AF_UNSPEC) {
+		msgb_free(msg);
+		return -2;
+	}
 
 	/* Add owner/creator (SDP) */
-	rc += msgb_printf(msg, "o=- %x 23 IN IP4 %s\r\n",
-			  mgcp_msg->call_id, local_ip);
+	rc += msgb_printf(msg, "o=- %x 23 IN IP%c %s\r\n", mgcp_msg->call_id,
+			  local_ip_family == AF_INET6 ? '6' : '4',
+			  local_ip);
 
 	/* Add session name (none) */
 	rc += msgb_printf(msg, "s=-\r\n");
@@ -1159,7 +1179,9 @@
 		msgb_free(msg);
 		return -2;
 	}
-	rc += msgb_printf(msg, "c=IN IP4 %s\r\n", mgcp_msg->audio_ip);
+	rc += msgb_printf(msg, "c=IN IP%c %s\r\n",
+			  audio_ip_family == AF_INET6 ? '6' : '4',
+			  mgcp_msg->audio_ip);
 
 	/* Add time description, active time (SDP) */
 	rc += msgb_printf(msg, "t=0 0\r\n");
diff --git a/tests/mgcp_client/mgcp_client_test.c b/tests/mgcp_client/mgcp_client_test.c
index db9f4f8..0f305b7 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -294,6 +294,7 @@
 	     MGCP_MSG_PRESENCE_CONN_ID | MGCP_MSG_PRESENCE_CONN_MODE |
 	     MGCP_MSG_PRESENCE_AUDIO_IP | MGCP_MSG_PRESENCE_AUDIO_PORT);
 	memset(audio_ip_overflow, 'X', sizeof(audio_ip_overflow));
+	audio_ip_overflow[1] = '.';
 	audio_ip_overflow[sizeof(audio_ip_overflow) - 1] = '\0';
 	mgcp_msg.audio_ip = audio_ip_overflow;
 	msg = mgcp_msg_gen(mgcp, &mgcp_msg);

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/19888
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I936bf57d37f5f0607dfe7fc66c37e424c3793f9b
Gerrit-Change-Number: 19888
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200828/8b3b7e3a/attachment.htm>


More information about the gerrit-log mailing list