pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-mgw/+/39206?usp=email )
Change subject: mgcp_endp: Add helpers accessing endp connections
......................................................................
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
---
M include/osmocom/mgcp/mgcp_endp.h
M src/libosmo-mgcp/mgcp_endp.c
M src/libosmo-mgcp/mgcp_protocol.c
3 files changed, 25 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/06/39206/1
diff --git a/include/osmocom/mgcp/mgcp_endp.h b/include/osmocom/mgcp/mgcp_endp.h
index 5ecebda..fbe0850 100644
--- a/include/osmocom/mgcp/mgcp_endp.h
+++ b/include/osmocom/mgcp/mgcp_endp.h
@@ -139,6 +139,8 @@
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);
diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index 4c51266..5653168 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -569,6 +569,24 @@
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.
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 4e63e4d..4c8f47c 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -967,7 +967,7 @@
}
/* 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 @@
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 @@
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 @@
* 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 @@
/* 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");
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-mgw/+/39206?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: I77c298abf0a1488b91f58c9e76507ef8add0168e
Gerrit-Change-Number: 39206
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>