linux-tproxy
Transparent Proxy
Overview
Transparent proxy allows to bind a non-local address(address belong to none interface), so that packet can be sent out with non-local address, meanwhile, with proper iptables and ip rule, incoming packet for transparent socket(non-local dst) can be received properly.
Implementation
In order to support this, changes needed as below
- Change kernel to allow bind non-local address.
 - Add a netfilter plugin to match transparent socket based on five tuples(src, sport, dst, dport, proto), tag the matched packet to make it go local by ip rule.
 
kernel commit for tproxy
1  | # allow bind non-local address  | 
Example to use
make sure your kernel is built with such config
- CONFIG_NETFILTER_XT_MATCH_SOCKET
 - CONFIG_NF_TPROXY_IPV4
 - CONFIG_NETFILTER_XT_TARGET_TPROXY
 
output, allow bind non-local
1  | fd = socket(AF_INET, SOCK_STREAM, 0);  | 
input packet
1  | # create a new chain  |