Re: SO_BINDTODEVICE and IP_TRANSPARENT (TPROXY)
From: Eric Dumazet <hidden>
Date: 2009-12-02 04:56:47
Ashwani Wason a écrit :
After debugging a bit into how nf_tproxy_get_sock_v4() looks up a listener for foreign connections using __inet_lookup_listener() and compute_score() I found that the problem was happening because of the way I had the TPROXY rules setup. Those rules work if the proxy has a single listening socket for INADDR_ANY. If multiple listening sockets must be used, one for each local address, which is the case for using SO_BINDTODEVICE then the TPROXY rules must also be "fully qualified" (with interface name [-i] and IP address thereof [--on-ip]). So the rules in my example change as follows... Instead of using:quoted
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 4002Use: iptables -t mangle -A PREROUTING *-i eth0* -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 *--on-ip 192.168.0.65* --on-port 4002 iptables -t mangle -A PREROUTING *-i eth1* -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 *--on-ip 192.168.1.65* --on-port 4002 With these rules the listening socket was looked up correctly and the sk_bound_dev_if of the socket was honored. - Ashwani PS: Sorry to anyone (Jamal) who already spent any time on this. PPS: Copying the tproxy list in case someone else is looking for this stuff in the future.
Thanks a lot for sharing your discoveries :)