mgcp: add prefix to virtual trunk
the virtual trunk is addressed without a prefix (just *@domain).
- reorganize find_endpoint() so that it accepts a prefix when
addressing the virtual trunk.
- do no longer accept wildcarded CRCX requests without prefix
(will not break anything, the feature of wildcarded CRCX is
not in use yet)
- keep the old prefix-less method but print a warning that it is
depreacted.
Change-Id: I2aac3ba0f1f3122dfbb3bf36f74198ecb2b21de5
diff --git a/include/osmocom/mgcp/mgcp_common.h b/include/osmocom/mgcp/mgcp_common.h
index 7684936..7aa5d3f 100644
--- a/include/osmocom/mgcp/mgcp_common.h
+++ b/include/osmocom/mgcp/mgcp_common.h
@@ -76,4 +76,7 @@
/ (see also RFC3435 section 3.2.1.3) */
#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+/* A prefix to denote the virtual trunk (RTP on both ends) */
+#define MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK "rtpbridge/"
+
#endif
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 9bb2805..3aa93b7 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -228,20 +228,38 @@
{
char *endptr = NULL;
unsigned int gw = INT_MAX;
+ const char *endpoint_number_str;
+ /* Check if the domainname in the request is correct */
if (check_domain_name(cfg, mgcp)) {
LOGP(DLMGCP, LOGL_ERROR, "Wrong domain name '%s'\n", mgcp);
return NULL;
}
+ /* Check if the E1 trunk is requested */
if (strncmp(mgcp, "ds/e1", 5) == 0)
return find_e1_endpoint(cfg, mgcp);
- if (strncmp(mgcp, "*", 1) == 0) {
- return find_free_endpoint(cfg->trunk.endpoints,
- cfg->trunk.number_endpoints);
+ /* Check if the virtual trunk is addressed (new, correct way with prefix) */
+ if (strncmp
+ (mgcp, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK,
+ strlen(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK)) == 0) {
+ endpoint_number_str =
+ mgcp + strlen(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK);
+ if (endpoint_number_str[0] == '*') {
+ return find_free_endpoint(cfg->trunk.endpoints,
+ cfg->trunk.number_endpoints);
+ }
+
+ gw = strtoul(endpoint_number_str, &endptr, 16);
+ if (gw < cfg->trunk.number_endpoints && endptr[0] == '@')
+ return &cfg->trunk.endpoints[gw];
}
+ /* Deprecated method without prefix */
+ LOGP(DLMGCP, LOGL_NOTICE,
+ "Addressing virtual trunk without prefix (deprecated), please use %s: '%s'\n",
+ MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, mgcp);
gw = strtoul(mgcp, &endptr, 16);
if (gw < cfg->trunk.number_endpoints && endptr[0] == '@')
return &cfg->trunk.endpoints[gw];
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 16e9cb8..daedc8d 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -198,9 +198,12 @@
{
int rc;
- if (endp->wildcarded_crcx) {
- rc = msgb_printf(msg, "Z: %u@%s\n", ENDPOINT_NUMBER(endp),
- endp->cfg->domain);
+ /* NOTE: Only in the virtual trunk we allow dynamic endpoint names */
+ if (endp->wildcarded_crcx
+ && endp->tcfg->trunk_type == MGCP_TRUNK_VIRTUAL) {
+ rc = msgb_printf(msg, "Z: %s%u@%s\n",
+ MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK,
+ ENDPOINT_NUMBER(endp), endp->cfg->domain);
if (rc < 0)
return -EINVAL;
}