Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IPv6 to IPv6 and IPv4 to IPv6 transparent proxying #370

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

synnack
Copy link

@synnack synnack commented Feb 27, 2021

Hi,

Currently, when the client is IPv4 and the destination is IPv4, transparent proxying works.
When the client is IPv6 and the destination is IPv6, it does not, because the wrong type of socket is created.
When the client is IPv4 and the destination is IPv6, no mapping is done and an address family error is thrown.

The address family error is thrown because when using ::ffff:192.0.2.1 as source address, the socket will create an IPv4 packet, not an IPv6 packet.

This patch fixes the socket type for IPv6 to IPv6, and also changes the source address from ::ffff:192.0.2.1 to ::192.0.2.1 for IPv4 to IPv6.

In the server logs on the destinations the IPv4-address is as human readable as possible, and replies go to ::0.0.0.0/96.

These replies can be captured using:
ip6tables -t mangle -A PREROUTING -m socket --transparent -j MARK --set-mark 1
ip -6 rule add fwmark 0x1 lookup 100
ip -6 route add local ::/96 dev lo table 100

With nftables in the table ip6 mangle chain PREROUTING: socket transparent 1 mark set 0x1 accept

@renaudallard
Copy link

Thanks, I fixed it in my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants