endp: add E1 endpoint interlocking

E1 endpoint names also represent different rates, this may mean that
some rate / subslot combinations are not possible because they overlap
within nthe timeslot. When the equipment (BSC) is properly configured,
this will be no problem, however invalid configuration may cause the
selection of overlapping endpoints and this needs to be prevented, and
logged. Also rate counters need to be in place.

Change-Id: I18e90b10648a7e504371179ad144645fc82e1c27
Related: OS#2547
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 1e393e2..f2fc20c 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -747,6 +747,10 @@
 	int rc;
 
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n");
+	if (!mgcp_endp_avail(endp)) {
+		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_AVAIL]);
+		return create_err_response(NULL, 501, "CRCX", p->trans);
+	}
 
 	/* parse CallID C: and LocalParameters L: */
 	for_each_line(line, p->save) {
@@ -1004,6 +1008,11 @@
 
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n");
 
+	if (!mgcp_endp_avail(endp)) {
+		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_AVAIL]);
+		return create_err_response(NULL, 501, "MDCX", p->trans);
+	}
+
 	/* Prohibit wildcarded requests */
 	if (endp->wildcarded_req) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
@@ -1224,6 +1233,11 @@
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
 		 "DLCX: deleting connection ...\n");
 
+	if (!mgcp_endp_avail(endp)) {
+		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_AVAIL]);
+		return create_err_response(NULL, 501, "DLCX", p->trans);
+	}
+
 	/* Prohibit wildcarded requests */
 	if (endp->wildcarded_req) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,