Skip to content

Commit

Permalink
Only check ipv6 when an IPv6 is configured
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Cambria <mccv1r0@gmail.com>
  • Loading branch information
mccv1r0 committed Jan 28, 2023
1 parent c4d24e8 commit fb5d195
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 fb5d195

Please sign in to comment.