From fbf78d13f1958ec9261d84c30125d01b783fb750 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 23 Aug 2021 22:31:39 +0200 Subject: [PATCH] endp: do not cache cfg pointer There is no obvious reason why we would want to complicate the code by caching pointers, since pointer traversal is probably not a performance bottleneck, and if it is we should rather take a look at our dozens of linked lists first.. Change-Id: I2456ba63598f76200d53e00223abf60bb36a49c0 --- include/osmocom/mgcp/mgcp_endp.h | 3 --- src/libosmo-mgcp/mgcp_conn.c | 2 +- src/libosmo-mgcp/mgcp_endp.c | 1 - src/libosmo-mgcp/mgcp_network.c | 18 ++++++++---------- src/libosmo-mgcp/mgcp_osmux.c | 4 ++-- src/libosmo-mgcp/mgcp_protocol.c | 18 +++++++++--------- src/libosmo-mgcp/mgcp_sdp.c | 4 ++-- src/libosmo-mgcp/mgcp_stat.c | 3 ++- src/libosmo-mgcp/mgcp_vty.c | 2 +- tests/mgcp/mgcp_test.c | 4 +--- 10 files changed, 26 insertions(+), 33 deletions(-) diff --git a/include/osmocom/mgcp/mgcp_endp.h b/include/osmocom/mgcp/mgcp_endp.h index f687bae76..b8796c1cf 100644 --- a/include/osmocom/mgcp/mgcp_endp.h +++ b/include/osmocom/mgcp/mgcp_endp.h @@ -97,9 +97,6 @@ struct mgcp_endpoint { /*! List of struct mgcp_conn, of the connections active on this endpoint */ struct llist_head conns; - /*! Backpointer to the MGW configuration */ - struct mgcp_config *cfg; - /*! Backpointer to the trunk this endpoint belongs to */ struct mgcp_trunk *trunk; diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index ca1234731..4acf18cf9 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -143,7 +143,7 @@ void mgcp_conn_watchdog_cb(void *data) void mgcp_conn_watchdog_kick(struct mgcp_conn *conn) { - int timeout = conn->endp->cfg->conn_timeout; + int timeout = conn->endp->trunk->cfg->conn_timeout; if (!timeout) return; diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c index 4fcddb80f..19446cea5 100644 --- a/src/libosmo-mgcp/mgcp_endp.c +++ b/src/libosmo-mgcp/mgcp_endp.c @@ -89,7 +89,6 @@ struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, return NULL; INIT_LLIST_HEAD(&endp->conns); - endp->cfg = trunk->cfg; endp->trunk = trunk; switch (trunk->trunk_type) { diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 5249fef1d..2d275ec8d 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -112,7 +112,7 @@ void mgcp_get_local_addr(char *addr, struct mgcp_conn_rtp *conn) char *bind_addr; /* Try probing the local IP-Address */ - if (endp->cfg->net_ports.bind_addr_probe && rem_addr_set) { + if (endp->trunk->cfg->net_ports.bind_addr_probe && rem_addr_set) { rc = osmo_sock_local_ip(addr, osmo_sockaddr_ntop(&conn->end.addr.u.sa, ipbuf)); if (rc < 0) LOGPCONN(conn->conn, DRTP, LOGL_ERROR, @@ -130,13 +130,13 @@ void mgcp_get_local_addr(char *addr, struct mgcp_conn_rtp *conn) /* Check there is a bind IP for the RTP traffic configured, * if so, use that IP-Address */ bind_addr = conn->end.addr.u.sa.sa_family == AF_INET6 ? - endp->cfg->net_ports.bind_addr_v6 : - endp->cfg->net_ports.bind_addr_v4; + endp->trunk->cfg->net_ports.bind_addr_v6 : + endp->trunk->cfg->net_ports.bind_addr_v4; } else { /* Choose any of the bind addresses, preferring v6 over v4 */ - bind_addr = endp->cfg->net_ports.bind_addr_v6; + bind_addr = endp->trunk->cfg->net_ports.bind_addr_v6; if (!strlen(bind_addr)) - bind_addr = endp->cfg->net_ports.bind_addr_v4; + bind_addr = endp->trunk->cfg->net_ports.bind_addr_v4; } if (strlen(bind_addr)) { LOGPCONN(conn->conn, DRTP, LOGL_DEBUG, @@ -146,7 +146,7 @@ void mgcp_get_local_addr(char *addr, struct mgcp_conn_rtp *conn) /* No specific bind IP is configured for the RTP traffic, so * assume the IP where we listen for incoming MGCP messages * as bind IP */ - bind_addr = endp->cfg->source_addr; + bind_addr = endp->trunk->cfg->source_addr; LOGPCONN(conn->conn, DRTP, LOGL_DEBUG, "using mgcp bind ip as local rtp bind ip: %s\n", bind_addr); } @@ -1177,9 +1177,7 @@ int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct osmo_sockaddr *addr do { /* Run transcoder */ - cont = endp->cfg->rtp_processing_cb(endp, rtp_end, - (char *)msgb_data(msg), &buflen, - RTP_BUF_SIZE); + cont = endp->trunk->cfg->rtp_processing_cb(endp, rtp_end, (char *)msgb_data(msg), &buflen, RTP_BUF_SIZE); if (cont < 0) break; @@ -1657,7 +1655,7 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port, osmo_fd_setup(&end->rtp, -1, OSMO_FD_READ, rtp_data_net, conn, 0); osmo_fd_setup(&end->rtcp, -1, OSMO_FD_READ, rtp_data_net, conn, 0); - return bind_rtp(endp->cfg, conn->end.local_addr, end, endp); + return bind_rtp(endp->trunk->cfg, conn->end.local_addr, end, endp); } /*! free allocated RTP and RTCP ports. diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c index 8f0a90689..de19042e3 100644 --- a/src/libosmo-mgcp/mgcp_osmux.c +++ b/src/libosmo-mgcp/mgcp_osmux.c @@ -116,7 +116,7 @@ static struct osmux_handle * osmux_handle_alloc(struct mgcp_conn_rtp *conn, struct in_addr *addr, int rem_port) { struct osmux_handle *h; - struct mgcp_config *cfg = conn->conn->endp->cfg; + struct mgcp_config *cfg = conn->conn->endp->trunk->cfg; h = talloc_zero(osmux, struct osmux_handle); if (!h) @@ -460,7 +460,7 @@ int osmux_enable_conn(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn, */ struct in6_addr addr_unset = {}; static const uint32_t rtp_ssrc_winlen = UINT32_MAX / (OSMUX_CID_MAX + 1); - uint16_t osmux_dummy = endp->cfg->osmux_dummy; + uint16_t osmux_dummy = endp->trunk->cfg->osmux_dummy; /* Check if osmux is enabled for the specified connection */ if (conn->osmux.state != OSMUX_STATE_ACTIVATING) { diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 736b071a3..6341f07cf 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -144,7 +144,7 @@ static const struct mgcp_request mgcp_requests[] = { static int setup_rtp_processing(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn) { - struct mgcp_config *cfg = endp->cfg; + struct mgcp_config *cfg = endp->trunk->cfg; struct mgcp_conn_rtp *conn_src = NULL; struct mgcp_conn_rtp *conn_dst = conn; struct mgcp_conn *_conn; @@ -273,7 +273,7 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp, * us for OSMUX connections. Perhaps adding a new internal API to get it * based on conn type. */ - const char *addr = strlen(endp->cfg->local_ip) ? endp->cfg->local_ip : conn->end.local_addr; + const char *addr = strlen(endp->trunk->cfg->local_ip) ? endp->trunk->cfg->local_ip : conn->end.local_addr; struct msgb *sdp; int rc; struct msgb *result; @@ -477,7 +477,7 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn) OSMO_ASSERT(conn); - range = &endp->cfg->net_ports; + range = &endp->trunk->cfg->net_ports; pthread_mutex_lock(&range->lock); /* attempt to find a port */ @@ -741,8 +741,8 @@ uint32_t mgcp_rtp_packet_duration(const struct mgcp_endpoint *endp, */ static int mgcp_osmux_setup(struct mgcp_endpoint *endp, const char *line) { - if (!endp->cfg->osmux_init) { - if (osmux_init(OSMUX_ROLE_BSC, endp->cfg) < 0) { + if (!endp->trunk->cfg->osmux_init) { + if (osmux_init(OSMUX_ROLE_BSC, endp->trunk->cfg) < 0) { LOGPENDP(endp, DLMGCP, LOGL_ERROR, "Cannot init OSMUX\n"); return -3; } @@ -887,7 +887,7 @@ static struct msgb *handle_create_con(struct mgcp_request_data *rq) case 'X': if (strncasecmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) { /* If osmux is disabled, just skip setting it up */ - if (!rq->endp->cfg->osmux) + if (!rq->endp->trunk->cfg->osmux) break; osmux_cid = mgcp_osmux_setup(endp, line); break; @@ -1001,7 +1001,7 @@ mgcp_header_done: rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_OSMUX)); goto error2; } - } else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) { + } else if (endp->trunk->cfg->osmux == 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)); @@ -1165,7 +1165,7 @@ static struct msgb *handle_modify_con(struct mgcp_request_data *rq) case 'X': if (strncasecmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) { /* If osmux is disabled, just skip setting it up */ - if (!endp->cfg->osmux) + if (!endp->trunk->cfg->osmux) break; osmux_cid = mgcp_osmux_setup(endp, line); break; @@ -1680,7 +1680,7 @@ int mgcp_send_reset_ep(struct mgcp_endpoint *endp) if (len < 0) return -1; - rc = send_agent(endp->cfg, buf, len); + rc = send_agent(endp->trunk->cfg, buf, len); if (rc <= 0) return -1; diff --git a/src/libosmo-mgcp/mgcp_sdp.c b/src/libosmo-mgcp/mgcp_sdp.c index 077ac9659..a36c6d2d5 100644 --- a/src/libosmo-mgcp/mgcp_sdp.c +++ b/src/libosmo-mgcp/mgcp_sdp.c @@ -576,7 +576,7 @@ int mgcp_write_response_sdp(const struct mgcp_endpoint *endp, OSMO_ASSERT(addr); /* FIXME: constify endp and conn args in get_net_donwlink_format_cb() */ - endp->cfg->get_net_downlink_format_cb((struct mgcp_endpoint *)endp, + endp->trunk->cfg->get_net_downlink_format_cb((struct mgcp_endpoint *)endp, &codec, &fmtp_extra, (struct mgcp_conn_rtp *)conn); @@ -601,7 +601,7 @@ int mgcp_write_response_sdp(const struct mgcp_endpoint *endp, payload_types[0] = payload_type; if (mgcp_conn_rtp_is_osmux(conn)) - local_port = endp->cfg->osmux_port; + local_port = endp->trunk->cfg->osmux_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 357b59343..59ef9170e 100644 --- a/src/libosmo-mgcp/mgcp_stat.c +++ b/src/libosmo-mgcp/mgcp_stat.c @@ -28,6 +28,7 @@ #include #include #include +#include /* Helper function for mgcp_format_stats_rtp() to calculate packet loss */ #if defined(__has_attribute) @@ -98,7 +99,7 @@ static void mgcp_format_stats_rtp(char *str, size_t str_len, str += nchars; str_len -= nchars; - if (conn->conn->endp->cfg->osmux != OSMUX_USAGE_OFF) { + if (conn->conn->endp->trunk->cfg->osmux != 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 738bfcc03..a05733f48 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -218,7 +218,7 @@ static void dump_endpoint(struct vty *vty, struct mgcp_endpoint *endp, vty_out(vty, " CONN: %s%s", mgcp_conn_dump(conn), VTY_NEWLINE); if (show_stats) { - if (endp->cfg->conn_timeout) { + if (endp->trunk->cfg->conn_timeout) { struct timeval remaining; osmo_timer_remaining(&conn->watchdog, NULL, &remaining); vty_out(vty, " Currently remaining timeout (seconds): %d.%06d%s", diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index 1c0d3cc1a..a8aad1400 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -960,7 +960,7 @@ static void test_retransmission(void) static int rqnt_cb(struct mgcp_endpoint *endp, char _tone) { ptrdiff_t tone = _tone; - endp->cfg->data = (void *)tone; + endp->trunk->cfg->data = (void *)tone; return 0; } @@ -1050,7 +1050,6 @@ static void test_packet_loss_calc(void) memset(&endp, 0, sizeof(endp)); cfg = mgcp_config_alloc(); trunk = mgcp_trunk_alloc(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID); - endp.cfg = cfg; endp.type = &ep_typeset.rtp; trunk->v.vty_number_endpoints = 1; trunk->endpoints = endpoints; @@ -1307,7 +1306,6 @@ static void test_packet_error_detection(int patch_ssrc, int patch_ts) state.in_stream.err_ts_ctr = &test_ctr_in; state.out_stream.err_ts_ctr = &test_ctr_out; - endp.cfg = cfg; endp.type = &ep_typeset.rtp; trunk->v.vty_number_endpoints = 1;