DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ning Li <muziding001@163.com>
To: Yuanhan Liu <yliu@fridaylinux.org>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Tiwei Bie <tiwei.bie@intel.com>
Cc: dev@dpdk.org, Ning Li <muziding001@163.com>
Subject: [dpdk-dev] [PATCH] net/virtio-user: specify the MAC of the tap
Date: Fri, 29 Dec 2017 11:38:42 +0800	[thread overview]
Message-ID: <1514518722-27302-1-git-send-email-muziding001@163.com> (raw)
In-Reply-To: <1513251494-9980-1-git-send-email-muziding001@163.com>

When using virtio-user with vhost-kernel to exchange
packet with kernel networking stack, application can
set the MAC of the tap interface via parameter.

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 | 14 +++++++++++++-
 drivers/net/virtio/virtio_user/vhost_kernel_tap.h |  3 ++-
 3 files changed, 17 insertions(+), 3 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..d036428 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
+++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
@@ -36,15 +36,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;
@@ -123,6 +127,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, 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);
 
diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
index eae340c..402f964 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
+++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
@@ -64,4 +64,5 @@
 /* Constants */
 #define PATH_NET_TUN	"/dev/net/tun"
 
-int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq);
+int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq,
+			 const char *mac);
-- 
1.8.3.1

  parent reply	other threads:[~2017-12-29  3:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Ning Li [this message]
2017-12-29  9:44   ` [dpdk-dev] [PATCH] net/virtio-user: specify the MAC of the tap 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514518722-27302-1-git-send-email-muziding001@163.com \
    --to=muziding001@163.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=tiwei.bie@intel.com \
    --cc=yliu@fridaylinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).