From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy90-5.mail.163.com (mail-proxy905.ym.163.com [43.230.90.5]) by dpdk.org (Postfix) with ESMTP id 6C9201B012 for ; Thu, 14 Dec 2017 12:38:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=dnHuRTcGD34ZA+ho8C nlGRCJgIpvCz4nrHXmOO+V6Zk=; b=qESfKq2T0N1PfhHDEP7Cws9WZKBzFRV2pB UerfmDBYe/r6kIm713EOFKntvpPOSNS0uYRLNSfeYvTKjmARwO0tzmbMfFLsgFWv 9ffRmS471/SjC3Arao0tjvb/yA8rvRCpVqagEdXOffLr3GoPjDCzs86662Q2GPNs WHp4MqCOs= Received: from localhost.localdomain (unknown [221.226.39.82]) by smtp9 (Coremail) with SMTP id DcCowABXa72pYjJa1h4+Aw--.15779S3; Thu, 14 Dec 2017 19:38:22 +0800 (CST) From: Ning Li To: Yuanhan Liu , Maxime Coquelin Cc: dev@dpdk.org, Ning Li Date: Thu, 14 Dec 2017 19:38:14 +0800 Message-Id: <1513251494-9980-1-git-send-email-muziding001@163.com> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: DcCowABXa72pYjJa1h4+Aw--.15779S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw1fuFWkCF1xXFWUWF48WFg_yoW5Gryrpw 4DArZxZr13tr4xAa1rJF18ury5Z3Z3JrW7Kr9xW3Wrur4vvFnrCrWUua4Ygr47tFWUGF4I yFy09F9Ig3s8uw7anT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UD-PUUUUUU= X-Originating-IP: [221.226.39.82] X-CM-SenderInfo: ppx2xvhlqjiiqr6rljoofrz/xtbB0BOu0lUMB-qpWwABso Subject: [dpdk-dev] [PATCH] net/virtio-user: specify MAC address for tap port X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Dec 2017 11:38:45 -0000 When use virtio_user as exception path, we need to specify a MAC address for the tap port. Signed-off-by: Ning Li --- 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