]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetdevtap: add virNetDevTapGetName
authorPaolo Bonzini <pbonzini@redhat.com>
Sat, 20 Apr 2013 09:11:24 +0000 (11:11 +0200)
committerEric Blake <eblake@redhat.com>
Fri, 26 Apr 2013 21:37:15 +0000 (15:37 -0600)
This will be used on a tap file descriptor returned by the bridge helper
to populate the <target> element, because the helper does not provide
the interface name.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
src/libvirt_private.syms
src/util/virnetdevtap.c
src/util/virnetdevtap.h

index 0bb6f5f3d5b998da8b1c16b06f886181b9b40ec8..a7e1eeb65dcefd3659526f44c3f880b8617911f8 100644 (file)
@@ -1533,6 +1533,7 @@ virNetDevOpenvswitchSetMigrateData;
 virNetDevTapCreate;
 virNetDevTapCreateInBridgePort;
 virNetDevTapDelete;
+virNetDevTapGetName;
 
 
 # util/virnetdevveth.h
index e4ce223657758d981d870cb5b4d7863413219618..fac95ecfff2b6e807d1965e7cafdc016f38d09a5 100644 (file)
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+/**
+ * virNetDevTapGetName:
+ * @tapfd: a tun/tap file descriptor
+ * @ifname: a pointer that will receive the interface name
+ *
+ * Retrieve the interface name given a file descriptor for a tun/tap
+ * interface.
+ *
+ * Returns 0 if the interface name is successfully queried, -1 otherwise
+ */
+int
+virNetDevTapGetName(int tapfd, char **ifname)
+{
+#ifdef TUNGETIFF
+    struct ifreq ifr;
+
+    if (ioctl(tapfd, TUNGETIFF, &ifr) < 0) {
+        virReportSystemError(errno, "%s",
+                             _("Unable to query tap interface name"));
+        return -1;
+    }
+
+    *ifname = strdup(ifr.ifr_name);
+    if (*ifname == NULL) {
+        virReportOOMError();
+        return -1;
+    }
+    return 0;
+#else
+    return -1;
+#endif
+}
+
+
 /**
  * virNetDevProbeVnetHdr:
  * @tapfd: a tun/tap file descriptor
index 980db61e5ecb262f25e3ec4229165dbf3d179d84..6bfc80c575d6b5dc33e5ce5b104b051748c5d48a 100644 (file)
@@ -35,6 +35,9 @@ int virNetDevTapCreate(char **ifname,
 int virNetDevTapDelete(const char *ifname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 
+int virNetDevTapGetName(int tapfd, char **ifname)
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+
 typedef enum {
    VIR_NETDEV_TAP_CREATE_NONE = 0,
    /* Bring the interface up */