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