<p><a href="https://github.com/miconda" class="user-mention">@miconda</a> I found a simple way to get the value of the X-Forwarded-For header without changing the code in the websocket module.<br>
I thought about this after reading again the comment for Juha.<br>
I'm retrieving the X-Forwarded-For header in the event:xhttp and use htable to track the conid associated:</p>
<div class="highlight highlight-source-shell"><pre>event_route[xhttp:request] {
....
        <span class="pl-smi">$var</span>(orig_ip) = <span class="pl-smi">$hdr</span>(X-Forwarded-For)<span class="pl-k">;</span>
        <span class="pl-k">if</span> <span class="pl-s"><span class="pl-pds">((</span><span class="pl-smi">$var</span>(orig_ip) <span class="pl-k">!=</span> <span class="pl-smi">$null</span>) <span class="pl-k">&&</span> (<span class="pl-smi">$var</span>(orig_ip) <span class="pl-k">!=</span> ""<span class="pl-pds">))</span></span> {
            <span class="pl-smi">$sht</span>(ws_src=<span class="pl-k">></span><span class="pl-smi">$conid</span>) = <span class="pl-smi">$var</span>(orig_ip)<span class="pl-k">;</span>
            xlog(<span class="pl-s"><span class="pl-pds">"</span>L_INFO<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>WebSocket <span class="pl-smi">$conid</span> original source ip is <span class="pl-smi">$var</span>(orig_ip)\n<span class="pl-pds">"</span></span>)<span class="pl-k">;</span>
        }</pre></div>
<p>And in any context where $conid is available, I can retrieve the value with (in my case to set xavp attr in the location_attrs table when the phone registers) :</p>
<div class="highlight highlight-source-shell"><pre>        <span class="pl-smi">$var</span>(real_src_ip) = <span class="pl-smi">$sht</span>(ws_src=<span class="pl-k">></span><span class="pl-smi">$conid</span>)<span class="pl-k">;</span>
        <span class="pl-k">if</span> <span class="pl-s"><span class="pl-pds">((</span><span class="pl-smi">$var</span>(real_src_ip) <span class="pl-k">!=</span> "") <span class="pl-k">&&</span> (<span class="pl-smi">$var</span>(real_src_ip) <span class="pl-k">!=</span> <span class="pl-smi">$null</span><span class="pl-pds">))</span></span> {
            xavp_params_explode(<span class="pl-s"><span class="pl-pds">"</span>real_src_ip=<span class="pl-smi">$var</span>(real_src_ip)<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>contact_extras<span class="pl-pds">"</span></span>)<span class="pl-k">;</span>
        }</pre></div>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you commented.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/1002#issuecomment-281148921">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZTlu7LwFiSScaEgrriERtmXxFrHcks5redjhgaJpZM4MFqcu">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZRuhLOnvKwSCcmWmmK7JiN7wj94Fks5redjhgaJpZM4MFqcu.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/pull/1002#issuecomment-281148921"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request 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":"PERSON","message":"@tamiel in #1002: @miconda I found a simple way to get the value of the X-Forwarded-For header without changing the code in the websocket module.\r\nI thought about this after reading again the comment for Juha.\r\nI'm retrieving the X-Forwarded-For header in the event:xhttp and use htable to track the conid associated:\r\n```shell\r\nevent_route[xhttp:request] {\r\n....\r\n        $var(orig_ip) = $hdr(X-Forwarded-For);\r\n        if (($var(orig_ip) != $null) \u0026\u0026 ($var(orig_ip) != \"\")) {\r\n            $sht(ws_src=\u003e$conid) = $var(orig_ip);\r\n            xlog(\"L_INFO\", \"WebSocket $conid original source ip is $var(orig_ip)\\n\");\r\n        }\r\n```\r\n\r\nAnd in any context where $conid is available, I can retrieve the value with (in my case to set xavp attr in the location_attrs table when the phone registers) :\r\n```shell\r\n        $var(real_src_ip) = $sht(ws_src=\u003e$conid);\r\n        if (($var(real_src_ip) != \"\") \u0026\u0026 ($var(real_src_ip) != $null)) {\r\n            xavp_params_explode(\"real_src_ip=$var(real_src_ip)\", \"contact_extras\");\r\n        }\r\n```"}],"action":{"name":"View Pull Request","url":"https://github.com/kamailio/kamailio/pull/1002#issuecomment-281148921"}}}</script>