mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Shutdown loopback-to-loopback proxy when unmapping a port
This commit is contained in:
parent
930e9a7e43
commit
7f1a32b9ff
1 changed files with 7 additions and 1 deletions
|
@ -184,6 +184,7 @@ func getIfaceAddr(name string) (net.Addr, error) {
|
|||
// It keeps track of all mappings and is able to unmap at will
|
||||
type PortMapper struct {
|
||||
mapping map[int]net.TCPAddr
|
||||
proxies map[int]net.Listener
|
||||
}
|
||||
|
||||
func (mapper *PortMapper) cleanup() error {
|
||||
|
@ -197,6 +198,7 @@ func (mapper *PortMapper) cleanup() error {
|
|||
iptables("-t", "nat", "-F", "DOCKER")
|
||||
iptables("-t", "nat", "-X", "DOCKER")
|
||||
mapper.mapping = make(map[int]net.TCPAddr)
|
||||
mapper.proxies = make(map[int]net.Listener)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -229,7 +231,7 @@ func (mapper *PortMapper) Map(port int, dest net.TCPAddr) error {
|
|||
mapper.Unmap(port)
|
||||
return err
|
||||
}
|
||||
// FIXME: store the listener so we can close it at Unmap
|
||||
mapper.proxies[port] = listener
|
||||
go proxy(listener, "tcp", dest.String())
|
||||
return nil
|
||||
}
|
||||
|
@ -276,6 +278,10 @@ func (mapper *PortMapper) Unmap(port int) error {
|
|||
if !ok {
|
||||
return errors.New("Port is not mapped")
|
||||
}
|
||||
if proxy, exists := mapper.proxies[port]; exists {
|
||||
proxy.Close()
|
||||
delete(mapper.proxies, port)
|
||||
}
|
||||
if err := mapper.iptablesForward("-D", port, dest); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue