pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-mgw/+/39739?usp=email )
Change subject: mgw: Split MDCX read-only validation on conn into its own function
......................................................................
mgw: Split MDCX read-only validation on conn into its own function
Add a second read-only validation step once the conn to be modified is
found in the endpoint.
Change-Id: I025ca5352eff9ee35c977c69b71934513646b1f2
---
M src/libosmo-mgcp/mgcp_protocol.c
1 file changed, 40 insertions(+), 14 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/39/39739/1
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 79a647a..6a731a3 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -891,6 +891,37 @@
return 0;
}
+/* Read-only checks for parsed MDCX request, applied to existing found conn.
+ * Returns negative MGCP error code on failure, 0 on scucess. */
+static int validate_parsed_mdcx_conn(struct mgcp_request_data *rq, struct mgcp_conn
*conn)
+{
+ struct mgcp_parse_data *pdata = rq->pdata;
+ struct mgcp_parse_hdr_pars *hpars = &pdata->hpars;
+ struct mgcp_conn_rtp *conn_rtp = mgcp_conn_get_conn_rtp(conn);
+
+ OSMO_ASSERT(conn_rtp);
+
+ if (mgcp_conn_rtp_is_osmux(conn_rtp)) {
+ OSMO_ASSERT(conn_rtp->osmux.local_cid_allocated);
+ if (hpars->remote_osmux_cid == MGCP_PARSE_HDR_PARS_OSMUX_CID_UNSET) {
+ LOGPCONN(conn, DLMGCP, LOGL_ERROR, "MDCX: Failed to parse Osmux CID!\n");
+ return -500;
+ }
+ if (hpars->remote_osmux_cid == MGCP_PARSE_HDR_PARS_OSMUX_CID_WILDCARD) {
+ LOGPCONN(conn, DLMGCP, LOGL_ERROR, "MDCX: wilcard in MDCX is not
supported!\n");
+ return -500;
+ }
+ if (conn_rtp->osmux.remote_cid_present &&
+ hpars->remote_osmux_cid != conn_rtp->osmux.remote_cid) {
+ LOGPCONN(conn, DLMGCP, LOGL_ERROR, "MDCX: changing already allocated CID is not
supported!\n");
+ return -500;
+ }
+ }
+
+ /* Everything fine, continue */
+ return 0;
+}
+
/* MDCX command handler, processes the received command */
static struct msgb *handle_modify_con(struct mgcp_request_data *rq)
{
@@ -953,6 +984,15 @@
return create_err_response(endp, endp, 400, "MDCX", pdata->trans);
}
+ rc = validate_parsed_mdcx_conn(rq, conn);
+ if (rc < 0)
+ return create_err_response(rq->trunk, NULL, -rc, "MDCX",
pdata->trans);
+
+ /*******************************************************************
+ * Modify endpoint and conn.
+ * From here on below we start updating endpoint and modifying conn:
+ *******************************************************************/
+
/* Set local connection options, if present */
if (hpars->lco.present)
mgcp_endp_update_lco(endp, &hpars->lco);
@@ -983,20 +1023,6 @@
rc = mgcp_conn_iuup_init(conn_rtp);
if (mgcp_conn_rtp_is_osmux(conn_rtp)) {
- OSMO_ASSERT(conn_rtp->osmux.local_cid_allocated);
- if (hpars->remote_osmux_cid < -1) {
- LOGPCONN(conn, DLMGCP, LOGL_ERROR, "MDCX: Failed to parse Osmux CID!\n");
- goto error3;
- }
- if (hpars->remote_osmux_cid == -1) {
- LOGPCONN(conn, DLMGCP, LOGL_ERROR, "MDCX: wilcard in MDCX is not
supported!\n");
- goto error3;
- }
- if (conn_rtp->osmux.remote_cid_present &&
- hpars->remote_osmux_cid != conn_rtp->osmux.remote_cid) {
- LOGPCONN(conn, DLMGCP, LOGL_ERROR, "MDCX: changing already allocated CID is not
supported!\n");
- goto error3;
- }
conn_rtp->osmux.remote_cid_present = true;
conn_rtp->osmux.remote_cid = hpars->remote_osmux_cid;
if (conn_osmux_event_rx_crcx_mdcx(conn_rtp) < 0) {
--
To view, visit
https://gerrit.osmocom.org/c/osmo-mgw/+/39739?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I025ca5352eff9ee35c977c69b71934513646b1f2
Gerrit-Change-Number: 39739
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>