diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c index f3785cd30..55a895309 100644 --- a/src/libosmo-mgcp/mgcp_trunk.c +++ b/src/libosmo-mgcp/mgcp_trunk.c @@ -47,7 +47,7 @@ struct mgcp_trunk *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_typ trunk->audio_send_ptime = 1; trunk->audio_send_name = 1; - trunk->vty_number_endpoints = 33; + trunk->vty_number_endpoints = 32; trunk->omit_rtcp = 0; mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE); @@ -67,13 +67,8 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk) { int i; struct mgcp_endpoint *endp; - - /* Make sure the amount of requested endpoints does not execeed - * sane limits. The VTY already limits the possible amount, - * however miss-initalation of the struct or memory corruption - * could still lead to an excessive allocation of endpoints, so - * better stop early if that is the case. */ - OSMO_ASSERT(trunk->vty_number_endpoints < 65534); + unsigned int number_endpoints; + unsigned int first_endpoint_nr; /* This function is called once on startup by the VTY to allocate the * endpoints. The number of endpoints must not change througout the @@ -81,15 +76,39 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk) OSMO_ASSERT(trunk->number_endpoints == 0); OSMO_ASSERT(trunk->endpoints == NULL); + switch (trunk->trunk_type) { + case MGCP_TRUNK_VIRTUAL: + /* Due to historical reasons the endpoints on the virtual + * trunk start counting at 1. */ + first_endpoint_nr = 1; + number_endpoints = trunk->vty_number_endpoints; + break; + case MGCP_TRUNK_E1: + /* The first timeslot on an E1 line is reserved for framing + * and alignment and can not be used for audio transport */ + first_endpoint_nr = 1 * MGCP_ENDP_E1_SUBSLOTS; + number_endpoints = 31 * MGCP_ENDP_E1_SUBSLOTS; + break; + default: + OSMO_ASSERT(false); + } + + /* Make sure the amount of requested endpoints does not execeed + * sane limits. The VTY already limits the possible amount, + * however miss-initialization of the struct or memory corruption + * could still lead to an excessive allocation of endpoints, so + * better stop early if that is the case. */ + OSMO_ASSERT(number_endpoints < 65534); + /* allocate pointer array for the endpoints */ trunk->endpoints = _talloc_zero_array(trunk->cfg, - sizeof(struct mgcp_endpoint *), trunk->vty_number_endpoints, "endpoints"); + sizeof(struct mgcp_endpoint *), number_endpoints, "endpoints"); if (!trunk->endpoints) return -1; /* create endpoints */ - for (i = 0; i < trunk->vty_number_endpoints; ++i) { - endp = mgcp_endp_alloc(trunk, i); + for (i = 0; i < number_endpoints; i++) { + endp = mgcp_endp_alloc(trunk, i + first_endpoint_nr); if (!endp) { talloc_free(trunk->endpoints); return -1; @@ -98,7 +117,7 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk) } /* make the endpoints we just created available to the MGW code */ - trunk->number_endpoints = trunk->vty_number_endpoints; + trunk->number_endpoints = number_endpoints; return 0; } diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c index 2f862f19d..35b75fb2d 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -112,7 +112,7 @@ static int config_write_mgcp(struct vty *vty) trunk->audio_send_name ? "" : "no ", VTY_NEWLINE); vty_out(vty, " loop %u%s", ! !trunk->audio_loop, VTY_NEWLINE); vty_out(vty, " number endpoints %u%s", - trunk->vty_number_endpoints - 1, VTY_NEWLINE); + trunk->vty_number_endpoints, VTY_NEWLINE); vty_out(vty, " %sallow-transcoding%s", trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE); if (g_cfg->call_agent_addr) @@ -289,7 +289,7 @@ static void dump_trunk(struct vty *vty, struct mgcp_trunk *trunk, int show_stats vty_out(vty, "%s trunk %d with %d endpoints:%s", trunk->trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1", - trunk->trunk_nr, trunk->number_endpoints - 1, VTY_NEWLINE); + trunk->trunk_nr, trunk->number_endpoints, VTY_NEWLINE); if (!trunk->endpoints) { vty_out(vty, "No endpoints allocated yet.%s", VTY_NEWLINE); @@ -710,13 +710,12 @@ DEFUN(cfg_mgcp_rtp_accept_all, DEFUN(cfg_mgcp_number_endp, cfg_mgcp_number_endp_cmd, - "number endpoints <0-65534>", + "number endpoints <1-65534>", "Number options\n" "Endpoints available\n" "Number endpoints\n") { struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID); OSMO_ASSERT(trunk); - /* + 1 as we start counting at one */ - trunk->vty_number_endpoints = atoi(argv[0]) + 1; + trunk->vty_number_endpoints = atoi(argv[0]); return CMD_SUCCESS; } diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index 9cafcf7b2..792ae1f60 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -605,7 +605,7 @@ static int mgcp_test_policy_cb(struct mgcp_endpoint *endp, trunk = endp->trunk; last_endpoint[0] = '\0'; - for (i = 0; i < trunk->vty_number_endpoints; i++) { + for (i = 0; i < trunk->number_endpoints; i++) { if (strcmp(endp->name, trunk->endpoints[i]->name) == 0) osmo_strlcpy(last_endpoint, trunk->endpoints[i]->name, sizeof(last_endpoint)); @@ -656,7 +656,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) static void mgcp_endpoints_release(struct mgcp_trunk *trunk) { int i; - for (i = 1; i < trunk->number_endpoints; i++) + for (i = 0; i < trunk->number_endpoints; i++) mgcp_endp_release(trunk->endpoints[i]); }