From 2ff84a481e380a8a418e9838259dbaf794ffa0c1 Mon Sep 17 00:00:00 2001 From: Bruce Ma Date: Wed, 29 Jan 2020 20:03:15 +0800 Subject: [PATCH] pkg/ip: use type cast instead of untrusty error message Signed-off-by: Bruce Ma --- pkg/ip/link_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ip/link_linux.go b/pkg/ip/link_linux.go index c0053cabe..9bd7f471f 100644 --- a/pkg/ip/link_linux.go +++ b/pkg/ip/link_linux.go @@ -178,7 +178,7 @@ func SetupVeth(contVethName string, mtu int, hostNS ns.NetNS) (net.Interface, ne func DelLinkByName(ifName string) error { iface, err := netlink.LinkByName(ifName) if err != nil { - if err.Error() == "Link not found" { + if _, ok := err.(netlink.LinkNotFoundError); ok { return ErrLinkNotFound } return fmt.Errorf("failed to lookup %q: %v", ifName, err) @@ -195,7 +195,7 @@ func DelLinkByName(ifName string) error { func DelLinkByNameAddr(ifName string) ([]*net.IPNet, error) { iface, err := netlink.LinkByName(ifName) if err != nil { - if err != nil && err.Error() == "Link not found" { + if _, ok := err.(netlink.LinkNotFoundError); ok { return nil, ErrLinkNotFound } return nil, fmt.Errorf("failed to lookup %q: %v", ifName, err)