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

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



---
 src/util/virnetdev.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 7ffd3c2..c7eeb50 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -83,10 +83,32 @@ static int virNetDevSetupControl(const char *ifname,
 {
     return virNetDevSetupControlFull(ifname, ifr, AF_PACKET, SOCK_DGRAM);
 }
-#endif
+#elif defined(__FreeBSD__)
+static int virNetDevSetupControl(const char *ifname,
+                                 struct ifreq *ifr)
+{
+    int s;
 
+    memset(ifr, 0, sizeof(*ifr));
 
-#if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ)
+    if (virStrcpyStatic(ifr->ifr_name, ifname) == NULL) {
+        virReportSystemError(ERANGE,
+                             _("Network interface name '%s' is too long"),
+                             ifname);
+        return -1;
+    }
+
+    if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
+        virReportSystemError(errno, "%s",
+                             _("Cannot open network interface control socket"));
+        return -1;
+    }
+
+    return s;
+}
+#endif
+
+#if defined(SIOCGIFFLAGS) && (defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__))
 /**
  * virNetDevExists:
  * @ifname
@@ -105,7 +127,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 +486,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 +505,16 @@ int virNetDevSetName(const char* ifname, const char *newifname)
     if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
         return -1;
 
+#if defined(__FreeBSD__)
+    ifr.ifr_data = 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


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