The issue we are having is where Kamailio relays an INVITE with the correct To header field domain, however when it relays the subsequent CANCEL it seems like it does not correctly change the To header field domain.

Here is what we use to try and put in the correct To header in the CANCEL:

                  remove_hf("To");
                   if ($tt == null)
                       insert_hf("To: <sip:$rU@1.2.3.4>\r\n", "From");
                   else
                       insert_hf("To: <sip:$rU@1.2.3.4>;tag=$tt\r\n", "From");
                   xlog("DBG1: Trying to fix CANCEL: td=$td ci=$ci rm=$rm ru=$ru ou=$ou\n");

Changes to the left side of the at-symbol persist, however changes to the domain are reverted and changed back to what was received from adjacent proxy.

Any ideas why it reverts?