blob: b97c161e574235e916552031d4748477b1b56d54 [file] [log] [blame]
Philipp Maier87bd9be2017-08-22 16:35:41 +02001/* Message connection list handling */
2
3/*
4 * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
5 * All Rights Reserved
6 *
7 * Author: Philipp Maier
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
Erica94c56e2021-09-07 00:10:31 +020024#include <stdatomic.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020025#include <osmocom/mgcp/mgcp_conn.h>
Philipp Maier993ea6b2020-08-04 18:26:50 +020026#include <osmocom/mgcp/mgcp_network.h>
27#include <osmocom/mgcp/mgcp_protocol.h>
Neels Hofmeyr67793542017-09-08 04:25:16 +020028#include <osmocom/mgcp/mgcp_common.h>
Philipp Maier37d11c82018-02-01 14:38:12 +010029#include <osmocom/mgcp/mgcp_endp.h>
Philipp Maierc66ab2c2020-06-02 20:55:34 +020030#include <osmocom/mgcp/mgcp_trunk.h>
Philipp Maierbc0346e2018-06-07 09:52:16 +020031#include <osmocom/mgcp/mgcp_sdp.h>
32#include <osmocom/mgcp/mgcp_codec.h>
Pau Espin Pedrolbb3ccde2021-12-23 19:49:26 +010033#include <osmocom/mgcp/mgcp_iuup.h>
34
Philipp Maierffd75e42017-11-22 11:44:50 +010035#include <osmocom/gsm/gsm_utils.h>
Philipp Maier9e1d1642018-05-09 16:26:34 +020036#include <osmocom/core/rate_ctr.h>
Oliver Smithe36b7752019-01-22 16:31:36 +010037#include <osmocom/core/timer.h>
Philipp Maierffd75e42017-11-22 11:44:50 +010038#include <ctype.h>
39
Pau Espin Pedrol663ba5c2022-09-22 21:43:31 +020040static const struct rate_ctr_group_desc rate_ctr_group_desc = {
Philipp Maier9e1d1642018-05-09 16:26:34 +020041 .group_name_prefix = "conn_rtp",
42 .group_description = "rtp connection statistics",
43 .class_id = 1,
Stefan Sperlingba25eab2018-10-30 14:32:31 +010044 .num_ctr = ARRAY_SIZE(mgcp_conn_rate_ctr_desc),
45 .ctr_desc = mgcp_conn_rate_ctr_desc
Philipp Maier9e1d1642018-05-09 16:26:34 +020046};
47
48
Philipp Maierffd75e42017-11-22 11:44:50 +010049/* Allocate a new connection identifier. According to RFC3435, they must
Philipp Maierf8bfbe82017-11-23 19:32:31 +010050 * be unique only within the scope of the endpoint. (Caller must provide
51 * memory for id) */
Philipp Maierffd75e42017-11-22 11:44:50 +010052static int mgcp_alloc_id(struct mgcp_endpoint *endp, char *id)
53{
Neels Hofmeyra729db62018-08-28 16:20:51 +020054#define MGCP_CONN_ID_GEN_LEN 8
Philipp Maierffd75e42017-11-22 11:44:50 +010055 int i;
56 int k;
57 int rc;
Neels Hofmeyra729db62018-08-28 16:20:51 +020058 uint8_t id_bin[MGCP_CONN_ID_GEN_LEN / 2];
Philipp Maierffd75e42017-11-22 11:44:50 +010059 char *id_hex;
60
61 /* Generate a connection id that is unique for the current endpoint.
62 * Technically a counter would be sufficient, but in order to
63 * be able to find a specific connection in large logfiles and to
64 * prevent unintentional connections we assign the connection
65 * identifiers randomly from a reasonable large number space */
66 for (i = 0; i < 32; i++) {
67 rc = osmo_get_rand_id(id_bin, sizeof(id_bin));
68 if (rc < 0)
69 return rc;
70
71 id_hex = osmo_hexdump_nospc(id_bin, sizeof(id_bin));
72 for (k = 0; k < strlen(id_hex); k++)
73 id_hex[k] = toupper(id_hex[k]);
74
75 /* ensure that the generated conn_id is unique
76 * for this endpoint */
77 if (!mgcp_conn_get_rtp(endp, id_hex)) {
Neels Hofmeyr55e0dcf2018-09-03 21:36:56 +020078 osmo_strlcpy(id, id_hex, MGCP_CONN_ID_MAXLEN);
Philipp Maierffd75e42017-11-22 11:44:50 +010079 return 0;
80 }
81 }
82
Pau Espin Pedrol3239f622019-04-24 18:47:46 +020083 LOGPENDP(endp, DLMGCP, LOGL_ERROR, "unable to generate a unique connectionIdentifier\n");
Philipp Maierffd75e42017-11-22 11:44:50 +010084
85 return -1;
86}
Philipp Maier87bd9be2017-08-22 16:35:41 +020087
Philipp Maierc430d192018-03-16 12:11:18 +010088/* Initialize rtp connection struct with default values */
Harald Welte3ac604e2019-05-08 14:07:41 +020089static int mgcp_rtp_conn_init(struct mgcp_conn_rtp *conn_rtp, struct mgcp_conn *conn)
Philipp Maier87bd9be2017-08-22 16:35:41 +020090{
Philipp Maier892dec02018-03-16 12:32:01 +010091 struct mgcp_rtp_end *end = &conn_rtp->end;
Philipp Maier9e1d1642018-05-09 16:26:34 +020092 /* FIXME: Each new rate counter group requires an unique index. At the
93 * moment we generate this index using this counter, but perhaps there
94 * is a more concious way to assign the indexes. */
Erica94c56e2021-09-07 00:10:31 +020095 static atomic_uint rate_ctr_index = 0;
Philipp Maier87bd9be2017-08-22 16:35:41 +020096
Philipp Maier892dec02018-03-16 12:32:01 +010097 conn_rtp->type = MGCP_RTP_DEFAULT;
Pau Espin Pedrolc0e1b1a2022-10-06 16:21:37 +020098
99 /* Osmux specific defaults, only used if conn is later on Osmux-enabled: */
100 conn_rtp->osmux.state = OSMUX_STATE_DISABLED;
Pau Espin Pedrol21779192022-09-23 16:46:33 +0200101 conn_rtp->osmux.local_cid_allocated = false;
102 conn_rtp->osmux.local_cid = 0;
103 conn_rtp->osmux.remote_cid_present = false;
104 conn_rtp->osmux.remote_cid = 0;
Philipp Maier892dec02018-03-16 12:32:01 +0100105
106 /* backpointer to the generic part of the connection */
107 conn->u.rtp.conn = conn;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200108
109 end->rtp.fd = -1;
110 end->rtcp.fd = -1;
Pau Espin Pedrol5ffd1272022-10-04 13:45:48 +0200111 memset(&end->addr, 0, sizeof(end->addr));
112 end->rtcp_port = 0;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200113 talloc_free(end->fmtp_extra);
114 end->fmtp_extra = NULL;
115
116 /* Set default values */
117 end->frames_per_packet = 0; /* unknown */
118 end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS;
Pau Espin Pedrol2c401642021-12-24 14:48:26 +0100119 end->output_enabled = false;
Philipp Maierbc0346e2018-06-07 09:52:16 +0200120 end->maximum_packet_time = -1;
Philipp Maier9e1d1642018-05-09 16:26:34 +0200121
Pau Espin Pedroldaf5bce2022-09-22 19:14:24 +0200122 conn_rtp->ctrg = rate_ctr_group_alloc(conn, &rate_ctr_group_desc, rate_ctr_index++);
123 if (!conn_rtp->ctrg)
Harald Welte3ac604e2019-05-08 14:07:41 +0200124 return -1;
125
Pau Espin Pedroldaf5bce2022-09-22 19:14:24 +0200126 conn_rtp->state.in_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, IN_STREAM_ERR_TSTMP_CTR);
127 conn_rtp->state.out_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, OUT_STREAM_ERR_TSTMP_CTR);
Philipp Maierbc0346e2018-06-07 09:52:16 +0200128
129 /* Make sure codec table is reset */
130 mgcp_codec_reset_all(conn_rtp);
Harald Welte3ac604e2019-05-08 14:07:41 +0200131
132 return 0;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200133}
134
Philipp Maierd0b470d2018-03-16 12:45:53 +0100135/* Cleanup rtp connection struct */
136static void mgcp_rtp_conn_cleanup(struct mgcp_conn_rtp *conn_rtp)
137{
Pau Espin Pedrol85978da2019-05-17 14:38:19 +0200138 if (mgcp_conn_rtp_is_osmux(conn_rtp))
139 conn_osmux_disable(conn_rtp);
Pau Espin Pedrolbb3ccde2021-12-23 19:49:26 +0100140 if (mgcp_conn_rtp_is_iuup(conn_rtp))
141 mgcp_conn_iuup_cleanup(conn_rtp);
Philipp Maierd0b470d2018-03-16 12:45:53 +0100142 mgcp_free_rtp_port(&conn_rtp->end);
Pau Espin Pedroldaf5bce2022-09-22 19:14:24 +0200143 rate_ctr_group_free(conn_rtp->ctrg);
Neels Hofmeyr401b7402019-08-08 22:14:08 +0200144 mgcp_codec_reset_all(conn_rtp);
Philipp Maierd0b470d2018-03-16 12:45:53 +0100145}
146
Oliver Smithe36b7752019-01-22 16:31:36 +0100147void mgcp_conn_watchdog_cb(void *data)
148{
149 struct mgcp_conn *conn = data;
Pau Espin Pedrol3239f622019-04-24 18:47:46 +0200150 LOGPCONN(conn, DLMGCP, LOGL_ERROR, "connection timed out!\n");
Oliver Smithe36b7752019-01-22 16:31:36 +0100151 mgcp_conn_free(conn->endp, conn->id);
152}
153
154void mgcp_conn_watchdog_kick(struct mgcp_conn *conn)
155{
Ericfbf78d12021-08-23 22:31:39 +0200156 int timeout = conn->endp->trunk->cfg->conn_timeout;
Oliver Smithe36b7752019-01-22 16:31:36 +0100157 if (!timeout)
158 return;
159
Pau Espin Pedrol3239f622019-04-24 18:47:46 +0200160 LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "watchdog kicked\n");
Oliver Smithe36b7752019-01-22 16:31:36 +0100161 osmo_timer_schedule(&conn->watchdog, timeout, 0);
162}
163
Philipp Maier87bd9be2017-08-22 16:35:41 +0200164/*! allocate a new connection list entry.
165 * \param[in] ctx talloc context
166 * \param[in] endp associated endpoint
167 * \param[in] id identification number of the connection
168 * \param[in] type connection type (e.g. MGCP_CONN_TYPE_RTP)
169 * \returns pointer to allocated connection, NULL on error */
170struct mgcp_conn *mgcp_conn_alloc(void *ctx, struct mgcp_endpoint *endp,
Philipp Maierffd75e42017-11-22 11:44:50 +0100171 enum mgcp_conn_type type, char *name)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200172{
173 struct mgcp_conn *conn;
Philipp Maierffd75e42017-11-22 11:44:50 +0100174 int rc;
175
Philipp Maier87bd9be2017-08-22 16:35:41 +0200176 /* Do not allow more then two connections */
177 if (llist_count(&endp->conns) >= endp->type->max_conns)
178 return NULL;
179
Philipp Maier87bd9be2017-08-22 16:35:41 +0200180 /* Create new connection and add it to the list */
181 conn = talloc_zero(ctx, struct mgcp_conn);
182 if (!conn)
183 return NULL;
184 conn->endp = endp;
185 conn->type = type;
186 conn->mode = MGCP_CONN_NONE;
187 conn->mode_orig = MGCP_CONN_NONE;
Philipp Maierf8bfbe82017-11-23 19:32:31 +0100188 osmo_strlcpy(conn->name, name, sizeof(conn->name));
Philipp Maierffd75e42017-11-22 11:44:50 +0100189 rc = mgcp_alloc_id(endp, conn->id);
190 if (rc < 0) {
191 talloc_free(conn);
192 return NULL;
193 }
Philipp Maier87bd9be2017-08-22 16:35:41 +0200194
195 switch (type) {
196 case MGCP_CONN_TYPE_RTP:
Harald Welte3ac604e2019-05-08 14:07:41 +0200197 if (mgcp_rtp_conn_init(&conn->u.rtp, conn) < 0) {
198 talloc_free(conn);
199 return NULL;
200 }
Philipp Maier87bd9be2017-08-22 16:35:41 +0200201 break;
202 default:
203 /* NOTE: This should never be called with an
204 * invalid type, its up to the programmer
205 * to ensure propery types */
206 OSMO_ASSERT(false);
207 }
208
Oliver Smithe36b7752019-01-22 16:31:36 +0100209 /* Initialize watchdog */
210 osmo_timer_setup(&conn->watchdog, mgcp_conn_watchdog_cb, conn);
211 mgcp_conn_watchdog_kick(conn);
Pau Espin Pedrol6d0a59a2020-09-08 16:50:22 +0200212 mgcp_endp_add_conn(endp, conn);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200213
214 return conn;
215}
216
217/*! find a connection by its ID.
218 * \param[in] endp associated endpoint
219 * \param[in] id identification number of the connection
220 * \returns pointer to allocated connection, NULL if not found */
Philipp Maier01d24a32017-11-21 17:26:09 +0100221struct mgcp_conn *mgcp_conn_get(struct mgcp_endpoint *endp, const char *id)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200222{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200223 struct mgcp_conn *conn;
Neels Hofmeyr65317262018-09-03 22:11:05 +0200224 const char *id_upper;
Neels Hofmeyra77eade2018-08-29 02:30:39 +0200225 const char *conn_id;
Neels Hofmeyr65317262018-09-03 22:11:05 +0200226
227 if (!id || !*id)
228 return NULL;
229
Neels Hofmeyra77eade2018-08-29 02:30:39 +0200230 /* Ignore leading zeros in needle */
231 while (*id == '0')
232 id++;
233
Neels Hofmeyr65317262018-09-03 22:11:05 +0200234 /* Use uppercase to compare identifiers, to avoid mismatches: RFC3435 2.1.3.2 "Names of
235 * Connections" defines the id as a hex string, so clients may return lower case hex even though
236 * we sent upper case hex in the CRCX response. */
237 id_upper = osmo_str_toupper(id);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200238
239 llist_for_each_entry(conn, &endp->conns, entry) {
Neels Hofmeyra77eade2018-08-29 02:30:39 +0200240 /* Ignore leading zeros in haystack */
241 for (conn_id=conn->id; *conn_id == '0'; conn_id++);
242
243 if (strcmp(conn_id, id_upper) == 0)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200244 return conn;
245 }
246
247 return NULL;
248}
249
250/*! find an RTP connection by its ID.
251 * \param[in] endp associated endpoint
252 * \param[in] id identification number of the connection
253 * \returns pointer to allocated connection, NULL if not found */
Philipp Maier01d24a32017-11-21 17:26:09 +0100254struct mgcp_conn_rtp *mgcp_conn_get_rtp(struct mgcp_endpoint *endp,
255 const char *id)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200256{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200257 struct mgcp_conn *conn;
258
259 conn = mgcp_conn_get(endp, id);
260 if (!conn)
261 return NULL;
262
263 if (conn->type == MGCP_CONN_TYPE_RTP)
264 return &conn->u.rtp;
265
266 return NULL;
267}
268
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200269static void aggregate_rtp_conn_stats(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn_rtp)
Stefan Sperlingba25eab2018-10-30 14:32:31 +0100270{
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200271 struct rate_ctr_group *all_stats = endp->trunk->ratectr.all_rtp_conn_stats;
Pau Espin Pedroldaf5bce2022-09-22 19:14:24 +0200272 struct rate_ctr_group *conn_stats = conn_rtp->ctrg;
Stefan Sperlingba25eab2018-10-30 14:32:31 +0100273
274 if (all_stats == NULL || conn_stats == NULL)
275 return;
276
277 /* Compared to per-connection RTP statistics, aggregated RTP statistics
278 * contain one additional rate couter item (RTP_NUM_CONNECTIONS).
279 * All other counters in both counter groups correspond to each other. */
280 OSMO_ASSERT(conn_stats->desc->num_ctr + 1 == all_stats->desc->num_ctr);
281
Harald Weltea48ff4a2020-03-08 14:45:08 +0100282 /* all other counters are [now] updated in real-time */
Pau Espin Pedrol907744e2021-06-04 17:57:34 +0200283 rate_ctr_add(rate_ctr_group_get_ctr(all_stats, IN_STREAM_ERR_TSTMP_CTR),
284 rate_ctr_group_get_ctr(conn_stats, IN_STREAM_ERR_TSTMP_CTR)->current);
285 rate_ctr_add(rate_ctr_group_get_ctr(all_stats, OUT_STREAM_ERR_TSTMP_CTR),
286 rate_ctr_group_get_ctr(conn_stats, OUT_STREAM_ERR_TSTMP_CTR)->current);
Stefan Sperlingba25eab2018-10-30 14:32:31 +0100287
Pau Espin Pedrol907744e2021-06-04 17:57:34 +0200288 rate_ctr_inc(rate_ctr_group_get_ctr(all_stats, RTP_NUM_CONNECTIONS));
Stefan Sperlingba25eab2018-10-30 14:32:31 +0100289}
290
Philipp Maier87bd9be2017-08-22 16:35:41 +0200291/*! free a connection by its ID.
292 * \param[in] endp associated endpoint
293 * \param[in] id identification number of the connection */
Philipp Maier01d24a32017-11-21 17:26:09 +0100294void mgcp_conn_free(struct mgcp_endpoint *endp, const char *id)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200295{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200296 struct mgcp_conn *conn;
297
298 conn = mgcp_conn_get(endp, id);
299 if (!conn)
300 return;
301
302 switch (conn->type) {
303 case MGCP_CONN_TYPE_RTP:
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200304 aggregate_rtp_conn_stats(endp, &conn->u.rtp);
Philipp Maierd0b470d2018-03-16 12:45:53 +0100305 mgcp_rtp_conn_cleanup(&conn->u.rtp);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200306 break;
307 default:
308 /* NOTE: This should never be called with an
309 * invalid type, its up to the programmer
310 * to ensure propery types */
311 OSMO_ASSERT(false);
312 }
313
Oliver Smithe36b7752019-01-22 16:31:36 +0100314 osmo_timer_del(&conn->watchdog);
Pau Espin Pedrol6d0a59a2020-09-08 16:50:22 +0200315 mgcp_endp_remove_conn(endp, conn);
316 /* WARN: endp may have be freed after call to mgcp_endp_remove_conn */
Philipp Maier87bd9be2017-08-22 16:35:41 +0200317 talloc_free(conn);
318}
319
320/*! free oldest connection in the list.
321 * \param[in] endp associated endpoint */
322void mgcp_conn_free_oldest(struct mgcp_endpoint *endp)
323{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200324 struct mgcp_conn *conn;
325
326 if (llist_empty(&endp->conns))
327 return;
328
329 conn = llist_last_entry(&endp->conns, struct mgcp_conn, entry);
330 if (!conn)
331 return;
332
333 mgcp_conn_free(endp, conn->id);
334}
335
336/*! free all connections at once.
337 * \param[in] endp associated endpoint */
Eric7c0fe312021-11-09 21:45:44 +0100338#if defined(__has_attribute)
339#if __has_attribute(no_sanitize)
340__attribute__((no_sanitize("undefined"))) /* ubsan detects a misaligned load */
341#endif
342#endif
Philipp Maier87bd9be2017-08-22 16:35:41 +0200343void mgcp_conn_free_all(struct mgcp_endpoint *endp)
344{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200345 struct mgcp_conn *conn;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200346
Ericfdbefde2021-09-06 19:49:24 +0200347 /* Drop all items in the list, might be consecutive! */
348 while ((conn = llist_first_entry_or_null(&endp->conns, struct mgcp_conn, entry)))
Philipp Maier87bd9be2017-08-22 16:35:41 +0200349 mgcp_conn_free(endp, conn->id);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200350
351 return;
352}
353
Harald Welte1d1b98f2017-12-25 10:03:40 +0100354/*! dump basic connection information to human readable string.
Philipp Maier87bd9be2017-08-22 16:35:41 +0200355 * \param[in] conn to dump
Harald Welte1d1b98f2017-12-25 10:03:40 +0100356 * \returns human readable string */
Philipp Maier87bd9be2017-08-22 16:35:41 +0200357char *mgcp_conn_dump(struct mgcp_conn *conn)
358{
Philipp Maier01d24a32017-11-21 17:26:09 +0100359 static char str[sizeof(conn->name)+sizeof(conn->id)+256];
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +0200360 char ipbuf[INET6_ADDRSTRLEN];
Philipp Maier87bd9be2017-08-22 16:35:41 +0200361
362 if (!conn) {
363 snprintf(str, sizeof(str), "(null connection)");
364 return str;
365 }
366
367 switch (conn->type) {
368 case MGCP_CONN_TYPE_RTP:
Pau Espin Pedrol07bbd762022-10-06 18:49:16 +0200369 switch (conn->u.rtp.type) {
370 case MGCP_RTP_DEFAULT:
371 /* Dump RTP connection */
372 snprintf(str, sizeof(str), "(%s/rtp, id:0x%s, ip:%s, "
373 "rtp:%u rtcp:%u)",
374 conn->name, conn->id,
375 osmo_sockaddr_ntop(&conn->u.rtp.end.addr.u.sa, ipbuf),
376 osmo_sockaddr_port(&conn->u.rtp.end.addr.u.sa),
377 ntohs(conn->u.rtp.end.rtcp_port));
378 break;
379 case MGCP_RTP_OSMUX:
380 snprintf(str, sizeof(str), "(%s/osmux, id:0x%s, ip:%s, "
381 "port:%u CID:%u)",
382 conn->name, conn->id,
383 osmo_sockaddr_ntop(&conn->u.rtp.end.addr.u.sa, ipbuf),
384 osmo_sockaddr_port(&conn->u.rtp.end.addr.u.sa),
385 conn->u.rtp.osmux.local_cid);
386 break;
387 case MGCP_RTP_IUUP:
388 snprintf(str, sizeof(str), "(%s/iuup, id:0x%s, ip:%s, "
389 "port:%u)",
390 conn->name, conn->id,
391 osmo_sockaddr_ntop(&conn->u.rtp.end.addr.u.sa, ipbuf),
392 osmo_sockaddr_port(&conn->u.rtp.end.addr.u.sa));
393 break;
394 default:
395 /* Should not happen, we should be able to dump
396 * every possible connection type. */
397 snprintf(str, sizeof(str), "(unknown conn_rtp connection type %u)",
398 conn->u.rtp.type);
399 break;
400 }
Philipp Maier87bd9be2017-08-22 16:35:41 +0200401 break;
402
403 default:
404 /* Should not happen, we should be able to dump
405 * every possible connection type. */
406 snprintf(str, sizeof(str), "(unknown connection type)");
407 break;
408 }
409
410 return str;
411}
412
413/*! find destination connection on a specific endpoint.
414 * \param[in] conn to search a destination for
415 * \returns destination connection, NULL on failure */
416struct mgcp_conn *mgcp_find_dst_conn(struct mgcp_conn *conn)
417{
418 struct mgcp_endpoint *endp;
419 struct mgcp_conn *partner_conn;
420 endp = conn->endp;
421
422 /*! NOTE: This simply works by grabbing the first connection that is
423 * not the supplied connection, which is suitable for endpoints that
424 * do not serve more than two connections. */
425
426 llist_for_each_entry(partner_conn, &endp->conns, entry) {
427 if (conn != partner_conn) {
428 return partner_conn;
429 }
430 }
431
432 return NULL;
433}
Philipp Maier889fe7f2020-07-06 17:44:12 +0200434
435/*! get oldest connection in the list.
436 * \param[in] endp associated endpoint */
437struct mgcp_conn *mgcp_conn_get_oldest(struct mgcp_endpoint *endp)
438{
439 if (llist_empty(&endp->conns))
440 return NULL;
441
442 return llist_last_entry(&endp->conns, struct mgcp_conn, entry);
443}