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
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..5f1a734 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,16 @@
* \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);
+ if (len < 0)
+ return -1;
- rc = send_agent(cfg, mgcp_reset, sizeof mgcp_reset - 1);
+ rc = send_agent(cfg, buf, len);
if (rc <= 0)
return -1;
@@ -1228,12 +1233,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@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@172.16.6.66 MGCP 1.0\r\n"
+#define AUEP1 "AUEP 158663169 ds/e1-1/2@mgw MGCP 1.0\r\n"
#define AUEP1_RET "200 158663169 OK\r\n"
-#define AUEP2 "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n"
+#define AUEP2 "AUEP 18983213 ds/e1-2/1@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@172.16.6.66 MGCP 1.0\r\n"
+#define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1@mgw MGCP 1.0\r\n"
#define MDCX_ERR_RET "500 18983213 FAIL\r\n"
-#define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n"
+#define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2@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
Binary files differ