Skip to contentSkip to conversation

Should "Transparent web-caching" work with ppp0/pptp? (It doesn't...)

DISCUSSION Aleksey Tsalolikhin 2 participants 8 messages Apr 25, 2009

lore
Share & tools
lore
#0 lore raw

Hi. I am trying to get outbounds packets destined for TCP port 80 tunneled through a pptp VPN (out the ppp0 interface).

I've tried following the example at
http://lartc.org/howto/lartc.cookbook.squid.html
but from the remote web site's viewpoint, the request comes from the eth0 address
of my server, instead of through the VPN.

Diagram of what I am trying to accomplish:

[my server] ---pptp--> [VPN server] --> website

Should this work with an ppp0 interface?

How do I get help debugging this, please?

My server: 38.98.245.202

pppd: local IP address 192.168.2.131
pppd: remote IP address 192.168.2.125

[root@vulture ~]# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination
MARK       tcp  --  anywhere             anywhere            tcp

dpt:http MARK set 0x2

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
[root@vulture ~]#

[root@vulture ~]# ip rule ls

0:      from all lookup 255
32765:  from all fwmark 0x2 lookup www.out
32766:  from all lookup main
32767:  from all lookup default

[root@vulture ~]# ip route list table www.out
default via 192.168.2.125 dev ppp0
[root@vulture ~]# ip route
192.168.2.125 dev ppp0 proto kernel scope link src 192.168.2.133 69.15.192.18 via 38.98.245.201 dev eth0 src 38.98.245.202 38.98.245.200/29 dev eth0 proto kernel scope link src 38.98.245.202 169.254.0.0/16 dev eth0 scope link
default via 38.98.245.201 dev eth0
[root@vulture ~]#

I am on CentOS release 5.3 (Final)
Linux 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686 i686 i386 GNU/Linux

I've tried using PREROUTING instead of OUTPUT, for the mark rule, and then if I try to connect to port 80 (telnet www.google.com 80), it just hangs...

If I don't use iptables and instead set a static route for www.google.com via the VPN server, it works, I can connect and do an HTTP session (via the VPN).

So is it possible to do route outgoing packets with destination port 80 out a ppp0 interface?

Would appreciate any help in debugging this.

Best,
-at

Signature · 5 lines
Aleksey Tsalolikhin
UNIX System Administrator
"I get stuff done!"
http://www.verticalsysadmin.com/
LinkedIn - http://www.linkedin.com/in/atsaloli
#1 lore raw

Hello,

Quoted 9 lines · Aleksey Tsalolikhin

Hi. I am trying to get outbounds packets destined for TCP port 80 tunneled through a pptp VPN (out the ppp0 interface).

I've tried following the example at
http://lartc.org/howto/lartc.cookbook.squid.html
but from the remote web site's viewpoint, the request comes from the eth0 address
of my server, instead of through the VPN.

Quoted 3 lines

Diagram of what I am trying to accomplish:

[my server] ---pptp--> [VPN server] --> website

Where is the squid proxy ?

Quoted 1 line

Should this work with an ppp0 interface?

Sure. The interface type makes no difference.

Quoted 5 lines

[root@vulture ~]# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination
MARK       tcp  --  anywhere             anywhere            tcp

dpt:http MARK set 0x2

If your server does not act as a router for other hosts, this has no effect. Outgoing packets generated by the local host are handled in the OUTPUT chain.

Quoted 5 lines

[root@vulture ~]# ip rule ls

0:      from all lookup 255
32765:  from all fwmark 0x2 lookup www.out
32766:  from all lookup main
32767:  from all lookup default
Quoted 9 lines

[root@vulture ~]# ip route list table www.out
default via 192.168.2.125 dev ppp0
[root@vulture ~]# ip route
192.168.2.125 dev ppp0 proto kernel scope link src 192.168.2.133 69.15.192.18 via 38.98.245.201 dev eth0 src 38.98.245.202 38.98.245.200/29 dev eth0 proto kernel scope link src 38.98.245.202 169.254.0.0/16 dev eth0 scope link
default via 38.98.245.201 dev eth0
[root@vulture ~]#

Looks fine.

Quoted 3 lines

I've tried using PREROUTING instead of OUTPUT, for the mark rule, and then if I try to connect to port 80 (telnet www.google.com 80), it just hangs...

Isn't it the other way around (OUTPUT instead of PREROUTING) ?
Have you checked that source validation aka reverse-path filtering is disabled for ppp0 (/proc/sys/net/ipv4/conf/ppp0/rp_filter=0) or all interfaces (/proc/sys/net/ipv4/conf/all/rp_filter=0) ?

#2 lore raw

Dear Pascal,

Thank you for your reply (Merci).

Just to restate my issue:  I am trying to get outbounds packets
destined for TCP port 80
tunneled through a pptp VPN (out the ppp0 interface).

Diagram of what I am trying to accomplish:

[my server] ---pptp--> [VPN server] --> website

Quoted 1 line

Where is the squid proxy ?

There is none. Instead of going through squid, the packets must go through the VPN. There is some kind of transparent proxy in the VPN, because when I route packets destined to a particular website (by static route using the website's IP address) via the VPN server, the webserver records HTTP access from the VPN server.

But instead of using select static routes, we want to do this for all port 80 packets, route them through the VPN server.

[my server] ---pptp--> [VPN server] --> websites

Quoted 3 lines
Quoted 1 line

Should this work with an ppp0 interface?

Sure. The interface type makes no difference.

Ok. Here is my trouble: Connection times out.

# telnet www.google.com 80
Trying 74.125.93.99...
telnet: connect to address 74.125.93.99: Connection timed out

Thanks for explaining about the OUTPUT and the marking. Here is what I have now:

My server: 38.98.245.202

pppd: local IP address 192.168.2.131
pppd: remote IP address 192.168.2.125

[root@vulture ~]# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination
MARK       tcp  --  anywhere             anywhere            tcp

dpt:http MARK set 0x2

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
[root@vulture ~]#

[root@vulture ~]# ip rule ls

0:      from all lookup 255
32765:  from all fwmark 0x2 lookup www.out
32766:  from all lookup main
32767:  from all lookup default

[root@vulture ~]# ip route list table www.out
default via 192.168.2.125 dev ppp0
[root@vulture ~]# ip route
192.168.2.125 dev ppp0 proto kernel scope link src 192.168.2.133 69.15.192.18 via 38.98.245.201 dev eth0 src 38.98.245.202 38.98.245.200/29 dev eth0 proto kernel scope link src 38.98.245.202 169.254.0.0/16 dev eth0 scope link
default via 38.98.245.201 dev eth0
[root@vulture ~]#

I've checked and disabled source validation aka reverse-path filtering for ppp0, thanks for that tip!

echo 0 > /proc/sys/net/ipv4/conf/ppp0/rp_filter

I've confirmed source validation is disabled on all interfaces.

(/proc/sys/net/ipv4/conf/all/rp_filter=0)

Now my outgoing port 80 connections are hanging... What can I do next, please?

Best,
Aleksey

#3 lore raw
Quoted 7 lines · Aleksey Tsalolikhin

[my server] ---pptp--> [VPN server] --> website

Quoted 1 line

Where is the squid proxy ?

There is none. Instead of going through squid, the packets must go through the VPN.

IIUC, the PPTP server acts as a router and forwards the packets to their destination.

Quoted 4 lines

There is some kind of transparent proxy in the VPN, because when I route packets destined to a particular website (by static route using the website's IP address) via the VPN server, the webserver records HTTP access from the VPN server.

Maybe it's not transparent proxy but plain source NAT/masquerading.
If I traceroute to the IP address that I believe is the PPTP server, I can see the last two hops with that same address :

17 69.15.192.18 176.584 ms 175.154 ms 176.838 ms 18 69.15.192.18 [open] 176.160 ms 2855.959 ms *

This could mean that the address belongs to a NAT device which forwards the PPTP session to the actual PPTP server behind it. So when the PPTP server forwards the packets to the HTTP server through the NAT device, they are masqueraded with the NAT device address.

Quoted 5 lines

Ok. Here is my trouble: Connection times out.

# telnet www.google.com 80
Trying 74.125.93.99...
telnet: connect to address 74.125.93.99: Connection timed out

Can you capture the network traffic on the PPTP interface of your server (ppp0) e.g. using tcpdump or wireshark/tshark ? Then can you check whether outgoing HTTP connection requests and replies go through this interface ? Can you check what is the source address of the requests ?

If you didn't SNAT or MASQUERADE packets going out through the PPTP tunnel, here is a possible scenario :

- telnet asks for a HTTP connection to 74.125.93.99.
- initial routing selects the output interface and default source address according to the default route in the main routing table : eth0 and its address.
- rerouting due to the mark changes the output interface to ppp0 but does not alter the source address.
- the packet travels through the PPTP tunnel to the PPTP server.

Depending on the PPTP server's behaviour, a lot of different scenarios may then happen. Here are some.

1a) the PPTP server sees a source address different from the remote endpoint address and drops the packet because of rp_filter=1 or iptables filtering. So the connection times out. 1b) or the server does not care about the source address and forwards the packet to the HTTP server. So far so good.

2a) The PPTP server is not behind a NAT device and does not do SNAT or masquerading itself, so the packet reaches the HTTP server with its original source address.
3a) The HTTP server sends a reply to this address, so the packet arrives to your box on eth0. You may want to check this with a packet sniffer. If you don't drop the packet because of rp_filter or iptables, the connection should work. This is not what seems to happen however, as you wrote that the server sees the PPTP server's address and the connection times out.

