[PATCH v3 1/4] FreeBSD: implement virNetDevExists() and virNetDevSetName().

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

 



---
 src/util/virnetdev.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 295884f..503db9d 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -44,7 +44,7 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
-#if defined(HAVE_STRUCT_IFREQ)
+#if defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__)
 static int virNetDevSetupControlFull(const char *ifname,
                                      struct ifreq *ifr,
                                      int domain,
@@ -81,12 +81,15 @@ static int virNetDevSetupControlFull(const char *ifname,
 static int virNetDevSetupControl(const char *ifname,
                                  struct ifreq *ifr)
 {
+#if defined(__FreeBSD__)
+    return virNetDevSetupControlFull(ifname, ifr, AF_LOCAL, SOCK_DGRAM);
+#else
     return virNetDevSetupControlFull(ifname, ifr, AF_PACKET, SOCK_DGRAM);
+#endif
 }
 #endif
 
-
-#if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ)
+#if defined(SIOCGIFFLAGS) && (defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__))
 /**
  * virNetDevExists:
  * @ifname
@@ -105,7 +108,12 @@ int virNetDevExists(const char *ifname)
         return -1;
 
     if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
+        /* FreeBSD throws ENXIO when interface doesn't exist */
+#if defined(__FreeBSD__)
+        if (errno == ENXIO)
+#else
         if (errno == ENODEV)
+#endif
             ret = 0;
         else
             virReportSystemError(errno,
@@ -459,7 +467,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
     return rc;
 }
 
-#if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ)
+#if defined(SIOCSIFNAME) && (defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__))
 /**
  * virNetDevSetName:
  * @ifname: name of device
@@ -478,12 +486,16 @@ int virNetDevSetName(const char* ifname, const char *newifname)
     if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
         return -1;
 
+#if defined(__FreeBSD__)
+    ifr.ifr_data = (caddr_t)newifname;
+#else
     if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) {
         virReportSystemError(ERANGE,
                              _("Network interface name '%s' is too long"),
                              newifname);
         goto cleanup;
     }
+#endif
 
     if (ioctl(fd, SIOCSIFNAME, &ifr)) {
         virReportSystemError(errno,
-- 
1.8.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]