From 641d387409b6d11f7166784344701438be1a45e1 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 2 Oct 2015 15:56:35 +0200 Subject: osmux: Test cid allocation and de-allocation * Test that one can get an id * That they are assigned predicatble right now * That returning them will make the number of used ones go down * That allocating more will fail --- openbsc/src/libmgcp/mgcp_osmux.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'openbsc/src/libmgcp/mgcp_osmux.c') diff --git a/openbsc/src/libmgcp/mgcp_osmux.c b/openbsc/src/libmgcp/mgcp_osmux.c index 90b73680b..b0ef69fd4 100644 --- a/openbsc/src/libmgcp/mgcp_osmux.c +++ b/openbsc/src/libmgcp/mgcp_osmux.c @@ -532,6 +532,20 @@ int osmux_send_dummy(struct mgcp_endpoint *endp) /* bsc-nat allocates/releases the Osmux circuit ID */ static uint8_t osmux_cid_bitmap[16]; +int osmux_used_cid(void) +{ + int i, j, used = 0; + + for (i = 0; i < sizeof(osmux_cid_bitmap) / 8; i++) { + for (j = 0; j < 8; j++) { + if (osmux_cid_bitmap[i] & (1 << j)) + used += 1; + } + } + + return used; +} + int osmux_get_cid(void) { int i, j; -- cgit v1.2.3 From b45e4d80b6b6b6bb597ccb3a14c16395481f7816 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 2 Oct 2015 16:11:15 +0200 Subject: osmux: Do not divide the number of bytes by eight. sizeof(uint8_t) == 1 and there is no need to create an array with 16 bytes and then only use the first two of them. This means the CID range is from 0 to 127 and we should be able to extend this to 256 by changing the array size to 32. Update the testcase now that we can have more than 16 calls with Osmux. --- openbsc/src/libmgcp/mgcp_osmux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsc/src/libmgcp/mgcp_osmux.c') diff --git a/openbsc/src/libmgcp/mgcp_osmux.c b/openbsc/src/libmgcp/mgcp_osmux.c index b0ef69fd4..30a81cbc3 100644 --- a/openbsc/src/libmgcp/mgcp_osmux.c +++ b/openbsc/src/libmgcp/mgcp_osmux.c @@ -536,7 +536,7 @@ int osmux_used_cid(void) { int i, j, used = 0; - for (i = 0; i < sizeof(osmux_cid_bitmap) / 8; i++) { + for (i = 0; i < sizeof(osmux_cid_bitmap); i++) { for (j = 0; j < 8; j++) { if (osmux_cid_bitmap[i] & (1 << j)) used += 1; @@ -550,7 +550,7 @@ int osmux_get_cid(void) { int i, j; - for (i = 0; i < sizeof(osmux_cid_bitmap) / 8; i++) { + for (i = 0; i < sizeof(osmux_cid_bitmap); i++) { for (j = 0; j < 8; j++) { if (osmux_cid_bitmap[i] & (1 << j)) continue; -- cgit v1.2.3 From 1afe7c7fe5e79435a1ebe9aff622ca20b901d923 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 4 Oct 2015 11:11:11 +0200 Subject: osmux: Remember the allocated CID and make sure it is released There appears to be a leak of CIDs: <000b> mgcp_osmux.c:544 All Osmux circuits are in use! There are paths that a CID had been requested and never released of the NAT. Remember the allocated CID inside the endpoint so it can always be released. It is using a new variable as the behavior for the NAT and MGCP MGW is different. The allocated_cid must be signed so that we can assign outside of the 0-255 range of it. Fixes: OW#1493 --- openbsc/src/libmgcp/mgcp_osmux.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'openbsc/src/libmgcp/mgcp_osmux.c') diff --git a/openbsc/src/libmgcp/mgcp_osmux.c b/openbsc/src/libmgcp/mgcp_osmux.c index 30a81cbc3..2d39b2c5e 100644 --- a/openbsc/src/libmgcp/mgcp_osmux.c +++ b/openbsc/src/libmgcp/mgcp_osmux.c @@ -492,6 +492,19 @@ void osmux_disable_endpoint(struct mgcp_endpoint *endp) osmux_handle_put(endp->osmux.in); } +void osmux_release_cid(struct mgcp_endpoint *endp) +{ + if (endp->osmux.allocated_cid >= 0) + osmux_put_cid(endp->osmux.allocated_cid); + endp->osmux.allocated_cid = -1; +} + +void osmux_allocate_cid(struct mgcp_endpoint *endp) +{ + osmux_release_cid(endp); + endp->osmux.allocated_cid = osmux_get_cid(); +} + /* We don't need to send the dummy load for osmux so often as another endpoint * may have already punched the hole in the firewall. This approach is simple * though. -- cgit v1.2.3