2b) Or the PPTP server is behind a NAT device or does SNAT or masquerading itself, so the packet reaches the HTTP server with the source address of the PPTP server or its NAT device.
3b) The HTTP server sends a reply to this address, so the packet arrives to the PPTP server (or its NAT device). It is un-masqueraded so its destination is now your eth0's address. The PPTP server then forwards the packet back to its destination, i.e. your box.

4a) If the PPTP server is not behind a NAT device and does not do "dumb" SNAT/masquerading itself, the source address of the reply packet is not altered. The packet reaches eth0 on your box and the connection should work unless you filter too hard. Check with a packet sniffer on eth0.

4b) If the PPTP server is behind a NAT device, note that the device did not see the request packet which was encapsuled in the PPTP tunnel, so it considers the reply packet as a "new" connection and masquerades it. The reply arrives at your box with the wrong source address and is discarded.

4c) Alternatively, the NAT device seeing the reply packet without seeing the request packets may consider it invalid and drop it. End of the journey.

The problem in this scenario is that the reply packet does not travel trough the PPTP tunnel because you didn't use ppp0's address as source address.

As a test, you can try to force the source address in the telnet command line :

$ telnet -b 192.168.2.131 www.google.com 80

If it works, you know what to do : SNAT or MASQUERADE on ppp0.

