---
src/util/virnetdev.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 9ee84c3..b94e503 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) || defined(__FreeBSD__)
@@ -183,6 +188,54 @@ 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;
+ char mac[VIR_MAC_STRING_BUFLEN + 1];
+ 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();
+ goto cleanup;
+ }
+ virMacAddrFormat(macaddr, macstr);
+ memset(mac, 0, sizeof(mac));
+ mac[0] = ':';
+ if (virStrncpy(mac + 1, macstr, strlen(macstr),
+ sizeof(mac)) == NULL) {
+ virReportSystemError(ERANGE,
+ _("invalid MAC %s"),
+ macstr);
+ goto cleanup;
+ }
+ 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)
@@ -329,7 +382,7 @@ virNetDevRestoreMacAddress(const char *linkdev,
}
-#if defined(SIOCGIFMTU) && defined(HAVE_STRUCT_IFREQ)
+#if defined(SIOCGIFMTU) && defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__)
/**
* virNetDevGetMTU:
* @ifname: interface name get MTU for
--
1.8.0