mirror of
https://github.com/containers/podman.git
synced 2025-09-26 00:06:04 +08:00
Drop dependency on iproute
We only use the `ip` util to remove a network interface. We can do this directly via the netlink lib, no need to call a external binary. [NO TESTS NEEDED] Fixes #11403 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -2,12 +2,11 @@ package network
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
"github.com/containers/podman/v3/pkg/util"
|
"github.com/containers/podman/v3/pkg/util"
|
||||||
"github.com/containers/podman/v3/utils"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetFreeDeviceName returns a device name that is unused; used when no network
|
// GetFreeDeviceName returns a device name that is unused; used when no network
|
||||||
@ -52,12 +51,9 @@ func GetFreeDeviceName(config *config.Config) (string, error) {
|
|||||||
|
|
||||||
// RemoveInterface removes an interface by the given name
|
// RemoveInterface removes an interface by the given name
|
||||||
func RemoveInterface(interfaceName string) error {
|
func RemoveInterface(interfaceName string) error {
|
||||||
// Make sure we have the ip command on the system
|
link, err := netlink.LinkByName(interfaceName)
|
||||||
ipPath, err := exec.LookPath("ip")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Delete the network interface
|
return netlink.LinkDel(link)
|
||||||
_, err = utils.ExecCmd(ipPath, []string{"link", "del", interfaceName}...)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,9 @@ func removeNetwork(config *config.Config, name string) error {
|
|||||||
return errors.Wrapf(err, "failed to get live network names")
|
return errors.Wrapf(err, "failed to get live network names")
|
||||||
}
|
}
|
||||||
if util.StringInSlice(interfaceName, liveNetworkNames) {
|
if util.StringInSlice(interfaceName, liveNetworkNames) {
|
||||||
if err := RemoveInterface(interfaceName); err != nil {
|
if err = RemoveInterface(interfaceName); err != nil {
|
||||||
return errors.Wrapf(err, "failed to delete the network interface %q", interfaceName)
|
// only log the error, it is not fatal
|
||||||
|
logrus.Infof("failed to remove network interface %s: %v", interfaceName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user