#4 lore raw

Dear Pascal,

Quoted 6 lines

As a test, you can try to force the source address in the telnet command line :

$ telnet -b 192.168.2.131 www.google.com 80

If it works, you know what to do : SNAT or MASQUERADE on ppp0.

[root@vulture ~]# telnet -b 192.168.2.131 www.google.com 80
telnet: invalid option -- b
Usage: telnet [-8] [-E] [-K] [-L] [-X atype] [-a] [-d] [-e char] [-k realm]

        [-l user] [-f/-F] [-n tracefile] [-r] [-x] [host-name [port]]

[root@vulture ~]#

[root@vulture ~]# uname -a
Linux vulture.coreitpro.com 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686 i686 i386 GNU/Linux [root@vulture ~]# cat /etc/redhat-release
CentOS release 5.3 (Final)
[root@vulture ~]#

However, I've run tcpdump as you suggested and the packets are being routed out the ppp0 interface!

[root@vulture ~]# tcpdump -i ppp0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ppp0, link-type LINUX_SLL (Linux cooked), capture size 96 bytes 10:32:21.908975 IP vulture.coreitpro.com.33352 > qw-in-f104.google.com.http: S 1458102499:1458102499(0) win 5840 <mss 1460,sackOK,timestamp 27190999 0,nop,wscale 7>
10:32:24.910107 IP vulture.coreitpro.com.33352 > qw-in-f104.google.com.http: S 1458102499:1458102499(0) win 5840 <mss 1460,sackOK,timestamp 27194000 0,nop,wscale 7>
10:32:30.913391 IP vulture.coreitpro.com.33352 > qw-in-f104.google.com.http: S 1458102499:1458102499(0) win 5840 <mss 1460,sackOK,timestamp 27200000 0,nop,wscale 7>

"tcpdump -i eth0 port 80" shows no return packets. (obviously,
neither does ppp0)

I've tried running tcpdump on the web server as well, and I don't see ANY packets coming in from the VPN server when I run "telnet website 80" on the pptp client... (the CentOS box).

Could I be running into 1a?

1a) the PPTP server sees a source address different from the remote endpoint address and drops the packet because of rp_filter=1 or iptables filtering. So the connection times out.

If I don't use iptables, and just set up a static route for that web site via the PPTP server, and telnet to website 80, it works!! tcpdump shows the packets are addressed to the website and it answers back:

10:58:39.759071 IP 192.168.2.133.60744 > qw-in-f104.google.com.http: S 3121597650:3121597650(0) win 5424 <mss 1356,sackOK,timestamp 28768118 0,nop,wscale 7>
10:58:39.855024 IP qw-in-f104.google.com.http > 192.168.2.133.60744: S 3367683736:3367683736(0) ack 3121597651 win 5672 <mss 1430,sackOK,timestamp 1670282111 28768118,nop,wscale 6> 10:58:39.855055 IP 192.168.2.133.60744 > qw-in-f104.google.com.http: . ack 1 win 43 <nop,nop,timestamp 28768214 1670282111>

So why does it work with static route and doesn't work with the alt routing table trick? The only difference I can see is, in the static route case, the packets are a little bit smaller.

Any ideas?

Thanks,
Aleksey

P.S. I am including my previous post below for reference.

I am trying to get outbounds packets
destined for TCP port 80
tunneled through a pptp VPN (out the ppp0 interface).

