From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from m12-14.163.com (m12-14.163.com [220.181.12.14]) by dpdk.org (Postfix) with ESMTP id EA9CD237 for ; Fri, 29 Dec 2017 04:39:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=NOHTWnuNpO3zl0FDsV c68ovbAr4y298fYzPSFT5tAZI=; b=o6035SoUmLw2fPtny21GZwqxUS3yO+L4j6 prtZx52ZdgES6qwLPLK4Z0v0kWoGdyBiwTG/Z1co+9+Wrm/uKW+Uaarl/1VVa8Ov YDrHorYLX31D7eWlOqfBLcXC72Fyb7QH+B9PIVoH9mNChfIZXOrveHfhjbcuwLrW WQqzGTQLE= Received: from localhost.localdomain (unknown [221.226.39.82]) by smtp10 (Coremail) with SMTP id DsCowAB3NXLiuEVa2msiAQ--.2781S3; Fri, 29 Dec 2017 11:39:21 +0800 (CST) From: Ning Li To: Yuanhan Liu , Maxime Coquelin , Tiwei Bie Cc: dev@dpdk.org, Ning Li Date: Fri, 29 Dec 2017 11:38:42 +0800 Message-Id: <1514518722-27302-1-git-send-email-muziding001@163.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513251494-9980-1-git-send-email-muziding001@163.com> References: <1513251494-9980-1-git-send-email-muziding001@163.com> X-CM-TRANSID: DsCowAB3NXLiuEVa2msiAQ--.2781S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxXr4DArW3tF1UuF4kur4Uurg_yoW5Ww1fpa 1DArsxZr13Jr17Aa1rJF109ry5A3Z7Jr17Kr9xW3Wrurs2qF1UGrWUua4Ygr47JFWUGF4I yFy09asIg3s8Zw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRhL0rUUUUU= X-Originating-IP: [221.226.39.82] X-CM-SenderInfo: ppx2xvhlqjiiqr6rljoofrz/xtbB0Aq90lUMCKmJ5wAAsj Subject: [dpdk-dev] [PATCH] net/virtio-user: specify the MAC of the tap 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: Fri, 29 Dec 2017 03:39:26 -0000 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 --- 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 #include #include +#include #include #include #include +#include + #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