From ba96d277b0e0c49436649b6f9f235e05a01e6c50 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sat, 6 Oct 2012 14:20:29 -0500 Subject: [PATCH] interface: add udevIfaceIsActive() to udev backend Add support to check if a specific interface is active by supporting the following API function in the udev based virInterface backend: * virConnectInterfaceIsActive() --- src/interface/interface_backend_udev.c | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 75b9f1a6a9..1cb6dfe172 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -489,6 +489,35 @@ err: return ret; } +static int +udevIfaceIsActive(virInterfacePtr ifinfo) +{ + struct udev_iface_driver *driverState = ifinfo->conn->interfacePrivateData; + struct udev *udev = udev_ref(driverState->udev); + struct udev_device *dev; + int status; + + dev = udev_device_new_from_subsystem_sysname(udev, "net", + ifinfo->name); + if (!dev) { + virReportError(VIR_ERR_NO_INTERFACE, + _("couldn't find interface named '%s'"), + ifinfo->name); + status = -1; + goto cleanup; + } + + /* Check if it's active or not */ + status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up"); + + udev_device_unref(dev); + +cleanup: + udev_unref(udev); + + return status; +} + static virInterfaceDriver udevIfaceDriver = { "udev", .open = udevIfaceOpenInterface, /* 0.10.3 */ @@ -500,6 +529,7 @@ static virInterfaceDriver udevIfaceDriver = { .listAllInterfaces = udevIfaceListAllInterfaces, /* 0.10.3 */ .interfaceLookupByName = udevIfaceLookupByName, /* 0.10.3 */ .interfaceLookupByMACString = udevIfaceLookupByMACString, /* 0.10.3 */ + .interfaceIsActive = udevIfaceIsActive, /* 0.10.3 */ }; int -- GitLab