@@ -24,6 +24,7 @@ import (
2424 "github.com/safchain/ethtool"
2525 "github.com/vishvananda/netlink"
2626
27+ "github.com/containernetworking/plugins/pkg/netlinksafe"
2728 "github.com/containernetworking/plugins/pkg/ns"
2829 "github.com/containernetworking/plugins/pkg/utils/sysctl"
2930)
@@ -52,7 +53,7 @@ func makeVethPair(name, peer string, mtu int, mac string, hostNS ns.NetNS) (netl
5253 return nil , err
5354 }
5455 // Re-fetch the container link to get its creation-time parameters, e.g. index and mac
55- veth2 , err := netlink .LinkByName (name )
56+ veth2 , err := netlinksafe .LinkByName (name )
5657 if err != nil {
5758 netlink .LinkDel (veth ) // try and clean up the link if possible.
5859 return nil , err
@@ -62,7 +63,7 @@ func makeVethPair(name, peer string, mtu int, mac string, hostNS ns.NetNS) (netl
6263}
6364
6465func peerExists (name string ) bool {
65- if _ , err := netlink .LinkByName (name ); err != nil {
66+ if _ , err := netlinksafe .LinkByName (name ); err != nil {
6667 return false
6768 }
6869 return true
@@ -114,7 +115,7 @@ func RandomVethName() (string, error) {
114115}
115116
116117func RenameLink (curName , newName string ) error {
117- link , err := netlink .LinkByName (curName )
118+ link , err := netlinksafe .LinkByName (curName )
118119 if err == nil {
119120 err = netlink .LinkSetName (link , newName )
120121 }
@@ -145,7 +146,7 @@ func SetupVethWithName(contVethName, hostVethName string, mtu int, contVethMac s
145146
146147 var hostVeth netlink.Link
147148 err = hostNS .Do (func (_ ns.NetNS ) error {
148- hostVeth , err = netlink .LinkByName (hostVethName )
149+ hostVeth , err = netlinksafe .LinkByName (hostVethName )
149150 if err != nil {
150151 return fmt .Errorf ("failed to lookup %q in %q: %v" , hostVethName , hostNS .Path (), err )
151152 }
@@ -174,7 +175,7 @@ func SetupVeth(contVethName string, mtu int, contVethMac string, hostNS ns.NetNS
174175
175176// DelLinkByName removes an interface link.
176177func DelLinkByName (ifName string ) error {
177- iface , err := netlink .LinkByName (ifName )
178+ iface , err := netlinksafe .LinkByName (ifName )
178179 if err != nil {
179180 if _ , ok := err .(netlink.LinkNotFoundError ); ok {
180181 return ErrLinkNotFound
@@ -191,15 +192,15 @@ func DelLinkByName(ifName string) error {
191192
192193// DelLinkByNameAddr remove an interface and returns its addresses
193194func DelLinkByNameAddr (ifName string ) ([]* net.IPNet , error ) {
194- iface , err := netlink .LinkByName (ifName )
195+ iface , err := netlinksafe .LinkByName (ifName )
195196 if err != nil {
196197 if _ , ok := err .(netlink.LinkNotFoundError ); ok {
197198 return nil , ErrLinkNotFound
198199 }
199200 return nil , fmt .Errorf ("failed to lookup %q: %v" , ifName , err )
200201 }
201202
202- addrs , err := netlink .AddrList (iface , netlink .FAMILY_ALL )
203+ addrs , err := netlinksafe .AddrList (iface , netlink .FAMILY_ALL )
203204 if err != nil {
204205 return nil , fmt .Errorf ("failed to get IP addresses for %q: %v" , ifName , err )
205206 }
@@ -222,7 +223,7 @@ func DelLinkByNameAddr(ifName string) ([]*net.IPNet, error) {
222223// veth, or an error. This peer ifindex will only be valid in the peer's
223224// network namespace.
224225func GetVethPeerIfindex (ifName string ) (netlink.Link , int , error ) {
225- link , err := netlink .LinkByName (ifName )
226+ link , err := netlinksafe .LinkByName (ifName )
226227 if err != nil {
227228 return nil , - 1 , fmt .Errorf ("could not look up %q: %v" , ifName , err )
228229 }
0 commit comments