mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-10-23 08:12:01 +00:00
mgcp_endp: Add helpers accessing endp connections
This has several benefits: * easily improving/changing the impelemntation later on (eg. by storing a count instead of iterating the whole list). * Remove code complexity from mgcp_protocol.c. Change-Id: I77c298abf0a1488b91f58c9e76507ef8add0168e
This commit is contained in:
@@ -139,6 +139,8 @@ struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname,
|
||||
struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname,
|
||||
struct mgcp_config *cfg);
|
||||
bool mgcp_endp_avail(const struct mgcp_endpoint *endp);
|
||||
unsigned int mgcp_endp_num_conns(const struct mgcp_endpoint *endp);
|
||||
bool mgcp_endp_is_full(const struct mgcp_endpoint *endp);
|
||||
void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn);
|
||||
void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn);
|
||||
void mgcp_endp_free_conn_oldest(struct mgcp_endpoint *endp);
|
||||
|
@@ -569,6 +569,24 @@ bool mgcp_endp_avail(const struct mgcp_endpoint *endp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*! Get number of conns in an endpoint.
|
||||
* \param[in] endp endpoint to check.
|
||||
* \returns Number of connections present in the endpoint. */
|
||||
unsigned int mgcp_endp_num_conns(const struct mgcp_endpoint *endp)
|
||||
{
|
||||
return llist_count(&endp->conns);
|
||||
}
|
||||
|
||||
/*! check if an endpoint can in current state allocate new conns.
|
||||
* \param[in] endp endpoint to check.
|
||||
* \returns true if more connections can be allowed on endpoint, false if it is already busy. */
|
||||
bool mgcp_endp_is_full(const struct mgcp_endpoint *endp)
|
||||
{
|
||||
if (endp->type->max_conns == 0)
|
||||
return false;
|
||||
return mgcp_endp_num_conns(endp) >= endp->type->max_conns;
|
||||
}
|
||||
|
||||
/*! claim endpoint, sets callid and activates endpoint, should be called at the
|
||||
* beginning of the CRCX procedure when it is clear that a new call should be
|
||||
* created.
|
||||
|
@@ -967,7 +967,7 @@ mgcp_header_done:
|
||||
}
|
||||
|
||||
/* Check if we are able to accept the creation of another connection */
|
||||
if (endp->type->max_conns > 0 && llist_count(&endp->conns) >= endp->type->max_conns) {
|
||||
if (mgcp_endp_is_full(endp)) {
|
||||
LOGPENDP(endp, DLMGCP, LOGL_ERROR,
|
||||
"CRCX: endpoint full, max. %i connections allowed!\n",
|
||||
endp->type->max_conns);
|
||||
@@ -1173,7 +1173,7 @@ static struct msgb *handle_modify_con(struct mgcp_request_data *rq)
|
||||
LOGPENDP(endp, DLMGCP, LOGL_ERROR, "MDCX: selected endpoint not available!\n");
|
||||
return create_err_response(rq->trunk, NULL, 501, "MDCX", pdata->trans);
|
||||
}
|
||||
if (llist_count(&endp->conns) <= 0) {
|
||||
if (mgcp_endp_num_conns(endp) <= 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));
|
||||
@@ -1396,7 +1396,7 @@ static struct msgb *handle_delete_con(struct mgcp_request_data *rq)
|
||||
if (rq->wildcarded) {
|
||||
int num_conns = 0;
|
||||
for (i = 0; i < trunk->number_endpoints; i++) {
|
||||
num_conns += llist_count(&trunk->endpoints[i]->conns);
|
||||
num_conns += mgcp_endp_num_conns(trunk->endpoints[i]);
|
||||
mgcp_endp_release(trunk->endpoints[i]);
|
||||
}
|
||||
rate_ctr_add(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS), num_conns);
|
||||
@@ -1458,7 +1458,7 @@ static struct msgb *handle_delete_con(struct mgcp_request_data *rq)
|
||||
* that we drop all connections on that specific endpoint at once.
|
||||
* (See also RFC3435 Section F.7) */
|
||||
if (!conn_id) {
|
||||
int num_conns = llist_count(&endp->conns);
|
||||
int num_conns = mgcp_endp_num_conns(endp);
|
||||
LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
|
||||
"DLCX: missing ci (connectionIdentifier), will remove all connections (%d total) at once\n",
|
||||
num_conns);
|
||||
@@ -1492,7 +1492,7 @@ static struct msgb *handle_delete_con(struct mgcp_request_data *rq)
|
||||
|
||||
/* When all connections are closed, the endpoint will be released
|
||||
* in order to be ready to be used by another call. */
|
||||
if (llist_count(&endp->conns) <= 0) {
|
||||
if (mgcp_endp_num_conns(endp) <= 0) {
|
||||
mgcp_endp_release(endp);
|
||||
LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "DLCX: endpoint released\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user