Skip to content

Commit

Permalink
Merge pull request #261 from l1b0k/cni2
Browse files Browse the repository at this point in the history
fix get eni by mac may get incorrect nic in ipvlan mode
  • Loading branch information
BSWANG authored Sep 1, 2021
2 parents be931c6 + bd160e1 commit fe47998
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions pkg/link/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,17 @@ func GetDeviceNumber(mac string) (int32, error) {
}

for _, link := range linkList {
// ignore virtual nic type. eg. ipvlan veth bridge
if _, ok := link.(*netlink.Device); !ok {
continue
}
if link.Attrs().HardwareAddr.String() == mac {
return int32(link.Attrs().Index), nil
}
}
return 0, errors.Wrapf(ErrNotFound, "can't found dev by mac %s", mac)
}

// GetDeviceName get interface device name by mac address
func GetDeviceName(mac string) (string, error) {
linkList, err := netlink.LinkList()
if err != nil {
return "", errors.Wrapf(err, "error get link list from netlink")
}

for _, link := range linkList {
if link.Attrs().HardwareAddr.String() == mac {
return link.Attrs().Name, nil
}
}
return "", errors.Wrapf(ErrNotFound, "can't found dev by mac %s", mac)
}

// DeleteIPRulesByIP delete all ip rule related to the addr
func DeleteIPRulesByIP(addr *net.IPNet) error {
family := netlink.FAMILY_V4
Expand Down

0 comments on commit fe47998

Please sign in to comment.