Asterisk - The Open Source Telephony Project GIT-master-55f4e6d
pjsip_message_filter.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2014-2016, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#include "asterisk.h"
20
21#include <pjsip.h>
22#include <pjsip_ua.h>
23
24#include "asterisk/res_pjsip.h"
27#include "asterisk/module.h"
28
29#define MOD_DATA_RESTRICTIONS "restrictions"
30
31static pj_status_t filter_on_tx_message(pjsip_tx_data *tdata);
32static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata);
33
34/*! \brief Outgoing message modification restrictions */
36 /*! \brief Disallow modification of the From domain */
38};
39
40static pjsip_module filter_module_transport = {
41 .name = { "Message Filtering Transport", 27 },
42 .id = -1,
43 .priority = PJSIP_MOD_PRIORITY_TRANSPORT_LAYER,
44 .on_rx_request = filter_on_rx_message,
45};
46
47static pjsip_module filter_module_tsx = {
48 .name = { "Message Filtering TSX", 21 },
49 .id = -1,
50 .priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 1,
51 .on_tx_request = filter_on_tx_message,
52 .on_tx_response = filter_on_tx_message,
53};
54
55/*! \brief Helper function to get (or allocate if not already present) restrictions on a message */
56static struct filter_message_restrictions *get_restrictions(pjsip_tx_data *tdata)
57{
58 struct filter_message_restrictions *restrictions;
59
60 restrictions = ast_sip_mod_data_get(tdata->mod_data, filter_module_tsx.id, MOD_DATA_RESTRICTIONS);
61 if (restrictions) {
62 return restrictions;
63 }
64
65 restrictions = PJ_POOL_ALLOC_T(tdata->pool, struct filter_message_restrictions);
66 ast_sip_mod_data_set(tdata->pool, tdata->mod_data, filter_module_tsx.id, MOD_DATA_RESTRICTIONS, restrictions);
67
68 return restrictions;
69}
70
71/*! \brief Callback invoked on non-session outgoing messages */
72static void filter_outgoing_message(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata)
73{
74 struct filter_message_restrictions *restrictions = get_restrictions(tdata);
75
77}
78
79/*! \brief PJSIP Supplement for tagging messages with restrictions */
82 .outgoing_request = filter_outgoing_message,
83 .outgoing_response = filter_outgoing_message,
84};
85
86/*! \brief Callback invoked on session outgoing messages */
87static void filter_session_outgoing_message(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
88{
89 struct filter_message_restrictions *restrictions = get_restrictions(tdata);
90
91 restrictions->disallow_from_domain_modification = !ast_strlen_zero(session->endpoint->fromdomain);
92}
93
94/*! \brief PJSIP Session Supplement for tagging messages with restrictions */
96 .priority = 1,
97 .outgoing_request = filter_session_outgoing_message,
98 .outgoing_response = filter_session_outgoing_message,
99};
100
101/*! \brief Helper function which returns a UDP transport bound to the given address and port */
102static pjsip_transport *get_udp_transport(pj_str_t *address, int port)
103{
105 struct ast_sip_transport_state *transport_state;
106 struct ao2_iterator iter;
107 pjsip_transport *sip_transport = NULL;
108
109 if (!transport_states) {
110 return NULL;
111 }
112
113 for (iter = ao2_iterator_init(transport_states, 0); (transport_state = ao2_iterator_next(&iter)); ao2_ref(transport_state, -1)) {
114 if (!transport_state->flow &&
115 transport_state->type == AST_TRANSPORT_UDP &&
116 !pj_strcmp(&transport_state->transport->local_name.host, address) &&
117 transport_state->transport->local_name.port == port) {
118 sip_transport = transport_state->transport;
119 ao2_ref(transport_state, -1);
120 break;
121 }
122 }
124
126
127 return sip_transport;
128}
129
130/*! \brief Helper function which determines if a transport is bound to any */
131static int is_bound_any(pjsip_transport *transport)
132{
133 pj_uint32_t loop6[4] = {0, 0, 0, 0};
134
135 if ((transport->local_addr.addr.sa_family == pj_AF_INET() &&
136 transport->local_addr.ipv4.sin_addr.s_addr == PJ_INADDR_ANY) ||
137 (transport->local_addr.addr.sa_family == pj_AF_INET6() &&
138 !pj_memcmp(&transport->local_addr.ipv6.sin6_addr, loop6, sizeof(loop6)))) {
139 return 1;
140 }
141
142 return 0;
143}
144
145/*! \brief Helper function which determines if the address within SDP should be rewritten */
146static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp)
147{
148 if (!sdp->conn) {
149 return 0;
150 }
151
152 /* If the host address is used in the SDP replace it with the address of what this is going out on */
153 if ((!pj_strcmp2(&sdp->conn->addr_type, "IP4") && !pj_strcmp2(&sdp->conn->addr,
154 ast_sip_get_host_ip_string(pj_AF_INET()))) ||
155 (!pj_strcmp2(&sdp->conn->addr_type, "IP6") && !pj_strcmp2(&sdp->conn->addr,
156 ast_sip_get_host_ip_string(pj_AF_INET6())))) {
157 return 1;
158 }
159
160 return 0;
161}
162
163#define is_sip_uri(uri) \
164 (PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri))
165
166static void print_sanitize_debug(char *msg, pjsip_uri_context_e context, pjsip_sip_uri *uri)
167{
168#ifdef AST_DEVMODE
169 char hdrbuf[512];
170 int hdrbuf_len;
171
172 hdrbuf_len = pjsip_uri_print(context, uri, hdrbuf, 512);
173 hdrbuf[hdrbuf_len] = '\0';
174 ast_debug(2, "%s: %s\n", msg, hdrbuf);
175#endif
176}
177
178/* If in DEVMODE, prevent inlining to assist in debugging */
179#ifdef AST_DEVMODE
180#define FUNC_ATTRS __attribute__ ((noinline))
181#else
182#define FUNC_ATTRS
183#endif
184
185static void FUNC_ATTRS sanitize_tdata(pjsip_tx_data *tdata)
186{
187 static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN };
188 pjsip_param *x_transport;
189 pjsip_sip_uri *uri;
190 pjsip_hdr *hdr;
191
192 if (tdata->msg->type == PJSIP_REQUEST_MSG) {
193 if (ast_sip_is_uri_sip_sips(tdata->msg->line.req.uri)) {
194 uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
195 print_sanitize_debug("Sanitizing Request", PJSIP_URI_IN_REQ_URI, uri);
196 while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
197 pj_list_erase(x_transport);
198 }
199 }
200 }
201
202 for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
203 if (hdr->type == PJSIP_H_TO || hdr->type == PJSIP_H_FROM) {
204 if (ast_sip_is_uri_sip_sips(((pjsip_fromto_hdr *) hdr)->uri)) {
205 uri = pjsip_uri_get_uri(((pjsip_fromto_hdr *) hdr)->uri);
206 print_sanitize_debug("Sanitizing From/To header", PJSIP_URI_IN_FROMTO_HDR, uri);
207 while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
208 pj_list_erase(x_transport);
209 }
210 }
211 } else if (hdr->type == PJSIP_H_CONTACT) {
212 if (!((pjsip_contact_hdr *) hdr)->star && ast_sip_is_uri_sip_sips(((pjsip_contact_hdr *) hdr)->uri)) {
213 uri = pjsip_uri_get_uri(((pjsip_contact_hdr *) hdr)->uri);
214 print_sanitize_debug("Sanitizing Contact header", PJSIP_URI_IN_CONTACT_HDR, uri);
215 while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
216 pj_list_erase(x_transport);
217 }
218 }
219 }
220 }
221
222 pjsip_tx_data_invalidate_msg(tdata);
223}
224
225static pj_status_t filter_on_tx_message(pjsip_tx_data *tdata)
226{
227 struct filter_message_restrictions *restrictions =
229 pjsip_tpmgr_fla2_param prm;
230 pjsip_cseq_hdr *cseq;
231 pjsip_via_hdr *via;
232 pjsip_fromto_hdr *from;
233 pjsip_tpselector sel;
234 pjsip_sdp_info *sdp_info;
235 pjmedia_sdp_session *sdp;
236
237 sanitize_tdata(tdata);
238
239 /* Use the destination information to determine what local interface this message will go out on */
240 pjsip_tpmgr_fla2_param_default(&prm);
241 prm.tp_type = tdata->tp_info.transport->key.type;
242 pj_strset2(&prm.dst_host, tdata->tp_info.dst_name);
243 prm.local_if = PJ_TRUE;
244
245 if ((tdata->tp_info.transport->key.type != PJSIP_TRANSPORT_UDP) &&
246 (tdata->tp_info.transport->key.type != PJSIP_TRANSPORT_UDP6)) {
247 sel.type = PJSIP_TPSELECTOR_LISTENER;
248 sel.u.listener = tdata->tp_info.transport->factory;
249 prm.tp_sel = &sel;
250 }
251
252 /* If we can't get the local address use best effort and let it pass */
253 if (pjsip_tpmgr_find_local_addr2(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), tdata->pool, &prm) != PJ_SUCCESS) {
254 return PJ_SUCCESS;
255 }
256
257 /* For UDP we can have multiple transports so the port needs to be maintained */
258 if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
259 tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
260 prm.ret_port = tdata->tp_info.transport->local_name.port;
261 }
262
263 /* If the IP source differs from the existing transport see if we need to update it */
264 if (pj_strcmp(&prm.ret_addr, &tdata->tp_info.transport->local_name.host)) {
265
266 /* If the transport it is going out on is different reflect it in the message */
267 if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
268 tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
269 pjsip_transport *transport;
270
271 transport = get_udp_transport(&prm.ret_addr, prm.ret_port);
272
273 if (transport) {
274 tdata->tp_info.transport = transport;
275 }
276 }
277
278 /* If the chosen transport is not bound to any we can't use the source address as it won't get back to us */
279 if (!is_bound_any(tdata->tp_info.transport)) {
280 pj_strassign(&prm.ret_addr, &tdata->tp_info.transport->local_name.host);
281 }
282 } else {
283 /* The transport chosen will deliver this but ensure it is updated with the right information */
284 pj_strassign(&prm.ret_addr, &tdata->tp_info.transport->local_name.host);
285 }
286
287 /* If the message needs to be updated with new address do so */
288 if (tdata->msg->type == PJSIP_REQUEST_MSG || !(cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL)) ||
289 pj_strcmp2(&cseq->method.name, "REGISTER")) {
290 pjsip_contact_hdr *contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
291 if (contact && ast_sip_is_uri_sip_sips(contact->uri)
292 && !(tdata->msg->type == PJSIP_RESPONSE_MSG && tdata->msg->line.status.code / 100 == 3)) {
293 pjsip_sip_uri *uri = pjsip_uri_get_uri(contact->uri);
294
295 /* prm.ret_addr is allocated from the tdata pool OR the transport so it is perfectly fine to just do an assignment like this */
296 pj_strassign(&uri->host, &prm.ret_addr);
297 uri->port = prm.ret_port;
298 ast_debug(5, "Re-wrote Contact URI host/port to %.*s:%d (this may be re-written again later)\n",
299 (int)pj_strlen(&uri->host), pj_strbuf(&uri->host), uri->port);
300
301 if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
302 tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
303 uri->transport_param.slen = 0;
304 } else {
305 pj_strdup2(tdata->pool, &uri->transport_param, pjsip_transport_get_type_name(tdata->tp_info.transport->key.type));
306 }
307
308 pjsip_tx_data_invalidate_msg(tdata);
309 }
310 }
311
312 if (tdata->msg->type == PJSIP_REQUEST_MSG && (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL))) {
313 pj_strassign(&via->sent_by.host, &prm.ret_addr);
314 via->sent_by.port = prm.ret_port;
315
316 pjsip_tx_data_invalidate_msg(tdata);
317 }
318
319 if (tdata->msg->type == PJSIP_REQUEST_MSG && (from = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_FROM, NULL)) &&
320 (restrictions && !restrictions->disallow_from_domain_modification)) {
321 pjsip_name_addr *id_name_addr = (pjsip_name_addr *)from->uri;
322 pjsip_sip_uri *uri = pjsip_uri_get_uri(id_name_addr);
323 pj_sockaddr ip;
324
325 if (pj_strcmp2(&uri->host, "localhost") && pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &uri->host, &ip) == PJ_SUCCESS) {
326 pj_strassign(&uri->host, &prm.ret_addr);
327 pjsip_tx_data_invalidate_msg(tdata);
328 }
329 }
330
331 /* If there's no body in the tdata we can just return here. */
332 if (!tdata->msg->body) {
333 return PJ_SUCCESS;
334 }
335
336 /*
337 * pjsip_get_sdp_info will search for an SDP even if it's in
338 * a multipart message body.
339 */
340 sdp_info = pjsip_get_sdp_info(tdata->pool, tdata->msg->body, NULL, &pjsip_media_type_application_sdp);
341 if (sdp_info->sdp_err != PJ_SUCCESS || !sdp_info->sdp) {
342 return PJ_SUCCESS;
343 }
344
345 sdp = sdp_info->sdp;
346
347 if (multihomed_rewrite_sdp(sdp)) {
348 static const pj_str_t STR_IP4 = { "IP4", 3 };
349 static const pj_str_t STR_IP6 = { "IP6", 3 };
350 pj_str_t STR_IP;
351 int stream;
352
353 STR_IP = tdata->tp_info.transport->key.type & PJSIP_TRANSPORT_IPV6 ? STR_IP6 : STR_IP4;
354
355 pj_strassign(&sdp->origin.addr, &prm.ret_addr);
356 sdp->origin.addr_type = STR_IP;
357 pj_strassign(&sdp->conn->addr, &prm.ret_addr);
358 sdp->conn->addr_type = STR_IP;
359
360 for (stream = 0; stream < sdp->media_count; ++stream) {
361 if (sdp->media[stream]->conn) {
362 pj_strassign(&sdp->media[stream]->conn->addr, &prm.ret_addr);
363 sdp->media[stream]->conn->addr_type = STR_IP;
364 }
365 }
366
367 pjsip_tx_data_invalidate_msg(tdata);
368 }
369
370 return PJ_SUCCESS;
371}
372
375 URI_TYPE_TO = PJSIP_H_TO,
376 URI_TYPE_FROM = PJSIP_H_FROM,
377 URI_TYPE_CONTACT = PJSIP_H_CONTACT,
378};
379
380static void print_uri_debug(enum uri_type ut, pjsip_rx_data *rdata, pjsip_hdr *hdr)
381{
382#ifdef AST_DEVMODE
383 pjsip_uri *local_uri = NULL;
384 char hdrbuf[512];
385 int hdrbuf_len;
386 char *request_uri;
387 pjsip_uri_context_e context = PJSIP_URI_IN_OTHER;
388 char header_name[32];
389
390 switch (ut) {
391 case(URI_TYPE_REQUEST):
392 context = PJSIP_URI_IN_REQ_URI;
393 strcpy(header_name, "Request"); /* Safe */
394 local_uri = rdata->msg_info.msg->line.req.uri;
395 break;
396 case(PJSIP_H_FROM):
397 strcpy(header_name, "From"); /* Safe */
398 context = PJSIP_URI_IN_FROMTO_HDR;
399 local_uri = pjsip_uri_get_uri(((pjsip_from_hdr *)hdr)->uri);
400 break;
401 case(PJSIP_H_TO):
402 strcpy(header_name, "To"); /* Safe */
403 context = PJSIP_URI_IN_FROMTO_HDR;
404 local_uri = pjsip_uri_get_uri(((pjsip_to_hdr *)hdr)->uri);
405 break;
406 case(PJSIP_H_CONTACT):
407 strcpy(header_name, "Contact"); /* Safe */
408 context = PJSIP_URI_IN_CONTACT_HDR;
409 local_uri = pjsip_uri_get_uri(((pjsip_contact_hdr *)hdr)->uri);
410 break;
411 }
412
413 hdrbuf_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, rdata->msg_info.msg->line.req.uri, hdrbuf, 512);
414 hdrbuf[hdrbuf_len] = '\0';
415 request_uri = ast_strdupa(hdrbuf);
416 hdrbuf_len = pjsip_uri_print(context, local_uri, hdrbuf, 512);
417 hdrbuf[hdrbuf_len] = '\0';
418
419 ast_debug(2, "There was a non sip(s) URI scheme in %s URI '%s' for request '%*.*s %s'\n",
420 header_name, hdrbuf,
421 (int)rdata->msg_info.msg->line.req.method.name.slen,
422 (int)rdata->msg_info.msg->line.req.method.name.slen,
423 rdata->msg_info.msg->line.req.method.name.ptr, request_uri);
424#endif
425}
426
427/*!
428 * /internal
429 *
430 * We want to make sure that any incoming requests don't already
431 * have x-ast-* parameters in any URIs or we may get confused
432 * if symmetric transport (x-ast-txp) or rewrite_contact (x-ast-orig-host)
433 * is used later on.
434 */
435static void remove_x_ast_params(pjsip_uri *header_uri){
436 pjsip_sip_uri *uri;
437 pjsip_param *param;
438
439 if (!header_uri) {
440 return;
441 }
442
443 if (PJSIP_URI_SCHEME_IS_TEL(header_uri)) {
444 return;
445 }
446
447 uri = pjsip_uri_get_uri(header_uri);
448 if (!uri) {
449 return;
450 }
451
452 param = uri->other_param.next;
453
454 while (param != &uri->other_param) {
455 /* We need to save off 'next' because pj_list_erase will remove it */
456 pjsip_param *next = param->next;
457
458 if (pj_strncmp2(&param->name, "x-ast-", 6) == 0) {
459 pj_list_erase(param);
460 }
461 param = next;
462 }
463}
464
465/* An allow list helper function for tel URI requests */
466static int is_allowed_tel_uri_request(pjsip_rx_data *rdata)
467{
468 struct pjsip_request_line req = rdata->msg_info.msg->line.req;
469 const pjsip_method method = (const pjsip_method)req.method;
470
471 if (pjsip_method_cmp(&method, pjsip_get_invite_method())) {
472 return 1;
473 } else if (pjsip_method_cmp(&method, pjsip_get_ack_method())) {
474 return 1;
475 } else if (pjsip_method_cmp(&method, pjsip_get_bye_method())) {
476 return 1;
477 } else if (pjsip_method_cmp(&method, pjsip_get_cancel_method())) {
478 return 1;
479 }
480
481 return 0;
482}
483
484static pj_bool_t on_rx_process_uris(pjsip_rx_data *rdata)
485{
486 pjsip_contact_hdr *contact = NULL;
487
488 if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) {
489 return PJ_FALSE;
490 }
491
492 if (PJSIP_URI_SCHEME_IS_TEL(rdata->msg_info.msg->line.req.uri)
493 && !is_allowed_tel_uri_request(rdata)) {
495 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
496 PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
497 return PJ_TRUE;
498 }
499 remove_x_ast_params(rdata->msg_info.msg->line.req.uri);
500
501 if (!ast_sip_is_allowed_uri(rdata->msg_info.from->uri)) {
502 print_uri_debug(URI_TYPE_FROM, rdata, (pjsip_hdr *)rdata->msg_info.from);
503 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
504 PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
505 return PJ_TRUE;
506 }
507 remove_x_ast_params(rdata->msg_info.from->uri);
508
509 if (!ast_sip_is_allowed_uri(rdata->msg_info.to->uri)) {
510 print_uri_debug(URI_TYPE_TO, rdata, (pjsip_hdr *)rdata->msg_info.to);
511 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
512 PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
513 return PJ_TRUE;
514 }
515 remove_x_ast_params(rdata->msg_info.to->uri);
516
517 contact = (pjsip_contact_hdr *) pjsip_msg_find_hdr(
518 rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
519
520 if (!contact && pjsip_method_creates_dialog(&rdata->msg_info.msg->line.req.method)) {
521 /* A contact header is required for dialog creating methods */
522 static const pj_str_t missing_contact = { "Missing Contact header", 22 };
523 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 400,
524 &missing_contact, NULL, NULL);
525 return PJ_TRUE;
526 }
527
528 while (contact) {
529 if (!contact->star && !is_sip_uri(contact->uri)) {
530 print_uri_debug(URI_TYPE_CONTACT, rdata, (pjsip_hdr *)contact);
531 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
532 PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
533 return PJ_TRUE;
534 }
535 remove_x_ast_params(contact->uri);
536
537 contact = (pjsip_contact_hdr *) pjsip_msg_find_hdr(
538 rdata->msg_info.msg, PJSIP_H_CONTACT, contact->next);
539 }
540
541 return PJ_FALSE;
542}
543
544static pj_bool_t on_rx_process_symmetric_transport(pjsip_rx_data *rdata)
545{
546 pjsip_contact_hdr *contact;
547 pjsip_sip_uri *uri;
548 const char *transport_id;
549 struct ast_sip_transport *transport;
550 pjsip_param *x_transport;
551
552 if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) {
553 return PJ_FALSE;
554 }
555
556 contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
557 if (!(contact && contact->uri
558 && ast_begins_with(rdata->tp_info.transport->info, AST_SIP_X_AST_TXP ":"))) {
559 return PJ_FALSE;
560 }
561
562 uri = pjsip_uri_get_uri(contact->uri);
563
564 transport_id = rdata->tp_info.transport->info + AST_SIP_X_AST_TXP_LEN + 1;
565 transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_id);
566
567 if (!(transport && transport->symmetric_transport)) {
568 ao2_cleanup(transport);
569 return PJ_FALSE;
570 }
571 ao2_cleanup(transport);
572
573 x_transport = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param);
574 x_transport->name = pj_strdup3(rdata->tp_info.pool, AST_SIP_X_AST_TXP);
575 x_transport->value = pj_strdup3(rdata->tp_info.pool, transport_id);
576
577 pj_list_insert_before(&uri->other_param, x_transport);
578
579 ast_debug(1, "Set transport '%s' on %.*s from %.*s:%d\n", transport_id,
580 (int)rdata->msg_info.msg->line.req.method.name.slen,
581 rdata->msg_info.msg->line.req.method.name.ptr,
582 (int)uri->host.slen, uri->host.ptr, uri->port);
583
584 return PJ_FALSE;
585}
586
587static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata)
588{
589 pj_bool_t rc;
590
591 rc = on_rx_process_uris(rdata);
592 if (rc == PJ_TRUE) {
593 return rc;
594 }
595
597 if (rc == PJ_TRUE) {
598 return rc;
599 }
600
601 return PJ_FALSE;
602}
603
605{
610}
611
613{
616
618 ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
620 return -1;
621 }
622
624 ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
626 return -1;
627 }
628
629 return 0;
630}
if(!yyg->yy_init)
Definition: ast_expr2f.c:854
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static struct ao2_container * transport_states
char * address
Definition: f2c.h:59
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
Asterisk module definitions.
@ AST_TRANSPORT_UDP
Definition: netsock2.h:60
static pj_bool_t on_rx_process_uris(pjsip_rx_data *rdata)
#define MOD_DATA_RESTRICTIONS
static pj_bool_t on_rx_process_symmetric_transport(pjsip_rx_data *rdata)
static void FUNC_ATTRS sanitize_tdata(pjsip_tx_data *tdata)
static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp)
Helper function which determines if the address within SDP should be rewritten.
static struct filter_message_restrictions * get_restrictions(pjsip_tx_data *tdata)
Helper function to get (or allocate if not already present) restrictions on a message.
static void filter_session_outgoing_message(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
Callback invoked on session outgoing messages.
static pjsip_module filter_module_tsx
#define FUNC_ATTRS
static int is_allowed_tel_uri_request(pjsip_rx_data *rdata)
static pjsip_module filter_module_transport
static struct ast_sip_session_supplement filter_session_supplement
PJSIP Session Supplement for tagging messages with restrictions.
#define is_sip_uri(uri)
static int is_bound_any(pjsip_transport *transport)
Helper function which determines if a transport is bound to any.
static void remove_x_ast_params(pjsip_uri *header_uri)
static struct ast_sip_supplement filter_supplement
PJSIP Supplement for tagging messages with restrictions.
@ URI_TYPE_TO
@ URI_TYPE_CONTACT
@ URI_TYPE_FROM
@ URI_TYPE_REQUEST
static void filter_outgoing_message(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata)
Callback invoked on non-session outgoing messages.
static pjsip_transport * get_udp_transport(pj_str_t *address, int port)
Helper function which returns a UDP transport bound to the given address and port.
int ast_res_pjsip_init_message_filter(void)
static void print_uri_debug(enum uri_type ut, pjsip_rx_data *rdata, pjsip_hdr *hdr)
static pj_status_t filter_on_tx_message(pjsip_tx_data *tdata)
void ast_res_pjsip_cleanup_message_filter(void)
static void print_sanitize_debug(char *msg, pjsip_uri_context_e context, pjsip_sip_uri *uri)
static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata)
const char * method
Definition: res_pjsip.c:1279
void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement)
Unregister a an supplement to SIP out of dialog processing.
Definition: res_pjsip.c:1476
void ast_sip_unregister_service(pjsip_module *module)
Definition: res_pjsip.c:133
const char * ast_sip_get_host_ip_string(int af)
Retrieve the local host address in string form.
Definition: res_pjsip.c:2493
struct ao2_container * ast_sip_get_transport_states(void)
Retrieves all transport states.
int ast_sip_register_service(pjsip_module *module)
Register a SIP service in Asterisk.
Definition: res_pjsip.c:117
int ast_sip_is_allowed_uri(pjsip_uri *uri)
Check whether a pjsip_uri is allowed or not.
Definition: res_pjsip.c:3472
pjsip_media_type pjsip_media_type_application_sdp
Definition: res_pjsip.c:3916
void ast_sip_register_supplement(struct ast_sip_supplement *supplement)
Register a supplement to SIP out of dialog processing.
Definition: res_pjsip.c:1456
#define AST_SIP_X_AST_TXP
Definition: res_pjsip.h:1076
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
@ AST_SIP_SUPPLEMENT_PRIORITY_FIRST
Definition: res_pjsip.h:3179
int ast_sip_is_uri_sip_sips(pjsip_uri *uri)
Check whether a pjsip_uri is SIP/SIPS or not.
Definition: res_pjsip.c:3467
#define ast_sip_mod_data_set(pool, mod_data, id, key, val)
Utilizing a mod_data array for a given id, set the value associated with the given key.
Definition: res_pjsip.h:2978
#define ast_sip_mod_data_get(mod_data, id, key)
Using the dictionary stored in mod_data array at a given id, retrieve the value associated with the g...
Definition: res_pjsip.h:2946
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define AST_SIP_X_AST_TXP_LEN
Definition: res_pjsip.h:1077
#define ast_sip_session_register_supplement(supplement)
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
Definition: pjsip_session.c:63
#define NULL
Definition: resample.c:96
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
Contact associated with an address of record.
Definition: res_pjsip.h:392
An entity with which Asterisk communicates.
Definition: res_pjsip.h:961
const ast_string_field fromdomain
Definition: res_pjsip.h:990
A supplement to SIP message processing.
enum ast_sip_supplement_priority priority
A structure describing a SIP session.
A supplement to SIP message processing.
Definition: res_pjsip.h:3196
enum ast_sip_supplement_priority priority
Definition: res_pjsip.h:3200
Structure for SIP transport information.
Definition: res_pjsip.h:119
enum ast_transport type
Definition: res_pjsip.h:133
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:121
Transport to bind to.
Definition: res_pjsip.h:221
Outgoing message modification restrictions.
unsigned int disallow_from_domain_modification
Disallow modification of the From domain.