pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-mgw/+/39716?usp=email )
Change subject: mgw: Delay osmux trunk setup to point where it is really needed
......................................................................
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
---
M src/libosmo-mgcp/mgcp_osmux.c
M src/libosmo-mgcp/mgcp_protocol.c
2 files changed, 17 insertions(+), 25 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/16/39716/1
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index 31f128a..620220f 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -495,6 +495,9 @@
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,19 +510,19 @@
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",
- cfg->osmux.local_addr_v4, cfg->osmux.local_port);
+ 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;
}
fd = ret;
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,8 +534,8 @@
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",
- cfg->osmux.local_addr_v6, cfg->osmux.local_port);
+ 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;
}
fd = ret;
@@ -543,9 +546,10 @@
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 @@
osmo_iofd_free(osmux_fd_v4);
osmux_fd_v4 = NULL;
out:
+ LOGPTRUNK(trunk, DOSMUX, LOGL_ERROR, "Cannot init OSMUX\n");
return -1;
}
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index b985a1b..35d0811 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -702,20 +702,6 @@
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 @@
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 @@
/* 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;
--
To view, visit
https://gerrit.osmocom.org/c/osmo-mgw/+/39716?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: I27f7355ee99f1781fc2034a23c7cca756fb203d2
Gerrit-Change-Number: 39716
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>