osmux: Allocate CID during CRCX
Change-Id: Ie0e1835ff7e99421de9a5741a5eb57a11c004f7e
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 5dae5a2..a31bff4 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -354,21 +354,27 @@
/*! Extract OSMUX CID from an MGCP parameter line (string).
* \param[in] line single parameter line from the MGCP message
- * \returns OSMUX CID, -1 on error */
+ * \returns OSMUX CID, -1 wildcard, -2 on error */
int mgcp_parse_osmux_cid(const char *line)
{
int osmux_cid;
+
+ if (strstr(line + 2, "Osmux: *")) {
+ LOGP(DLMGCP, LOGL_DEBUG, "Parsed wilcard Osmux CID\n");
+ return -1;
+ }
+
if (sscanf(line + 2, "Osmux: %u", &osmux_cid) != 1) {
LOGP(DLMGCP, LOGL_ERROR, "Failed parsing Osmux in MGCP msg line: %s\n",
line);
- return -1;
+ return -2;
}
if (osmux_cid > OSMUX_CID_MAX) {
LOGP(DLMGCP, LOGL_ERROR, "Osmux ID too large: %u > %u\n",
osmux_cid, OSMUX_CID_MAX);
- return -1;
+ return -2;
}
LOGP(DLMGCP, LOGL_DEBUG, "bsc-nat offered Osmux CID %u\n", osmux_cid);
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 807e34a..0ec9c78 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -783,7 +783,7 @@
const char *callid = NULL;
const char *mode = NULL;
char *line;
- int have_sdp = 0, osmux_cid = -1;
+ int have_sdp = 0, osmux_cid = -2;
struct mgcp_conn_rtp *conn = NULL;
struct mgcp_conn *_conn = NULL;
char conn_name[512];
@@ -917,9 +917,12 @@
/* Annotate Osmux circuit ID and set it to negotiating state until this
* is fully set up from the dummy load. */
conn->osmux.state = OSMUX_STATE_DISABLED;
- if (osmux_cid >= 0) {
- conn->osmux.cid = osmux_cid;
+ if (osmux_cid >= -1) { /* -1 is wilcard, alloc next avail CID */
conn->osmux.state = OSMUX_STATE_NEGOTIATING;
+ if (conn_osmux_allocate_cid(conn, osmux_cid) == -1) {
+ rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_OSMUX]);
+ goto error2;
+ }
} else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) {
LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
"CRCX: osmux only and no osmux offered\n");