mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 02:51:55 +00:00
proxy: add a -no-local-ip option
docker itself seems to bind to the port globally inside Moby, so we get an EADDRINUSE if we try to do it too. Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
parent
3183d9c72a
commit
3c6ad76461
@ -11,11 +11,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func onePort() {
|
func onePort() {
|
||||||
host, _, container := parseHostContainerAddrs()
|
host, _, container, localIP := parseHostContainerAddrs()
|
||||||
|
|
||||||
ipP, err := libproxy.NewIPProxy(host, container)
|
var ipP libproxy.Proxy
|
||||||
if err != nil {
|
var err error
|
||||||
sendError(err)
|
|
||||||
|
if localIP {
|
||||||
|
ipP, err = libproxy.NewIPProxy(host, container)
|
||||||
|
if err != nil {
|
||||||
|
sendError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctl, err := exposePort(host, container)
|
ctl, err := exposePort(host, container)
|
||||||
@ -23,10 +28,14 @@ func onePort() {
|
|||||||
sendError(err)
|
sendError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go handleStopSignals(ipP)
|
go handleStopSignals()
|
||||||
// TODO: avoid this line if we are running in a TTY
|
// TODO: avoid this line if we are running in a TTY
|
||||||
sendOK()
|
sendOK()
|
||||||
ipP.Run()
|
if ipP != nil {
|
||||||
|
ipP.Run()
|
||||||
|
} else {
|
||||||
|
select{} // sleep forever
|
||||||
|
}
|
||||||
ctl.Close() // ensure ctl remains alive and un-GCed until here
|
ctl.Close() // ensure ctl remains alive and un-GCed until here
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"proxy/libproxy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var interactiveMode bool
|
var interactiveMode bool
|
||||||
@ -48,7 +46,7 @@ var vSockUDPPortOffset = 0x20000
|
|||||||
|
|
||||||
// parseHostContainerAddrs parses the flags passed on reexec to create the TCP or UDP
|
// parseHostContainerAddrs parses the flags passed on reexec to create the TCP or UDP
|
||||||
// net.Addrs to map the host and container ports
|
// 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 (
|
var (
|
||||||
proto = flag.String("proto", "tcp", "proxy protocol")
|
proto = flag.String("proto", "tcp", "proxy protocol")
|
||||||
hostIP = flag.String("host-ip", "", "host ip")
|
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")
|
containerIP = flag.String("container-ip", "", "container ip")
|
||||||
containerPort = flag.Int("container-port", -1, "container port")
|
containerPort = flag.Int("container-port", -1, "container port")
|
||||||
interactive = flag.Bool("i", false, "print success/failure to stdout/stderr")
|
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()
|
flag.Parse()
|
||||||
@ -73,17 +72,15 @@ func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr) {
|
|||||||
default:
|
default:
|
||||||
log.Fatalf("unsupported protocol %s", *proto)
|
log.Fatalf("unsupported protocol %s", *proto)
|
||||||
}
|
}
|
||||||
|
localIP = ! *noLocalIP
|
||||||
return host, port, container
|
return host, port, container, localIP
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleStopSignals(p libproxy.Proxy) {
|
func handleStopSignals() {
|
||||||
s := make(chan os.Signal, 10)
|
s := make(chan os.Signal, 10)
|
||||||
signal.Notify(s, os.Interrupt, syscall.SIGTERM, syscall.SIGSTOP)
|
signal.Notify(s, os.Interrupt, syscall.SIGTERM, syscall.SIGSTOP)
|
||||||
|
|
||||||
for range s {
|
for range s {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
// The vsock proxy cannot be shutdown the same way as the TCP one:
|
|
||||||
//p.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user