Revert "pjsip_message_filter: Only do interface lookup for wildcard addresses."
[asterisk/asterisk.git] / res / res_pjsip / pjsip_message_filter.c
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"
25 #include "asterisk/res_pjsip_session.h"
26 #include "include/res_pjsip_private.h"
27 #include "asterisk/module.h"
28
29 #define MOD_DATA_RESTRICTIONS "restrictions"
30
31 static pj_status_t filter_on_tx_message(pjsip_tx_data *tdata);
32 static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata);
33
34 /*! \brief Outgoing message modification restrictions */
35 struct filter_message_restrictions {
36         /*! \brief Disallow modification of the From domain */
37         unsigned int disallow_from_domain_modification;
38 };
39
40 static 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
47 static 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 */
56 static 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 */
72 static 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
76         restrictions->disallow_from_domain_modification = !ast_strlen_zero(endpoint->fromdomain);
77 }
78
79 /*! \brief PJSIP Supplement for tagging messages with restrictions */
80 static struct ast_sip_supplement filter_supplement = {
81         .priority = AST_SIP_SUPPLEMENT_PRIORITY_FIRST,
82         .outgoing_request = filter_outgoing_message,
83         .outgoing_response = filter_outgoing_message,
84 };
85
86 /*! \brief Callback invoked on session outgoing messages */
87 static 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 */
95 static struct ast_sip_session_supplement filter_session_supplement = {
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 */
102 static pjsip_transport *get_udp_transport(pj_str_t *address, int port)
103 {
104         struct ao2_container *transport_states = ast_sip_get_transport_states();
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 && ((transport_state->type != AST_TRANSPORT_UDP) ||
115                         (pj_strcmp(&transport_state->transport->local_name.host, address)) ||
116                         (transport_state->transport->local_name.port != port))) {
117                         continue;
118                 }
119
120                 sip_transport = transport_state->transport;
121                 break;
122         }
123         ao2_iterator_destroy(&iter);
124
125         ao2_ref(transport_states, -1);
126
127         return sip_transport;
128 }
129
130 /*! \brief Helper function which determines if a transport is bound to any */
131 static 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 */
146 static 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
166 static 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
185 static 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 (is_sip_uri(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 (is_sip_uri(((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 && is_sip_uri(((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
225 static pj_status_t filter_on_tx_message(pjsip_tx_data *tdata)
226 {
227         struct filter_message_restrictions *restrictions =
228                 ast_sip_mod_data_get(tdata->mod_data, filter_module_transport.id, MOD_DATA_RESTRICTIONS);
229         pjsip_tpmgr_fla2_param prm;
230         pjsip_cseq_hdr *cseq;
231         pjsip_via_hdr *via;
232         pjsip_fromto_hdr *from;
233
234         sanitize_tdata(tdata);
235
236         /* Use the destination information to determine what local interface this message will go out on */
237         pjsip_tpmgr_fla2_param_default(&prm);
238         prm.tp_type = tdata->tp_info.transport->key.type;
239         pj_strset2(&prm.dst_host, tdata->tp_info.dst_name);
240         prm.local_if = PJ_TRUE;
241
242         /* If we can't get the local address use best effort and let it pass */
243         if (pjsip_tpmgr_find_local_addr2(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), tdata->pool, &prm) != PJ_SUCCESS) {
244                 return PJ_SUCCESS;
245         }
246
247         /* For UDP we can have multiple transports so the port needs to be maintained */
248         if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
249                 tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
250                 prm.ret_port = tdata->tp_info.transport->local_name.port;
251         }
252
253         /* If the IP source differs from the existing transport see if we need to update it */
254         if (pj_strcmp(&prm.ret_addr, &tdata->tp_info.transport->local_name.host)) {
255
256                 /* If the transport it is going out on is different reflect it in the message */
257                 if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
258                         tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
259                         pjsip_transport *transport;
260
261                         transport = get_udp_transport(&prm.ret_addr, prm.ret_port);
262
263                         if (transport) {
264                                 tdata->tp_info.transport = transport;
265                         }
266                 }
267
268                 /* If the chosen transport is not bound to any we can't use the source address as it won't get back to us */
269                 if (!is_bound_any(tdata->tp_info.transport)) {
270                         pj_strassign(&prm.ret_addr, &tdata->tp_info.transport->local_name.host);
271                 }
272         } else {
273                 /* The transport chosen will deliver this but ensure it is updated with the right information */
274                 pj_strassign(&prm.ret_addr, &tdata->tp_info.transport->local_name.host);
275         }
276
277         /* If the message needs to be updated with new address do so */
278         if (tdata->msg->type == PJSIP_REQUEST_MSG || !(cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL)) ||
279                 pj_strcmp2(&cseq->method.name, "REGISTER")) {
280                 pjsip_contact_hdr *contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
281                 if (contact && (PJSIP_URI_SCHEME_IS_SIP(contact->uri) || PJSIP_URI_SCHEME_IS_SIPS(contact->uri))
282                         && !(tdata->msg->type == PJSIP_RESPONSE_MSG && tdata->msg->line.status.code / 100 == 3)) {
283                         pjsip_sip_uri *uri = pjsip_uri_get_uri(contact->uri);
284
285                         /* prm.ret_addr is allocated from the tdata pool OR the transport so it is perfectly fine to just do an assignment like this */
286                         pj_strassign(&uri->host, &prm.ret_addr);
287                         uri->port = prm.ret_port;
288                         ast_debug(5, "Re-wrote Contact URI host/port to %.*s:%d (this may be re-written again later)\n",
289                                 (int)pj_strlen(&uri->host), pj_strbuf(&uri->host), uri->port);
290
291                         if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
292                                 tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
293                                 uri->transport_param.slen = 0;
294                         } else {
295                                 pj_strdup2(tdata->pool, &uri->transport_param, pjsip_transport_get_type_name(tdata->tp_info.transport->key.type));
296                         }
297
298                         pjsip_tx_data_invalidate_msg(tdata);
299                 }
300         }
301
302         if (tdata->msg->type == PJSIP_REQUEST_MSG && (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL))) {
303                 pj_strassign(&via->sent_by.host, &prm.ret_addr);
304                 via->sent_by.port = prm.ret_port;
305
306                 pjsip_tx_data_invalidate_msg(tdata);
307         }
308
309         if (tdata->msg->type == PJSIP_REQUEST_MSG && (from = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_FROM, NULL)) &&
310                 (restrictions && !restrictions->disallow_from_domain_modification)) {
311                 pjsip_name_addr *id_name_addr = (pjsip_name_addr *)from->uri;
312                 pjsip_sip_uri *uri = pjsip_uri_get_uri(id_name_addr);
313                 pj_sockaddr ip;
314
315                 if (pj_strcmp2(&uri->host, "localhost") && pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &uri->host, &ip) == PJ_SUCCESS) {
316                         pj_strassign(&uri->host, &prm.ret_addr);
317                         pjsip_tx_data_invalidate_msg(tdata);
318                 }
319         }
320
321         /* Update the SDP if it is present */
322         if (tdata->msg->body && ast_sip_is_content_type(&tdata->msg->body->content_type, "application", "sdp") &&
323                 multihomed_rewrite_sdp(tdata->msg->body->data)) {
324                 struct pjmedia_sdp_session *sdp = tdata->msg->body->data;
325                 static const pj_str_t STR_IP4 = { "IP4", 3 };
326                 static const pj_str_t STR_IP6 = { "IP6", 3 };
327                 pj_str_t STR_IP;
328                 int stream;
329
330                 STR_IP = tdata->tp_info.transport->key.type & PJSIP_TRANSPORT_IPV6 ? STR_IP6 : STR_IP4;
331
332                 pj_strassign(&sdp->origin.addr, &prm.ret_addr);
333                 sdp->origin.addr_type = STR_IP;
334                 pj_strassign(&sdp->conn->addr, &prm.ret_addr);
335                 sdp->conn->addr_type = STR_IP;
336
337                 for (stream = 0; stream < sdp->media_count; ++stream) {
338                         if (sdp->media[stream]->conn) {
339                                 pj_strassign(&sdp->media[stream]->conn->addr, &prm.ret_addr);
340                                 sdp->media[stream]->conn->addr_type = STR_IP;
341                         }
342                 }
343
344                 pjsip_tx_data_invalidate_msg(tdata);
345         }
346
347         return PJ_SUCCESS;
348 }
349
350 enum uri_type {
351         URI_TYPE_REQUEST = -1,
352         URI_TYPE_TO = PJSIP_H_TO,
353         URI_TYPE_FROM = PJSIP_H_FROM,
354         URI_TYPE_CONTACT = PJSIP_H_CONTACT,
355 };
356
357 static void print_uri_debug(enum uri_type ut, pjsip_rx_data *rdata, pjsip_hdr *hdr)
358 {
359 #ifdef AST_DEVMODE
360         pjsip_uri *local_uri = NULL;
361         char hdrbuf[512];
362         int hdrbuf_len;
363         char *request_uri;
364         pjsip_uri_context_e context = PJSIP_URI_IN_OTHER;
365         char header_name[32];
366
367         switch (ut) {
368         case(URI_TYPE_REQUEST):
369                 context = PJSIP_URI_IN_REQ_URI;
370                 strcpy(header_name, "Request"); /* Safe */
371                 local_uri = rdata->msg_info.msg->line.req.uri;
372                 break;
373         case(PJSIP_H_FROM):
374                 strcpy(header_name, "From"); /* Safe */
375                 context = PJSIP_URI_IN_FROMTO_HDR;
376                 local_uri = pjsip_uri_get_uri(((pjsip_from_hdr *)hdr)->uri);
377                 break;
378         case(PJSIP_H_TO):
379                 strcpy(header_name, "To"); /* Safe */
380                 context = PJSIP_URI_IN_FROMTO_HDR;
381                 local_uri = pjsip_uri_get_uri(((pjsip_to_hdr *)hdr)->uri);
382                 break;
383         case(PJSIP_H_CONTACT):
384                 strcpy(header_name, "Contact"); /* Safe */
385                 context = PJSIP_URI_IN_CONTACT_HDR;
386                 local_uri = pjsip_uri_get_uri(((pjsip_contact_hdr *)hdr)->uri);
387                 break;
388         }
389
390         hdrbuf_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, rdata->msg_info.msg->line.req.uri, hdrbuf, 512);
391         hdrbuf[hdrbuf_len] = '\0';
392         request_uri = ast_strdupa(hdrbuf);
393         hdrbuf_len = pjsip_uri_print(context, local_uri, hdrbuf, 512);
394         hdrbuf[hdrbuf_len] = '\0';
395
396         ast_debug(2, "There was a non sip(s) URI scheme in %s URI '%s' for request '%*.*s %s'\n",
397                 header_name, hdrbuf,
398                 (int)rdata->msg_info.msg->line.req.method.name.slen,
399                 (int)rdata->msg_info.msg->line.req.method.name.slen,
400                 rdata->msg_info.msg->line.req.method.name.ptr, request_uri);
401 #endif
402 }
403
404 static pj_bool_t on_rx_process_uris(pjsip_rx_data *rdata)
405 {
406         pjsip_contact_hdr *contact = NULL;
407
408         if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) {
409                 return PJ_FALSE;
410         }
411
412         if (!is_sip_uri(rdata->msg_info.msg->line.req.uri)) {
413                 print_uri_debug(URI_TYPE_REQUEST, rdata, NULL);
414                 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
415                         PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
416                 return PJ_TRUE;
417         }
418
419         if (!is_sip_uri(rdata->msg_info.from->uri)) {
420                 print_uri_debug(URI_TYPE_FROM, rdata, (pjsip_hdr *)rdata->msg_info.from);
421                 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
422                         PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
423                 return PJ_TRUE;
424         }
425
426         if (!is_sip_uri(rdata->msg_info.to->uri)) {
427                 print_uri_debug(URI_TYPE_TO, rdata, (pjsip_hdr *)rdata->msg_info.to);
428                 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
429                         PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
430                 return PJ_TRUE;
431         }
432
433
434         contact = (pjsip_contact_hdr *) pjsip_msg_find_hdr(
435                 rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
436
437         if (!contact && pjsip_method_creates_dialog(&rdata->msg_info.msg->line.req.method)) {
438                 /* A contact header is required for dialog creating methods */
439                 static const pj_str_t missing_contact = { "Missing Contact header", 22 };
440                 pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 400,
441                                 &missing_contact, NULL, NULL);
442                 return PJ_TRUE;
443         }
444
445         while (contact) {
446                 if (!contact->star && !is_sip_uri(contact->uri)) {
447                         print_uri_debug(URI_TYPE_CONTACT, rdata, (pjsip_hdr *)contact);
448                         pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
449                                 PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
450                         return PJ_TRUE;
451                 }
452                 contact = (pjsip_contact_hdr *) pjsip_msg_find_hdr(
453                         rdata->msg_info.msg, PJSIP_H_CONTACT, contact->next);
454         }
455
456         return PJ_FALSE;
457 }
458
459 static pj_bool_t on_rx_process_symmetric_transport(pjsip_rx_data *rdata)
460 {
461         pjsip_contact_hdr *contact;
462         pjsip_sip_uri *uri;
463         const char *transport_id;
464         struct ast_sip_transport *transport;
465         pjsip_param *x_transport;
466
467         if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) {
468                 return PJ_FALSE;
469         }
470
471         contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
472         if (!(contact && contact->uri
473                 && ast_begins_with(rdata->tp_info.transport->info, AST_SIP_X_AST_TXP ":"))) {
474                 return PJ_FALSE;
475         }
476
477         uri = pjsip_uri_get_uri(contact->uri);
478
479         transport_id = rdata->tp_info.transport->info + AST_SIP_X_AST_TXP_LEN + 1;
480         transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_id);
481
482         if (!(transport && transport->symmetric_transport)) {
483                 ao2_cleanup(transport);
484                 return PJ_FALSE;
485         }
486         ao2_cleanup(transport);
487
488         x_transport = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param);
489         x_transport->name = pj_strdup3(rdata->tp_info.pool, AST_SIP_X_AST_TXP);
490         x_transport->value = pj_strdup3(rdata->tp_info.pool, transport_id);
491
492         pj_list_insert_before(&uri->other_param, x_transport);
493
494         ast_debug(1, "Set transport '%s' on %.*s from %.*s:%d\n", transport_id,
495                 (int)rdata->msg_info.msg->line.req.method.name.slen,
496                 rdata->msg_info.msg->line.req.method.name.ptr,
497                 (int)uri->host.slen, uri->host.ptr, uri->port);
498
499         return PJ_FALSE;
500 }
501
502 static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata)
503 {
504         pj_bool_t rc;
505
506         rc = on_rx_process_uris(rdata);
507         if (rc == PJ_TRUE) {
508                 return rc;
509         }
510
511         rc = on_rx_process_symmetric_transport(rdata);
512         if (rc == PJ_TRUE) {
513                 return rc;
514         }
515
516         return PJ_FALSE;
517 }
518
519 void ast_res_pjsip_cleanup_message_filter(void)
520 {
521         ast_sip_unregister_service(&filter_module_tsx);
522         ast_sip_unregister_service(&filter_module_transport);
523         ast_sip_unregister_supplement(&filter_supplement);
524         ast_sip_session_unregister_supplement(&filter_session_supplement);
525 }
526
527 int ast_res_pjsip_init_message_filter(void)
528 {
529         ast_sip_session_register_supplement(&filter_session_supplement);
530         ast_sip_register_supplement(&filter_supplement);
531
532         if (ast_sip_register_service(&filter_module_transport)) {
533                 ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
534                 ast_res_pjsip_cleanup_message_filter();
535                 return -1;
536         }
537
538         if (ast_sip_register_service(&filter_module_tsx)) {
539                 ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
540                 ast_res_pjsip_cleanup_message_filter();
541                 return -1;
542         }
543
544         return 0;
545 }