REDIRECT changes DST address of the packet
Subsystems (2)
Hello,
My question is if I use REDIRECT action in NAT PREROUTING table is it going to change the tcp packet DST address.
If I lose original DST address, how can I persist that value in that packet.
Can you give information how the packet is getting converted in this scenario.
Thanks in advance.
Nari.
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
Quoted 9 lines · Venkata Narayana
Hello,
My question is if I use REDIRECT action in NAT PREROUTING table is it going to change the tcp packet DST address.
If I lose original DST address, how can I persist
that value in that packet.
Please use getsockopt() with SO_ORIGINAL_DST.
Best regards,
Krzysztof Olędzki
Quoted 3 lines · On Thu, 30 Jun 2005 10:08:55 +0200 (CEST) Krzysztof Oledzki <[email protected]>…
Quoted 2 lines
If I lose original DST address, how can I persist
that value in that packet.Please use
getsockopt()withSO_ORIGINAL_DST.
Hehe you were faster than me :-).
Nari, if you don't understand how to do this, check out the source of some transparent proxies (squid, p3scan) for examples (as Krzysztof said, grep for SO_ORIGINAL_DST). I think it's straightforward, I even managed to reproduce this in perl without using any C.
Quoted 2 lines
Best regards,
Krzysztof Olędzki
Yours sincerely,
Peter
Thanks Peter, Krzysztof and All,
I am able to get the original Destination address and able to solve the problem.
Thanks once again.
Nari.
Quoted 17 lines · --- Peter Surda
Quoted 3 lines · On Thu, 30 Jun 2005 10:08:55 +0200 (CEST) Krzysztof Oledzki <[email protected]>…
Quoted 2 lines
If I lose original DST address, how can I persist
that value in that packet.Please use
getsockopt()withSO_ORIGINAL_DST.Hehe you were faster than me :-).
Nari, if you don't understand how to do this, check out the source of some
transparent proxies (squid, p3scan) for examples (as Krzysztof said, grep forSO_ORIGINAL_DST). I think it's straightforward, I even managed to reproduce this
in perl without using any C.
Quoted 6 lines
Quoted 2 lines
Best regards,
Krzysztof OlędzkiYours sincerely,
Peter
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
Quoted 8 lines
Hello,
My question is if I use REDIRECT action in NAT PREROUTING table is it going to change the tcp packet DST address.
If I lose original DST address, how can I persist
that value in that packet.
You can't really with PREROUTING (except of course, said getsockopt() call) If you want to transparently redirect packets, you might want to use ROUTE or TPROXY, depending on what you really want.
Jan Engelhardt
Signature · 2 lines
| Gesellschaft fuer Wissenschaftliche Datenverarbeitung Goettingen, | Am Fassberg, 37077 Goettingen, www.gwdg.de
Hi,
Thanks,
I am able to get the original dst address when I am using tcp connection.
How can I get with UDP???
I my case of UDP we bind to single
fd and all packets irrespective of original destination get delivered to same fd.
Thanks,
Venkat.
Quoted 17 lines · --- Jan Engelhardt
Quoted 8 lines
Hello,
My question is if I use REDIRECT action in NAT PREROUTING table is it going to change the tcp packet DST address.
If I lose original DST address, how can I persist
that value in that packet.You can't really with PREROUTING (except of course, said
getsockopt()call)
If you want to transparently redirect packets, you might want to use ROUTE or
TPROXY, depending on what you really want.
Quoted 8 lines
Jan Engelhardt
Signature · 3 lines
| Gesellschaft fuer Wissenschaftliche Datenverarbeitung Goettingen, | Am Fassberg, 37077 Goettingen, www.gwdg.de
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Quoted 6 lines · Venkata Narayana
Hi,
Thanks,
I am able to get the original dst address when I am using tcp connection.
How can I get with UDP???
Does this patch help? It should make SO_ORIGINAL_DST usable with UDP as well.
[NETFILTER]: Make SO_ORIGINAL_DST usable for UDP
---
commit f65e246c7c05b208494de20f38973393d6b30155
tree 6437e0491ba99ec326c59ca0ac65300c2f01a804
parent eb82d02518ac3a400663163995097749d91c7c4c
author Patrick McHardy <[email protected]> Tue, 26 Jul 2005 01:58:27 +0200 committer Patrick McHardy <[email protected]> Tue, 26 Jul 2005 01:58:27 +0200
net/ipv4/netfilter/ip_conntrack_core.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
net/ipv4/netfilter/ip_conntrack_core.c +2 -3
@@ -1310,9 +1310,8 @@ getorigdst(struct sock *sk, int optval, tuple.dst.u.tcp.port = inet->dport; tuple.dst.protonum =IPPROTO_TCP ; -/* We only do TCP at the moment: is there a better way? */ -if (strcmp (sk->sk_prot->name,"TCP" )) { -DEBUGP ("SO_ORIGINAL_DST: Not a TCP socket\n" ); +if (sk->sk_protocol !=IPPROTO_TCP && sk->sk_protocol !=IPPROTO_UDP ) { +DEBUGP ("SO_ORIGINAL_DST: Not a TCP/UDP socket\n" );return -ENOPROTOOPT ; }
Quoted 13 lines · Patrick McHardy
Quoted 3 lines · Venkata Narayana
I am able to get the original dst address when I am using tcp connection.
How can I get with UDP???Does this patch help? It should make
SO_ORIGINAL_DSTusable with UDP as well.
net/ipv4/netfilter/ip_conntrack_core.c getorigdst(struct sock *sk, int optval, · line 1311
Quoted 2 lines
net/ipv4/netfilter/ip_conntrack_core.c +0
-0@@ -1310,9 +1310,8 @@ getorigdst(struct sock *sk, int optval, tuple.dst.u.tcp.port = inet->dport; tuple.dst.protonum =IPPROTO_TCP ;
Please try this patch instead, I missed the above line.
[NETFILTER]: Make SO_ORIGINAL_DST usable for UDP
---
commit 59740eead041f1e9c22555a5107bf9ca98a780da
tree a4d80f970e9fa526bff6c173cfe6d5a0610279a4
parent eb82d02518ac3a400663163995097749d91c7c4c
author Patrick McHardy <[email protected]> Tue, 26 Jul 2005 02:19:09 +0200 committer Patrick McHardy <[email protected]> Tue, 26 Jul 2005 02:19:09 +0200
net/ipv4/netfilter/ip_conntrack_core.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
net/ipv4/netfilter/ip_conntrack_core.c +3 -4
@@ -1308,11 +1308,10 @@ getorigdst(struct sock *sk, int optval, tuple.src.u.tcp.port = inet->sport; tuple.dst.ip = inet->daddr; tuple.dst.u.tcp.port = inet->dport; - tuple.dst.protonum =IPPROTO_TCP ; + tuple.dst.protonum = sk->sk_protocol; -/* We only do TCP at the moment: is there a better way? */ -if (strcmp (sk->sk_prot->name,"TCP" )) { -DEBUGP ("SO_ORIGINAL_DST: Not a TCP socket\n" ); +if (sk->sk_protocol !=IPPROTO_TCP && sk->sk_protocol !=IPPROTO_UDP ) { +DEBUGP ("SO_ORIGINAL_DST: Not a TCP/UDP socket\n" );return -ENOPROTOOPT ; }
Thank you Patrick.
Here I'm using single fd wor multiple addresses. so theoritically speaking it won't work with this... In udp recvmsg function if we can get the address then it sounds good.
If I am wrong sorry for that.
Thanks,
Venkat
Quoted 63 lines · --- Patrick McHardy
Quoted 3 lines · Patrick McHardy
Quoted 1 line · Venkata Narayana
I am able to get the original dst address when I
am
Quoted 4 lines
Quoted 2 lines
using tcp connection.
How can I get with UDP???Does this patch help? It should make
SO_ORIGINAL_DSTusableQuoted 3 lines
with UDP as well.
diff --git
a/net/ipv4/netfilter/ip_conntrack_core.cb/net/ipv4/netfilter/ip_conntrack_core.cnet/ipv4/netfilter/ip_conntrack_core.c getorigdst(struct sock *sk,
Quoted 3 lines
net/ipv4/netfilter/ip_conntrack_core.c +0
-0@@ -1310,9 +1310,8 @@ getorigdst(struct sock *sk,int optval,
net/ipv4/netfilter/ip_conntrack_core.c getorigdst(struct sock *sk, · line 1311
Quoted 2 lines
net/ipv4/netfilter/ip_conntrack_core.c +0
-0tuple.dst.u.tcp.port = inet->dport; tuple.dst.protonum =IPPROTO_TCP ;Please try this patch instead, I missed the above
line.Quoted 1 line
[NETFILTER]: Make
SO_ORIGINAL_DSTusable for UDPSigned-off-by Patrick McHardy <[email protected]>---
commit59740eead041f1e9c22555a5107bf9ca98a780datreea4d80f970e9fa526bff6c173cfe6d5a0610279a4parenteb82d02518ac3a400663163995097749d91c7c4cauthor Patrick McHardy <[email protected]> Tue, 26 Jul 2005 02:19:09 +0200
committer Patrick McHardy <[email protected]> Tue, 26 Jul 2005 02:19:09 +0200net/ipv4/netfilter/ip_conntrack_core.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)net/ipv4/netfilter/ip_conntrack_core.c +1
-2@@ -1308,11 +1308,10 @@ getorigdst(struct sock *sk,int optval, tuple.src.u.tcp.port = inet->sport; tuple.dst.ip = inet->daddr; tuple.dst.u.tcp.port = inet->dport; - tuple.dst.protonum =IPPROTO_TCP ; + tuple.dst.protonum = sk->sk_protocol; -/* We only do TCP at the moment: is there a better way? */
net/ipv4/netfilter/ip_conntrack_core.c +1
-2-if (strcmp (sk->sk_prot->name,"TCP" )) { -DEBUGP ("SO_ORIGINAL_DST: Not a TCP socket\n" ); + if (sk->sk_protocol != IPPROTO_TCP &&
sk->sk_protocol!=IPPROTO_UDP) {net/ipv4/netfilter/ip_conntrack_core.c +1
-0+ DEBUGP("SO_ORIGINAL_DST: Not a TCP/UDPsocket\n");
net/ipv4/netfilter/ip_conntrack_core.c getorigdst(struct sock *sk, int optval, · line 1316
Quoted 2 lines
net/ipv4/netfilter/ip_conntrack_core.c +0
-0return -ENOPROTOOPT ; }
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Hi,
2005-07-26, k keltezéssel 02.20-kor Patrick McHardy ezt írta:
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I am able to get the original dst address when I am using tcp connection.
How can I get with UDP???Does this patch help? It should make
SO_ORIGINAL_DSTusable with UDP as well.
Quoted 6 lines
net/ipv4/netfilter/ip_conntrack_core.c getorigdst(struct sock *sk, int optval, · line 1311
Quoted 6 lines
net/ipv4/netfilter/ip_conntrack_core.c +0
-0@@ -1310,9 +1310,8 @@ getorigdst(struct sock *sk, int optval, tuple.dst.u.tcp.port = inet->dport; tuple.dst.protonum =IPPROTO_TCP ;
Patrick, I'm afraid this is not enough for a full-featured UDP
solution. If you're using a single socket to receive UDP packets sent to multiple original addresses this approach simply fails. A better solution would require receiving the original destination address in a per-packet manner.
We're using something similar as part of the transparent proxying
patchset, but unfortunately this requires enlarging the skb and is a little hackish. The patch introduces an IP_RECVORIGADDRS socket option. If you enable this sockopt on a UDP socket, then recvmsg() will return the original addresses as a control message.
Signature · 2 lines
Regards, Krisztian Kovacs
Quoted 5 lines · KOVACS Krisztian
Patrick, I'm afraid this is not enough for a full-featured UDP
solution. If you're using a single socket to receive UDP packets sent to multiple original addresses this approach simply fails. A better solution would require receiving the original destination address in a per-packet manner.
You're right, it doesn't work for unconnected sockets. I'm looking into other possibilities now. I'm thinking of something similar to SIOCGSTAMP - altough this would require increasing the size of struct sock.
Quoted 5 lines
We're using something similar as part of the transparent proxying
patchset, but unfortunately this requires enlarging the skb and is a little hackish. The patch introduces anIP_RECVORIGADDRSsocket option. If you enable this sockopt on a UDP socket, thenrecvmsg()will return the original addresses as a control message.
Why does the skb need to be enlarged?
Regards
Patrick
Hi,
2005-07-26, k keltezéssel 11.51-kor Patrick McHardy ezt írta:
Quoted 7 lines
Quoted 5 lines
We're using something similar as part of the transparent proxying
patchset, but unfortunately this requires enlarging the skb and is a little hackish. The patch introduces anIP_RECVORIGADDRSsocket option. If you enable this sockopt on a UDP socket, thenrecvmsg()will return the original addresses as a control message.Why does the skb need to be enlarged?
To store the original address (it's stored in IPCB(skb)). Hmm, now
that you say, actually I'm not sure you have to enlarge it. At the moment struct inet_skb_parm is small enough, so we might be able to put the original address information into skb->cb. I'm not sure what would be the right location for such information, however.
Signature · 2 lines
Regards, Krisztian Kovacs
Hello Patric/Krisztian,
As Mr Krisztian suggested I was able to patch the 2.6.11 kernel with tproxy but trying to use IP_RECVORIGADDRS socket option on udp socket. If it is natted traffic I am unable to receive the message. Can you suggest the alternative mechanism to get the original DSt address in UDP transaction.
Thanks,
Venkat.
Quoted 26 lines · --- Patrick McHardy
Quoted 1 line · KOVACS Krisztian
Patrick, I'm afraid this is not enough for a
full-featured UDP
Quoted 1 line
solution. If you're using a single socket to
receive UDP packets sent to
Quoted 1 line
multiple original addresses this approach simply
fails. A better
Quoted 1 line
solution would require receiving the original
destination address in a
Quoted 1 line
per-packet manner.
You're right, it doesn't work for unconnected sockets. I'm looking into
other possibilities now. I'm thinking of something similar to
SIOCGSTAMP - altough this would require increasing the size of struct
sock.Quoted 1 line
We're using something similar as part of the
transparent proxying
Quoted 1 line
patchset, but unfortunately this requires
enlarging the skb and is a
Quoted 1 line
little hackish. The patch introduces an
IP_RECVORIGADDRSsocket option.
Quoted 9 lines
Quoted 1 line
If you enable this sockopt on a UDP socket, then
recvmsg()will returnQuoted 1 line
the original addresses as a control message.
Why does the skb need to be enlarged?
Regards
Patrick
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
Rate limit
In reply to Venkata NarayanaHi All,
Can i get any developer documentation on rate limit module.
I would like to work on rate limit stuff.
Please provide me the details releated to that.
Thanks,
Venkat.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Netfilter Hook
Hi All,
Can you please guide me to write a hook for netfilter...
How we can write like NF_ACCEPT/NF_DROP/NF_STOLEN/ ...
Thanks,
Venkat.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: Rate limit
In reply to Venkata NarayanaQuoted 4 lines
Hi All,
Can i get any developer documentation on rate limit module.
It is documented. See man iptables. If it does not show up there under the section "limit", "dstlimit" or "hashlimit", check the POM-ng tree which definitely does have the help texts.
Jan Engelhardt
UDP Transparent Proxy
In reply to Venkata NarayanaHi,
I am developing a transparent proxy feature for my UDP based server. I am using iptables to redirect message to my server but I am not able to persist the original dst address.
I am able implement similar feature for TCP server using getoption.
Can you plese guide me in this.
Thanks,
Venkat.
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs