<h3>Description</h3>
<p>fix_nated_contact() and removing and appending a contact will malform the SIP packet.<br>
I read somewhere that all of the *_hf functions are applied only when the packet is sent out again. Perhaps things are working as intended and I am just asking too much of these functions.</p>
<h4>Reproduction</h4>
<p>In my onreply_route for 200 OK with SDP:</p>
<p>fix_nated_contact();<br>
#dlg_setflag(1); # I want the contact in the dialog table to be the fixed one<br>
#Then I want to replace that contact with a contact to Kamailio's public IP and route it to Asterisk<br>
#for ACK response. This contact must be here for Asterisk to relay this back to me.<br>
remove_hf("Contact");<br>
append_hf("Contact: sip:$sel(cfg_get.global.publicIP):5060\r\n"); # insert_hf same problem</p>
<h3>Troubleshooting</h3>
<p>This results in two contacts, but does not malform. remove_hf after the nat_fix_contact is the issue.<br>
fix_nated_contact();<br>
insert_hf("Contact: sip:$sel(cfg_get.global.publicIP):5060\r\n");</p>
<h4>SIP Traffic</h4>
<p>The inbound 200 OK<br>
CSeq: 9865 INVITE<br>
Contact: sip:424242143@devicePrivateIP:5060<br>
Content-Type: application/sdp</p>
<p>After fix_nated_contact(); remove_hf("Contact"); append_hf("Contact: sip:serverIP:5060\r\n");<br>
CSeq: 9865 INVITE<br>
sip:424242143@devicePublicIP:1026Content-Type: application/sdp</p>
<h3>Possible Solutions</h3>
<p>I managed to get the functionality I wanted with either of these, but they result in two contact headers.<br>
I have also noticed that a remove->append->remove->append ignores the remove between appends.</p>
<p>Workaround 1<br>
remove_hf("Contact");<br>
insert_hf("Contact: sip:$tU@$si:$sp\r\n");<br>
dlg_setflag(1);<br>
insert_hf("Contact: sip:$sel(cfg_get.global.publicIP):5060\r\n");</p>
<p>Workaround 2<br>
fix_nated_contact();<br>
dlg_setflag(1);<br>
insert_hf("Contact: sip:$sel(cfg_get.global.publicIP):5060\r\n");</p>
<h3>Additional Information</h3>
<ul>
<li>
<p><strong>Kamailio Version</strong>: kamailio 4.4.5 (x86_64/linux) f98162</p>
</li>
<li>
<p><strong>Operating System</strong>: Linux 3.10.0-514.2.2.el7.x86_64 # 1 SMP Tue Dec 6 23:06:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux</p>
</li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/977">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZR2AIZgCql34bqjhRiFklP6R2sd_ks5raJzwgaJpZM4L5uis">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZXeHpLwKJ3PUl_87vVuNy4gIBqHqks5raJzwgaJpZM4L5uis.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/977"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"fix_nated_contact() and remove_hf malform packet (#977)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/977"}}}</script>