diff --git a/alpine/packages/proxy/one.go b/alpine/packages/proxy/one.go index b8f4e1730..e91aa30af 100644 --- a/alpine/packages/proxy/one.go +++ b/alpine/packages/proxy/one.go @@ -11,11 +11,16 @@ import ( ) func onePort() { - host, _, container := parseHostContainerAddrs() + host, _, container, localIP := parseHostContainerAddrs() - ipP, err := libproxy.NewIPProxy(host, container) - if err != nil { - sendError(err) + var ipP libproxy.Proxy + var err error + + if localIP { + ipP, err = libproxy.NewIPProxy(host, container) + if err != nil { + sendError(err) + } } ctl, err := exposePort(host, container) @@ -23,10 +28,14 @@ func onePort() { sendError(err) } - go handleStopSignals(ipP) + go handleStopSignals() // TODO: avoid this line if we are running in a TTY sendOK() - ipP.Run() + if ipP != nil { + ipP.Run() + } else { + select{} // sleep forever + } ctl.Close() // ensure ctl remains alive and un-GCed until here os.Exit(0) } diff --git a/alpine/packages/proxy/proxy.go b/alpine/packages/proxy/proxy.go index c89ff8db2..adc3b8191 100644 --- a/alpine/packages/proxy/proxy.go +++ b/alpine/packages/proxy/proxy.go @@ -8,8 +8,6 @@ import ( "os" "os/signal" "syscall" - - "proxy/libproxy" ) var interactiveMode bool @@ -48,7 +46,7 @@ var vSockUDPPortOffset = 0x20000 // parseHostContainerAddrs parses the flags passed on reexec to create the TCP or UDP // net.Addrs to map the host and container ports -func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr) { +func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr, localIP bool) { var ( proto = flag.String("proto", "tcp", "proxy protocol") hostIP = flag.String("host-ip", "", "host ip") @@ -56,6 +54,7 @@ func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr) { containerIP = flag.String("container-ip", "", "container ip") containerPort = flag.Int("container-port", -1, "container port") interactive = flag.Bool("i", false, "print success/failure to stdout/stderr") + noLocalIP = flag.Bool("no-local-ip", false, "bind only on the Host, not in the VM") ) flag.Parse() @@ -73,17 +72,15 @@ func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr) { default: log.Fatalf("unsupported protocol %s", *proto) } - - return host, port, container + localIP = ! *noLocalIP + return host, port, container, localIP } -func handleStopSignals(p libproxy.Proxy) { +func handleStopSignals() { s := make(chan os.Signal, 10) signal.Notify(s, os.Interrupt, syscall.SIGTERM, syscall.SIGSTOP) for range s { os.Exit(0) - // The vsock proxy cannot be shutdown the same way as the TCP one: - //p.Close() } }