[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/9] util: new function virNetDevMacVLanIsMacvtap()



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>
---
 src/libvirt_private.syms    |  3 +++
 src/util/virnetdevmacvlan.c | 23 +++++++++++++++++++++++
 src/util/virnetdevmacvlan.h |  3 +++
 3 files changed, 29 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a34d92f5ef..afea00b629 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2523,10 +2523,13 @@ virNetDevMacVLanCreate;
 virNetDevMacVLanCreateWithVPortProfile;
 virNetDevMacVLanDelete;
 virNetDevMacVLanDeleteWithVPortProfile;
+virNetDevMacVLanIsMacvtap;
 virNetDevMacVLanModeTypeFromString;
 virNetDevMacVLanReleaseName;
 virNetDevMacVLanReserveName;
 virNetDevMacVLanRestartWithVPortProfile;
+virNetDevMacVLanTapOpen;
+virNetDevMacVLanTapSetup;
 virNetDevMacVLanVPortProfileRegisterCallback;
 
 
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 3302522289..79aa7ed5ac 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -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:
  *
diff --git a/src/util/virnetdevmacvlan.h b/src/util/virnetdevmacvlan.h
index d1b479ed9f..8ac7643e49 100644
--- a/src/util/virnetdevmacvlan.h
+++ b/src/util/virnetdevmacvlan.h
@@ -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,
-- 
2.21.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]