mirror of
https://github.com/containers/podman.git
synced 2025-08-03 01:37:51 +08:00
Implement automatic port reassignment on Windows
While only leveraged by the WSL backend, this commit also adds core infrastructure for all other backends for future enhancement. - Adds a common port cross backend allocation registry to prevent duplicate assignment across multiple machine instances - Introduces logic in Start() that detects OS port conflicts and scans for a viable replacement port - Updates connection definitions and server configuration accordingly - Utilizes a coordinated file lock strategy to prevent racing overwrites of port and connection registries - WSL backend coordinates locking for containers.conf until a future common enhancement exists to replace it [NO NEW TESTS NEEDED] Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
29
pkg/machine/ports_unix.go
Normal file
29
pkg/machine/ports_unix.go
Normal file
@ -0,0 +1,29 @@
|
||||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getPortCheckListenConfig() *net.ListenConfig {
|
||||
return &net.ListenConfig{
|
||||
Control: func(network, address string, c syscall.RawConn) (cerr error) {
|
||||
if err := c.Control(func(fd uintptr) {
|
||||
// Prevent listening socket from holding over in TIME_WAIT in the rare case a connection
|
||||
// attempt occurs in the short window the socket is listening. This ensures the registration
|
||||
// will be gone when close() completes, freeing it up for the real subsequent listen by another
|
||||
// process
|
||||
cerr = syscall.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{
|
||||
Onoff: 1,
|
||||
Linger: 0,
|
||||
})
|
||||
}); err != nil {
|
||||
cerr = err
|
||||
}
|
||||
return
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user