Skip to content

Commit

Permalink
Ensure kernel sends GARPs to avoid communication failures
Browse files Browse the repository at this point in the history
Signed-off-by: Cyclinder Kuo <[email protected]>
  • Loading branch information
cyclinder committed Feb 13, 2025
1 parent 62d4e07 commit 2b88f4d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/spiderpool/cmd/command_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ func CmdAdd(args *skel.CmdArgs) (err error) {
return err
}

// CNI will set the interface to up, and the kernel only sends GARPs/Unsolicited NA when the interface
// goes from down to up or when the link-layer address changes on the interfaces.
// if we don't set the interface to down, it doesn't affect when CNI re-set the interface to up,
// the kernel wouldn't send GARPs/Unsolicited NA. so we MUST be set it to down, in order to the
// kernel send GARPs/Unsolicited NA when the interface goes from down to up.
err = netns.Do(func(netNS ns.NetNS) error {
l, err := netlink.LinkByName(args.IfName)
if err != nil {
return fmt.Errorf("failed to get link: %w", err)
}

Check warning on line 191 in cmd/spiderpool/cmd/command_add.go

View check run for this annotation

Codecov / codecov/patch

cmd/spiderpool/cmd/command_add.go#L190-L191

Added lines #L190 - L191 were not covered by tests

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

Check warning on line 195 in cmd/spiderpool/cmd/command_add.go

View check run for this annotation

Codecov / codecov/patch

cmd/spiderpool/cmd/command_add.go#L194-L195

Added lines #L194 - L195 were not covered by tests

logger.Sugar().Debugf("Set link %s to down", args.IfName)
return nil
})

if err != nil {
logger.Error(err.Error())
return err
}

Check warning on line 204 in cmd/spiderpool/cmd/command_add.go

View check run for this annotation

Codecov / codecov/patch

cmd/spiderpool/cmd/command_add.go#L202-L204

Added lines #L202 - L204 were not covered by tests

// Assemble the result of IPAM request response.
result, err := assembleResult(conf.CNIVersion, args.IfName, ipamResponse)
if err != nil {
Expand Down

0 comments on commit 2b88f4d

Please sign in to comment.