Add TPROXY inbound (TCP and UDP) - #493
Open
SafaSafari wants to merge 1 commit into
Open
Conversation
Add a Linux TPROXY inbound listener for transparent proxying, enabled by the `inbound-tproxy` feature and configured as an inbound with protocol "tproxy". TCP: a listening socket with IP_TRANSPARENT accepts connections redirected by the iptables TPROXY target; the original destination is the accepted socket's local address. UDP: a socket with IP_TRANSPARENT and IP_RECVORIGDSTADDR receives redirected datagrams; the original destination is read from the IP_ORIGDSTADDR control message via recvmsg(2). Replies are sent from a transparent socket bound to the original destination, so the client sees the reply coming from the address it originally talked to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Linux TPROXY inbound listener so leaf can be used as a transparent proxy via the iptables
TPROXYtarget. The README lists TPROXY as "Coming soon"; this implements it for both TCP and UDP.How it works
TCP — a listening socket with
IP_TRANSPARENTaccepts connections redirected by theTPROXYtarget. The original destination is simply the accepted socket's local address.UDP — a socket with
IP_TRANSPARENT+IP_RECVORIGDSTADDRreceives redirected datagrams. The original destination is read from theIP_ORIGDSTADDRcontrol message viarecvmsg(2). Replies are sent from a transparent socket bound to the original destination, so the client sees the reply coming from the address it originally talked to.Usage
Enabled by the
inbound-tproxyfeature (Linux only; added toall-endpoints). Configured as a JSON inbound:{ "tag": "tproxy-in", "protocol": "tproxy", "address": "0.0.0.0", "port": 12345 }leaf needs
CAP_NET_ADMINto open transparent sockets. The usualip rule/ip route local/ iptablesTPROXYsetup is required.Testing
Verified in an isolated network-namespace setup (client ns → router ns running leaf+TPROXY → upstream): TCP transfers (256 KiB, md5-verified) and UDP datagrams were both proxied correctly, with the UDP reply source matching the original destination.
Notes
cfg-gated ontarget_os = "linux".confformat is not covered.