pkg/ip: Fix ipmasq teardown on v6-only interfaces

This commit is contained in:
Casey Callendrello
2017-08-25 16:58:19 +02:00
parent 556e509097
commit 7a62515407
8 changed files with 47 additions and 27 deletions

View File

@ -474,10 +474,10 @@ func cmdDel(args *skel.CmdArgs) error {
// There is a netns so try to clean up. Delete can be called multiple times
// so don't return an error if the device is already removed.
// If the device isn't there then don't try to clean up IP masq either.
var ipn *net.IPNet
var ipnets []*net.IPNet
err = ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
var err error
ipn, err = ip.DelLinkByNameAddr(args.IfName, netlink.FAMILY_ALL)
ipnets, err = ip.DelLinkByNameAddr(args.IfName)
if err != nil && err == ip.ErrLinkNotFound {
return nil
}
@ -488,10 +488,14 @@ func cmdDel(args *skel.CmdArgs) error {
return err
}
if ipn != nil && n.IPMasq {
if n.IPMasq {
chain := utils.FormatChainName(n.Name, args.ContainerID)
comment := utils.FormatComment(n.Name, args.ContainerID)
err = ip.TeardownIPMasq(ipn, chain, comment)
for _, ipn := range ipnets {
if err := ip.TeardownIPMasq(ipn, chain, comment); err != nil {
return err
}
}
}
return err