# Linux netfilter NAT variable

**URL:** <https://www.ruby-forum.com/t/linux-netfilter-nat-variable/200266>\
**Category:** NGINX\
**Created:** [December 8, 2010, 3:54am UTC](https://www.ruby-forum.com/t/linux-netfilter-nat-variable/200266 "2010-12-08T03:54:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 8, 2010, 3:54am UTC](https://www.ruby-forum.com/t/linux-netfilter-nat-variable/200266/1 "2010-12-08T03:54:19Z")

</div>

Hi,

I’ve added very useful for me variable which helps get destination IP  
from netfilter NAT table, in this case we don’t need to make extra  
resolving requests, adding code for this variable, is it useful for  
other?  
Also I have question what best attributes for this var? I’m using  
NGX\_HTTP\_VAR\_NOHASH.

static ngx\_int\_t  
ngx\_http\_orig\_ip(ngx\_http\_request\_t \*r, ngx\_http\_variable\_value\_t \*v,  
uintptr\_t data)  
{  
struct sockaddr\_in addr;  
socklen\_t addr\_sz = sizeof(addr);  
bzero(&addr, addr\_sz);  
addr.sin\_family = AF\_INET;

if (getsockopt(r-\>connection-\>fd, SOL\_IP, SO\_ORIGINAL\_DST, &addr,  
&addr\_sz) != 0) {  
ngx\_log\_error(NGX\_LOG\_ERR, r-\>connection-\>log, 0,  
“Couldn’t read SO\_ORIGINAL\_DST from socket errno: %d”, errno);  
return NGX\_ERROR;  
}

v-\>data = ngx\_palloc(r-\>pool, NGX\_INET\_ADDRSTRLEN);  
v-\>len=ngx\_inet\_ntop(AF\_INET, &addr.sin\_addr, v-\>data,  
NGX\_INET\_ADDRSTRLEN);  
return NGX\_OK;  
}

---

<div class="post-metadata">

**Author:** ![Roman\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@Roman\_V](https://www.ruby-forum.com/u/Roman_V)\
**Post date:** [April 1, 2011, 7:06pm UTC](https://www.ruby-forum.com/t/linux-netfilter-nat-variable/200266/2 "2011-04-01T19:06:33Z")

</div>

Hi,  
I have interests in this variable.  
Would you please send me the whole patch ?  
I will test it.  
Thanks in advance.

BR,  
DeltaY

2010/12/8 Roman V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
