mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-10-23 16:14:03 +00:00
mgw: Delay osmux trunk setup to point where it is really needed
This way code is simplified by putting all osmux code together. Change-Id: I27f7355ee99f1781fc2034a23c7cca756fb203d2
This commit is contained in:
@@ -495,6 +495,9 @@ int osmux_init(struct mgcp_trunk *trunk)
|
||||
int ret, fd;
|
||||
struct mgcp_config *cfg = trunk->cfg;
|
||||
|
||||
if (cfg->osmux.initialized)
|
||||
return 0;
|
||||
|
||||
/* So far we only support running on one trunk: */
|
||||
OSMO_ASSERT(trunk == mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID));
|
||||
|
||||
@@ -507,7 +510,7 @@ int osmux_init(struct mgcp_trunk *trunk)
|
||||
ret = mgcp_create_bind(cfg->osmux.local_addr_v4, cfg->osmux.local_port,
|
||||
cfg->endp_dscp, cfg->endp_priority);
|
||||
if (ret < 0) {
|
||||
LOGP(DOSMUX, LOGL_ERROR, "Cannot bind OSMUX IPv4 socket to %s:%u\n",
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_ERROR, "Cannot bind OSMUX IPv4 socket to %s:%u\n",
|
||||
cfg->osmux.local_addr_v4, cfg->osmux.local_port);
|
||||
goto out_free_v4;
|
||||
}
|
||||
@@ -515,11 +518,11 @@ int osmux_init(struct mgcp_trunk *trunk)
|
||||
|
||||
ret = osmo_iofd_register(osmux_fd_v4, fd);
|
||||
if (ret < 0) {
|
||||
LOGP(DOSMUX, LOGL_ERROR, "Cannot register OSMUX IPv4 socket %s\n", osmo_sock_get_name2(fd));
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_ERROR, "Cannot register OSMUX IPv4 socket %s\n", osmo_sock_get_name2(fd));
|
||||
close(fd);
|
||||
goto out_free_v4;
|
||||
}
|
||||
LOGP(DOSMUX, LOGL_INFO, "OSMUX IPv4 socket listening on %s\n", osmo_sock_get_name2(fd));
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_INFO, "OSMUX IPv4 socket listening on %s\n", osmo_sock_get_name2(fd));
|
||||
}
|
||||
|
||||
osmux_fd_v6 = osmo_iofd_setup(trunk, -1, "osmux_fd_v6", OSMO_IO_FD_MODE_RECVFROM_SENDTO, &osmux_ioops, trunk);
|
||||
@@ -531,7 +534,7 @@ int osmux_init(struct mgcp_trunk *trunk)
|
||||
ret = mgcp_create_bind(cfg->osmux.local_addr_v6, cfg->osmux.local_port,
|
||||
cfg->endp_dscp, cfg->endp_priority);
|
||||
if (ret < 0) {
|
||||
LOGP(DOSMUX, LOGL_ERROR, "Cannot bind OSMUX IPv6 socket to [%s]:%u\n",
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_ERROR, "Cannot bind OSMUX IPv6 socket to [%s]:%u\n",
|
||||
cfg->osmux.local_addr_v6, cfg->osmux.local_port);
|
||||
goto out_free_v6;
|
||||
}
|
||||
@@ -543,9 +546,10 @@ int osmux_init(struct mgcp_trunk *trunk)
|
||||
close(fd);
|
||||
goto out_free_v6;
|
||||
}
|
||||
LOGP(DOSMUX, LOGL_INFO, "OSMUX IPv6 socket listening on %s\n", osmo_sock_get_name2(fd));
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_INFO, "OSMUX IPv6 socket listening on %s\n", osmo_sock_get_name2(fd));
|
||||
}
|
||||
cfg->osmux.initialized = true;
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_NOTICE, "OSMUX socket has been set up\n");
|
||||
return 0;
|
||||
|
||||
out_free_v6:
|
||||
@@ -557,6 +561,7 @@ out_free_v4:
|
||||
osmo_iofd_free(osmux_fd_v4);
|
||||
osmux_fd_v4 = NULL;
|
||||
out:
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_ERROR, "Cannot init OSMUX\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -702,20 +702,6 @@ uint32_t mgcp_rtp_packet_duration(const struct mgcp_endpoint *endp,
|
||||
codec->frame_duration_den;
|
||||
}
|
||||
|
||||
static int mgcp_trunk_osmux_init_if_needed(struct mgcp_trunk *trunk)
|
||||
{
|
||||
if (trunk->cfg->osmux.initialized)
|
||||
return 0;
|
||||
|
||||
if (osmux_init(trunk) < 0) {
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_ERROR, "Cannot init OSMUX\n");
|
||||
return -3;
|
||||
}
|
||||
LOGPTRUNK(trunk, DOSMUX, LOGL_NOTICE, "OSMUX socket has been set up\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Apply parsed SDP information stored in struct mgcp_parse_sdp to conn_rtp: */
|
||||
static int handle_sdp(struct mgcp_conn_rtp *conn, struct mgcp_request_data *rq)
|
||||
{
|
||||
@@ -905,10 +891,6 @@ static struct msgb *handle_create_con(struct mgcp_request_data *rq)
|
||||
return create_err_response(endp, endp, 517, "CRCX", pdata->trans);
|
||||
}
|
||||
|
||||
/* Make sure osmux is setup: */
|
||||
if (hpars->remote_osmux_cid != MGCP_PARSE_HDR_PARS_OSMUX_CID_UNSET)
|
||||
mgcp_trunk_osmux_init_if_needed(trunk);
|
||||
|
||||
/* Check if we are able to accept the creation of another connection */
|
||||
if (mgcp_endp_is_full(endp)) {
|
||||
LOGPENDP(endp, DLMGCP, LOGL_ERROR,
|
||||
@@ -990,6 +972,11 @@ static struct msgb *handle_create_con(struct mgcp_request_data *rq)
|
||||
|
||||
/* If X-Osmux (remote CID) was received, alloc next avail CID as local CID */
|
||||
if (hpars->remote_osmux_cid != MGCP_PARSE_HDR_PARS_OSMUX_CID_UNSET) {
|
||||
/* Make sure osmux is setup: */
|
||||
if (osmux_init(trunk) < 0) {
|
||||
rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_OSMUX));
|
||||
goto error2;
|
||||
}
|
||||
if (osmux_init_conn(conn_rtp) < 0) {
|
||||
rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_OSMUX));
|
||||
goto error2;
|
||||
|
Reference in New Issue
Block a user