]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: new function virNetDevMacVLanIsMacvtap()
authorLaine Stump <laine@redhat.com>
Mon, 26 Aug 2019 05:24:08 +0000 (01:24 -0400)
committerLaine Stump <laine@redhat.com>
Mon, 9 Sep 2019 18:29:33 +0000 (14:29 -0400)
This function returns T if the given name is a macvtap device. This is
determined by 1) getting the ifindex of the device with that name (if
there is one), and 2) checking for existence of /dev/tapXX, where "XX"
is the ifindex learned in (1).

It's also possible to learn this by getting a netlink dump of the
interface and parsing through it to look for some attributes, but that
is complicated to figure out, takes longer to execute, and I'm lazy.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt_private.syms
src/util/virnetdevmacvlan.c
src/util/virnetdevmacvlan.h

index f1fe7259f9987c8625fd9112ca48f998cb94b3de..7adb07aac07b7db96c5addc9209ecee8637b55db 100644 (file)
@@ -2524,6 +2524,7 @@ virNetDevMacVLanCreate;
 virNetDevMacVLanCreateWithVPortProfile;
 virNetDevMacVLanDelete;
 virNetDevMacVLanDeleteWithVPortProfile;
+virNetDevMacVLanIsMacvtap;
 virNetDevMacVLanModeTypeFromString;
 virNetDevMacVLanReleaseName;
 virNetDevMacVLanReserveName;
index 3302522289b797c14ab0dc9504f06bdbe13cfdad..79aa7ed5ac7e1c1df4608a24d89c3ac7adf87c99 100644 (file)
@@ -278,6 +278,29 @@ virNetDevMacVLanReleaseName(const char *name)
 }
 
 
+/**
+ * virNetDevMacVLanIsMacvtap:
+ * @ifname: Name of the interface
+ *
+ * Return T if the named netdev exists and is a macvtap device
+ * F in all other cases.
+ */
+bool
+virNetDevMacVLanIsMacvtap(const char *ifname)
+{
+    int ifindex;
+    VIR_AUTOFREE(char *) tapname = NULL;
+
+    if (virNetDevGetIndex(ifname, &ifindex) < 0)
+        return false;
+
+    if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
+        return false;
+
+    return virFileExists(tapname);
+}
+
+
 /**
  * virNetDevMacVLanCreate:
  *
index d1b479ed9f08f8d582d4817873588158ad712bb2..8ac7643e49607e046fa718559178afd7d3e258ca 100644 (file)
@@ -57,6 +57,9 @@ typedef enum {
 int virNetDevMacVLanReserveName(const char *name, bool quietfail);
 int virNetDevMacVLanReleaseName(const char *name);
 
+bool virNetDevMacVLanIsMacvtap(const char *ifname)
+   ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NOINLINE;
+
 int virNetDevMacVLanCreate(const char *ifname,
                            const char *type,
                            const virMacAddr *macaddress,