Skip to content

Commit

Permalink
Merge pull request spidernet-io#2639 from cyclinder/ifacer/fix_bond
Browse files Browse the repository at this point in the history
ifacer: Fix the slave with bond was not set if vlanId was set to 0
  • Loading branch information
weizhoublue authored Nov 22, 2023
2 parents e74bc26 + d75bb1f commit eab0cb1
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions cmd/ifacer/cmd/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,6 @@ func CmdAdd(args *skel.CmdArgs) error {
return types.PrintResult(result, conf.CNIVersion)
}

for _, slave := range conf.Interfaces {
link, err := netlink.LinkByName(slave)
if err != nil {
return fmt.Errorf("failed to InterfaceByName %s: %w", slave, err)
}

if err = netlink.LinkSetDown(link); err != nil {
return fmt.Errorf("failed to set slave %s down: %w", slave, err)
}

if err = networking.LinkSetBondSlave(slave, bond); err != nil {
return err
}
}

if err = netlink.LinkSetUp(bond); err != nil {
return fmt.Errorf("failed to set %s up", bond.Name)
}

vlanName := getVlanIfaceName(conf.Bond.Name, conf.VlanID)
if err := checkInterfaceWithSameVlan(conf.VlanID, vlanName); err != nil {
return err
Expand Down Expand Up @@ -150,8 +131,35 @@ func createBondDevice(conf *Ifacer) (*netlink.Bond, error) {
}
}

if err = netlink.LinkAdd(bond); err != nil {
return nil, err
}

for _, slave := range conf.Interfaces {
link, err := netlink.LinkByName(slave)
if err != nil {
return nil, fmt.Errorf("failed to InterfaceByName %s: %w", slave, err)
}

if err = netlink.LinkSetDown(link); err != nil {
return nil, fmt.Errorf("failed to set slave %s down: %w", slave, err)
}

if err = networking.LinkSetBondSlave(slave, bond); err != nil {
return nil, err
}

if err = netlink.LinkSetUp(link); err != nil {
return nil, err
}
}

if err = netlink.LinkSetUp(bond); err != nil {
return nil, fmt.Errorf("failed to set %s up", bond.Name)
}

// create vlan interface base on bond
return bond, netlink.LinkAdd(bond)
return bond, nil
}

func createVlanDevice(conf *Ifacer) error {
Expand Down

0 comments on commit eab0cb1

Please sign in to comment.