]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_nat.c: remove x-ast-orig-host from request URI and To header
authorPirmin Walthert <infos@nappsoft.ch>
Wed, 13 May 2020 12:06:19 +0000 (14:06 +0200)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 22 May 2020 12:47:48 +0000 (07:47 -0500)
While asterisk is filtering out the x-ast-orig-host parameter from the
contact on response messages, it is not filtering it out from the
request URI and the to header on SIP requests (for example INVITE).

ASTERISK-28884 #close

Change-Id: Id032b33098a1befea9b243ca994184baecccc59e

res/res_pjsip_nat.c

index 8b3ec426d95d8f9ad5e3b32acfa40ecdf30a8dbc..26fedaaac2ffcf4d57a8d26d212160d8b34d9772 100644 (file)
@@ -37,6 +37,9 @@
 #define AST_SIP_X_AST_ORIG_HOST "x-ast-orig-host"
 #define AST_SIP_X_AST_ORIG_HOST_LEN 15
 
+#define is_sip_uri(uri) \
+       (PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri))
+
 static void save_orig_contact_host(pjsip_rx_data *rdata, pjsip_sip_uri *uri)
 {
        pjsip_param *x_orig_host;
@@ -303,6 +306,29 @@ static int nat_invoke_hook(void *obj, void *arg, int flags)
 static void restore_orig_contact_host(pjsip_tx_data *tdata)
 {
        pjsip_contact_hdr *contact;
+       pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };
+       pjsip_param *x_orig_host;
+       pjsip_sip_uri *uri;
+       pjsip_hdr *hdr;
+
+       if (tdata->msg->type == PJSIP_REQUEST_MSG) {
+               if (is_sip_uri(tdata->msg->line.req.uri)) {
+                       uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
+                       while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {
+                               pj_list_erase(x_orig_host);
+                       }
+               }
+               for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
+                       if (hdr->type == PJSIP_H_TO) {
+                               if (is_sip_uri(((pjsip_fromto_hdr *) hdr)->uri)) {
+                                       uri = pjsip_uri_get_uri(((pjsip_fromto_hdr *) hdr)->uri);
+                                       while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {
+                                               pj_list_erase(x_orig_host);
+                                       }
+                               }
+                       }
+               }
+       }
 
        if (tdata->msg->type != PJSIP_RESPONSE_MSG) {
                return;
@@ -311,8 +337,7 @@ static void restore_orig_contact_host(pjsip_tx_data *tdata)
        contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
        while (contact) {
                pjsip_sip_uri *contact_uri = pjsip_uri_get_uri(contact->uri);
-               pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };
-               pjsip_param *x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);
+               x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);
 
                if (x_orig_host) {
                        char host_port[x_orig_host->value.slen + 1];