pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/29725 )
Change subject: osmux: Clean up mgcp_config osmux fields ......................................................................
osmux: Clean up mgcp_config osmux fields
* Move all of them to an anonymous "osmux" substruct to have them all together. * Rename some fields to clarify its meanings, similar to what was already done in osmo-bts. * Move the port VTY config next to the ip address ones.
Change-Id: Icc1c1ce3ab3a8beb941cda7c112485a0db882a90 --- M include/osmocom/mgcp/mgcp.h M src/libosmo-mgcp/mgcp_network.c M src/libosmo-mgcp/mgcp_osmux.c M src/libosmo-mgcp/mgcp_protocol.c M src/libosmo-mgcp/mgcp_sdp.c M src/libosmo-mgcp/mgcp_stat.c M src/libosmo-mgcp/mgcp_vty.c 7 files changed, 81 insertions(+), 79 deletions(-)
Approvals: Jenkins Builder: Verified osmith: Looks good to me, but someone else must approve laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved
diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h index a48dec8..224d756 100644 --- a/include/osmocom/mgcp/mgcp.h +++ b/include/osmocom/mgcp/mgcp.h @@ -157,24 +157,26 @@
enum mgcp_role role;
- /* Osmux usage policy: */ - enum osmux_usage osmux_use; - /* addr to bind the server to */ - char *osmux_addr_v4; - char *osmux_addr_v6; - /* The osmux socket is allocated on demand (1st time used). - * This tells us if the osmux socket is already initialized. */ - bool osmux_initialized; - /* osmux batch factor: from 1 to 4 maximum */ - int osmux_batch; - /* osmux batch size (in bytes) */ - int osmux_batch_size; - /* osmux port */ - uint16_t osmux_port; - /* Pad circuit with dummy AMR frames if no payload to transmit is available */ - bool osmux_dummy; - /* Whether peer is behind NAT (Retrieve remote addr from 1st received Osmux packet) */ - bool osmux_peer_behind_nat; + struct { + /* Osmux usage policy: */ + enum osmux_usage usage; + /* addr to bind the server to */ + char *local_addr_v4; + char *local_addr_v6; + /* osmux port */ + uint16_t local_port; + /* The osmux socket is allocated on demand (1st time used). + * This tells us if the osmux socket is already initialized. */ + bool initialized; + /* osmux batch factor: from 1 to 4 maximum */ + int batch_factor; + /* osmux batch size (in bytes) */ + int batch_size; + /* Pad circuit with dummy AMR frames if no payload to transmit is available */ + bool dummy_padding; + /* Whether peer is behind NAT (Retrieve remote addr from 1st received Osmux packet) */ + bool peer_behind_nat; + } osmux; /* domain name of the media gateway */ char domain[255+1];
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 781bb44..3981975 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -102,19 +102,19 @@ if (rem_addr_set) { /* Match IP version with what was requested from remote: */ bind_addr = conn->end.addr.u.sa.sa_family == AF_INET6 ? - cfg->osmux_addr_v6 : - cfg->osmux_addr_v4; + cfg->osmux.local_addr_v6 : + cfg->osmux.local_addr_v4; } else { /* Choose any of the bind addresses, preferring v6 over v4 if available: */ - bind_addr = cfg->osmux_addr_v6; + bind_addr = cfg->osmux.local_addr_v6; if (!bind_addr) - bind_addr = cfg->osmux_addr_v4; + bind_addr = cfg->osmux.local_addr_v4; } if (!bind_addr) { LOGPCONN(conn->conn, DOSMUX, LOGL_ERROR, "Unable to locate local Osmux address, check your configuration! v4=%u v6=%u remote_known=%s\n", - !!cfg->osmux_addr_v4, - !!cfg->osmux_addr_v6, + !!cfg->osmux.local_addr_v4, + !!cfg->osmux.local_addr_v6, rem_addr_set ? osmo_sockaddr_ntop(&conn->end.addr.u.sa, ipbuf) : "no"); return -1; } diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c index f0d9e15..0fd1ba7 100644 --- a/src/libosmo-mgcp/mgcp_osmux.c +++ b/src/libosmo-mgcp/mgcp_osmux.c @@ -169,9 +169,9 @@ } /* sequence number to start OSMUX message from */ osmux_xfrm_input_set_initial_seqnum(h->in, 0); - osmux_xfrm_input_set_batch_factor(h->in, cfg->osmux_batch); + osmux_xfrm_input_set_batch_factor(h->in, cfg->osmux.batch_factor); /* If batch size is zero, the library defaults to 1472 bytes. */ - osmux_xfrm_input_set_batch_size(h->in, cfg->osmux_batch_size); + osmux_xfrm_input_set_batch_size(h->in, cfg->osmux.batch_size); osmux_xfrm_input_set_deliver_cb(h->in, osmux_deliver_cb, h);
llist_add(&h->head, &osmux_handle_list); @@ -287,7 +287,7 @@ h = osmux_xfrm_input_get_deliver_cb_data(conn_rtp->osmux.in); if (osmo_sockaddr_cmp(&h->rem_addr, rem_addr) != 0) continue; - } else if (!trunk->cfg->osmux_peer_behind_nat) { + } else if (!trunk->cfg->osmux.peer_behind_nat) { LOGPCONN(conn, DOSMUX, LOGL_DEBUG, "osmux_conn_lookup(rem_addr=%s local_cid=%d): Skipping because not (yet) ENABLED\n", osmo_sockaddr_to_str(rem_addr), local_cid); continue; /* skip, read above */ @@ -353,7 +353,7 @@ * conn_osmux_rx_mdcx() whenever a CRCX/MDCX with the remote address is received. */ cfg = conn->conn->endp->trunk->cfg; - if (!cfg->osmux_peer_behind_nat) { + if (!cfg->osmux.peer_behind_nat) { /* osmux_conn_lookup() should never provide us with an * ACTIVATING conn without NAT in first place. This should never happen. */ LOGPCONN(conn->conn, DOSMUX, LOGL_ERROR, @@ -392,7 +392,7 @@ /* If peer is behind NAT, we have to wait until 1st osmux frame is received * to discover peer's real remote address */ cfg = conn->conn->endp->trunk->cfg; - if (cfg->osmux_peer_behind_nat) + if (cfg->osmux.peer_behind_nat) return 0; /* Keep waiting to receive remote CID through CRCX/MDCX */ if (!conn->osmux.remote_cid_present) @@ -454,7 +454,7 @@ rate_ctr_inc(rate_ctr_group_get_ctr(all_rtp_stats, OSMUX_PACKETS_RX_CTR)); osmo_sockaddr_to_str_buf(addr_str, sizeof(addr_str), &rem_addr);
- if (trunk->cfg->osmux_use == OSMUX_USAGE_OFF) { + if (trunk->cfg->osmux.usage == OSMUX_USAGE_OFF) { LOGP(DOSMUX, LOGL_ERROR, "Peer %s wants to use Osmux but MGCP Client did not request it\n", addr_str); @@ -505,12 +505,12 @@ osmo_fd_setup(&osmux_fd_v4, -1, OSMO_FD_READ, osmux_read_fd_cb, trunk, 0); osmo_fd_setup(&osmux_fd_v6, -1, OSMO_FD_READ, osmux_read_fd_cb, trunk, 0);
- if (cfg->osmux_addr_v4) { - ret = mgcp_create_bind(cfg->osmux_addr_v4, &osmux_fd_v4, cfg->osmux_port, + if (cfg->osmux.local_addr_v4) { + ret = mgcp_create_bind(cfg->osmux.local_addr_v4, &osmux_fd_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_addr_v4, cfg->osmux_port); + cfg->osmux.local_addr_v4, cfg->osmux.local_port); return ret; }
@@ -523,12 +523,12 @@ LOGP(DOSMUX, LOGL_INFO, "OSMUX IPv4 socket listening on %s\n", osmo_sock_get_name2(osmux_fd_v4.fd)); } - if (cfg->osmux_addr_v6) { - ret = mgcp_create_bind(cfg->osmux_addr_v6, &osmux_fd_v6, cfg->osmux_port, + if (cfg->osmux.local_addr_v6) { + ret = mgcp_create_bind(cfg->osmux.local_addr_v6, &osmux_fd_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_addr_v6, cfg->osmux_port); + cfg->osmux.local_addr_v6, cfg->osmux.local_port); return ret; }
@@ -541,7 +541,7 @@ LOGP(DOSMUX, LOGL_INFO, "OSMUX IPv6 socket listening on %s\n", osmo_sock_get_name2(osmux_fd_v6.fd)); } - cfg->osmux_initialized = true; + cfg->osmux.initialized = true; return 0; }
@@ -608,7 +608,7 @@ */ const struct mgcp_trunk *trunk = conn->conn->endp->trunk; static const uint32_t rtp_ssrc_winlen = UINT32_MAX / (OSMUX_CID_MAX + 1); - bool osmux_dummy = trunk->cfg->osmux_dummy; + bool osmux_dummy = trunk->cfg->osmux.dummy_padding;
/* Wait until we have the remote connection information, be it from MDCX (peer not behind NAT) * or later learned from first received remote osmux packet (peer behind NAT) */ diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index f3ebe60..77c99f3 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -745,7 +745,7 @@ */ static int mgcp_osmux_setup(struct mgcp_endpoint *endp, const char *line) { - if (!endp->trunk->cfg->osmux_initialized) { + if (!endp->trunk->cfg->osmux.initialized) { if (osmux_init(endp->trunk) < 0) { LOGPENDP(endp, DOSMUX, LOGL_ERROR, "Cannot init OSMUX\n"); return -3; @@ -898,7 +898,7 @@ case 'X': if (strncasecmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) { /* If osmux is disabled, just skip setting it up */ - if (rq->endp->trunk->cfg->osmux_use == OSMUX_USAGE_OFF) + if (rq->endp->trunk->cfg->osmux.usage == OSMUX_USAGE_OFF) break; remote_osmux_cid = mgcp_osmux_setup(endp, line); break; @@ -1013,7 +1013,7 @@ conn->osmux.remote_cid_present = true; conn->osmux.remote_cid = remote_osmux_cid; } - } else if (endp->trunk->cfg->osmux_use == OSMUX_USAGE_ONLY) { + } else if (endp->trunk->cfg->osmux.usage == OSMUX_USAGE_ONLY) { LOGPCONN(_conn, DLMGCP, LOGL_ERROR, "CRCX: osmux only and no osmux offered\n"); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_OSMUX)); @@ -1190,7 +1190,7 @@ case 'X': if (strncasecmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) { /* If osmux is disabled, just skip setting it up */ - if (endp->trunk->cfg->osmux_use == OSMUX_USAGE_OFF) + if (endp->trunk->cfg->osmux.usage == OSMUX_USAGE_OFF) break; remote_osmux_cid = mgcp_osmux_setup(endp, line); break; diff --git a/src/libosmo-mgcp/mgcp_sdp.c b/src/libosmo-mgcp/mgcp_sdp.c index 1414cf9..ad2da7f 100644 --- a/src/libosmo-mgcp/mgcp_sdp.c +++ b/src/libosmo-mgcp/mgcp_sdp.c @@ -601,7 +601,7 @@
payload_types[0] = payload_type; if (mgcp_conn_rtp_is_osmux(conn)) - local_port = endp->trunk->cfg->osmux_port; + local_port = endp->trunk->cfg->osmux.local_port; else local_port = conn->end.local_port; rc = add_audio(sdp, payload_types, 1, local_port); diff --git a/src/libosmo-mgcp/mgcp_stat.c b/src/libosmo-mgcp/mgcp_stat.c index acc9419..c66ce6b 100644 --- a/src/libosmo-mgcp/mgcp_stat.c +++ b/src/libosmo-mgcp/mgcp_stat.c @@ -99,7 +99,7 @@ str += nchars; str_len -= nchars;
- if (conn->conn->endp->trunk->cfg->osmux_use != OSMUX_USAGE_OFF) { + if (conn->conn->endp->trunk->cfg->osmux.usage != OSMUX_USAGE_OFF) { /* Error Counter */ nchars = snprintf(str, str_len, "\r\nX-Osmo-CP: EC TI=%" PRIu64 ", TO=%" PRIu64, diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c index faa6479..e404fb5 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -129,7 +129,7 @@ vty_out(vty, " rtp force-ptime %d%s", g_cfg->force_ptime, VTY_NEWLINE);
- switch (g_cfg->osmux_use) { + switch (g_cfg->osmux.usage) { case OSMUX_USAGE_ON: vty_out(vty, " osmux on%s", VTY_NEWLINE); break; @@ -141,23 +141,23 @@ vty_out(vty, " osmux off%s", VTY_NEWLINE); break; } - if (g_cfg->osmux_use != OSMUX_USAGE_OFF) { - if (g_cfg->osmux_addr_v4) + if (g_cfg->osmux.usage != OSMUX_USAGE_OFF) { + if (g_cfg->osmux.local_addr_v4) vty_out(vty, " osmux bind-ip %s%s", - g_cfg->osmux_addr_v4, VTY_NEWLINE); - if (g_cfg->osmux_addr_v6) + g_cfg->osmux.local_addr_v4, VTY_NEWLINE); + if (g_cfg->osmux.local_addr_v6) vty_out(vty, " osmux bind-ip-v6 %s%s", - g_cfg->osmux_addr_v6, VTY_NEWLINE); + g_cfg->osmux.local_addr_v6, VTY_NEWLINE); vty_out(vty, " osmux batch-factor %d%s", - g_cfg->osmux_batch, VTY_NEWLINE); + g_cfg->osmux.batch_factor, VTY_NEWLINE); vty_out(vty, " osmux batch-size %u%s", - g_cfg->osmux_batch_size, VTY_NEWLINE); + g_cfg->osmux.batch_size, VTY_NEWLINE); vty_out(vty, " osmux port %u%s", - g_cfg->osmux_port, VTY_NEWLINE); + g_cfg->osmux.local_port, VTY_NEWLINE); vty_out(vty, " osmux dummy %s%s", - g_cfg->osmux_dummy ? "on" : "off", VTY_NEWLINE); + g_cfg->osmux.dummy_padding ? "on" : "off", VTY_NEWLINE); vty_out(vty, " osmux peer-behind-nat %s%s", - g_cfg->osmux_peer_behind_nat ? "on" : "off", VTY_NEWLINE); + g_cfg->osmux.peer_behind_nat ? "on" : "off", VTY_NEWLINE); }
if (g_cfg->conn_timeout) @@ -380,7 +380,7 @@ llist_for_each_entry(trunk, &g_cfg->trunks, entry) dump_trunk(vty, trunk, show_stats, active_only);
- if (g_cfg->osmux_use != OSMUX_USAGE_OFF) + if (g_cfg->osmux.usage != OSMUX_USAGE_OFF) vty_out(vty, "Osmux used CID: %d%s", osmux_cid_pool_count_used(), VTY_NEWLINE);
@@ -1577,12 +1577,12 @@ OSMO_ASSERT(trunk);
if (strcmp(argv[0], "off") == 0) { - g_cfg->osmux_use = OSMUX_USAGE_OFF; + g_cfg->osmux.usage = OSMUX_USAGE_OFF; return CMD_SUCCESS; } else if (strcmp(argv[0], "on") == 0) - g_cfg->osmux_use = OSMUX_USAGE_ON; + g_cfg->osmux.usage = OSMUX_USAGE_ON; else if (strcmp(argv[0], "only") == 0) - g_cfg->osmux_use = OSMUX_USAGE_ONLY; + g_cfg->osmux.usage = OSMUX_USAGE_ONLY;
return CMD_SUCCESS;
@@ -1594,7 +1594,7 @@ OSMUX_STR IP_STR "IPv4 Address to bind to\n") { - osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr_v4, argv[0]); + osmo_talloc_replace_string(g_cfg, &g_cfg->osmux.local_addr_v4, argv[0]); return CMD_SUCCESS; }
@@ -1604,7 +1604,15 @@ OSMUX_STR IP_STR "IPv6 Address to bind to\n") { - osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr_v6, argv[0]); + osmo_talloc_replace_string(g_cfg, &g_cfg->osmux.local_addr_v6, argv[0]); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgcp_osmux_port, + cfg_mgcp_osmux_port_cmd, + "osmux port <1-65535>", OSMUX_STR "port\n" "UDP port\n") +{ + g_cfg->osmux.local_port = atoi(argv[0]); return CMD_SUCCESS; }
@@ -1613,7 +1621,7 @@ "osmux batch-factor <1-8>", OSMUX_STR "Batching factor\n" "Number of messages in the batch\n") { - g_cfg->osmux_batch = atoi(argv[0]); + g_cfg->osmux.batch_factor = atoi(argv[0]); return CMD_SUCCESS; }
@@ -1622,15 +1630,7 @@ "osmux batch-size <1-65535>", OSMUX_STR "batch size\n" "Batch size in bytes\n") { - g_cfg->osmux_batch_size = atoi(argv[0]); - return CMD_SUCCESS; -} - -DEFUN(cfg_mgcp_osmux_port, - cfg_mgcp_osmux_port_cmd, - "osmux port <1-65535>", OSMUX_STR "port\n" "UDP port\n") -{ - g_cfg->osmux_port = atoi(argv[0]); + g_cfg->osmux.batch_size = atoi(argv[0]); return CMD_SUCCESS; }
@@ -1641,9 +1641,9 @@ "Disable dummy padding\n") { if (strcmp(argv[0], "on") == 0) - g_cfg->osmux_dummy = true; + g_cfg->osmux.dummy_padding = true; else if (strcmp(argv[0], "off") == 0) - g_cfg->osmux_dummy = false; + g_cfg->osmux.dummy_padding = false;
return CMD_SUCCESS; } @@ -1656,9 +1656,9 @@ "Peer is NOT behind NAT\n") { if (strcmp(argv[0], "on") == 0) - g_cfg->osmux_peer_behind_nat = true; + g_cfg->osmux.peer_behind_nat = true; else if (strcmp(argv[0], "off") == 0) - g_cfg->osmux_peer_behind_nat = false; + g_cfg->osmux.peer_behind_nat = false;
return CMD_SUCCESS; } @@ -1749,9 +1749,9 @@ install_element(MGCP_NODE, &cfg_mgcp_osmux_cmd); install_element(MGCP_NODE, &cfg_mgcp_osmux_ip_cmd); install_element(MGCP_NODE, &cfg_mgcp_osmux_ip_v6_cmd); + install_element(MGCP_NODE, &cfg_mgcp_osmux_port_cmd); install_element(MGCP_NODE, &cfg_mgcp_osmux_batch_factor_cmd); install_element(MGCP_NODE, &cfg_mgcp_osmux_batch_size_cmd); - install_element(MGCP_NODE, &cfg_mgcp_osmux_port_cmd); install_element(MGCP_NODE, &cfg_mgcp_osmux_dummy_cmd); install_element(MGCP_NODE, &cfg_mgcp_osmux_peer_behind_nat_cmd); install_element(MGCP_NODE, &cfg_mgcp_allow_transcoding_cmd); @@ -1798,9 +1798,9 @@ int rc; struct mgcp_trunk *trunk;
- cfg->osmux_port = OSMUX_DEFAULT_PORT; - cfg->osmux_batch = 4; - cfg->osmux_batch_size = OSMUX_BATCH_DEFAULT_MAX; + cfg->osmux.local_port = OSMUX_DEFAULT_PORT; + cfg->osmux.batch_factor = 4; + cfg->osmux.batch_size = OSMUX_BATCH_DEFAULT_MAX;
g_cfg = cfg; rc = vty_read_config_file(config_file, NULL);