Skip to content

Commit

Permalink
Merge pull request #821 from mccv1r0/portmapCheck
Browse files Browse the repository at this point in the history
Only check or del ipv6 when an IPv6 is configured
  • Loading branch information
dcbw authored Feb 1, 2023
2 parents c4d24e8 + fb5d195 commit e2e14ee
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugins/meta/portmap/portmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,22 @@ func forwardPorts(config *PortMapConf, containerNet net.IPNet) error {
}

func checkPorts(config *PortMapConf, containerNet net.IPNet) error {
isV6 := (containerNet.IP.To4() == nil)
dnatChain := genDnatChain(config.Name, config.ContainerID)
fillDnatRules(&dnatChain, config, containerNet)

ip4t, err4 := maybeGetIptables(false)
ip6t, err6 := maybeGetIptables(true)
// check is called for each address, not once for all addresses
var ip4t *iptables.IPTables
var err4 error
var ip6t *iptables.IPTables
var err6 error

if isV6 {
ip6t, err6 = maybeGetIptables(true)
} else {
ip4t, err4 = maybeGetIptables(false)
}

if ip4t == nil && ip6t == nil {
err := fmt.Errorf("neither iptables nor ip6tables is usable")
err = fmt.Errorf("%v, (iptables) %v", err, err4)
Expand Down

0 comments on commit e2e14ee

Please sign in to comment.