[PATCH] osmo-mgw[master]: mgcp: make domain name configurable

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/.

dexter gerrit-no-reply at lists.osmocom.org
Thu Jan 18 17:32:27 UTC 2018


Review at  https://gerrit.osmocom.org/5878

mgcp: make domain name configurable

At the moment the MGW has a fixed domain name string that is not even
checked properly.

- Make domain name configurable, use the current "mgw" string as
  defualt to maintain compatibility

- Check the domain name with each request. If the endpoint contains
  an unexpected domain name, the request must be rejected.

Change-Id: Ia91ac428ba83ac1f9b52a0ec8dbf00ef7876da9e
---
M include/osmocom/mgcp/mgcp.h
M src/libosmo-mgcp/mgcp_msg.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
M tests/mgcp/mgcp_test.ok
6 files changed, 50 insertions(+), 14 deletions(-)


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

diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index d6397d3..0d156c6 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -212,6 +212,8 @@
 	 * message.
 	 */
 	uint16_t osmux_dummy;
+	/* domain name of the media gateway */
+	char domain[255+1];
 };
 
 /* config management */
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 45195de..74acffa 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -181,6 +181,22 @@
 	return &tcfg->endpoints[endp];
 }
 
+/* Check if the domain name, which is supplied with the endpoint name
+ * matches the configuration. */
+static int check_domain_name(struct mgcp_config *cfg, const char *mgcp)
+{
+	char *domain_to_check;
+
+	domain_to_check = strstr(mgcp, "@");
+	if (!domain_to_check)
+		return -EINVAL;
+
+	if (strcmp(domain_to_check+1, cfg->domain) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
 /* Search the endpoint pool for the endpoint that had been selected via the
  * MGCP message (helper function for mgcp_analyze_header()) */
 static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg,
@@ -189,6 +205,11 @@
 	char *endptr = NULL;
 	unsigned int gw = INT_MAX;
 
+	if (check_domain_name(cfg, mgcp)) {
+		LOGP(DLMGCP, LOGL_ERROR, "Wrong domain name '%s'\n", mgcp);
+		return NULL;
+	}
+
 	if (strncmp(mgcp, "ds/e1", 5) == 0)
 		return find_e1_endpoint(cfg, mgcp);
 
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 9d79343..9c21d38 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -1072,6 +1072,8 @@
 		return NULL;
 	}
 
+	osmo_strlcpy(cfg->domain, "mgw", sizeof(cfg->domain));
+
 	cfg->net_ports.range_start = RTP_PORT_DEFAULT_RANGE_START;
 	cfg->net_ports.range_end = RTP_PORT_DEFAULT_RANGE_END;
 	cfg->net_ports.last_port = cfg->net_ports.range_start;
@@ -1208,13 +1210,14 @@
  *  \returns 0 on success, -1 on error */
 int mgcp_send_reset_all(struct mgcp_config *cfg)
 {
+	char buf[MGCP_ENDPOINT_MAXLEN + 128];
+	int len;
 	int rc;
 
-	static const char mgcp_reset[] = {
-		"RSIP 1 *@mgw MGCP 1.0\r\n"
-	};
+	len = snprintf(buf, sizeof(buf),
+		       "RSIP 1 *@%s MGCP 1.0\r\n", cfg->domain);
 
-	rc = send_agent(cfg, mgcp_reset, sizeof mgcp_reset - 1);
+	rc = send_agent(cfg, buf, len);
 	if (rc <= 0)
 		return -1;
 
@@ -1228,12 +1231,12 @@
  *  \returns 0 on success, -1 on error */
 int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint)
 {
-	char buf[128];
+	char buf[MGCP_ENDPOINT_MAXLEN + 128];
 	int len;
 	int rc;
 
 	len = snprintf(buf, sizeof(buf),
-		       "RSIP 39 %x at mgw MGCP 1.0\r\n", endpoint);
+		       "RSIP 39 %x@%s MGCP 1.0\r\n", endpoint, endp->cfg->domain);
 	if (len < 0)
 		return -1;
 
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 7fa3949..7043527 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -63,6 +63,7 @@
 static int config_write_mgcp(struct vty *vty)
 {
 	vty_out(vty, "mgcp%s", VTY_NEWLINE);
+	vty_out(vty, "  domain %s%s", g_cfg->domain, VTY_NEWLINE);
 	if (g_cfg->local_ip)
 		vty_out(vty, "  local ip %s%s", g_cfg->local_ip, VTY_NEWLINE);
 	vty_out(vty, "  bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
@@ -1179,6 +1180,14 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_mgcp_domain,
+      cfg_mgcp_domain_cmd,
+      "domain NAME", "domain\n" "qualified domain name\n")
+{
+	osmo_strlcpy(g_cfg->domain, argv[0], sizeof(g_cfg->domain));
+	return CMD_SUCCESS;
+}
+
 int mgcp_vty_init(void)
 {
 	install_element_ve(&show_mgcp_cmd);
@@ -1240,6 +1249,7 @@
 	install_element(MGCP_NODE, &cfg_mgcp_osmux_dummy_cmd);
 	install_element(MGCP_NODE, &cfg_mgcp_allow_transcoding_cmd);
 	install_element(MGCP_NODE, &cfg_mgcp_no_allow_transcoding_cmd);
+	install_element(MGCP_NODE, &cfg_mgcp_domain_cmd);
 
 	install_element(MGCP_NODE, &cfg_mgcp_trunk_cmd);
 	install_node(&trunk_node, config_write_trunk);
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 46fd69b..467cb6c 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -66,18 +66,18 @@
 	OSMO_ASSERT(counter == EXPECTED_NUMBER_OF_LINES);
 }
 
-#define AUEP1	"AUEP 158663169 ds/e1-1/2 at 172.16.6.66 MGCP 1.0\r\n"
+#define AUEP1	"AUEP 158663169 ds/e1-1/2 at mgw MGCP 1.0\r\n"
 #define AUEP1_RET "200 158663169 OK\r\n"
-#define AUEP2	"AUEP 18983213 ds/e1-2/1 at 172.16.6.66 MGCP 1.0\r\n"
+#define AUEP2	"AUEP 18983213 ds/e1-2/1 at mgw MGCP 1.0\r\n"
 #define AUEP2_RET "500 18983213 FAIL\r\n"
 #define EMPTY	"\r\n"
 #define EMPTY_RET NULL
 #define SHORT	"CRCX \r\n"
 #define SHORT_RET "510 000000 FAIL\r\n"
 
-#define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1 at 172.16.6.66 MGCP 1.0\r\n"
+#define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1 at mgw MGCP 1.0\r\n"
 #define MDCX_ERR_RET "500 18983213 FAIL\r\n"
-#define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2 at 172.16.6.66 MGCP 1.0\r\n"
+#define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2 at mgw MGCP 1.0\r\n"
 #define MDCX_RET "400 18983214 FAIL\r\n"
 
 #define MDCX3 \
diff --git a/tests/mgcp/mgcp_test.ok b/tests/mgcp/mgcp_test.ok
index 23f0658..09ad9e1 100644
--- a/tests/mgcp/mgcp_test.ok
+++ b/tests/mgcp/mgcp_test.ok
@@ -16,7 +16,7 @@
 Testing AUEP1
 creating message from statically defined input:
 ---------8<---------
-AUEP 158663169 ds/e1-1/2 at 172.16.6.66 MGCP 1.0
+AUEP 158663169 ds/e1-1/2 at mgw MGCP 1.0
 
 ---------8<---------
 checking response:
@@ -28,7 +28,7 @@
 Testing AUEP2
 creating message from statically defined input:
 ---------8<---------
-AUEP 18983213 ds/e1-2/1 at 172.16.6.66 MGCP 1.0
+AUEP 18983213 ds/e1-2/1 at mgw MGCP 1.0
 
 ---------8<---------
 checking response:
@@ -40,7 +40,7 @@
 Testing MDCX1
 creating message from statically defined input:
 ---------8<---------
-MDCX 18983213 ds/e1-3/1 at 172.16.6.66 MGCP 1.0
+MDCX 18983213 ds/e1-3/1 at mgw MGCP 1.0
 
 ---------8<---------
 checking response:
@@ -52,7 +52,7 @@
 Testing MDCX2
 creating message from statically defined input:
 ---------8<---------
-MDCX 18983214 ds/e1-1/2 at 172.16.6.66 MGCP 1.0
+MDCX 18983214 ds/e1-1/2 at mgw MGCP 1.0
 
 ---------8<---------
 checking response:

-- 
To view, visit https://gerrit.osmocom.org/5878
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia91ac428ba83ac1f9b52a0ec8dbf00ef7876da9e
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>



More information about the gerrit-log mailing list