Diagram of what I am trying to accomplish:

[my server] ---pptp--> [VPN server] --> website

Quoted 1 line

Where is the squid proxy ?

There is none. Instead of going through squid, the packets must go through the VPN. There is some kind of transparent proxy in the VPN, because when I route packets destined to a particular website (by static route using the website's IP address) via the VPN server, the webserver records HTTP access from the VPN server.

But instead of using select static routes, we want to do this for all port 80 packets, route them through the VPN server.

[my server] ---pptp--> [VPN server] --> websites

Quoted 3 lines
Quoted 1 line

Should this work with an ppp0 interface?

Sure. The interface type makes no difference.

Ok. Here is my trouble: Connection times out.

# telnet www.google.com 80
Trying 74.125.93.99...
telnet: connect to address 74.125.93.99: Connection timed out

Thanks for explaining about the OUTPUT and the marking. Here is what I have now:

My server: 38.98.245.202

pppd: local IP address 192.168.2.131
pppd: remote IP address 192.168.2.125

[root@vulture ~]# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination
MARK       tcp  --  anywhere             anywhere            tcp

dpt:http MARK set 0x2

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
[root@vulture ~]#

[root@vulture ~]# ip rule ls

0:      from all lookup 255
32765:  from all fwmark 0x2 lookup www.out
32766:  from all lookup main
32767:  from all lookup default

[root@vulture ~]# ip route list table www.out
default via 192.168.2.125 dev ppp0
[root@vulture ~]# ip route
192.168.2.125 dev ppp0 proto kernel scope link src 192.168.2.133 69.15.192.18 via 38.98.245.201 dev eth0 src 38.98.245.202 38.98.245.200/29 dev eth0 proto kernel scope link src 38.98.245.202 169.254.0.0/16 dev eth0 scope link
default via 38.98.245.201 dev eth0
[root@vulture ~]#

I've checked and disabled source validation aka reverse-path filtering for ppp0, thanks for that tip!

echo 0 > /proc/sys/net/ipv4/conf/ppp0/rp_filter

I've confirmed source validation is disabled on all interfaces.

(/proc/sys/net/ipv4/conf/all/rp_filter=0)

#5 lore raw
Quoted 3 lines · Aleksey Tsalolikhin

[root@vulture ~]# telnet -b 192.168.2.131 www.google.com 80
telnet: invalid option -- b

Well, the telnet client in RedHat does not seem to support this option while the one in Debian does. You may try nc (netcat) instead.

$ nc -v -s 192.168.2.133 www.google.com 80

Note that from your tcpdump trace ppp0's address seem to be varying. Use the current one.

Quoted 5 lines

I've tried running tcpdump on the web server as well, and I don't see ANY packets coming in from the VPN server when I run "telnet website 80" on the pptp client... (the CentOS box).

Could I be running into 1a?

I'm afraid so.

Quoted 2 lines

If I don't use iptables, and just set up a static route for that web site via the PPTP server, and telnet to website 80, it works!!

[...]

Quoted 3 lines

So why does it work with static route and doesn't work with the alt routing table trick? The only difference I can see is, in the static route case, the packets are a little bit smaller.

The difference is the source address, as explained in my previous posts.

Quoted 1 line

Any ideas?

Yes, one :

iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

#6 lore raw

Dear Pascal, (and rob0),

Quoted 6 lines · Pascal Hambourg
Quoted 2 lines

Any ideas?

Yes, one :

iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

That is a very good idea! Thank you for the tip re netcat as well (nc).

I won't get to try it out - I ran out of time on this one, my client
decided to go with the static routing instead of the alternate routing trick... It'll do the job for him, though it's less elegant and more admin overhead...

I want to say something - this was my first foray into advanced
traffic control, and I found #iptables and this list VERY helpful,
thank you, all, I really appreciate it! Continue! :) What a great
community! You guys are awesome.

Yours very fondly,
Aleksey

#7 lore raw
In reply to Aleksey Tsalolikhin
Quoted 5 lines · Aleksey Tsalolikhin

I've tried following the example at
http://lartc.org/howto/lartc.cookbook.squid.html
but from the remote web site's viewpoint, the request comes from the eth0 address of my server, instead of through the VPN.

Oops, I forgot to comment on this. The default source address of a locally generated datagram or connection is selected before the OUTPUT chain, before the mark was set :

1) initial routing without using the mark selects the output interface and source address
2) iptables changes the mark in the OUTPUT chain
3) rerouting using the mark updates the output interface but not the source address

Rerouting through a different interface does not change the source address accordingly, so it is normal that packets have eth0's address as source even though they are rerouted through ppp0. If you want to change the source address, you may use iptables' SNAT or MASQUERADE. (I fear this will be a problem with IPv6 which has no - and must not have - NAT).