mgw: Clean up access to conn_rtp from conn

Add a new mgcp_conn_get_conn_rtp() and use it everywhere instead of
accessing deep structure fields.

Change-Id: Iee2c19598e9570ea3b1ceba3cdfd2a5f5be2c954
This commit is contained in:
Pau Espin Pedrol
2024-12-19 19:21:01 +01:00
parent 5d6931881a
commit cc97f58d96
9 changed files with 39 additions and 27 deletions

View File

@@ -28,6 +28,7 @@
#include <osmocom/mgcp/osmux.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/iuup.h>
#include <inttypes.h>
@@ -237,6 +238,12 @@ static inline bool mgcp_conn_rtp_is_iuup(const struct mgcp_conn_rtp *conn)
return conn->type == MGCP_RTP_IUUP;
}
static inline struct mgcp_conn_rtp *mgcp_conn_get_conn_rtp(struct mgcp_conn *conn)
{
OSMO_ASSERT(conn->type == MGCP_CONN_TYPE_RTP);
return &conn->u.rtp;
}
struct mgcp_conn *mgcp_conn_alloc(void *ctx, struct mgcp_endpoint *endp,
enum mgcp_conn_type type, char *name);
void mgcp_conn_free(struct mgcp_conn *conn);

View File

@@ -239,13 +239,16 @@ static void aggregate_rtp_conn_stats(struct mgcp_endpoint *endp, struct mgcp_con
*/
void mgcp_conn_free(struct mgcp_conn *conn)
{
struct mgcp_conn_rtp *conn_rtp;
if (!conn)
return;
switch (conn->type) {
case MGCP_CONN_TYPE_RTP:
aggregate_rtp_conn_stats(conn->endp, &conn->u.rtp);
mgcp_rtp_conn_cleanup(&conn->u.rtp);
conn_rtp = mgcp_conn_get_conn_rtp(conn);
aggregate_rtp_conn_stats(conn->endp, conn_rtp);
mgcp_rtp_conn_cleanup(conn_rtp);
break;
default:
/* NOTE: This should never be called with an
@@ -268,24 +271,26 @@ char *mgcp_conn_dump(struct mgcp_conn *conn)
static char str[sizeof(conn->name)+sizeof(conn->id)+256];
char ipbuf[INET6_ADDRSTRLEN];
struct osmo_strbuf sb = { .buf = str, .len = sizeof(str) };
struct mgcp_conn_rtp *conn_rtp;
if (!conn)
return "NULL";
switch (conn->type) {
case MGCP_CONN_TYPE_RTP:
conn_rtp = mgcp_conn_get_conn_rtp(conn);
OSMO_STRBUF_PRINTF(sb, "(%s/%s C:%s r=%s:%u<->l=%s:%u",
conn->name,
mgcp_conn_rtp_type_name(conn->type),
conn->id,
osmo_sockaddr_ntop(&conn->u.rtp.end.addr.u.sa, ipbuf) ? : "NULL",
osmo_sockaddr_port(&conn->u.rtp.end.addr.u.sa),
conn->u.rtp.end.local_addr ? : "NULL",
conn->u.rtp.end.local_port);
osmo_sockaddr_ntop(&conn_rtp->end.addr.u.sa, ipbuf) ? : "NULL",
osmo_sockaddr_port(&conn_rtp->end.addr.u.sa),
conn_rtp->end.local_addr ? : "NULL",
conn_rtp->end.local_port);
switch (conn->u.rtp.type) {
switch (conn_rtp->type) {
case MGCP_RTP_OSMUX:
OSMO_STRBUF_PRINTF(sb, " CID=%u", conn->u.rtp.osmux.local_cid);
OSMO_STRBUF_PRINTF(sb, " CID=%u", conn_rtp->osmux.local_cid);
break;
default:
break;

View File

@@ -650,6 +650,7 @@ int mgcp_e1_endp_equip(struct mgcp_endpoint *endp, uint8_t ts, uint8_t ss, uint8
void mgcp_e1_endp_update(struct mgcp_endpoint *endp)
{
struct mgcp_conn *conn;
struct mgcp_conn_rtp *conn_rtp;
struct mgcp_rtp_codec *codec;
enum osmo_tray_sync_pat_id sync_pat_id;
@@ -658,7 +659,8 @@ void mgcp_e1_endp_update(struct mgcp_endpoint *endp)
* endpoint no more than one connection should exist. */
conn = mgcp_endp_get_conn_oldest(endp);
OSMO_ASSERT(conn);
codec = conn->u.rtp.end.codec;
conn_rtp = mgcp_conn_get_conn_rtp(conn);
codec = conn_rtp->end.codec;
OSMO_ASSERT(codec);
/* Update codec information */

View File

@@ -741,7 +741,7 @@ struct mgcp_conn_rtp *mgcp_endp_get_conn_rtp(struct mgcp_endpoint *endp,
return NULL;
if (conn->type == MGCP_CONN_TYPE_RTP)
return &conn->u.rtp;
return mgcp_conn_get_conn_rtp(conn);
return NULL;
}

View File

@@ -110,20 +110,16 @@ int mgcp_parse_conn_mode(const char *mode, struct mgcp_endpoint *endp,
ret = -1;
}
/* Special handling for RTP connections */
if (conn->type == MGCP_CONN_TYPE_RTP) {
conn->u.rtp.end.output_enabled = !!(conn->mode & MGCP_CONN_SEND_ONLY);
}
LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "conn:%s\n", mgcp_conn_dump(conn));
LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "connection mode '%s' %d\n",
mode, conn->mode);
/* Special handling für RTP connections */
/* Special handling for RTP connections */
if (conn->type == MGCP_CONN_TYPE_RTP) {
struct mgcp_conn_rtp *conn_rtp = mgcp_conn_get_conn_rtp(conn);
conn_rtp->end.output_enabled = !!(conn->mode & MGCP_CONN_SEND_ONLY);
LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "output_enabled %u\n",
conn->u.rtp.end.output_enabled);
conn_rtp->end.output_enabled);
}
/* The VTY might change the connection mode at any time, so we have

View File

@@ -265,7 +265,7 @@ osmux_conn_lookup(const struct mgcp_trunk *trunk, uint8_t local_cid, const struc
if (conn->type != MGCP_CONN_TYPE_RTP)
continue;
conn_rtp = &conn->u.rtp;
conn_rtp = mgcp_conn_get_conn_rtp(conn);
if (!mgcp_conn_rtp_is_osmux(conn_rtp))
continue;

View File

@@ -172,7 +172,7 @@ static int setup_rtp_processing(struct mgcp_endpoint *endp,
/* Find the "sister" connection */
llist_for_each_entry(_conn, &endp->conns, entry) {
if (_conn->id != conn->conn->id) {
conn_src = &_conn->u.rtp;
conn_src = mgcp_conn_get_conn_rtp(_conn);
break;
}
}
@@ -819,7 +819,7 @@ static int handle_codec_info(struct mgcp_conn_rtp *conn,
/* Try to find an destination RTP connection that we can include in the codec decision. */
conn_dst = mgcp_find_dst_conn(conn->conn);
if (conn_dst && conn_dst->type == MGCP_CONN_TYPE_RTP)
conn_dst_rtp = &conn_dst->u.rtp;
conn_dst_rtp = mgcp_conn_get_conn_rtp(conn_dst);
else
conn_dst_rtp = NULL;
@@ -1609,7 +1609,7 @@ static void mgcp_keepalive_timer_cb(void *_trunk)
llist_for_each_entry(conn, &endp->conns, entry) {
if (conn->type == MGCP_CONN_TYPE_RTP &&
conn->mode == MGCP_CONN_RECV_ONLY)
send_dummy(endp, &conn->u.rtp);
send_dummy(endp, mgcp_conn_get_conn_rtp(conn));
}
}

