Skip to content

Commit a10ffb1

Browse files
committed
Avoid handling mac duplication during deletion
The bond-cni should not attempt to modify the mac addresses of slaves during deletion of the bond interface. The bond driver takes care of reverting any modifications. Only balance-tlb and balance-alb do not support slaves with same mac addresses. The plugin now handles mac duplicates only for these modes. Signed-off-by: Marcelo Guerrero <[email protected]>
1 parent d996cc5 commit a10ffb1

File tree

3 files changed

+14
-70
lines changed

3 files changed

+14
-70
lines changed

bond/bond.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import (
2929
"github.com/containernetworking/cni/pkg/version"
3030
"github.com/containernetworking/plugins/pkg/ipam"
3131
"github.com/containernetworking/plugins/pkg/ns"
32-
"github.com/intel/bond-cni/bond/util"
3332
"github.com/vishvananda/netlink"
3433
"github.com/vishvananda/netns"
34+
35+
"github.com/intel/bond-cni/bond/util"
3536
)
3637

3738
type bondingConfig struct {
@@ -143,10 +144,15 @@ func createBondedLink(bondName string, bondConf *bondingConfig, netNsHandle *net
143144

144145
// loop over the linkObjectsToBond, set each DOWN, update the interface MASTER & set it UP again.
145146
// again we use the netNsHandle to interfact with these links in the namespace provided. return error
146-
func attachLinksToBond(bondLinkObj *netlink.Bond, linkObjectsToBond []netlink.Link, netNsHandle *netlink.Handle) error {
147-
err := util.HandleMacDuplicates(linkObjectsToBond, netNsHandle)
148-
if err != nil {
149-
return fmt.Errorf("failed to handle duplicated macs on link slaves, error: %+v", err)
147+
func attachLinksToBond(bondLinkObj *netlink.Bond, linkObjectsToBond []netlink.Link, mode string, netNsHandle *netlink.Handle) error {
148+
var err error
149+
150+
bondMode := netlink.StringToBondMode(mode)
151+
if bondMode == netlink.BOND_MODE_BALANCE_TLB || bondMode == netlink.BOND_MODE_BALANCE_ALB {
152+
err = util.HandleMacDuplicates(linkObjectsToBond, netNsHandle)
153+
if err != nil {
154+
return fmt.Errorf("failed to handle duplicated macs on link slaves, error: %+v", err)
155+
}
150156
}
151157

152158
bondLinkIndex := bondLinkObj.Index
@@ -283,12 +289,13 @@ func createBond(bondName string, bondConf *bondingConfig, nspath string, ns ns.N
283289
if bondConf.FailOverMac < 0 || bondConf.FailOverMac > 2 {
284290
return nil, fmt.Errorf("FailOverMac mode should be 0, 1 or 2 actual: %+v", bondConf.FailOverMac)
285291
}
292+
286293
bondLinkObj, err := createBondedLink(bondName, bondConf, netNsHandle)
287294
if err != nil {
288295
return nil, fmt.Errorf("failed to create bonded link (%+v), error: %+v", bondName, err)
289296
}
290297

291-
err = attachLinksToBond(bondLinkObj, linkObjectsToBond, netNsHandle)
298+
err = attachLinksToBond(bondLinkObj, linkObjectsToBond, bondConf.Mode, netNsHandle)
292299
if err != nil {
293300
return nil, fmt.Errorf("failed to attached links to bond, error: %+v", err)
294301
}
@@ -433,19 +440,6 @@ func cmdDel(args *skel.CmdArgs) error {
433440
return fmt.Errorf("failed to deattached links from bond, error: %+v", err)
434441
}
435442

436-
// Fetch slave links again to have the latest state
437-
// For instance, Active-backup mode with fail_over_mac=0 reverts the mac address of backup slaves
438-
for i := range linkObjectsToDeattach {
439-
linkObjectsToDeattach[i], err = netNsHandle.LinkByName(linkObjectsToDeattach[i].Attrs().Name)
440-
if err != nil {
441-
return fmt.Errorf("failed to find link (%+v), error: %+v", linkObjectsToDeattach[i].Attrs().Name, err)
442-
}
443-
}
444-
445-
if err = util.HandleMacDuplicates(linkObjectsToDeattach, netNsHandle); err != nil {
446-
return fmt.Errorf("failed to validate deattached links macs, error: %+v", err)
447-
}
448-
449443
err = netNsHandle.LinkDel(linkObjToDel)
450444
if err != nil {
451445
return fmt.Errorf("failed to delete bonded link (%+v), error: %+v", linkObjToDel.Attrs().Name, err)

bond/bond_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -228,57 +228,6 @@ var _ = Describe("bond plugin", func() {
228228
Expect(err).NotTo(HaveOccurred())
229229
})
230230

231-
It("verifies the plugin handles duplicated macs on delete", func() {
232-
var slave1, slave2 netlink.Link
233-
var err error
234-
235-
err = podNS.Do(func(ns.NetNS) error {
236-
defer GinkgoRecover()
237-
slave1, err = netlink.LinkByName(Slave1)
238-
Expect(err).NotTo(HaveOccurred())
239-
240-
slave2, err = netlink.LinkByName(Slave2)
241-
Expect(err).NotTo(HaveOccurred())
242-
243-
err = netlink.LinkSetHardwareAddr(slave2, slave1.Attrs().HardwareAddr)
244-
Expect(err).NotTo(HaveOccurred())
245-
return nil
246-
})
247-
248-
By("creating the plugin")
249-
r, _, err := testutils.CmdAddWithArgs(args, func() error {
250-
return cmdAdd(args)
251-
})
252-
Expect(err).NotTo(HaveOccurred())
253-
254-
By("checking the bond was created")
255-
checkAddReturnResult(&r, IfName)
256-
257-
err = podNS.Do(func(ns.NetNS) error {
258-
defer GinkgoRecover()
259-
By("duplicating the macs on the slaves")
260-
err = netlink.LinkSetHardwareAddr(slave2, slave1.Attrs().HardwareAddr)
261-
Expect(err).NotTo(HaveOccurred())
262-
return nil
263-
})
264-
By("deleting the plugin")
265-
err = testutils.CmdDel(podNS.Path(),
266-
args.ContainerID, "", func() error { return cmdDel(args) })
267-
Expect(err).NotTo(HaveOccurred())
268-
269-
err = podNS.Do(func(ns.NetNS) error {
270-
defer GinkgoRecover()
271-
By("validating the macs are not duplicated")
272-
slave1, err = netlink.LinkByName(Slave1)
273-
Expect(err).NotTo(HaveOccurred())
274-
slave2, err = netlink.LinkByName(Slave2)
275-
Expect(err).NotTo(HaveOccurred())
276-
Expect(slave1.Attrs().HardwareAddr.String()).NotTo(Equal(slave2.Attrs().HardwareAddr.String()))
277-
return nil
278-
})
279-
Expect(err).NotTo(HaveOccurred())
280-
})
281-
282231
It("verifies that mac addresses are restored correctly in active-backup with fail_over_mac 0", func() {
283232
var bond netlink.Link
284233
var slave1 netlink.Link

bond/util/validation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"crypto/rand"
66
"fmt"
7+
78
"github.com/vishvananda/netlink"
89
)
910

0 commit comments

Comments
 (0)