[PATCH 3/4] FreeBSD: implement virNetDevSetMAC().

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

 



---
 src/util/virnetdev.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index c7eeb50..6e4f7ad 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -42,6 +42,11 @@
 # undef HAVE_STRUCT_IFREQ
 #endif
 
+#if defined(__FreeBSD__)
+# include <sys/sockio.h>
+# include <net/if_dl.h>
+#endif
+
 #define VIR_FROM_THIS VIR_FROM_NONE
 
 #if defined(HAVE_STRUCT_IFREQ)
@@ -200,6 +205,51 @@ cleanup:
     VIR_FORCE_CLOSE(fd);
     return ret;
 }
+#elif defined(__FreeBSD__)
+int virNetDevSetMAC(const char *ifname,
+                    const virMacAddrPtr macaddr)
+{
+        struct ifreq ifr;
+        struct sockaddr_dl sdl;
+        uint8_t mac[19];
+        char *macstr;
+        int s;
+        int ret = -1;
+
+        if ((s = virNetDevSetupControl(ifname, &ifr)) < 0)
+            return -1;
+
+        if (VIR_ALLOC_N(macstr, VIR_MAC_STRING_BUFLEN) < 0) {
+            virReportOOMError();
+            ret = - 1;
+            goto cleanup;
+        }
+        virMacAddrFormat(&macaddr, macstr);
+
+        virStrncpy(ifr.ifr_name, ifname, IFNAMSIZ, sizeof(ifr.ifr_name));
+        memset(mac, 0, sizeof(mac));
+        mac[0] = ':';
+        virStrncpy(mac + 1, macstr, strlen(macstr), sizeof(mac));
+        sdl.sdl_len = sizeof(sdl);
+        link_addr(mac, &sdl);
+
+        bcopy(sdl.sdl_data, ifr.ifr_addr.sa_data, 6);
+        ifr.ifr_addr.sa_len = 6;
+
+        if (ioctl(s, SIOCSIFLLADDR, &ifr) < 0) {
+            virReportSystemError(errno,
+                                 _("Cannot set interface MAC on '%s'"),
+                                ifname);
+            goto cleanup;
+        }
+
+        ret = 0;
+cleanup:
+        VIR_FREE(macstr);
+        VIR_FORCE_CLOSE(s);
+
+        return ret;
+}
 #else
 int virNetDevSetMAC(const char *ifname,
                     const virMacAddrPtr macaddr ATTRIBUTE_UNUSED)
-- 
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]