@@ -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
3738type 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 )
0 commit comments