#747

virtualnetwork: add DialContextTCPFrom to propagate source IP

OpenAkihiroSudawants to merge intofrom

The source IP propagation implemented in #634 was originally intended to be used by RootlessKit's gvisor-tap-vsock port 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 https://github.com/rootless-containers/rootlesskit/pull/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:

diff --git a/pkg/port/gvisortapvsock/tcp.go b/pkg/port/gvisortapvsock/tcp.go
index 7171e3e..2401525 100644
--- a/pkg/port/gvisortapvsock/tcp.go
+++ b/pkg/port/gvisortapvsock/tcp.go
@@ -17,7 +17,7 @@ import (
 const tcpCopyBufferSize = 256 * 1024
 
 type tcpDialer interface {
-       DialContextTCP(context.Context, string) (net.Conn, error)
+       DialContextTCPFrom(context.Context, net.Addr, string) (net.Conn, error)
 }
 
 // exposeTCP is called with d.mu held, like the upstream expose API.
@@ -33,7 +33,8 @@ func (d *driver) exposeTCP(local, remote string) error {
        proxy.AddRoute(local, &tcpproxy.DialProxy{
                Addr: remote,
                DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
-                       conn, err := dialer.DialContextTCP(ctx, addr)
+                       src, _ := ctx.Value(tcpproxy.SourceAddrContextKey).(net.Addr)
+                       conn, err := dialer.DialContextTCPFrom(ctx, src, addr)
                        if err != nil {
                                return nil, err
                        }

Activity

3
openshift-ci[bot]17d ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AkihiroSuda Once this PR has been reviewed and has the lgtm label, please assign evidolob for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

AkihiroSuda7d ago

@evidolob @cfergeau Could you take a look? Thanks