From 969760395d55b675553d19d9f0690e22fa6e69f4 Mon Sep 17 00:00:00 2001 From: David Scott Date: Thu, 21 Apr 2016 14:45:55 +0100 Subject: [PATCH] proxy: map TCP ports at 0x10000-0x20000, and UDP at 0x20000- The proxy process command-line arguments assume we're exposing TCP or UDP ports on Moby's public IPs. Instead we're forwarding over vsock where we must map the Moby ports onto vsock ports. Normally TCP and UDP ports are different, but with vsock there is only one space of port numbers so we have to map them into different ranges. This patch maps Moby ports as follows: - TCP port x onto vsock port 0x10000 + x - UDP port x onto vsock port 0x20000 + x Signed-off-by: David Scott --- alpine/packages/proxy/proxy.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/alpine/packages/proxy/proxy.go b/alpine/packages/proxy/proxy.go index ee52bf6b5..30d7b11be 100644 --- a/alpine/packages/proxy/proxy.go +++ b/alpine/packages/proxy/proxy.go @@ -28,8 +28,11 @@ func sendOK() { f.Close() } -// Map dynamic ports onto vsock ports over this offset -var vSockPortOffset = 0x10000 +// Map dynamic TCP ports onto vsock ports over this offset +var vSockTCPPortOffset = 0x10000 + +// Map dynamic UDP ports onto vsock ports over this offset +var vSockUDPPortOffset = 0x20000 // From docker/libnetwork/portmapper/proxy.go: @@ -49,11 +52,11 @@ func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr) { switch *proto { case "tcp": host = &net.TCPAddr{IP: net.ParseIP(*hostIP), Port: *hostPort} - port = vSockPortOffset + *hostPort + port = vSockTCPPortOffset + *hostPort container = &net.TCPAddr{IP: net.ParseIP(*containerIP), Port: *containerPort} case "udp": host = &net.UDPAddr{IP: net.ParseIP(*hostIP), Port: *hostPort} - port = vSockPortOffset + *hostPort + port = vSockUDPPortOffset + *hostPort container = &net.UDPAddr{IP: net.ParseIP(*containerIP), Port: *containerPort} default: log.Fatalf("unsupported protocol %s", *proto)