This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Hoernchen gerrit-no-reply at lists.osmocom.orgHoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/25447 ) Change subject: adjust mgcp response context ...................................................................... adjust mgcp response context This patch also prepares for threading. Change-Id: Id17f51d8bc0d1ba26f7fca72b1679ffadc9d6dc8 --- M src/libosmo-mgcp/mgcp_protocol.c 1 file changed, 57 insertions(+), 47 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/47/25447/1 diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 6341f07..ecb1aff 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -173,12 +173,18 @@ } /* Helper function to allocate some memory for responses and retransmissions */ -static struct msgb *mgcp_msgb_alloc(void) +static struct msgb *mgcp_msgb_alloc(void *ctx) { struct msgb *msg; - msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); - if (!msg) + msg = msgb_alloc_c(ctx, 4096, "MGCP msg"); + + if (!msg) { LOGP(DLMGCP, LOGL_ERROR, "Failed to msgb for MGCP data.\n"); + return NULL; + } + + /* headroom */ + msgb_reserve(msg, 128); return msg; } @@ -186,7 +192,7 @@ /* Helper function for do_retransmission() and create_resp() */ static struct msgb *create_retransmission_response(const struct mgcp_endpoint *endp) { - struct msgb *msg = mgcp_msgb_alloc(); + struct msgb *msg = mgcp_msgb_alloc(endp->trunk); if (!msg) return NULL; @@ -196,7 +202,7 @@ return msg; } -static struct msgb *create_resp(struct mgcp_endpoint *endp, int code, +static struct msgb *create_resp(void* msgctx, struct mgcp_endpoint *endp, int code, const char *txt, const char *msg, const char *trans, const char *param, const char *sdp) @@ -204,7 +210,8 @@ int len; struct msgb *res; - res = mgcp_msgb_alloc(); + OSMO_ASSERT(msgctx != 0); + res = mgcp_msgb_alloc(msgctx); if (!res) return NULL; @@ -236,26 +243,26 @@ return res; } -static struct msgb *create_ok_resp_with_param(struct mgcp_endpoint *endp, +static struct msgb *create_ok_resp_with_param(void* msgctx, struct mgcp_endpoint *endp, int code, const char *msg, const char *trans, const char *param) { - return create_resp(endp, code, " OK", msg, trans, param, NULL); + return create_resp(msgctx, endp, code, " OK", msg, trans, param, NULL); } -static struct msgb *create_ok_response(struct mgcp_endpoint *endp, +static struct msgb *create_ok_response(void* msgctx, struct mgcp_endpoint *endp, int code, const char *msg, const char *trans) { - return create_ok_resp_with_param(endp, code, msg, trans, NULL); + return create_ok_resp_with_param(msgctx, endp, code, msg, trans, NULL); } -static struct msgb *create_err_response(struct mgcp_endpoint *endp, +static struct msgb *create_err_response(void* msgctx, struct mgcp_endpoint *endp, int code, const char *msg, const char *trans) { - return create_resp(endp, code, " FAIL", msg, trans, NULL, NULL); + return create_resp(msgctx, endp, code, " FAIL", msg, trans, NULL, NULL); } /* Format MGCP response string (with SDP attached) */ @@ -278,10 +285,13 @@ int rc; struct msgb *result; - sdp = msgb_alloc_headroom(4096, 128, "sdp record"); + sdp = msgb_alloc_c(endp->trunk, 4096, "sdp record"); if (!sdp) return NULL; + /* headroom */ + msgb_reserve(sdp, 128); + /* Attach optional endpoint name */ if (add_epname) { rc = msgb_printf(sdp, "Z: %s\r\n", endp->name); @@ -309,7 +319,7 @@ rc = mgcp_write_response_sdp(endp, conn, sdp, addr); if (rc < 0) goto error; - result = create_resp(endp, 200, " OK", msg, trans_id, NULL, (char*) sdp->data); + result = create_resp(endp->trunk, endp, 200, " OK", msg, trans_id, NULL, (char*) sdp->data); msgb_free(sdp); return result; error: @@ -376,7 +386,7 @@ if (rc < 0) { LOGP(DLMGCP, LOGL_ERROR, "%s: failed to parse MCGP message\n", rq.name); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_FAIL_MSG_PARSE)); - return create_err_response(NULL, -rc, rq.name, "000000"); + return create_err_response(cfg, NULL, -rc, rq.name, "000000"); } /* Locate endpoint and trunk, if no endpoint can be located try at least to identify the trunk. */ @@ -397,7 +407,7 @@ if (!rq.trunk) { LOGP(DLMGCP, LOGL_ERROR, "%s: failed to identify trunk for endpoint \"%s\" -- abort\n", rq.name, pdata.epname); - return create_err_response(NULL, -rq.mgcp_cause, rq.name, pdata.trans); + return create_err_response(cfg, NULL, -rq.mgcp_cause, rq.name, pdata.trans); } } else { /* If the endpoint name suggests that the request refers to a specific endpoint, then the @@ -405,7 +415,7 @@ LOGP(DLMGCP, LOGL_NOTICE, "%s: cannot find endpoint \"%s\", cause=%d -- abort\n", rq.name, pdata.epname, -rq.mgcp_cause); - return create_err_response(NULL, -rq.mgcp_cause, rq.name, pdata.trans); + return create_err_response(cfg, NULL, -rq.mgcp_cause, rq.name, pdata.trans); } } else { osmo_strlcpy(debug_last_endpoint_name, rq.endp->name, sizeof(debug_last_endpoint_name)); @@ -428,7 +438,7 @@ LOGP(DLMGCP, LOGL_ERROR, "%s: the request handler \"%s\" requires an endpoint resource for \"%s\", which is not available -- abort\n", rq.name, mgcp_requests[i].debug_name, pdata.epname); - return create_err_response(NULL, -rq.mgcp_cause, rq.name, pdata.trans); + return create_err_response(rq.trunk, NULL, -rq.mgcp_cause, rq.name, pdata.trans); } /* Execute request handler */ @@ -461,7 +471,7 @@ static struct msgb *handle_audit_endpoint(struct mgcp_request_data *rq) { LOGPENDP(rq->endp, DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n"); - return create_ok_response(rq->endp, 200, "AUEP", rq->pdata->trans); + return create_ok_response(rq->trunk, rq->endp, 200, "AUEP", rq->pdata->trans); } /* Try to find a free port by attempting to bind on it. Also handle the @@ -859,7 +869,7 @@ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_AVAIL)); LOGPENDP(endp, DLMGCP, LOGL_ERROR, "CRCX: selected endpoint not available!\n"); - return create_err_response(NULL, 501, "CRCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 501, "CRCX", pdata->trans); } /* parse CallID C: and LocalParameters L: */ @@ -879,7 +889,7 @@ * together with a CRCX, the MGW will assign the * connection identifier by itself on CRCX */ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BAD_ACTION)); - return create_err_response(NULL, 523, "CRCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 523, "CRCX", pdata->trans); break; case 'M': mode = (const char *)line + 3; @@ -905,7 +915,7 @@ LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: unhandled option: '%c'/%d\n", *line, *line); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_UNHANDLED_PARAM)); - return create_err_response(NULL, 539, "CRCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 539, "CRCX", pdata->trans); break; } } @@ -916,14 +926,14 @@ LOGPENDP(endp, DLMGCP, LOGL_ERROR, "CRCX: insufficient parameters, missing callid\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_MISSING_CALLID)); - return create_err_response(endp, 516, "CRCX", pdata->trans); + return create_err_response(endp, endp, 516, "CRCX", pdata->trans); } if (!mode) { LOGPENDP(endp, DLMGCP, LOGL_ERROR, "CRCX: insufficient parameters, missing mode\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_INVALID_MODE)); - return create_err_response(endp, 517, "CRCX", pdata->trans); + return create_err_response(endp, endp, 517, "CRCX", pdata->trans); } /* Check if we are able to accept the creation of another connection */ @@ -940,7 +950,7 @@ /* There is no more room for a connection, leave * everything as it is and return with an error */ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_LIMIT_EXCEEDED)); - return create_err_response(endp, 540, "CRCX", pdata->trans); + return create_err_response(endp, endp, 540, "CRCX", pdata->trans); } } @@ -958,7 +968,7 @@ /* This is not our call, leave everything as it is and * return with an error. */ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_UNKNOWN_CALLID)); - return create_err_response(endp, 400, "CRCX", pdata->trans); + return create_err_response(endp, endp, 400, "CRCX", pdata->trans); } } @@ -969,7 +979,7 @@ rc = mgcp_endp_claim(endp, callid); if (rc != 0) { rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_CLAIM)); - return create_err_response(endp, 502, "CRCX", pdata->trans); + return create_err_response(endp, endp, 502, "CRCX", pdata->trans); } } @@ -1088,7 +1098,7 @@ mgcp_endp_release(endp); LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: unable to create connection\n"); - return create_err_response(endp, error_code, "CRCX", pdata->trans); + return create_err_response(endp, endp, error_code, "CRCX", pdata->trans); } /* MDCX command handler, processes the received command */ @@ -1116,7 +1126,7 @@ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_AVAIL)); LOGPENDP(endp, DLMGCP, LOGL_ERROR, "MDCX: selected endpoint not available!\n"); - return create_err_response(NULL, 501, "MDCX", pdata->trans); + return create_err_response(endp, NULL, 501, "MDCX", pdata->trans); } /* Prohibit wildcarded requests */ @@ -1124,14 +1134,14 @@ LOGPENDP(endp, DLMGCP, LOGL_ERROR, "MDCX: wildcarded endpoint names not supported.\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_WILDCARD)); - return create_err_response(endp, 507, "MDCX", pdata->trans); + return create_err_response(rq->trunk, endp, 507, "MDCX", pdata->trans); } if (llist_count(&endp->conns) <= 0) { LOGPENDP(endp, DLMGCP, LOGL_ERROR, "MDCX: endpoint is not holding a connection.\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_NO_CONN)); - return create_err_response(endp, 400, "MDCX", pdata->trans); + return create_err_response(endp, endp, 400, "MDCX", pdata->trans); } for_each_line(line, pdata->save) { @@ -1181,7 +1191,7 @@ "MDCX: Unhandled MGCP option: '%c'/%d\n", line[0], line[0]); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_UNHANDLED_PARAM)); - return create_err_response(NULL, 539, "MDCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 539, "MDCX", pdata->trans); break; } } @@ -1191,13 +1201,13 @@ LOGPENDP(endp, DLMGCP, LOGL_ERROR, "MDCX: insufficient parameters, missing ci (connectionIdentifier)\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_NO_CONNID)); - return create_err_response(endp, 515, "MDCX", pdata->trans); + return create_err_response(endp, endp, 515, "MDCX", pdata->trans); } conn = mgcp_conn_get_rtp(endp, conn_id); if (!conn) { rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_CONN_NOT_FOUND)); - return create_err_response(endp, 400, "MDCX", pdata->trans); + return create_err_response(endp, endp, 400, "MDCX", pdata->trans); } mgcp_conn_watchdog_kick(conn->conn); @@ -1304,7 +1314,7 @@ mgcp_endp_update(endp); return create_response_with_sdp(endp, conn, "MDCX", pdata->trans, false, false); error3: - return create_err_response(endp, error_code, "MDCX", pdata->trans); + return create_err_response(endp, endp, error_code, "MDCX", pdata->trans); out_silent: LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "MDCX: silent exit\n"); @@ -1335,14 +1345,14 @@ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_AVAIL)); LOGPENDP(endp, DLMGCP, LOGL_ERROR, "DLCX: selected endpoint not available!\n"); - return create_err_response(NULL, 501, "DLCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 501, "DLCX", pdata->trans); } if (endp && !rq->wildcarded && llist_empty(&endp->conns)) { LOGPENDP(endp, DLMGCP, LOGL_ERROR, "DLCX: endpoint is not holding a connection.\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_NO_CONN)); - return create_err_response(endp, 515, "DLCX", pdata->trans); + return create_err_response(endp, endp, 515, "DLCX", pdata->trans); } for_each_line(line, pdata->save) { @@ -1357,7 +1367,7 @@ LOGPTRUNK(trunk, DLMGCP, LOGL_NOTICE, "cannot handle requests with call-id (C) without endpoint -- abort!"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_UNHANDLED_PARAM)); - return create_err_response(NULL, 539, "DLCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 539, "DLCX", pdata->trans); } if (mgcp_verify_call_id(endp, line + 3) != 0) { @@ -1373,7 +1383,7 @@ LOGPTRUNK(trunk, DLMGCP, LOGL_NOTICE, "cannot handle requests with conn-id (I) without endpoint -- abort!"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_UNHANDLED_PARAM)); - return create_err_response(NULL, 539, "DLCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 539, "DLCX", pdata->trans); } conn_id = (const char *)line + 3; @@ -1389,7 +1399,7 @@ LOGPEPTR(endp, trunk, DLMGCP, LOGL_NOTICE, "DLCX: Unhandled MGCP option: '%c'/%d\n", line[0], line[0]); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_UNHANDLED_PARAM)); - return create_err_response(NULL, 539, "DLCX", pdata->trans); + return create_err_response(rq->trunk, NULL, 539, "DLCX", pdata->trans); break; } } @@ -1404,7 +1414,7 @@ mgcp_endp_release(trunk->endpoints[i]); } rate_ctr_add(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS), num_conns); - return create_ok_response(NULL, 200, "DLCX", pdata->trans); + return create_ok_response(trunk, NULL, 200, "DLCX", pdata->trans); } /* The logic does not permit to go past this point without having the @@ -1429,7 +1439,7 @@ /* Note: In this case we do not return any statistics, * as we assume that the client is not interested in * this case. */ - return create_ok_response(endp, 200, "DLCX", pdata->trans); + return create_ok_response(endp, endp, 200, "DLCX", pdata->trans); } /* Find the connection */ @@ -1458,10 +1468,10 @@ rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS)); if (silent) goto out_silent; - return create_ok_resp_with_param(endp, 250, "DLCX", pdata->trans, stats); + return create_ok_resp_with_param(endp, endp, 250, "DLCX", pdata->trans, stats); error3: - return create_err_response(endp, error_code, "DLCX", pdata->trans); + return create_err_response(endp, endp, error_code, "DLCX", pdata->trans); out_silent: LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "DLCX: silent exit\n"); @@ -1516,14 +1526,14 @@ /* we didn't see a signal request with a tone */ if (tone == CHAR_MAX) - return create_ok_response(rq->endp, 200, "RQNT", rq->pdata->trans); + return create_ok_response(rq->endp, rq->endp, 200, "RQNT", rq->pdata->trans); if (rq->pdata->cfg->rqnt_cb) res = rq->pdata->cfg->rqnt_cb(rq->endp, tone); return res == 0 ? - create_ok_response(rq->endp, 200, "RQNT", rq->pdata->trans) : - create_err_response(rq->endp, res, "RQNT", rq->pdata->trans); + create_ok_response(rq->endp, rq->endp, 200, "RQNT", rq->pdata->trans) : + create_err_response(rq->endp, rq->endp, res, "RQNT", rq->pdata->trans); } /* Connection keepalive timer, will take care that dummy packets are send -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/25447 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: Id17f51d8bc0d1ba26f7fca72b1679ffadc9d6dc8 Gerrit-Change-Number: 25447 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210913/4d3c2481/attachment.htm>