View File

@@ -141,7 +141,7 @@ void mgcp_format_stats(char *str, size_t str_len, struct mgcp_conn *conn)
* keep this option open: */
switch (conn->type) {
case MGCP_CONN_TYPE_RTP:
mgcp_format_stats_rtp(str, str_len, &conn->u.rtp);
mgcp_format_stats_rtp(str, str_len, mgcp_conn_get_conn_rtp(conn));
break;
default:
break;

View File

@@ -254,7 +254,8 @@ static void dump_endpoint(struct vty *vty, struct mgcp_endpoint *endp,
* connection types (E1) as soon as
* the implementation is available */
if (conn->type == MGCP_CONN_TYPE_RTP) {
dump_rtp_end(vty, &conn->u.rtp);
struct mgcp_conn_rtp *conn_rtp = mgcp_conn_get_conn_rtp(conn);
dump_rtp_end(vty, conn_rtp);
}
}
}
@@ -1357,10 +1358,11 @@ DEFUN(loop_conn,
endp = trunk->endpoints[endp_no];
int loop = atoi(argv[2]);
llist_for_each_entry(conn, &endp->conns, entry) {
if (conn->type == MGCP_CONN_TYPE_RTP)
if (conn->type == MGCP_CONN_TYPE_RTP) {
/* Handle it like a MDCX, switch on SSRC patching if enabled */
mgcp_rtp_end_config(endp, 1, &conn->u.rtp.end);
else {
struct mgcp_conn_rtp *conn_rtp = mgcp_conn_get_conn_rtp(conn);
mgcp_rtp_end_config(endp, 1, &conn_rtp->end);
} else {
/* FIXME: Introduce support for other connection (E1)
* types when implementation is available */
vty_out(vty, "%%Can't enable SSRC patching,"