#747
virtualnetwork: add DialContextTCPFrom to propagate source IP
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
}
[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.
Approvers can indicate their approval by writing
/approvein a comment Approvers can cancel approval by writing/approve cancelin a comment