From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ning Li Subject: [PATCH] net/virtio-user: specify the MAC of the tap Date: Fri, 29 Dec 2017 11:38:42 +0800 Message-ID: <1514518722-27302-1-git-send-email-muziding001@163.com> References: <1513251494-9980-1-git-send-email-muziding001@163.com> Cc: dev@dpdk.org, Ning Li To: Yuanhan Liu , Maxime Coquelin , Tiwei Bie 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) In-Reply-To: <1513251494-9980-1-git-send-email-muziding001@163.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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