Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1 | /* 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 | |
| 24 | #include <osmocom/mgcp/mgcp_conn.h> |
| 25 | #include <osmocom/mgcp/mgcp_internal.h> |
Neels Hofmeyr | 6779354 | 2017-09-08 04:25:16 +0200 | [diff] [blame] | 26 | #include <osmocom/mgcp/mgcp_common.h> |
Philipp Maier | 37d11c8 | 2018-02-01 14:38:12 +0100 | [diff] [blame] | 27 | #include <osmocom/mgcp/mgcp_endp.h> |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 28 | #include <osmocom/mgcp/mgcp_sdp.h> |
| 29 | #include <osmocom/mgcp/mgcp_codec.h> |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 30 | #include <osmocom/gsm/gsm_utils.h> |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 31 | #include <osmocom/core/rate_ctr.h> |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 32 | #include <ctype.h> |
| 33 | |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 34 | const static struct rate_ctr_group_desc rate_ctr_group_desc = { |
| 35 | .group_name_prefix = "conn_rtp", |
| 36 | .group_description = "rtp connection statistics", |
| 37 | .class_id = 1, |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 38 | .num_ctr = ARRAY_SIZE(mgcp_conn_rate_ctr_desc), |
| 39 | .ctr_desc = mgcp_conn_rate_ctr_desc |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 43 | /* Allocate a new connection identifier. According to RFC3435, they must |
Philipp Maier | f8bfbe8 | 2017-11-23 19:32:31 +0100 | [diff] [blame] | 44 | * be unique only within the scope of the endpoint. (Caller must provide |
| 45 | * memory for id) */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 46 | static int mgcp_alloc_id(struct mgcp_endpoint *endp, char *id) |
| 47 | { |
Neels Hofmeyr | a729db6 | 2018-08-28 16:20:51 +0200 | [diff] [blame] | 48 | #define MGCP_CONN_ID_GEN_LEN 8 |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 49 | int i; |
| 50 | int k; |
| 51 | int rc; |
Neels Hofmeyr | a729db6 | 2018-08-28 16:20:51 +0200 | [diff] [blame] | 52 | uint8_t id_bin[MGCP_CONN_ID_GEN_LEN / 2]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 53 | char *id_hex; |
| 54 | |
| 55 | /* Generate a connection id that is unique for the current endpoint. |
| 56 | * Technically a counter would be sufficient, but in order to |
| 57 | * be able to find a specific connection in large logfiles and to |
| 58 | * prevent unintentional connections we assign the connection |
| 59 | * identifiers randomly from a reasonable large number space */ |
| 60 | for (i = 0; i < 32; i++) { |
| 61 | rc = osmo_get_rand_id(id_bin, sizeof(id_bin)); |
| 62 | if (rc < 0) |
| 63 | return rc; |
| 64 | |
| 65 | id_hex = osmo_hexdump_nospc(id_bin, sizeof(id_bin)); |
| 66 | for (k = 0; k < strlen(id_hex); k++) |
| 67 | id_hex[k] = toupper(id_hex[k]); |
| 68 | |
| 69 | /* ensure that the generated conn_id is unique |
| 70 | * for this endpoint */ |
| 71 | if (!mgcp_conn_get_rtp(endp, id_hex)) { |
Neels Hofmeyr | 55e0dcf | 2018-09-03 21:36:56 +0200 | [diff] [blame] | 72 | osmo_strlcpy(id, id_hex, MGCP_CONN_ID_MAXLEN); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 73 | return 0; |
| 74 | } |
| 75 | } |
| 76 | |
Philipp Maier | 230e4fc | 2017-11-28 09:38:45 +0100 | [diff] [blame] | 77 | LOGP(DLMGCP, LOGL_ERROR, "endpoint:0x%x, unable to generate a unique connectionIdentifier\n", |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 78 | ENDPOINT_NUMBER(endp)); |
| 79 | |
| 80 | return -1; |
| 81 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 82 | |
Philipp Maier | c430d19 | 2018-03-16 12:11:18 +0100 | [diff] [blame] | 83 | /* Initialize rtp connection struct with default values */ |
Philipp Maier | 892dec0 | 2018-03-16 12:32:01 +0100 | [diff] [blame] | 84 | static void mgcp_rtp_conn_init(struct mgcp_conn_rtp *conn_rtp, struct mgcp_conn *conn) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 85 | { |
Philipp Maier | 892dec0 | 2018-03-16 12:32:01 +0100 | [diff] [blame] | 86 | struct mgcp_rtp_end *end = &conn_rtp->end; |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 87 | /* FIXME: Each new rate counter group requires an unique index. At the |
| 88 | * moment we generate this index using this counter, but perhaps there |
| 89 | * is a more concious way to assign the indexes. */ |
| 90 | static unsigned int rate_ctr_index = 0; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 91 | |
Philipp Maier | 892dec0 | 2018-03-16 12:32:01 +0100 | [diff] [blame] | 92 | conn_rtp->type = MGCP_RTP_DEFAULT; |
| 93 | conn_rtp->osmux.allocated_cid = -1; |
| 94 | |
| 95 | /* backpointer to the generic part of the connection */ |
| 96 | conn->u.rtp.conn = conn; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 97 | |
| 98 | end->rtp.fd = -1; |
| 99 | end->rtcp.fd = -1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 100 | end->rtp_port = end->rtcp_port = 0; |
| 101 | talloc_free(end->fmtp_extra); |
| 102 | end->fmtp_extra = NULL; |
| 103 | |
| 104 | /* Set default values */ |
| 105 | end->frames_per_packet = 0; /* unknown */ |
| 106 | end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS; |
| 107 | end->output_enabled = 0; |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 108 | end->maximum_packet_time = -1; |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 109 | |
| 110 | conn_rtp->rate_ctr_group = rate_ctr_group_alloc(conn, &rate_ctr_group_desc, rate_ctr_index); |
| 111 | conn_rtp->state.in_stream.err_ts_ctr = &conn_rtp->rate_ctr_group->ctr[IN_STREAM_ERR_TSTMP_CTR]; |
| 112 | conn_rtp->state.out_stream.err_ts_ctr = &conn_rtp->rate_ctr_group->ctr[OUT_STREAM_ERR_TSTMP_CTR]; |
| 113 | rate_ctr_index++; |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 114 | |
| 115 | /* Make sure codec table is reset */ |
| 116 | mgcp_codec_reset_all(conn_rtp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Philipp Maier | d0b470d | 2018-03-16 12:45:53 +0100 | [diff] [blame] | 119 | /* Cleanup rtp connection struct */ |
| 120 | static void mgcp_rtp_conn_cleanup(struct mgcp_conn_rtp *conn_rtp) |
| 121 | { |
| 122 | osmux_disable_conn(conn_rtp); |
| 123 | osmux_release_cid(conn_rtp); |
| 124 | mgcp_free_rtp_port(&conn_rtp->end); |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 125 | rate_ctr_group_free(conn_rtp->rate_ctr_group); |
Philipp Maier | d0b470d | 2018-03-16 12:45:53 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 128 | /*! allocate a new connection list entry. |
| 129 | * \param[in] ctx talloc context |
| 130 | * \param[in] endp associated endpoint |
| 131 | * \param[in] id identification number of the connection |
| 132 | * \param[in] type connection type (e.g. MGCP_CONN_TYPE_RTP) |
| 133 | * \returns pointer to allocated connection, NULL on error */ |
| 134 | struct mgcp_conn *mgcp_conn_alloc(void *ctx, struct mgcp_endpoint *endp, |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 135 | enum mgcp_conn_type type, char *name) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 136 | { |
| 137 | struct mgcp_conn *conn; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 138 | int rc; |
| 139 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 140 | /* Do not allow more then two connections */ |
| 141 | if (llist_count(&endp->conns) >= endp->type->max_conns) |
| 142 | return NULL; |
| 143 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 144 | /* Create new connection and add it to the list */ |
| 145 | conn = talloc_zero(ctx, struct mgcp_conn); |
| 146 | if (!conn) |
| 147 | return NULL; |
| 148 | conn->endp = endp; |
| 149 | conn->type = type; |
| 150 | conn->mode = MGCP_CONN_NONE; |
| 151 | conn->mode_orig = MGCP_CONN_NONE; |
Philipp Maier | f8bfbe8 | 2017-11-23 19:32:31 +0100 | [diff] [blame] | 152 | osmo_strlcpy(conn->name, name, sizeof(conn->name)); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 153 | rc = mgcp_alloc_id(endp, conn->id); |
| 154 | if (rc < 0) { |
| 155 | talloc_free(conn); |
| 156 | return NULL; |
| 157 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 158 | |
| 159 | switch (type) { |
| 160 | case MGCP_CONN_TYPE_RTP: |
Philipp Maier | 892dec0 | 2018-03-16 12:32:01 +0100 | [diff] [blame] | 161 | mgcp_rtp_conn_init(&conn->u.rtp, conn); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 162 | break; |
| 163 | default: |
| 164 | /* NOTE: This should never be called with an |
| 165 | * invalid type, its up to the programmer |
| 166 | * to ensure propery types */ |
| 167 | OSMO_ASSERT(false); |
| 168 | } |
| 169 | |
| 170 | llist_add(&conn->entry, &endp->conns); |
| 171 | |
| 172 | return conn; |
| 173 | } |
| 174 | |
| 175 | /*! find a connection by its ID. |
| 176 | * \param[in] endp associated endpoint |
| 177 | * \param[in] id identification number of the connection |
| 178 | * \returns pointer to allocated connection, NULL if not found */ |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 179 | struct mgcp_conn *mgcp_conn_get(struct mgcp_endpoint *endp, const char *id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 180 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 181 | struct mgcp_conn *conn; |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 182 | const char *id_upper; |
Neels Hofmeyr | a77eade | 2018-08-29 02:30:39 +0200 | [diff] [blame] | 183 | const char *conn_id; |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 184 | |
| 185 | if (!id || !*id) |
| 186 | return NULL; |
| 187 | |
Neels Hofmeyr | a77eade | 2018-08-29 02:30:39 +0200 | [diff] [blame] | 188 | /* Ignore leading zeros in needle */ |
| 189 | while (*id == '0') |
| 190 | id++; |
| 191 | |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 192 | /* Use uppercase to compare identifiers, to avoid mismatches: RFC3435 2.1.3.2 "Names of |
| 193 | * Connections" defines the id as a hex string, so clients may return lower case hex even though |
| 194 | * we sent upper case hex in the CRCX response. */ |
| 195 | id_upper = osmo_str_toupper(id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 196 | |
| 197 | llist_for_each_entry(conn, &endp->conns, entry) { |
Neels Hofmeyr | a77eade | 2018-08-29 02:30:39 +0200 | [diff] [blame] | 198 | /* Ignore leading zeros in haystack */ |
| 199 | for (conn_id=conn->id; *conn_id == '0'; conn_id++); |
| 200 | |
| 201 | if (strcmp(conn_id, id_upper) == 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 202 | return conn; |
| 203 | } |
| 204 | |
| 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | /*! find an RTP connection by its ID. |
| 209 | * \param[in] endp associated endpoint |
| 210 | * \param[in] id identification number of the connection |
| 211 | * \returns pointer to allocated connection, NULL if not found */ |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 212 | struct mgcp_conn_rtp *mgcp_conn_get_rtp(struct mgcp_endpoint *endp, |
| 213 | const char *id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 214 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 215 | struct mgcp_conn *conn; |
| 216 | |
| 217 | conn = mgcp_conn_get(endp, id); |
| 218 | if (!conn) |
| 219 | return NULL; |
| 220 | |
| 221 | if (conn->type == MGCP_CONN_TYPE_RTP) |
| 222 | return &conn->u.rtp; |
| 223 | |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 227 | static void |
| 228 | aggregate_rtp_conn_stats(struct mgcp_trunk_config *trunk, struct mgcp_conn_rtp *conn_rtp) |
| 229 | { |
| 230 | struct rate_ctr_group *all_stats = trunk->all_rtp_conn_stats; |
| 231 | struct rate_ctr_group *conn_stats = conn_rtp->rate_ctr_group; |
| 232 | int i; |
| 233 | |
| 234 | if (all_stats == NULL || conn_stats == NULL) |
| 235 | return; |
| 236 | |
| 237 | /* Compared to per-connection RTP statistics, aggregated RTP statistics |
| 238 | * contain one additional rate couter item (RTP_NUM_CONNECTIONS). |
| 239 | * All other counters in both counter groups correspond to each other. */ |
| 240 | OSMO_ASSERT(conn_stats->desc->num_ctr + 1 == all_stats->desc->num_ctr); |
| 241 | |
| 242 | for (i = 0; i < conn_stats->desc->num_ctr; i++) |
| 243 | rate_ctr_add(&all_stats->ctr[i], conn_stats->ctr[i].current); |
| 244 | |
| 245 | rate_ctr_inc(&all_stats->ctr[RTP_NUM_CONNECTIONS]); |
| 246 | } |
| 247 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 248 | /*! free a connection by its ID. |
| 249 | * \param[in] endp associated endpoint |
| 250 | * \param[in] id identification number of the connection */ |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 251 | void mgcp_conn_free(struct mgcp_endpoint *endp, const char *id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 252 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 253 | struct mgcp_conn *conn; |
| 254 | |
| 255 | conn = mgcp_conn_get(endp, id); |
| 256 | if (!conn) |
| 257 | return; |
| 258 | |
Philipp Maier | df5d219 | 2018-01-24 11:39:32 +0100 | [diff] [blame] | 259 | /* Run endpoint cleanup action. By this we inform the endpoint about |
| 260 | * the removal of the connection and allow it to clean up its inner |
| 261 | * state accordingly */ |
| 262 | if (endp->type->cleanup_cb) |
| 263 | endp->type->cleanup_cb(endp, conn); |
| 264 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 265 | switch (conn->type) { |
| 266 | case MGCP_CONN_TYPE_RTP: |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 267 | aggregate_rtp_conn_stats(endp->tcfg, &conn->u.rtp); |
Philipp Maier | d0b470d | 2018-03-16 12:45:53 +0100 | [diff] [blame] | 268 | mgcp_rtp_conn_cleanup(&conn->u.rtp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 269 | break; |
| 270 | default: |
| 271 | /* NOTE: This should never be called with an |
| 272 | * invalid type, its up to the programmer |
| 273 | * to ensure propery types */ |
| 274 | OSMO_ASSERT(false); |
| 275 | } |
| 276 | |
| 277 | llist_del(&conn->entry); |
| 278 | talloc_free(conn); |
| 279 | } |
| 280 | |
| 281 | /*! free oldest connection in the list. |
| 282 | * \param[in] endp associated endpoint */ |
| 283 | void mgcp_conn_free_oldest(struct mgcp_endpoint *endp) |
| 284 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 285 | struct mgcp_conn *conn; |
| 286 | |
| 287 | if (llist_empty(&endp->conns)) |
| 288 | return; |
| 289 | |
| 290 | conn = llist_last_entry(&endp->conns, struct mgcp_conn, entry); |
| 291 | if (!conn) |
| 292 | return; |
| 293 | |
| 294 | mgcp_conn_free(endp, conn->id); |
| 295 | } |
| 296 | |
| 297 | /*! free all connections at once. |
| 298 | * \param[in] endp associated endpoint */ |
| 299 | void mgcp_conn_free_all(struct mgcp_endpoint *endp) |
| 300 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 301 | struct mgcp_conn *conn; |
| 302 | struct mgcp_conn *conn_tmp; |
| 303 | |
| 304 | /* Drop all items in the list */ |
| 305 | llist_for_each_entry_safe(conn, conn_tmp, &endp->conns, entry) { |
| 306 | mgcp_conn_free(endp, conn->id); |
| 307 | } |
| 308 | |
| 309 | return; |
| 310 | } |
| 311 | |
Harald Welte | 1d1b98f | 2017-12-25 10:03:40 +0100 | [diff] [blame] | 312 | /*! dump basic connection information to human readable string. |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 313 | * \param[in] conn to dump |
Harald Welte | 1d1b98f | 2017-12-25 10:03:40 +0100 | [diff] [blame] | 314 | * \returns human readable string */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 315 | char *mgcp_conn_dump(struct mgcp_conn *conn) |
| 316 | { |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 317 | static char str[sizeof(conn->name)+sizeof(conn->id)+256]; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 318 | |
| 319 | if (!conn) { |
| 320 | snprintf(str, sizeof(str), "(null connection)"); |
| 321 | return str; |
| 322 | } |
| 323 | |
| 324 | switch (conn->type) { |
| 325 | case MGCP_CONN_TYPE_RTP: |
| 326 | /* Dump RTP connection */ |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 327 | snprintf(str, sizeof(str), "(%s/rtp, id:0x%s, ip:%s, " |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 328 | "rtp:%u rtcp:%u)", |
| 329 | conn->name, |
| 330 | conn->id, |
| 331 | inet_ntoa(conn->u.rtp.end.addr), |
| 332 | ntohs(conn->u.rtp.end.rtp_port), |
| 333 | ntohs(conn->u.rtp.end.rtcp_port)); |
| 334 | break; |
| 335 | |
| 336 | default: |
| 337 | /* Should not happen, we should be able to dump |
| 338 | * every possible connection type. */ |
| 339 | snprintf(str, sizeof(str), "(unknown connection type)"); |
| 340 | break; |
| 341 | } |
| 342 | |
| 343 | return str; |
| 344 | } |
| 345 | |
| 346 | /*! find destination connection on a specific endpoint. |
| 347 | * \param[in] conn to search a destination for |
| 348 | * \returns destination connection, NULL on failure */ |
| 349 | struct mgcp_conn *mgcp_find_dst_conn(struct mgcp_conn *conn) |
| 350 | { |
| 351 | struct mgcp_endpoint *endp; |
| 352 | struct mgcp_conn *partner_conn; |
| 353 | endp = conn->endp; |
| 354 | |
| 355 | /*! NOTE: This simply works by grabbing the first connection that is |
| 356 | * not the supplied connection, which is suitable for endpoints that |
| 357 | * do not serve more than two connections. */ |
| 358 | |
| 359 | llist_for_each_entry(partner_conn, &endp->conns, entry) { |
| 360 | if (conn != partner_conn) { |
| 361 | return partner_conn; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | return NULL; |
| 366 | } |