Repository navigation
virtualnetwork: add DialContextTCPFrom to propagate source IP - #747
Conversation
PortsForwarder propagates the client source IP to the guest since containers#634, but TCP proxies implemented outside of PortsForwarder cannot do so, as VirtualNetwork.DialContextTCP always connects from the gateway address and the gvisor stack is not accessible from outside the package. RootlessKit implements such a proxy with larger copy buffers for throughput, and thus cannot propagate the TCP source IP: rootless-containers/rootlesskit#573 Add VirtualNetwork.DialContextTCPFrom, which binds the connection to the given source address, following the same rules as PortsForwarder. forwarder.sourceBindAddr is exported as SourceBindAddr for reuse. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
There was a problem hiding this comment.
After this change, DialContextTCP can be simplified:
diff --git a/pkg/virtualnetwork/conn.go b/pkg/virtualnetwork/conn.go
index 6c6dd7dd..df3a8b70 100644
--- a/pkg/virtualnetwork/conn.go
+++ b/pkg/virtualnetwork/conn.go
@@ -25,16 +25,7 @@ func (n *VirtualNetwork) Dial(network, addr string) (net.Conn, error) {
}
func (n *VirtualNetwork) DialContextTCP(ctx context.Context, addr string) (net.Conn, error) {
- ip, port, err := splitIPPort("tcp", addr)
- if err != nil {
- return nil, err
- }
- return gonet.DialContextTCP(ctx, n.stack,
- tcpip.FullAddress{
- NIC: 1,
- Addr: tcpip.AddrFrom4Slice(ip.To4()),
- Port: port,
- }, ipv4.ProtocolNumber)
+ return n.DialContextTCPFrom(ctx, nil, addr)
}
but I can deal with that in a followup PR, this does not have to be added to this one.
This PR looks good to me!
/lgtm
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AkihiroSuda, cfergeau The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm Seems this was not picked up in my earlier comment. |
I did this in #774 |
The source IP propagation implemented in #634 was originally intended to be used by RootlessKit's
gvisor-tap-vsockport forwarder (DOCKER_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=gvisor-tap-vsock), and it worked fine with RootlessKit at the time of the submission of the PR.However, the propagation no longer works with the current RootlessKit as it conflicts with the optimization PR rootless-containers/rootlesskit#630 .
To solve this conflict, this new PR adds
DialContextTCPFrom(ctx context.Context, src net.Addr, addr string)as another way to propagate the source IP.RootlessKit will consume this PR with the following modification: