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
This commit is contained in:
parent
6efb43a210
commit
12943ea0c1
|
@ -212,6 +212,8 @@ struct mgcp_config {
|
|||
* message.
|
||||
*/
|
||||
uint16_t osmux_dummy;
|
||||
/* domain name of the media gateway */
|
||||
char domain[255+1];
|
||||
};
|
||||
|
||||
/* config management */
|
||||
|
|
|
@ -181,6 +181,22 @@ static struct mgcp_endpoint *find_e1_endpoint(struct mgcp_config *cfg,
|
|||
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 @@ static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg,
|
|||
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);
|
||||
|
||||
|
|
|
@ -1072,6 +1072,8 @@ struct mgcp_config *mgcp_config_alloc(void)
|
|||
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 @@ static int send_agent(struct mgcp_config *cfg, const char *buf, int len)
|
|||
* \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 @@ int mgcp_send_reset_all(struct mgcp_config *cfg)
|
|||
* \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;
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ struct cmd_node trunk_node = {
|
|||
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 @@ DEFUN(cfg_mgcp_osmux_dummy,
|
|||
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 @@ int mgcp_vty_init(void)
|
|||
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);
|
||||
|
|
|
@ -66,18 +66,18 @@ static void test_strline(void)
|
|||
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 \
|
||||
|
|
|
@ -16,7 +16,7 @@ line: ''
|
|||
Testing AUEP1
|
||||
creating message from statically defined input:
|
||||
---------8<---------
|
||||
AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0
|
||||
AUEP 158663169 ds/e1-1/2@mgw MGCP 1.0
|
||||
|
||||
---------8<---------
|
||||
checking response:
|
||||
|
@ -28,7 +28,7 @@ Response matches our expectations.
|
|||
Testing AUEP2
|
||||
creating message from statically defined input:
|
||||
---------8<---------
|
||||
AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0
|
||||
AUEP 18983213 ds/e1-2/1@mgw MGCP 1.0
|
||||
|
||||
---------8<---------
|
||||
checking response:
|
||||
|
@ -40,7 +40,7 @@ Response matches our expectations.
|
|||
Testing MDCX1
|
||||
creating message from statically defined input:
|
||||
---------8<---------
|
||||
MDCX 18983213 ds/e1-3/1@172.16.6.66 MGCP 1.0
|
||||
MDCX 18983213 ds/e1-3/1@mgw MGCP 1.0
|
||||
|
||||
---------8<---------
|
||||
checking response:
|
||||
|
@ -52,7 +52,7 @@ Response matches our expectations.
|
|||
Testing MDCX2
|
||||
creating message from statically defined input:
|
||||
---------8<---------
|
||||
MDCX 18983214 ds/e1-1/2@172.16.6.66 MGCP 1.0
|
||||
MDCX 18983214 ds/e1-1/2@mgw MGCP 1.0
|
||||
|
||||
---------8<---------
|
||||
checking response:
|
||||
|
|
Loading…
Reference in New Issue