New upstream version 18.08
[deb_dpdk.git] / drivers / net / virtio / virtio_user / vhost_kernel_tap.c
index 1a47a34..9ea7ade 100644 (file)
@@ -7,15 +7,19 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <net/if.h>
+#include <net/if_arp.h>
 #include <errno.h>
 #include <string.h>
 #include <limits.h>
 
+#include <rte_ether.h>
+
 #include "vhost_kernel_tap.h"
 #include "../virtio_logs.h"
 
 int
-vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq)
+vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq,
+                        const char *mac)
 {
        unsigned int tap_features;
        int sndbuf = INT_MAX;
@@ -94,6 +98,14 @@ vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq)
                PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s",
                           strerror(errno));
 
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+       memcpy(ifr.ifr_hwaddr.sa_data, mac, ETHER_ADDR_LEN);
+       if (ioctl(tapfd, SIOCSIFHWADDR, (void *)&ifr) == -1) {
+               PMD_DRV_LOG(ERR, "SIOCSIFHWADDR failed: %s", strerror(errno));
+               goto error;
+       }
+
        if (!(*p_ifname))
                *p_ifname = strdup(ifr.ifr_name);