Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1 | /* A Media Gateway Control Protocol Media Gateway: RFC 3435 */ |
| 2 | /* The protocol implementation */ |
| 3 | |
| 4 | /* |
| 5 | * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * (C) 2009-2012 by On-Waves |
| 7 | * All Rights Reserved |
| 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 <ctype.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <time.h> |
| 28 | #include <limits.h> |
| 29 | #include <unistd.h> |
| 30 | #include <errno.h> |
| 31 | |
| 32 | #include <osmocom/core/msgb.h> |
| 33 | #include <osmocom/core/talloc.h> |
| 34 | #include <osmocom/core/select.h> |
| 35 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 36 | #include <osmocom/mgcp/mgcp.h> |
Neels Hofmeyr | 6779354 | 2017-09-08 04:25:16 +0200 | [diff] [blame] | 37 | #include <osmocom/mgcp/mgcp_common.h> |
Philipp Maier | 993ea6b | 2020-08-04 18:26:50 +0200 | [diff] [blame] | 38 | #include <osmocom/mgcp/osmux.h> |
| 39 | #include <osmocom/mgcp/mgcp_network.h> |
| 40 | #include <osmocom/mgcp/mgcp_protocol.h> |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 41 | #include <osmocom/mgcp/mgcp_stat.h> |
| 42 | #include <osmocom/mgcp/mgcp_msg.h> |
Philipp Maier | 37d11c8 | 2018-02-01 14:38:12 +0100 | [diff] [blame] | 43 | #include <osmocom/mgcp/mgcp_endp.h> |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 44 | #include <osmocom/mgcp/mgcp_trunk.h> |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 45 | #include <osmocom/mgcp/mgcp_sdp.h> |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 46 | #include <osmocom/mgcp/mgcp_codec.h> |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 47 | #include <osmocom/mgcp/mgcp_conn.h> |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 48 | |
| 49 | struct mgcp_request { |
| 50 | char *name; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 51 | struct msgb *(*handle_request) (struct mgcp_parse_data * data); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 52 | char *debug_name; |
| 53 | }; |
| 54 | |
| 55 | #define MGCP_REQUEST(NAME, REQ, DEBUG_NAME) \ |
| 56 | { .name = NAME, .handle_request = REQ, .debug_name = DEBUG_NAME }, |
| 57 | |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 58 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 59 | static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *data); |
| 60 | static struct msgb *handle_create_con(struct mgcp_parse_data *data); |
| 61 | static struct msgb *handle_delete_con(struct mgcp_parse_data *data); |
| 62 | static struct msgb *handle_modify_con(struct mgcp_parse_data *data); |
| 63 | static struct msgb *handle_rsip(struct mgcp_parse_data *data); |
| 64 | static struct msgb *handle_noti_req(struct mgcp_parse_data *data); |
| 65 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 66 | /* Initalize transcoder */ |
| 67 | static int setup_rtp_processing(struct mgcp_endpoint *endp, |
| 68 | struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 69 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 70 | struct mgcp_config *cfg = endp->cfg; |
| 71 | struct mgcp_conn_rtp *conn_src = NULL; |
| 72 | struct mgcp_conn_rtp *conn_dst = conn; |
| 73 | struct mgcp_conn *_conn; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 74 | |
Pau Espin Pedrol | fa810e8 | 2019-05-06 18:54:10 +0200 | [diff] [blame] | 75 | if (conn->type != MGCP_RTP_DEFAULT && !mgcp_conn_rtp_is_osmux(conn)) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 76 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 77 | "RTP-setup: Endpoint is not configured as RTP default, stopping here!\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 81 | if (conn->conn->mode == MGCP_CONN_LOOPBACK) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 82 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 83 | "RTP-setup: Endpoint is in loopback mode, stopping here!\n"); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | /* Find the "sister" connection */ |
| 88 | llist_for_each_entry(_conn, &endp->conns, entry) { |
| 89 | if (_conn->id != conn->conn->id) { |
| 90 | conn_src = &_conn->u.rtp; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | |
Philipp Maier | acc1035 | 2018-07-19 18:07:57 +0200 | [diff] [blame] | 95 | return cfg->setup_rtp_processing_cb(endp, conn_dst, conn_src); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 98 | /* array of function pointers for handling various |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 99 | * messages. In the future this might be binary sorted |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 100 | * for performance reasons. */ |
| 101 | static const struct mgcp_request mgcp_requests[] = { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 102 | MGCP_REQUEST("AUEP", handle_audit_endpoint, "AuditEndpoint") |
Oliver Smith | 622dd61 | 2019-01-30 14:14:45 +0100 | [diff] [blame] | 103 | MGCP_REQUEST("CRCX", handle_create_con, "CreateConnection") |
| 104 | MGCP_REQUEST("DLCX", handle_delete_con, "DeleteConnection") |
| 105 | MGCP_REQUEST("MDCX", handle_modify_con, "ModifiyConnection") |
| 106 | MGCP_REQUEST("RQNT", handle_noti_req, "NotificationRequest") |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 107 | |
Oliver Smith | 622dd61 | 2019-01-30 14:14:45 +0100 | [diff] [blame] | 108 | /* SPEC extension */ |
| 109 | MGCP_REQUEST("RSIP", handle_rsip, "ReSetInProgress") |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 112 | /* Helper function to allocate some memory for responses and retransmissions */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 113 | static struct msgb *mgcp_msgb_alloc(void) |
| 114 | { |
| 115 | struct msgb *msg; |
| 116 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
| 117 | if (!msg) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 118 | LOGP(DLMGCP, LOGL_ERROR, "Failed to msgb for MGCP data.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 119 | |
| 120 | return msg; |
| 121 | } |
| 122 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 123 | /* Helper function for do_retransmission() and create_resp() */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 124 | static struct msgb *do_retransmission(const struct mgcp_endpoint *endp) |
| 125 | { |
| 126 | struct msgb *msg = mgcp_msgb_alloc(); |
| 127 | if (!msg) |
| 128 | return NULL; |
| 129 | |
| 130 | msg->l2h = msgb_put(msg, strlen(endp->last_response)); |
| 131 | memcpy(msg->l2h, endp->last_response, msgb_l2len(msg)); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 132 | mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Retransmitted response"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 133 | return msg; |
| 134 | } |
| 135 | |
| 136 | static struct msgb *create_resp(struct mgcp_endpoint *endp, int code, |
| 137 | const char *txt, const char *msg, |
| 138 | const char *trans, const char *param, |
| 139 | const char *sdp) |
| 140 | { |
| 141 | int len; |
| 142 | struct msgb *res; |
| 143 | |
| 144 | res = mgcp_msgb_alloc(); |
| 145 | if (!res) |
| 146 | return NULL; |
| 147 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 148 | len = snprintf((char *)res->data, 2048, "%d %s%s%s\r\n%s", |
| 149 | code, trans, txt, param ? param : "", sdp ? sdp : ""); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 150 | if (len < 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 151 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, "Failed to sprintf MGCP response.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 152 | msgb_free(res); |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | res->l2h = msgb_put(res, len); |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 157 | LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "Generated response: code=%d\n", code); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 158 | mgcp_disp_msg(res->l2h, msgb_l2len(res), "Generated response"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * Remember the last transmission per endpoint. |
| 162 | */ |
| 163 | if (endp) { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 164 | struct mgcp_trunk *trunk = endp->trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 165 | talloc_free(endp->last_response); |
| 166 | talloc_free(endp->last_trans); |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 167 | endp->last_trans = talloc_strdup(trunk->endpoints, trans); |
| 168 | endp->last_response = talloc_strndup(trunk->endpoints, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 169 | (const char *)res->l2h, |
| 170 | msgb_l2len(res)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return res; |
| 174 | } |
| 175 | |
| 176 | static struct msgb *create_ok_resp_with_param(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 177 | int code, const char *msg, |
| 178 | const char *trans, |
| 179 | const char *param) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 180 | { |
| 181 | return create_resp(endp, code, " OK", msg, trans, param, NULL); |
| 182 | } |
| 183 | |
| 184 | static struct msgb *create_ok_response(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 185 | int code, const char *msg, |
| 186 | const char *trans) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 187 | { |
| 188 | return create_ok_resp_with_param(endp, code, msg, trans, NULL); |
| 189 | } |
| 190 | |
| 191 | static struct msgb *create_err_response(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 192 | int code, const char *msg, |
| 193 | const char *trans) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 194 | { |
| 195 | return create_resp(endp, code, " FAIL", msg, trans, NULL, NULL); |
| 196 | } |
| 197 | |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 198 | /* Add MGCP parameters to a message buffer */ |
| 199 | static int add_params(struct msgb *msg, const struct mgcp_endpoint *endp, |
| 200 | const struct mgcp_conn_rtp *conn) |
| 201 | { |
| 202 | int rc; |
| 203 | |
Philipp Maier | 7f0966c | 2018-01-17 18:18:12 +0100 | [diff] [blame] | 204 | /* NOTE: Only in the virtual trunk we allow dynamic endpoint names */ |
Philipp Maier | 207ab51 | 2018-02-02 14:19:26 +0100 | [diff] [blame] | 205 | if (endp->wildcarded_req |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 206 | && endp->trunk->trunk_type == MGCP_TRUNK_VIRTUAL) { |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 207 | rc = msgb_printf(msg, "Z: %s\r\n", endp->name); |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 208 | if (rc < 0) |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 212 | rc = msgb_printf(msg, "I: %s\r\n", conn->conn->id); |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 213 | if (rc < 0) |
| 214 | return -EINVAL; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 219 | /* Format MGCP response string (with SDP attached) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 220 | static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 221 | struct mgcp_conn_rtp *conn, |
| 222 | const char *msg, |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 223 | const char *trans_id, |
| 224 | bool add_conn_params) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 225 | { |
Pau Espin Pedrol | a93c6e9 | 2019-05-06 15:23:57 +0200 | [diff] [blame] | 226 | /* TODO: we may want to define another local_ip_osmux var to us for |
| 227 | OSMUX connections. Perhaps adding a new internal API to get it based |
| 228 | on conn type */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 229 | const char *addr = endp->cfg->local_ip; |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 230 | struct msgb *sdp; |
| 231 | int rc; |
| 232 | struct msgb *result; |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 233 | char local_ip_addr[INET_ADDRSTRLEN]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 234 | |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 235 | sdp = msgb_alloc_headroom(4096, 128, "sdp record"); |
| 236 | if (!sdp) |
| 237 | return NULL; |
| 238 | |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 239 | if (!addr) { |
| 240 | mgcp_get_local_addr(local_ip_addr, conn); |
| 241 | addr = local_ip_addr; |
| 242 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 243 | |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 244 | /* Attach optional connection parameters */ |
| 245 | if (add_conn_params) { |
| 246 | rc = add_params(sdp, endp, conn); |
| 247 | if (rc < 0) |
| 248 | goto error; |
| 249 | } |
| 250 | |
Philipp Maier | 3cbfb8a | 2018-01-22 11:39:59 +0100 | [diff] [blame] | 251 | /* Attach optional OSMUX parameters */ |
Pau Espin Pedrol | c63f15a | 2019-05-10 16:52:08 +0200 | [diff] [blame] | 252 | if (mgcp_conn_rtp_is_osmux(conn)) { |
Pau Espin Pedrol | 5e8d799 | 2019-04-24 19:56:43 +0200 | [diff] [blame] | 253 | rc = msgb_printf(sdp, "X-Osmux: %u\r\n", conn->osmux.cid); |
Philipp Maier | 3cbfb8a | 2018-01-22 11:39:59 +0100 | [diff] [blame] | 254 | if (rc < 0) |
| 255 | goto error; |
| 256 | } |
| 257 | |
| 258 | /* Attach line break to separate the parameters from the SDP block */ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 259 | rc = msgb_printf(sdp, "\r\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 260 | |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 261 | rc = mgcp_write_response_sdp(endp, conn, sdp, addr); |
| 262 | if (rc < 0) |
| 263 | goto error; |
| 264 | result = create_resp(endp, 200, " OK", msg, trans_id, NULL, (char*) sdp->data); |
| 265 | msgb_free(sdp); |
| 266 | return result; |
| 267 | error: |
| 268 | msgb_free(sdp); |
| 269 | return NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 272 | /* Send out dummy packet to keep the connection open, if the connection is an |
| 273 | * osmux connection, send the dummy packet via OSMUX */ |
| 274 | static void send_dummy(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 275 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 276 | if (conn->osmux.state != OSMUX_STATE_DISABLED) |
| 277 | osmux_send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 278 | else |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 279 | mgcp_send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 282 | /* handle incoming messages: |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 283 | * - this can be a command (four letters, space, transaction id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 284 | * - or a response (three numbers, space, transaction id) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 285 | struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg) |
| 286 | { |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 287 | struct rate_ctr_group *rate_ctrs = cfg->ratectr.mgcp_general_ctr_group; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 288 | struct mgcp_parse_data pdata; |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 289 | int rc, i, code, handled = 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 290 | struct msgb *resp = NULL; |
| 291 | char *data; |
| 292 | |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 293 | /* Count all messages, even incorect ones */ |
| 294 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_TOTAL]); |
| 295 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 296 | if (msgb_l2len(msg) < 4) { |
| 297 | LOGP(DLMGCP, LOGL_ERROR, "msg too short: %d\n", msg->len); |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 298 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_MSG_PARSE]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 299 | return NULL; |
| 300 | } |
| 301 | |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 302 | if (mgcp_msg_terminate_nul(msg)) { |
| 303 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_MSG_PARSE]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 304 | return NULL; |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 305 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 306 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 307 | mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Received message"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 308 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 309 | /* attempt to treat it as a response */ |
| 310 | if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 311 | LOGP(DLMGCP, LOGL_DEBUG, "Response: Code: %d\n", code); |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 312 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_MSG_PARSE]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | msg->l3h = &msg->l2h[4]; |
| 317 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 318 | /* |
| 319 | * Check for a duplicate message and respond. |
| 320 | */ |
| 321 | memset(&pdata, 0, sizeof(pdata)); |
| 322 | pdata.cfg = cfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 323 | data = mgcp_strline((char *)msg->l3h, &pdata.save); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 324 | rc = mgcp_parse_header(&pdata, data); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 325 | if (pdata.endp && pdata.trans |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 326 | && pdata.endp->last_trans |
| 327 | && strcmp(pdata.endp->last_trans, pdata.trans) == 0) { |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 328 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_RETRANSMITTED]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 329 | return do_retransmission(pdata.endp); |
| 330 | } |
| 331 | |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 332 | /* check for general parser failure */ |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 333 | if (rc < 0) { |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 334 | LOGP(DLMGCP, LOGL_NOTICE, "%s: failed to find the endpoint\n", msg->l2h); |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 335 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_NO_ENDPOINT]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 336 | return create_err_response(NULL, -rc, (const char *) msg->l2h, pdata.trans); |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 339 | for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 340 | if (strncmp |
| 341 | (mgcp_requests[i].name, (const char *)&msg->l2h[0], |
| 342 | 4) == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 343 | handled = 1; |
| 344 | resp = mgcp_requests[i].handle_request(&pdata); |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 349 | if (handled) { |
| 350 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_HANDLED]); |
| 351 | } else { |
| 352 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_UNHANDLED]); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 353 | LOGP(DLMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", |
| 354 | &msg->l2h[0]); |
Alexander Chemeris | 6386600 | 2020-05-05 17:18:40 +0300 | [diff] [blame] | 355 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 356 | |
| 357 | return resp; |
| 358 | } |
| 359 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 360 | /* AUEP command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 361 | static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *p) |
| 362 | { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 363 | LOGPENDP(p->endp, DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n"); |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 364 | return create_ok_response(p->endp, 200, "AUEP", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Harald Welte | 1d1b98f | 2017-12-25 10:03:40 +0100 | [diff] [blame] | 367 | /* Try to find a free port by attempting to bind on it. Also handle the |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 368 | * counter that points on the next free port. Since we have a pointer |
Philipp Maier | b38fb89 | 2018-05-22 13:52:21 +0200 | [diff] [blame] | 369 | * to the next free port, binding should in work on the first attempt in |
Pau Espin Pedrol | fc80673 | 2019-04-23 00:18:43 +0200 | [diff] [blame] | 370 | * general. In case of failure the next port is tried until the whole port |
| 371 | * range is tried once. */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 372 | static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 373 | { |
| 374 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 375 | struct mgcp_port_range *range; |
Philipp Maier | b38fb89 | 2018-05-22 13:52:21 +0200 | [diff] [blame] | 376 | unsigned int tries; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 377 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 378 | OSMO_ASSERT(conn); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 379 | |
| 380 | range = &endp->cfg->net_ports; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 381 | |
| 382 | /* attempt to find a port */ |
Philipp Maier | b38fb89 | 2018-05-22 13:52:21 +0200 | [diff] [blame] | 383 | tries = (range->range_end - range->range_start) / 2; |
| 384 | for (i = 0; i < tries; ++i) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 385 | int rc; |
| 386 | |
| 387 | if (range->last_port >= range->range_end) |
| 388 | range->last_port = range->range_start; |
| 389 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 390 | rc = mgcp_bind_net_rtp_port(endp, range->last_port, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 391 | |
| 392 | range->last_port += 2; |
| 393 | if (rc == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | } |
| 398 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 399 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 400 | "Allocating a RTP/RTCP port failed %u times.\n", |
| 401 | tries); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 402 | return -1; |
| 403 | } |
| 404 | |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 405 | /*! Helper function for check_local_cx_options() to get a pointer of the next |
| 406 | * lco option identifier |
| 407 | * \param[in] lco string |
| 408 | * \returns pointer to the beginning of the LCO identifier, NULL on failure */ |
| 409 | char *get_lco_identifier(const char *options) |
| 410 | { |
| 411 | char *ptr; |
| 412 | unsigned int count = 0; |
| 413 | |
| 414 | /* Jump to the end of the lco identifier */ |
| 415 | ptr = strstr(options, ":"); |
| 416 | if (!ptr) |
| 417 | return NULL; |
| 418 | |
| 419 | /* Walk backwards until the pointer points to the beginning of the |
| 420 | * lco identifier. We know that we stand at the beginning when we |
| 421 | * are either at the beginning of the memory or see a space or |
| 422 | * comma. (this is tolerant, it will accept a:10, b:11 as well as |
| 423 | * a:10,b:11) */ |
| 424 | while (1) { |
| 425 | /* Endless loop protection */ |
| 426 | if (count > 10000) |
| 427 | return NULL; |
| 428 | else if (ptr < options || *ptr == ' ' || *ptr == ',') { |
| 429 | ptr++; |
| 430 | break; |
| 431 | } |
| 432 | ptr--; |
| 433 | count++; |
| 434 | } |
| 435 | |
| 436 | /* Check if we got any result */ |
| 437 | if (*ptr == ':') |
| 438 | return NULL; |
| 439 | |
| 440 | return ptr; |
| 441 | } |
| 442 | |
| 443 | /*! Check the LCO option. This function checks for multiple appearence of LCO |
| 444 | * options, which is illegal |
| 445 | * \param[in] ctx talloc context |
| 446 | * \param[in] lco string |
| 447 | * \returns 0 on success, -1 on failure */ |
| 448 | int check_local_cx_options(void *ctx, const char *options) |
| 449 | { |
| 450 | int i; |
| 451 | char *options_copy; |
| 452 | char *lco_identifier; |
| 453 | char *lco_identifier_end; |
| 454 | char *next_lco_identifier; |
| 455 | |
| 456 | char **lco_seen; |
| 457 | unsigned int lco_seen_n = 0; |
| 458 | |
| 459 | if (!options) |
| 460 | return -1; |
| 461 | |
| 462 | lco_seen = |
| 463 | (char **)talloc_zero_size(ctx, strlen(options) * sizeof(char *)); |
| 464 | options_copy = talloc_strdup(ctx, options); |
| 465 | lco_identifier = options_copy; |
| 466 | |
| 467 | do { |
| 468 | /* Move the lco_identifier pointer to the beginning of the |
| 469 | * current lco option identifier */ |
| 470 | lco_identifier = get_lco_identifier(lco_identifier); |
| 471 | if (!lco_identifier) |
| 472 | goto error; |
| 473 | |
| 474 | /* Look ahead to the next LCO option early, since we |
| 475 | * will parse destructively */ |
| 476 | next_lco_identifier = strstr(lco_identifier + 1, ","); |
| 477 | |
| 478 | /* Pinch off the end of the lco field identifier name |
| 479 | * and see if we still got something, also check if |
| 480 | * there is some value after the colon. */ |
| 481 | lco_identifier_end = strstr(lco_identifier, ":"); |
| 482 | if (!lco_identifier_end) |
| 483 | goto error; |
| 484 | if (*(lco_identifier_end + 1) == ' ' |
| 485 | || *(lco_identifier_end + 1) == ',' |
| 486 | || *(lco_identifier_end + 1) == '\0') |
| 487 | goto error; |
| 488 | *lco_identifier_end = '\0'; |
| 489 | if (strlen(lco_identifier) == 0) |
| 490 | goto error; |
| 491 | |
| 492 | /* Check if we have already seen the current field identifier |
| 493 | * before. If yes, we must bail, an LCO must only appear once |
| 494 | * in the LCO string */ |
| 495 | for (i = 0; i < lco_seen_n; i++) { |
Pau Espin Pedrol | 7eb6f2c | 2019-06-26 13:00:52 +0200 | [diff] [blame] | 496 | if (strcasecmp(lco_seen[i], lco_identifier) == 0) |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 497 | goto error; |
| 498 | } |
| 499 | lco_seen[lco_seen_n] = lco_identifier; |
| 500 | lco_seen_n++; |
| 501 | |
| 502 | /* The first identifier must always be found at the beginnning |
| 503 | * of the LCO string */ |
| 504 | if (lco_seen[0] != options_copy) |
| 505 | goto error; |
| 506 | |
| 507 | /* Go to the next lco option */ |
| 508 | lco_identifier = next_lco_identifier; |
| 509 | } while (lco_identifier); |
| 510 | |
| 511 | talloc_free(lco_seen); |
| 512 | talloc_free(options_copy); |
| 513 | return 0; |
| 514 | error: |
| 515 | talloc_free(lco_seen); |
| 516 | talloc_free(options_copy); |
| 517 | return -1; |
| 518 | } |
| 519 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 520 | /* Set the LCO from a string (see RFC 3435). |
Harald Welte | 1d1b98f | 2017-12-25 10:03:40 +0100 | [diff] [blame] | 521 | * The string is stored in the 'string' field. A NULL string is handled exactly |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 522 | * like an empty string, the 'string' field is never NULL after this function |
| 523 | * has been called. */ |
Philipp Maier | a390d0b | 2018-01-31 17:30:19 +0100 | [diff] [blame] | 524 | static int set_local_cx_options(void *ctx, struct mgcp_lco *lco, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 525 | const char *options) |
| 526 | { |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 527 | char *lco_id; |
Philipp Maier | 8dbc9ed | 2018-10-26 14:50:25 +0200 | [diff] [blame] | 528 | char codec[17]; |
Pau Espin Pedrol | 83fd8a5 | 2019-06-26 12:55:26 +0200 | [diff] [blame] | 529 | int len; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 530 | |
Philipp Maier | 604410c | 2018-06-06 10:02:16 +0200 | [diff] [blame] | 531 | if (!options) |
| 532 | return 0; |
| 533 | if (strlen(options) == 0) |
| 534 | return 0; |
| 535 | |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 536 | /* Make sure the encoding of the LCO is consistant before we proceed */ |
| 537 | if (check_local_cx_options(ctx, options) != 0) { |
| 538 | LOGP(DLMGCP, LOGL_ERROR, |
| 539 | "local CX options: Internal inconsistency in Local Connection Options!\n"); |
| 540 | return 524; |
| 541 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 542 | |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 543 | talloc_free(lco->string); |
| 544 | lco->string = talloc_strdup(ctx, options); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 545 | |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 546 | lco_id = lco->string; |
| 547 | while ((lco_id = get_lco_identifier(lco_id))) { |
| 548 | switch (tolower(lco_id[0])) { |
| 549 | case 'p': |
| 550 | if (sscanf(lco_id + 1, ":%d-%d", |
| 551 | &lco->pkt_period_min, &lco->pkt_period_max) == 1) |
| 552 | lco->pkt_period_max = lco->pkt_period_min; |
| 553 | break; |
| 554 | case 'a': |
| 555 | /* FIXME: LCO also supports the negotiation of more then one codec. |
| 556 | * (e.g. a:PCMU;G726-32) But this implementation only supports a single |
| 557 | * codec only. */ |
| 558 | if (sscanf(lco_id + 1, ":%16[^,]", codec) == 1) { |
| 559 | talloc_free(lco->codec); |
Pau Espin Pedrol | 83fd8a5 | 2019-06-26 12:55:26 +0200 | [diff] [blame] | 560 | /* MGCP header is case insensive, and we'll need |
| 561 | codec in uppercase when using it later: */ |
| 562 | len = strlen(codec); |
| 563 | lco->codec = talloc_size(ctx, len + 1); |
| 564 | osmo_str_toupper_buf(lco->codec, len + 1, codec); |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 565 | } |
| 566 | break; |
| 567 | default: |
| 568 | LOGP(DLMGCP, LOGL_NOTICE, |
| 569 | "LCO: unhandled option: '%c'/%d in \"%s\"\n", |
| 570 | *lco_id, *lco_id, lco->string); |
| 571 | break; |
| 572 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 573 | |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 574 | lco_id = strchr(lco_id, ','); |
| 575 | if (!lco_id) |
| 576 | break; |
Philipp Maier | 604410c | 2018-06-06 10:02:16 +0200 | [diff] [blame] | 577 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 578 | |
| 579 | LOGP(DLMGCP, LOGL_DEBUG, |
| 580 | "local CX options: lco->pkt_period_max: %i, lco->codec: %s\n", |
| 581 | lco->pkt_period_max, lco->codec); |
Philipp Maier | a390d0b | 2018-01-31 17:30:19 +0100 | [diff] [blame] | 582 | |
| 583 | /* Check if the packetization fits the 20ms raster */ |
| 584 | if (lco->pkt_period_min % 20 && lco->pkt_period_max % 20) { |
| 585 | LOGP(DLMGCP, LOGL_ERROR, |
| 586 | "local CX options: packetization interval is not a multiple of 20ms!\n"); |
| 587 | return 535; |
| 588 | } |
| 589 | |
| 590 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change, |
| 594 | struct mgcp_rtp_end *rtp) |
| 595 | { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 596 | struct mgcp_trunk *trunk = endp->trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 597 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 598 | int patch_ssrc = expect_ssrc_change && trunk->force_constant_ssrc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 599 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 600 | rtp->force_aligned_timing = trunk->force_aligned_timing; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 601 | rtp->force_constant_ssrc = patch_ssrc ? 1 : 0; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 602 | rtp->rfc5993_hr_convert = trunk->rfc5993_hr_convert; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 603 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 604 | LOGPENDP(endp, DLMGCP, LOGL_DEBUG, |
| 605 | "Configuring RTP endpoint: local port %d%s%s\n", |
| 606 | ntohs(rtp->rtp_port), |
| 607 | rtp->force_aligned_timing ? ", force constant timing" : "", |
| 608 | rtp->force_constant_ssrc ? ", force constant ssrc" : ""); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | uint32_t mgcp_rtp_packet_duration(struct mgcp_endpoint *endp, |
| 612 | struct mgcp_rtp_end *rtp) |
| 613 | { |
| 614 | int f = 0; |
| 615 | |
| 616 | /* Get the number of frames per channel and packet */ |
| 617 | if (rtp->frames_per_packet) |
| 618 | f = rtp->frames_per_packet; |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 619 | else if (rtp->packet_duration_ms && rtp->codec->frame_duration_num) { |
| 620 | int den = 1000 * rtp->codec->frame_duration_num; |
| 621 | f = (rtp->packet_duration_ms * rtp->codec->frame_duration_den + |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 622 | den / 2) |
| 623 | / den; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 626 | return rtp->codec->rate * f * rtp->codec->frame_duration_num / |
| 627 | rtp->codec->frame_duration_den; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Pau Espin Pedrol | 9fb8ddf | 2019-05-08 15:35:36 +0200 | [diff] [blame] | 630 | /*! Initializes osmux socket if not yet initialized. Parses Osmux CID from MGCP line. |
| 631 | * \param[in] endp Endpoint willing to initialize osmux |
| 632 | * \param[in] line Line X-Osmux from MGCP header msg to parse |
| 633 | * \returns OSMUX CID, -1 for wildcard, -2 on parse error, -3 on osmux initalize error |
| 634 | */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 635 | static int mgcp_osmux_setup(struct mgcp_endpoint *endp, const char *line) |
| 636 | { |
| 637 | if (!endp->cfg->osmux_init) { |
| 638 | if (osmux_init(OSMUX_ROLE_BSC, endp->cfg) < 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 639 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, "Cannot init OSMUX\n"); |
Pau Espin Pedrol | 9fb8ddf | 2019-05-08 15:35:36 +0200 | [diff] [blame] | 640 | return -3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 641 | } |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 642 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "OSMUX socket has been set up\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | return mgcp_parse_osmux_cid(line); |
| 646 | } |
| 647 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 648 | /* Process codec information contained in CRCX/MDCX */ |
| 649 | static int handle_codec_info(struct mgcp_conn_rtp *conn, |
| 650 | struct mgcp_parse_data *p, int have_sdp, bool crcx) |
| 651 | { |
| 652 | struct mgcp_endpoint *endp = p->endp; |
| 653 | int rc; |
| 654 | char *cmd; |
| 655 | |
| 656 | if (crcx) |
| 657 | cmd = "CRCX"; |
| 658 | else |
| 659 | cmd = "MDCX"; |
| 660 | |
| 661 | /* Collect codec information */ |
| 662 | if (have_sdp) { |
| 663 | /* If we have SDP, we ignore the local connection options and |
| 664 | * use only the SDP information. */ |
| 665 | mgcp_codec_reset_all(conn); |
| 666 | rc = mgcp_parse_sdp_data(endp, conn, p); |
| 667 | if (rc != 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 668 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 669 | "%s: sdp not parseable\n", cmd); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 670 | |
| 671 | /* See also RFC 3661: Protocol error */ |
| 672 | return 510; |
| 673 | } |
| 674 | } else if (endp->local_options.codec) { |
| 675 | /* When no SDP is available, we use the codec information from |
| 676 | * the local connection options (if present) */ |
| 677 | mgcp_codec_reset_all(conn); |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 678 | rc = mgcp_codec_add(conn, PTYPE_UNDEFINED, endp->local_options.codec, NULL); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 679 | if (rc != 0) |
| 680 | goto error; |
| 681 | } |
| 682 | |
| 683 | /* Make sure we always set a sane default codec */ |
| 684 | if (conn->end.codecs_assigned == 0) { |
| 685 | /* When SDP and/or LCO did not supply any codec information, |
| 686 | * than it makes sense to pick a sane default: (payload-type 0, |
| 687 | * PCMU), see also: OS#2658 */ |
| 688 | mgcp_codec_reset_all(conn); |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 689 | rc = mgcp_codec_add(conn, 0, NULL, NULL); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 690 | if (rc != 0) |
| 691 | goto error; |
| 692 | } |
| 693 | |
| 694 | /* Make codec decision */ |
| 695 | if (mgcp_codec_decide(conn) != 0) |
| 696 | goto error; |
| 697 | |
| 698 | return 0; |
| 699 | |
| 700 | error: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 701 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 702 | "%s: codec negotiation failure\n", cmd); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 703 | |
| 704 | /* See also RFC 3661: Codec negotiation failure */ |
| 705 | return 534; |
| 706 | } |
| 707 | |
Neels Hofmeyr | f2388ea | 2018-08-26 23:36:53 +0200 | [diff] [blame] | 708 | static bool parse_x_osmo_ign(struct mgcp_endpoint *endp, char *line) |
| 709 | { |
| 710 | char *saveptr = NULL; |
| 711 | |
| 712 | if (strncmp(line, MGCP_X_OSMO_IGN_HEADER, strlen(MGCP_X_OSMO_IGN_HEADER))) |
| 713 | return false; |
| 714 | line += strlen(MGCP_X_OSMO_IGN_HEADER); |
| 715 | |
| 716 | while (1) { |
| 717 | char *token = strtok_r(line, " ", &saveptr); |
| 718 | line = NULL; |
| 719 | if (!token) |
| 720 | break; |
| 721 | |
Pau Espin Pedrol | 6e26c70 | 2019-06-26 13:09:39 +0200 | [diff] [blame] | 722 | if (!strcasecmp(token, "C")) |
Neels Hofmeyr | f2388ea | 2018-08-26 23:36:53 +0200 | [diff] [blame] | 723 | endp->x_osmo_ign |= MGCP_X_OSMO_IGN_CALLID; |
| 724 | else |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 725 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, "received unknown X-Osmo-IGN item '%s'\n", token); |
Neels Hofmeyr | f2388ea | 2018-08-26 23:36:53 +0200 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | return true; |
| 729 | } |
| 730 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 731 | /* CRCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 732 | static struct msgb *handle_create_con(struct mgcp_parse_data *p) |
| 733 | { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 734 | struct mgcp_trunk *trunk = p->endp->trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 735 | struct mgcp_endpoint *endp = p->endp; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 736 | struct rate_ctr_group *rate_ctrs = trunk->ratectr.mgcp_crcx_ctr_group; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 737 | int error_code = 400; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 738 | const char *local_options = NULL; |
| 739 | const char *callid = NULL; |
| 740 | const char *mode = NULL; |
| 741 | char *line; |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 742 | int have_sdp = 0, osmux_cid = -2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 743 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 744 | struct mgcp_conn *_conn = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 745 | char conn_name[512]; |
Philipp Maier | a390d0b | 2018-01-31 17:30:19 +0100 | [diff] [blame] | 746 | int rc; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 747 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 748 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n"); |
Philipp Maier | 8d6a193 | 2020-06-18 12:19:31 +0200 | [diff] [blame] | 749 | if (!mgcp_endp_avail(endp)) { |
| 750 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_AVAIL]); |
| 751 | return create_err_response(NULL, 501, "CRCX", p->trans); |
| 752 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 753 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 754 | /* parse CallID C: and LocalParameters L: */ |
| 755 | for_each_line(line, p->save) { |
| 756 | if (!mgcp_check_param(endp, line)) |
| 757 | continue; |
| 758 | |
Pau Espin Pedrol | 0c6c3c1 | 2019-06-25 17:18:12 +0200 | [diff] [blame] | 759 | switch (toupper(line[0])) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 760 | case 'L': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 761 | local_options = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 762 | break; |
| 763 | case 'C': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 764 | callid = (const char *)line + 3; |
| 765 | break; |
| 766 | case 'I': |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 767 | /* It is illegal to send a connection identifier |
| 768 | * together with a CRCX, the MGW will assign the |
| 769 | * connection identifier by itself on CRCX */ |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 770 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_BAD_ACTION]); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 771 | return create_err_response(NULL, 523, "CRCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 772 | break; |
| 773 | case 'M': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 774 | mode = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 775 | break; |
| 776 | case 'X': |
Pau Espin Pedrol | c1bf469 | 2019-05-14 16:23:24 +0200 | [diff] [blame] | 777 | if (strncasecmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) { |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 778 | /* If osmux is disabled, just skip setting it up */ |
| 779 | if (!p->endp->cfg->osmux) |
| 780 | break; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 781 | osmux_cid = mgcp_osmux_setup(endp, line); |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 782 | break; |
| 783 | } |
| 784 | |
Neels Hofmeyr | f2388ea | 2018-08-26 23:36:53 +0200 | [diff] [blame] | 785 | if (parse_x_osmo_ign(endp, line)) |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 786 | break; |
Neels Hofmeyr | f2388ea | 2018-08-26 23:36:53 +0200 | [diff] [blame] | 787 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 788 | /* Ignore unknown X-headers */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 789 | break; |
| 790 | case '\0': |
| 791 | have_sdp = 1; |
| 792 | goto mgcp_header_done; |
| 793 | default: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 794 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 795 | "CRCX: unhandled option: '%c'/%d\n", *line, *line); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 796 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_UNHANDLED_PARAM]); |
Philipp Maier | dd0c522 | 2018-02-02 11:08:48 +0100 | [diff] [blame] | 797 | return create_err_response(NULL, 539, "CRCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 798 | break; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | mgcp_header_done: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 803 | /* Check parameters */ |
| 804 | if (!callid) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 805 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 806 | "CRCX: insufficient parameters, missing callid\n"); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 807 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_MISSING_CALLID]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 808 | return create_err_response(endp, 516, "CRCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 809 | } |
| 810 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 811 | if (!mode) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 812 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 813 | "CRCX: insufficient parameters, missing mode\n"); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 814 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_MODE]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 815 | return create_err_response(endp, 517, "CRCX", p->trans); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 816 | } |
| 817 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 818 | /* Check if we are able to accept the creation of another connection */ |
| 819 | if (llist_count(&endp->conns) >= endp->type->max_conns) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 820 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 821 | "CRCX: endpoint full, max. %i connections allowed!\n", |
| 822 | endp->type->max_conns); |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 823 | if (trunk->force_realloc) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 824 | /* There is no more room for a connection, make some |
| 825 | * room by blindly tossing the oldest of the two two |
| 826 | * connections */ |
| 827 | mgcp_conn_free_oldest(endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 828 | } else { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 829 | /* There is no more room for a connection, leave |
| 830 | * everything as it is and return with an error */ |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 831 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_LIMIT_EXCEEDED]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 832 | return create_err_response(endp, 540, "CRCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 836 | /* Check if this endpoint already serves a call, if so, check if the |
| 837 | * callids match up so that we are sure that this is our call */ |
| 838 | if (endp->callid && mgcp_verify_call_id(endp, callid)) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 839 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 840 | "CRCX: already seized by other call (%s)\n", |
| 841 | endp->callid); |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 842 | if (trunk->force_realloc) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 843 | /* This is not our call, toss everything by releasing |
| 844 | * the entire endpoint. (rude!) */ |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 845 | mgcp_endp_release(endp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 846 | else { |
| 847 | /* This is not our call, leave everything as it is and |
| 848 | * return with an error. */ |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 849 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_UNKNOWN_CALLID]); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 850 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 851 | } |
| 852 | } |
| 853 | |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 854 | if (!endp->callid) { |
| 855 | /* Claim endpoint resources. This will also set the callid, |
| 856 | * creating additional connections will only be possible if |
| 857 | * the callid matches up (see above). */ |
| 858 | rc = mgcp_endp_claim(endp, callid); |
| 859 | if (rc != 0) { |
| 860 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_CLAIM]); |
| 861 | return create_err_response(endp, 502, "CRCX", p->trans); |
| 862 | } |
| 863 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 864 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 865 | snprintf(conn_name, sizeof(conn_name), "%s", callid); |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 866 | _conn = mgcp_conn_alloc(trunk->endpoints, endp, MGCP_CONN_TYPE_RTP, conn_name); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 867 | if (!_conn) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 868 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 869 | "CRCX: unable to allocate RTP connection\n"); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 870 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_ALLOC_CONN]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 871 | goto error2; |
| 872 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 873 | } |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 874 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 875 | conn = mgcp_conn_get_rtp(endp, _conn->id); |
| 876 | OSMO_ASSERT(conn); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 877 | |
| 878 | if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) { |
| 879 | error_code = 517; |
Stefan Sperling | a714abf | 2018-10-29 14:19:54 +0100 | [diff] [blame] | 880 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_MODE]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 881 | goto error2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 882 | } |
| 883 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 884 | /* Annotate Osmux circuit ID and set it to negotiating state until this |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 885 | * is fully set up from the dummy load. */ |
| 886 | conn->osmux.state = OSMUX_STATE_DISABLED; |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 887 | if (osmux_cid >= -1) { /* -1 is wilcard, alloc next avail CID */ |
Pau Espin Pedrol | 14f8a08 | 2019-05-13 13:10:06 +0200 | [diff] [blame] | 888 | conn->osmux.state = OSMUX_STATE_ACTIVATING; |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 889 | if (conn_osmux_allocate_cid(conn, osmux_cid) == -1) { |
| 890 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_OSMUX]); |
| 891 | goto error2; |
| 892 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 893 | } else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 894 | LOGPCONN(_conn, DLMGCP, LOGL_ERROR, |
| 895 | "CRCX: osmux only and no osmux offered\n"); |
Stefan Sperling | a714abf | 2018-10-29 14:19:54 +0100 | [diff] [blame] | 896 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_OSMUX]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 897 | goto error2; |
| 898 | } |
| 899 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 900 | /* Set local connection options, if present */ |
| 901 | if (local_options) { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 902 | rc = set_local_cx_options(endp->trunk->endpoints, |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 903 | &endp->local_options, local_options); |
| 904 | if (rc != 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 905 | LOGPCONN(_conn, DLMGCP, LOGL_ERROR, |
| 906 | "CRCX: inavlid local connection options!\n"); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 907 | error_code = rc; |
Stefan Sperling | a714abf | 2018-10-29 14:19:54 +0100 | [diff] [blame] | 908 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_CONN_OPTIONS]); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 909 | goto error2; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | /* Handle codec information and decide for a suitable codec */ |
| 914 | rc = handle_codec_info(conn, p, have_sdp, true); |
| 915 | mgcp_codec_summary(conn); |
| 916 | if (rc) { |
| 917 | error_code = rc; |
Stefan Sperling | a714abf | 2018-10-29 14:19:54 +0100 | [diff] [blame] | 918 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_CODEC_NEGOTIATION]); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 919 | goto error2; |
| 920 | } |
| 921 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 922 | conn->end.fmtp_extra = talloc_strdup(trunk->endpoints, |
| 923 | trunk->audio_fmtp_extra); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 924 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 925 | if (p->cfg->force_ptime) { |
| 926 | conn->end.packet_duration_ms = p->cfg->force_ptime; |
| 927 | conn->end.force_output_ptime = 1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 930 | mgcp_rtp_end_config(endp, 0, &conn->end); |
| 931 | |
Philipp Maier | c3cc654 | 2018-02-02 12:58:42 +0100 | [diff] [blame] | 932 | /* check connection mode setting */ |
| 933 | if (conn->conn->mode != MGCP_CONN_LOOPBACK |
| 934 | && conn->conn->mode != MGCP_CONN_RECV_ONLY |
| 935 | && conn->end.rtp_port == 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 936 | LOGPCONN(_conn, DLMGCP, LOGL_ERROR, |
| 937 | "CRCX: selected connection mode type requires an opposite end!\n"); |
Philipp Maier | c3cc654 | 2018-02-02 12:58:42 +0100 | [diff] [blame] | 938 | error_code = 527; |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 939 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_REMOTE_CONN_DESC]); |
Philipp Maier | c3cc654 | 2018-02-02 12:58:42 +0100 | [diff] [blame] | 940 | goto error2; |
| 941 | } |
| 942 | |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 943 | if (allocate_port(endp, conn) != 0) { |
Stefan Sperling | a714abf | 2018-10-29 14:19:54 +0100 | [diff] [blame] | 944 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_BIND_PORT]); |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 945 | goto error2; |
| 946 | } |
| 947 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 948 | if (setup_rtp_processing(endp, conn) != 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 949 | LOGPCONN(_conn, DLMGCP, LOGL_ERROR, |
| 950 | "CRCX: could not start RTP processing!\n"); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 951 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_START_RTP]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 952 | goto error2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 953 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 954 | |
| 955 | /* policy CB */ |
| 956 | if (p->cfg->policy_cb) { |
| 957 | int rc; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 958 | rc = p->cfg->policy_cb(endp, MGCP_ENDP_CRCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 959 | switch (rc) { |
| 960 | case MGCP_POLICY_REJECT: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 961 | LOGPCONN(_conn, DLMGCP, LOGL_NOTICE, |
| 962 | "CRCX: CRCX rejected by policy\n"); |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 963 | mgcp_endp_release(endp); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 964 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_REJECTED_BY_POLICY]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 965 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 966 | break; |
| 967 | case MGCP_POLICY_DEFER: |
| 968 | /* stop processing */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 969 | return NULL; |
| 970 | break; |
| 971 | case MGCP_POLICY_CONT: |
| 972 | /* just continue */ |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 977 | LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG, |
| 978 | "CRCX: Creating connection: port: %u\n", conn->end.local_port); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 979 | if (p->cfg->change_cb) |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 980 | p->cfg->change_cb(endp, MGCP_ENDP_CRCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 981 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 982 | /* Send dummy packet, see also comments in mgcp_keepalive_timer_cb() */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 983 | OSMO_ASSERT(trunk->keepalive_interval >= MGCP_KEEPALIVE_ONCE); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 984 | if (conn->conn->mode & MGCP_CONN_RECV_ONLY |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 985 | && trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 986 | send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 987 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 988 | LOGPCONN(_conn, DLMGCP, LOGL_NOTICE, |
| 989 | "CRCX: connection successfully created\n"); |
Stefan Sperling | 9270e91 | 2018-10-29 14:10:00 +0100 | [diff] [blame] | 990 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_SUCCESS]); |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 991 | mgcp_endp_update(endp); |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 992 | return create_response_with_sdp(endp, conn, "CRCX", p->trans, true); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 993 | error2: |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 994 | mgcp_endp_release(endp); |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 995 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 996 | "CRCX: unable to create connection\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 997 | return create_err_response(endp, error_code, "CRCX", p->trans); |
| 998 | } |
| 999 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1000 | /* MDCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1001 | static struct msgb *handle_modify_con(struct mgcp_parse_data *p) |
| 1002 | { |
| 1003 | struct mgcp_endpoint *endp = p->endp; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1004 | struct rate_ctr_group *rate_ctrs = endp->trunk->ratectr.mgcp_mdcx_ctr_group; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1005 | int error_code = 500; |
| 1006 | int silent = 0; |
| 1007 | int have_sdp = 0; |
| 1008 | char *line; |
| 1009 | const char *local_options = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1010 | const char *mode = NULL; |
| 1011 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 1012 | const char *conn_id = NULL; |
Pau Espin Pedrol | 6be2c49 | 2019-05-08 15:22:59 +0200 | [diff] [blame] | 1013 | int osmux_cid = -2; |
Philipp Maier | a390d0b | 2018-01-31 17:30:19 +0100 | [diff] [blame] | 1014 | int rc; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1015 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1016 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1017 | |
Philipp Maier | 8d6a193 | 2020-06-18 12:19:31 +0200 | [diff] [blame] | 1018 | if (!mgcp_endp_avail(endp)) { |
| 1019 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_AVAIL]); |
| 1020 | return create_err_response(NULL, 501, "MDCX", p->trans); |
| 1021 | } |
| 1022 | |
Philipp Maier | 5656fbf | 2018-02-02 14:41:58 +0100 | [diff] [blame] | 1023 | /* Prohibit wildcarded requests */ |
| 1024 | if (endp->wildcarded_req) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1025 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 1026 | "MDCX: wildcarded endpoint names not supported.\n"); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1027 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_WILDCARD]); |
Philipp Maier | 5656fbf | 2018-02-02 14:41:58 +0100 | [diff] [blame] | 1028 | return create_err_response(endp, 507, "MDCX", p->trans); |
| 1029 | } |
| 1030 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1031 | if (llist_count(&endp->conns) <= 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1032 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 1033 | "MDCX: endpoint is not holding a connection.\n"); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1034 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_CONN]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1035 | return create_err_response(endp, 400, "MDCX", p->trans); |
| 1036 | } |
| 1037 | |
| 1038 | for_each_line(line, p->save) { |
| 1039 | if (!mgcp_check_param(endp, line)) |
| 1040 | continue; |
| 1041 | |
Pau Espin Pedrol | 0c6c3c1 | 2019-06-25 17:18:12 +0200 | [diff] [blame] | 1042 | switch (toupper(line[0])) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1043 | case 'C': |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1044 | if (mgcp_verify_call_id(endp, line + 3) != 0) { |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1045 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CALLID]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1046 | error_code = 516; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1047 | goto error3; |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1048 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1049 | break; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1050 | case 'I': |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 1051 | conn_id = (const char *)line + 3; |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1052 | if ((error_code = mgcp_verify_ci(endp, conn_id))) { |
| 1053 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CONNID]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1054 | goto error3; |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1055 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1056 | break; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1057 | case 'L': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1058 | local_options = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1059 | break; |
| 1060 | case 'M': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1061 | mode = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1062 | break; |
| 1063 | case 'Z': |
Pau Espin Pedrol | 9b508f6 | 2019-06-26 13:11:22 +0200 | [diff] [blame] | 1064 | silent = strcasecmp("noanswer", line + 3) == 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1065 | break; |
Pau Espin Pedrol | 6be2c49 | 2019-05-08 15:22:59 +0200 | [diff] [blame] | 1066 | case 'X': |
Pau Espin Pedrol | c1bf469 | 2019-05-14 16:23:24 +0200 | [diff] [blame] | 1067 | if (strncasecmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) { |
Pau Espin Pedrol | 6be2c49 | 2019-05-08 15:22:59 +0200 | [diff] [blame] | 1068 | /* If osmux is disabled, just skip setting it up */ |
| 1069 | if (!p->endp->cfg->osmux) |
| 1070 | break; |
| 1071 | osmux_cid = mgcp_osmux_setup(endp, line); |
| 1072 | break; |
| 1073 | } |
| 1074 | /* Ignore unknown X-headers */ |
| 1075 | break; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1076 | case '\0': |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1077 | have_sdp = 1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1078 | goto mgcp_header_done; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1079 | break; |
| 1080 | default: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1081 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 1082 | "MDCX: Unhandled MGCP option: '%c'/%d\n", |
| 1083 | line[0], line[0]); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1084 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_UNHANDLED_PARAM]); |
Philipp Maier | dd0c522 | 2018-02-02 11:08:48 +0100 | [diff] [blame] | 1085 | return create_err_response(NULL, 539, "MDCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1086 | break; |
| 1087 | } |
| 1088 | } |
| 1089 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1090 | mgcp_header_done: |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 1091 | if (!conn_id) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1092 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 1093 | "MDCX: insufficient parameters, missing ci (connectionIdentifier)\n"); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1094 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_CONNID]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1095 | return create_err_response(endp, 515, "MDCX", p->trans); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1099 | if (!conn) { |
| 1100 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_CONN_NOT_FOUND]); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1101 | return create_err_response(endp, 400, "MDCX", p->trans); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1102 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1103 | |
Oliver Smith | e36b775 | 2019-01-22 16:31:36 +0100 | [diff] [blame] | 1104 | mgcp_conn_watchdog_kick(conn->conn); |
| 1105 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1106 | if (mode) { |
| 1107 | if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) { |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1108 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_MODE]); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1109 | error_code = 517; |
| 1110 | goto error3; |
| 1111 | } |
| 1112 | } else |
Pau Espin Pedrol | 209eb9f | 2019-04-24 12:03:04 +0200 | [diff] [blame] | 1113 | conn->conn->mode = conn->conn->mode_orig; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1114 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1115 | /* Set local connection options, if present */ |
| 1116 | if (local_options) { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1117 | rc = set_local_cx_options(endp->trunk->endpoints, |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1118 | &endp->local_options, local_options); |
| 1119 | if (rc != 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1120 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 1121 | "MDCX: invalid local connection options!\n"); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1122 | error_code = rc; |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1123 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CONN_OPTIONS]); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1124 | goto error3; |
| 1125 | } |
| 1126 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1127 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1128 | /* Handle codec information and decide for a suitable codec */ |
| 1129 | rc = handle_codec_info(conn, p, have_sdp, false); |
| 1130 | mgcp_codec_summary(conn); |
| 1131 | if (rc) { |
Philipp Maier | af07f66 | 2018-02-02 11:34:02 +0100 | [diff] [blame] | 1132 | error_code = rc; |
| 1133 | goto error3; |
Philipp Maier | a390d0b | 2018-01-31 17:30:19 +0100 | [diff] [blame] | 1134 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1135 | |
Philipp Maier | c3cc654 | 2018-02-02 12:58:42 +0100 | [diff] [blame] | 1136 | /* check connection mode setting */ |
| 1137 | if (conn->conn->mode != MGCP_CONN_LOOPBACK |
| 1138 | && conn->conn->mode != MGCP_CONN_RECV_ONLY |
| 1139 | && conn->end.rtp_port == 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1140 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 1141 | "MDCX: selected connection mode type requires an opposite end!\n"); |
Philipp Maier | c3cc654 | 2018-02-02 12:58:42 +0100 | [diff] [blame] | 1142 | error_code = 527; |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1143 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_REMOTE_CONN_DESC]); |
Philipp Maier | c3cc654 | 2018-02-02 12:58:42 +0100 | [diff] [blame] | 1144 | goto error3; |
| 1145 | } |
| 1146 | |
Pau Espin Pedrol | 6be2c49 | 2019-05-08 15:22:59 +0200 | [diff] [blame] | 1147 | if (mgcp_conn_rtp_is_osmux(conn)) { |
| 1148 | OSMO_ASSERT(conn->osmux.cid_allocated); |
| 1149 | if (osmux_cid < -1) { |
| 1150 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 1151 | "MDCX: Failed to parse Osmux CID!\n"); |
| 1152 | goto error3; |
| 1153 | } else if (osmux_cid == -1) { |
| 1154 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 1155 | "MDCX: wilcard in MDCX is not supported!\n"); |
| 1156 | goto error3; |
| 1157 | } else if (osmux_cid != (int) conn->osmux.cid) { |
| 1158 | LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, |
| 1159 | "MDCX: changing already allocated CID is not supported!\n"); |
| 1160 | goto error3; |
| 1161 | } |
| 1162 | /* TODO: In the future (when we have recvCID!=sendCID), we need to |
| 1163 | tell Osmux code that osmux_cid is to be used as sendCID for |
| 1164 | that conn. */ |
| 1165 | } |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1166 | |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1167 | if (setup_rtp_processing(endp, conn) != 0) { |
| 1168 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_START_RTP]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1169 | goto error3; |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1170 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1171 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1172 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1173 | /* policy CB */ |
| 1174 | if (p->cfg->policy_cb) { |
| 1175 | int rc; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1176 | rc = p->cfg->policy_cb(endp, MGCP_ENDP_MDCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1177 | switch (rc) { |
| 1178 | case MGCP_POLICY_REJECT: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1179 | LOGPCONN(conn->conn, DLMGCP, LOGL_NOTICE, |
| 1180 | "MDCX: rejected by policy\n"); |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1181 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_REJECTED_BY_POLICY]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1182 | if (silent) |
| 1183 | goto out_silent; |
| 1184 | return create_err_response(endp, 400, "MDCX", p->trans); |
| 1185 | break; |
| 1186 | case MGCP_POLICY_DEFER: |
| 1187 | /* stop processing */ |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1188 | LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG, |
| 1189 | "MDCX: deferred by policy\n"); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1190 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_DEFERRED_BY_POLICY]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1191 | return NULL; |
| 1192 | break; |
| 1193 | case MGCP_POLICY_CONT: |
| 1194 | /* just continue */ |
| 1195 | break; |
| 1196 | } |
| 1197 | } |
| 1198 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1199 | mgcp_rtp_end_config(endp, 1, &conn->end); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1200 | |
| 1201 | /* modify */ |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1202 | LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG, |
| 1203 | "MDCX: modified conn:%s\n", mgcp_conn_dump(conn->conn)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1204 | if (p->cfg->change_cb) |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1205 | p->cfg->change_cb(endp, MGCP_ENDP_MDCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1206 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1207 | /* Send dummy packet, see also comments in mgcp_keepalive_timer_cb() */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1208 | OSMO_ASSERT(endp->trunk->keepalive_interval >= MGCP_KEEPALIVE_ONCE); |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1209 | if (conn->conn->mode & MGCP_CONN_RECV_ONLY |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1210 | && endp->trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1211 | send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1212 | |
Stefan Sperling | aa823bf | 2018-10-29 14:51:41 +0100 | [diff] [blame] | 1213 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_SUCCESS]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1214 | if (silent) |
| 1215 | goto out_silent; |
| 1216 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1217 | LOGPCONN(conn->conn, DLMGCP, LOGL_NOTICE, |
| 1218 | "MDCX: connection successfully modified\n"); |
Philipp Maier | 889fe7f | 2020-07-06 17:44:12 +0200 | [diff] [blame] | 1219 | mgcp_endp_update(endp); |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 1220 | return create_response_with_sdp(endp, conn, "MDCX", p->trans, false); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1221 | error3: |
| 1222 | return create_err_response(endp, error_code, "MDCX", p->trans); |
| 1223 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1224 | out_silent: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1225 | LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "MDCX: silent exit\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1226 | return NULL; |
| 1227 | } |
| 1228 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1229 | /* DLCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1230 | static struct msgb *handle_delete_con(struct mgcp_parse_data *p) |
| 1231 | { |
| 1232 | struct mgcp_endpoint *endp = p->endp; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1233 | struct rate_ctr_group *rate_ctrs = endp->trunk->ratectr.mgcp_dlcx_ctr_group; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1234 | int error_code = 400; |
| 1235 | int silent = 0; |
| 1236 | char *line; |
| 1237 | char stats[1048]; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 1238 | const char *conn_id = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1239 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1240 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1241 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 1242 | "DLCX: deleting connection ...\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1243 | |
Philipp Maier | 8d6a193 | 2020-06-18 12:19:31 +0200 | [diff] [blame] | 1244 | if (!mgcp_endp_avail(endp)) { |
| 1245 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_AVAIL]); |
| 1246 | return create_err_response(NULL, 501, "DLCX", p->trans); |
| 1247 | } |
| 1248 | |
Philipp Maier | 5656fbf | 2018-02-02 14:41:58 +0100 | [diff] [blame] | 1249 | /* Prohibit wildcarded requests */ |
| 1250 | if (endp->wildcarded_req) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1251 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 1252 | "DLCX: wildcarded endpoint names not supported.\n"); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1253 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_WILDCARD]); |
Philipp Maier | 5656fbf | 2018-02-02 14:41:58 +0100 | [diff] [blame] | 1254 | return create_err_response(endp, 507, "DLCX", p->trans); |
| 1255 | } |
| 1256 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1257 | if (llist_count(&endp->conns) <= 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1258 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 1259 | "DLCX: endpoint is not holding a connection.\n"); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1260 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_NO_CONN]); |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1261 | return create_err_response(endp, 515, "DLCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | for_each_line(line, p->save) { |
| 1265 | if (!mgcp_check_param(endp, line)) |
| 1266 | continue; |
| 1267 | |
Pau Espin Pedrol | 0c6c3c1 | 2019-06-25 17:18:12 +0200 | [diff] [blame] | 1268 | switch (toupper(line[0])) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1269 | case 'C': |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1270 | if (mgcp_verify_call_id(endp, line + 3) != 0) { |
| 1271 | error_code = 516; |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1272 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CALLID]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1273 | goto error3; |
Harald Welte | e35eeae | 2017-12-28 13:47:37 +0100 | [diff] [blame] | 1274 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1275 | break; |
| 1276 | case 'I': |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 1277 | conn_id = (const char *)line + 3; |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1278 | if ((error_code = mgcp_verify_ci(endp, conn_id))) { |
| 1279 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CONNID]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1280 | goto error3; |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1281 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1282 | break; |
| 1283 | case 'Z': |
Pau Espin Pedrol | 9b508f6 | 2019-06-26 13:11:22 +0200 | [diff] [blame] | 1284 | silent = strcasecmp("noanswer", line + 3) == 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1285 | break; |
| 1286 | default: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1287 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 1288 | "DLCX: Unhandled MGCP option: '%c'/%d\n", |
| 1289 | line[0], line[0]); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1290 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_UNHANDLED_PARAM]); |
Philipp Maier | dd0c522 | 2018-02-02 11:08:48 +0100 | [diff] [blame] | 1291 | return create_err_response(NULL, 539, "DLCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /* policy CB */ |
| 1297 | if (p->cfg->policy_cb) { |
| 1298 | int rc; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1299 | rc = p->cfg->policy_cb(endp, MGCP_ENDP_DLCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1300 | switch (rc) { |
| 1301 | case MGCP_POLICY_REJECT: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1302 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "DLCX: rejected by policy\n"); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1303 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_REJECTED_BY_POLICY]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1304 | if (silent) |
| 1305 | goto out_silent; |
| 1306 | return create_err_response(endp, 400, "DLCX", p->trans); |
| 1307 | break; |
| 1308 | case MGCP_POLICY_DEFER: |
| 1309 | /* stop processing */ |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1310 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_DEFERRED_BY_POLICY]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1311 | return NULL; |
| 1312 | break; |
| 1313 | case MGCP_POLICY_CONT: |
| 1314 | /* just continue */ |
| 1315 | break; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 1319 | /* When no connection id is supplied, we will interpret this as a |
| 1320 | * wildcarded DLCX and drop all connections at once. (See also |
| 1321 | * RFC3435 Section F.7) */ |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 1322 | if (!conn_id) { |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1323 | int num_conns = llist_count(&endp->conns); |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1324 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 1325 | "DLCX: missing ci (connectionIdentifier), will remove all connections (%d total) at once\n", |
| 1326 | num_conns); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1327 | |
| 1328 | if (num_conns > 0) |
| 1329 | rate_ctr_add(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS], num_conns); |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 1330 | |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 1331 | mgcp_endp_release(endp); |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 1332 | |
| 1333 | /* Note: In this case we do not return any statistics, |
| 1334 | * as we assume that the client is not interested in |
| 1335 | * this case. */ |
| 1336 | return create_ok_response(endp, 200, "DLCX", p->trans); |
| 1337 | } |
| 1338 | |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 1339 | /* Find the connection */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1340 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1341 | if (!conn) { |
| 1342 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CONNID]); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1343 | goto error3; |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1344 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1345 | /* save the statistics of the current connection */ |
| 1346 | mgcp_format_stats(stats, sizeof(stats), conn->conn); |
| 1347 | |
| 1348 | /* delete connection */ |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1349 | LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG, "DLCX: deleting conn:%s\n", |
| 1350 | mgcp_conn_dump(conn->conn)); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1351 | mgcp_conn_free(endp, conn_id); |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1352 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, |
| 1353 | "DLCX: connection successfully deleted\n"); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1354 | |
| 1355 | /* When all connections are closed, the endpoint will be released |
| 1356 | * in order to be ready to be used by another call. */ |
| 1357 | if (llist_count(&endp->conns) <= 0) { |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 1358 | mgcp_endp_release(endp); |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1359 | LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "DLCX: endpoint released\n"); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1360 | } |
| 1361 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1362 | if (p->cfg->change_cb) |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1363 | p->cfg->change_cb(endp, MGCP_ENDP_DLCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1364 | |
Stefan Sperling | 8ab3fbb | 2018-10-30 14:57:25 +0100 | [diff] [blame] | 1365 | rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1366 | if (silent) |
| 1367 | goto out_silent; |
| 1368 | return create_ok_resp_with_param(endp, 250, "DLCX", p->trans, stats); |
| 1369 | |
| 1370 | error3: |
| 1371 | return create_err_response(endp, error_code, "DLCX", p->trans); |
| 1372 | |
| 1373 | out_silent: |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 1374 | LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "DLCX: silent exit\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1375 | return NULL; |
| 1376 | } |
| 1377 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1378 | /* RSIP command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1379 | static struct msgb *handle_rsip(struct mgcp_parse_data *p) |
| 1380 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1381 | /* TODO: Also implement the resetting of a specific endpoint |
| 1382 | * to make mgcp_send_reset_ep() work. Currently this will call |
| 1383 | * mgcp_rsip_cb() in mgw_main.c, which sets reset_endpoints=1 |
| 1384 | * to make read_call_agent() reset all endpoints when called |
| 1385 | * next time. In order to selectively reset endpoints some |
| 1386 | * mechanism to distinguish which endpoint shall be resetted |
| 1387 | * is needed */ |
| 1388 | |
| 1389 | LOGP(DLMGCP, LOGL_NOTICE, "RSIP: resetting all endpoints ...\n"); |
| 1390 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1391 | if (p->cfg->reset_cb) |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1392 | p->cfg->reset_cb(p->endp->trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1393 | return NULL; |
| 1394 | } |
| 1395 | |
| 1396 | static char extract_tone(const char *line) |
| 1397 | { |
| 1398 | const char *str = strstr(line, "D/"); |
| 1399 | if (!str) |
| 1400 | return CHAR_MAX; |
| 1401 | |
| 1402 | return str[2]; |
| 1403 | } |
| 1404 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1405 | /* This can request like DTMF detection and forward, fax detection... it |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1406 | * can also request when the notification should be send and such. We don't |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1407 | * do this right now. */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1408 | static struct msgb *handle_noti_req(struct mgcp_parse_data *p) |
| 1409 | { |
| 1410 | int res = 0; |
| 1411 | char *line; |
| 1412 | char tone = CHAR_MAX; |
| 1413 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1414 | LOGP(DLMGCP, LOGL_NOTICE, "RQNT: processing request for notification ...\n"); |
| 1415 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1416 | for_each_line(line, p->save) { |
Pau Espin Pedrol | 0c6c3c1 | 2019-06-25 17:18:12 +0200 | [diff] [blame] | 1417 | switch (toupper(line[0])) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1418 | case 'S': |
| 1419 | tone = extract_tone(line); |
| 1420 | break; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /* we didn't see a signal request with a tone */ |
| 1425 | if (tone == CHAR_MAX) |
| 1426 | return create_ok_response(p->endp, 200, "RQNT", p->trans); |
| 1427 | |
| 1428 | if (p->cfg->rqnt_cb) |
| 1429 | res = p->cfg->rqnt_cb(p->endp, tone); |
| 1430 | |
| 1431 | return res == 0 ? |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1432 | create_ok_response(p->endp, 200, "RQNT", p->trans) : |
| 1433 | create_err_response(p->endp, res, "RQNT", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1434 | } |
| 1435 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1436 | /* Connection keepalive timer, will take care that dummy packets are send |
Harald Welte | 1d1b98f | 2017-12-25 10:03:40 +0100 | [diff] [blame] | 1437 | * regularly, so that NAT connections stay open */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1438 | static void mgcp_keepalive_timer_cb(void *_trunk) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1439 | { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1440 | struct mgcp_trunk *trunk = _trunk; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1441 | struct mgcp_conn *conn; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1442 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1443 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1444 | LOGP(DLMGCP, LOGL_DEBUG, "triggered trunk %d keepalive timer\n", |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1445 | trunk->trunk_nr); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1446 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1447 | /* Do not accept invalid configuration values |
| 1448 | * valid is MGCP_KEEPALIVE_NEVER, MGCP_KEEPALIVE_ONCE and |
| 1449 | * values greater 0 */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1450 | OSMO_ASSERT(trunk->keepalive_interval >= MGCP_KEEPALIVE_ONCE); |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1451 | |
| 1452 | /* The dummy packet functionality has been disabled, we will exit |
| 1453 | * immediately, no further timer is scheduled, which means we will no |
| 1454 | * longer send dummy packets even when we did before */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1455 | if (trunk->keepalive_interval == MGCP_KEEPALIVE_NEVER) |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1456 | return; |
| 1457 | |
| 1458 | /* In cases where only one dummy packet is sent, we do not need |
| 1459 | * the timer since the functions that handle the CRCX and MDCX are |
| 1460 | * triggering the sending of the dummy packet. So we behave like in |
| 1461 | * the MGCP_KEEPALIVE_NEVER case */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1462 | if (trunk->keepalive_interval == MGCP_KEEPALIVE_ONCE) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1463 | return; |
| 1464 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1465 | /* Send walk over all endpoints and send out dummy packets through |
| 1466 | * every connection present on each endpoint */ |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1467 | for (i = 1; i < trunk->number_endpoints; ++i) { |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1468 | struct mgcp_endpoint *endp = trunk->endpoints[i]; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1469 | llist_for_each_entry(conn, &endp->conns, entry) { |
| 1470 | if (conn->mode == MGCP_CONN_RECV_ONLY) |
| 1471 | send_dummy(endp, &conn->u.rtp); |
| 1472 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1473 | } |
| 1474 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1475 | /* Schedule the keepalive timer for the next round */ |
| 1476 | LOGP(DLMGCP, LOGL_DEBUG, "rescheduling trunk %d keepalive timer\n", |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1477 | trunk->trunk_nr); |
| 1478 | osmo_timer_schedule(&trunk->keepalive_timer, trunk->keepalive_interval, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1479 | 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1480 | } |
| 1481 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1482 | void mgcp_trunk_set_keepalive(struct mgcp_trunk *trunk, int interval) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1483 | { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1484 | trunk->keepalive_interval = interval; |
| 1485 | osmo_timer_setup(&trunk->keepalive_timer, mgcp_keepalive_timer_cb, trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1486 | |
| 1487 | if (interval <= 0) |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1488 | osmo_timer_del(&trunk->keepalive_timer); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1489 | else |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1490 | osmo_timer_schedule(&trunk->keepalive_timer, |
| 1491 | trunk->keepalive_interval, 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1492 | } |
| 1493 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1494 | /*! allocate configuration with default values. |
| 1495 | * (called once at startup by main function) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1496 | struct mgcp_config *mgcp_config_alloc(void) |
| 1497 | { |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1498 | /* FIXME: This is unrelated to the protocol, put this in some |
| 1499 | * appropiate place! */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1500 | struct mgcp_config *cfg; |
| 1501 | |
| 1502 | cfg = talloc_zero(NULL, struct mgcp_config); |
| 1503 | if (!cfg) { |
| 1504 | LOGP(DLMGCP, LOGL_FATAL, "Failed to allocate config.\n"); |
| 1505 | return NULL; |
| 1506 | } |
| 1507 | |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 1508 | osmo_strlcpy(cfg->domain, "mgw", sizeof(cfg->domain)); |
| 1509 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1510 | cfg->net_ports.range_start = RTP_PORT_DEFAULT_RANGE_START; |
| 1511 | cfg->net_ports.range_end = RTP_PORT_DEFAULT_RANGE_END; |
| 1512 | cfg->net_ports.last_port = cfg->net_ports.range_start; |
| 1513 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1514 | cfg->source_port = 2427; |
| 1515 | cfg->source_addr = talloc_strdup(cfg, "0.0.0.0"); |
| 1516 | cfg->osmux_addr = talloc_strdup(cfg, "0.0.0.0"); |
| 1517 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1518 | cfg->rtp_processing_cb = &mgcp_rtp_processing_default; |
| 1519 | cfg->setup_rtp_processing_cb = &mgcp_setup_rtp_processing_default; |
| 1520 | |
| 1521 | cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default; |
| 1522 | |
Philipp Maier | d19de2e | 2020-06-03 13:55:33 +0200 | [diff] [blame] | 1523 | INIT_LLIST_HEAD(&cfg->trunks); |
| 1524 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1525 | /* Allocate virtual trunk */ |
Philipp Maier | d19de2e | 2020-06-03 13:55:33 +0200 | [diff] [blame] | 1526 | if (!mgcp_trunk_alloc(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID)) { |
Harald Welte | 3ac604e | 2019-05-08 14:07:41 +0200 | [diff] [blame] | 1527 | talloc_free(cfg); |
| 1528 | return NULL; |
| 1529 | } |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1530 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1531 | mgcp_ratectr_global_alloc(cfg, &cfg->ratectr); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1532 | |
| 1533 | return cfg; |
| 1534 | } |
| 1535 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1536 | static int send_agent(struct mgcp_config *cfg, const char *buf, int len) |
| 1537 | { |
| 1538 | return write(cfg->gw_fd.bfd.fd, buf, len); |
| 1539 | } |
| 1540 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1541 | /*! Reset all endpoints by sending RSIP message to self. |
| 1542 | * (called by VTY) |
| 1543 | * \param[in] endp trunk endpoint |
| 1544 | * \param[in] endpoint number |
| 1545 | * \returns 0 on success, -1 on error */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1546 | int mgcp_send_reset_all(struct mgcp_config *cfg) |
| 1547 | { |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 1548 | char buf[MGCP_ENDPOINT_MAXLEN + 128]; |
| 1549 | int len; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1550 | int rc; |
| 1551 | |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 1552 | len = snprintf(buf, sizeof(buf), |
| 1553 | "RSIP 1 *@%s MGCP 1.0\r\n", cfg->domain); |
| 1554 | if (len < 0) |
| 1555 | return -1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1556 | |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 1557 | rc = send_agent(cfg, buf, len); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1558 | if (rc <= 0) |
| 1559 | return -1; |
| 1560 | |
| 1561 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1562 | } |
| 1563 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1564 | /*! Reset a single endpoint by sending RSIP message to self. |
| 1565 | * (called by VTY) |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1566 | * \param[in] endp to reset |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1567 | * \returns 0 on success, -1 on error */ |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1568 | int mgcp_send_reset_ep(struct mgcp_endpoint *endp) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1569 | { |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 1570 | char buf[MGCP_ENDPOINT_MAXLEN + 128]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1571 | int len; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1572 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1573 | |
| 1574 | len = snprintf(buf, sizeof(buf), |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1575 | "RSIP 39 %s MGCP 1.0\r\n", endp->name); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1576 | if (len < 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1577 | return -1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1578 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1579 | rc = send_agent(endp->cfg, buf, len); |
| 1580 | if (rc <= 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1581 | return -1; |
| 1582 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1583 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1584 | } |