DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/virtio-user: specify MAC address for tap port
@ 2017-12-14 11:38 Ning Li
  2017-12-18  6:19 ` Tiwei Bie
  2017-12-29  3:38 ` [dpdk-dev] [PATCH] net/virtio-user: specify the MAC of the tap Ning Li
  0 siblings, 2 replies; 12+ messages in thread
From: Ning Li @ 2017-12-14 11:38 UTC (permalink / raw)
  To: Yuanhan Liu, Maxime Coquelin; +Cc: dev, Ning Li

When use virtio_user as exception path, we need to specify a MAC
address for the tap port.

Signed-off-by: Ning Li <muziding001@163.com>
---
 drivers/net/virtio/virtio_user/vhost_kernel.c     |  3 ++-
 drivers/net/virtio/virtio_user/vhost_kernel_tap.c |  8 ++++++++
 drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 12 +++++++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c
index 68d28b1..dd24b6b 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel.c
+++ b/drivers/net/virtio/virtio_user/vhost_kernel.c
@@ -380,7 +380,8 @@ struct vhost_memory_kernel {
 	else
 		hdr_size = sizeof(struct virtio_net_hdr);
 
-	tapfd = vhost_kernel_open_tap(&dev->ifname, hdr_size, req_mq);
+	tapfd = vhost_kernel_open_tap(&dev->ifname, hdr_size, req_mq,
+			 (char *)dev->mac_addr);
 	if (tapfd < 0) {
 		PMD_DRV_LOG(ERR, "fail to open tap for vhost kernel");
 		return -1;
diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
index 689a5cf..756fde2 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
+++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
@@ -123,6 +123,14 @@
 		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, ETH_ALEN);
+	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);
 
diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
index eae340c..f59b1ac 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
+++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
@@ -64,4 +64,14 @@
 /* Constants */
 #define PATH_NET_TUN	"/dev/net/tun"
 
-int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq);
+/* Socket configuration controls. */
+#define SIOCSIFHWADDR   0x8924          /* set hardware address */
+
+/* ARP protocol HARDWARE identifiers. */
+#define ARPHRD_ETHER    1               /* Ethernet             */
+
+/* Length of Ethernet address. */
+#define ETH_ALEN  6
+
+int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq,
+			 const char *mac);
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-03-29 11:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14 11:38 [dpdk-dev] [PATCH] net/virtio-user: specify MAC address for tap port Ning Li
2017-12-18  6:19 ` Tiwei Bie
2017-12-19  9:27   ` Ning Li
2017-12-19 10:08   ` Ning Li
2017-12-28  8:43     ` Tiwei Bie
2017-12-29  3:04       ` Ning Li
2017-12-29  3:38 ` [dpdk-dev] [PATCH] net/virtio-user: specify the MAC of the tap Ning Li
2017-12-29  9:44   ` Tiwei Bie
2018-03-28 16:54     ` Seán Harte
2018-03-29  0:50       ` Tan, Jianfeng
2018-03-29  1:15         ` Tiwei Bie
2018-03-29 11:45   ` Maxime Coquelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).