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

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
---
M include/osmocom/mgcp/mgcp_common.h
M src/libosmo-mgcp/mgcp_msg.c
M src/libosmo-mgcp/mgcp_protocol.c
3 files changed, 32 insertions(+), 6 deletions(-)


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

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 994b00a..d4b04a7 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -227,20 +227,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 24d5bf1..ee744f9 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -235,9 +235,14 @@
         * there is this FIXME note instead. Also the I parameter, which is
         * misplaced as well has been introduced with an earlier patch. */
 
-       rc = msgb_printf(sdp, "Z: %u@%s\n", ENDPOINT_NUMBER(endp), 
endp->cfg->domain);
-       if (rc < 0)
-               goto error;
+       /* NOTE: Only in the virtual trunk we allow dynamic endpoint names */
+       if (endp->tcfg->trunk_type == MGCP_TRUNK_VIRTUAL) {
+               rc = msgb_printf(sdp, "Z: %s%u@%s\n",
+                                MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK,
+                                ENDPOINT_NUMBER(endp), endp->cfg->domain);
+               if (rc < 0)
+                       goto error;
+       }
 
        rc = msgb_printf(sdp, "I: %s%s\n\n", conn->conn->id, osmux_extension);
        if (rc < 0)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2aac3ba0f1f3122dfbb3bf36f74198ecb2b21de5
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <[email protected]>

Reply via email to