Skip to content

Commit

Permalink
Only check or del 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 27, 2023
1 parent c4d24e8 commit 6bb1fa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/meta/portmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ func cmdDel(args *skel.CmdArgs) error {
}

netConf.ContainerID = args.ContainerID

// We don't need to parse out whether or not we're using v6 or snat,
// deletion is idempotent
if err := unforwardPorts(netConf); err != nil {
return err
}

return nil
}

Expand Down
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 6bb1fa2

Please sign in to comment.