Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions libpod/oci_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,39 @@ func bindPorts(ports []types.PortMapping) ([]*os.File, error) {
var files []*os.File
sctpWarning := true
for _, port := range ports {
isV6 := net.ParseIP(port.HostIP).To4() == nil
if port.HostIP == "" {
isV6 = false
}
protocols := strings.SplitSeq(port.Protocol, ",")
for protocol := range protocols {
for i := uint16(0); i < port.Range; i++ {
f, err := bindPort(protocol, port.HostIP, port.HostPort+i, isV6, &sctpWarning)
if err != nil {
// close all open ports in case of early error so we do not
// rely garbage collector to close them
for _, f := range files {
f.Close()
if port.HostIP == "" {
f4, err := bindPort(protocol, "", port.HostPort+i, false, &sctpWarning)
if err != nil {
for _, f := range files {
f.Close()
}
return nil, fmt.Errorf("failed to bind IPv4 port: %w", err)
}
if f4 != nil {
files = append(files, f4)
}

f6, err := bindPort(protocol, "", port.HostPort+i, true, &sctpWarning)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be erred and not warn ? Some users might be expecting bind on v6 explicitly ?

logrus.Warnf("Failed to bind IPv6 for port %d, continuing with IPv4 only: %v", port.HostPort+i, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logrus.Warnf("Failed to bind IPv6 for port %d, continuing with IPv4 only: %v", port.HostPort+i, err)
logrus.Warnf("failed to bind IPv6 for port %d, continuing with IPv4 only: %v", port.HostPort+i, err)

} else if f6 != nil {
files = append(files, f6)
}
} else {
isV6 := net.ParseIP(port.HostIP).To4() == nil
f, err := bindPort(protocol, port.HostIP, port.HostPort+i, isV6, &sctpWarning)
if err != nil {
for _, f := range files {
f.Close()
}
return nil, err
}
if f != nil {
files = append(files, f)
}
return nil, err
}
if f != nil {
files = append(files, f)
}
}
}
Expand Down