From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id 3A16B16E for ; Thu, 22 Feb 2018 12:52:33 +0100 (CET) Received: by mail-wr0-f194.google.com with SMTP id w77so10247660wrc.6 for ; Thu, 22 Feb 2018 03:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=FPRY8UVWv9cGrdDInnXSpgiKJyif+ICxuE8W09cIuik=; b=nCjikUZdG7UcUrTqFX75lsmioWdyUJLgWniXvLUfjNcS0P4VwScsxXwuoPBvvRbu+U gQgRTZR0rCdFPgCjoV9KitCyyiTuwQN/BrsvkTIx4lQ9mJgN36coWot1sMGu5UPUhK76 UmNFQB5rPJaXs3HwT6pBF5hhQe3EqYhM7pSkesxhmgjZ0lEOYUc3uwBp0/A4YCVeUS0s GtR9DxFAQGCUqltKfrjjfhfnYNPW8RbAV2F8Z9tTdi86afRRwbhlBnp+QAaWGDwcVrZN +I/emyEcExatJ3f7+bkRvL/E31pKYtl+ipSFv3K1VXBy0D1ZJ16HD35UDc5VFNKu7DXg vlNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=FPRY8UVWv9cGrdDInnXSpgiKJyif+ICxuE8W09cIuik=; b=LZ1V7Ei5zh+X0c992WTXjtUGMcWNh+deSmO8o8K10mZkZtmd9zfjtNmy19Mlpa7x3E ZSF4M3/LNi2uTGEFv79NHN0wRWih8qc5WJImjcpbCvXrDnJ0kS2d61BN5qNar4BdFPGa TiMFG8IQWVhiJm7jnONrUxJtbT2Sxyy7bUFTgBGiufvk0MGpjVayhir6dvjNYjOLMDW9 5BfT3sTabCAxUL4MlO7pCGNPDX/uHE5MMNeo8xbVcmSML023hRDUFpR9yFgtzMAwoGBO Mi05AqntSQ7Ms6T/i92uCX2jDzOPvfSxFdQ+0vcWvIikxOdT3iNaHzgm3I3Xz8auBgSX CYZg== X-Gm-Message-State: APf1xPD+gzgqZPYxCSbZ/qgoDG3qqu4mpSS4XhLny1y/uF/K9mVdoCC9 uT4nUI7WrufOMxcYoHqKTSxOHEvLDjU= X-Google-Smtp-Source: AH8x226ki2ZHBqMSACMg+wtWzQAnMCmFUTsiF6J4/swKBDUZdwZL/Ou7HXDRLsPOPjGIxF1d1HmyGg== X-Received: by 10.223.150.65 with SMTP id c1mr6219286wra.167.1519300352916; Thu, 22 Feb 2018 03:52:32 -0800 (PST) Received: from ?IPv6:2a01:cb19:8114:fc00:6347:2353:f813:bb56? ([2a01:cb19:8114:fc00:6347:2353:f813:bb56]) by smtp.gmail.com with ESMTPSA id h50sm35070009wrf.65.2018.02.22.03.52.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 03:52:32 -0800 (PST) To: Vipin Varghese , dev@dpdk.org Cc: ferruh.yigit@intel.com, deepak.k.jain@intel.com References: <1518446689-26839-1-git-send-email-vipin.varghese@intel.com> From: Pascal Mazon Message-ID: <38c3cf78-4049-cc67-fdf7-4c3370a036de@6wind.com> Date: Thu, 22 Feb 2018 12:52:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1518446689-26839-1-git-send-email-vipin.varghese@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [dpdk-dev] [PATCH v1] net/tap: allow user MAC to be passed as args 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, 22 Feb 2018 11:52:33 -0000 Acked-by: Pascal Mazon On 12/02/2018 15:44, Vipin Varghese wrote: > Allow TAP PMD to pass user desired MAC address as argument. > The argument value is processed as string delimited by ':', > is parsed and converted to HEX MAC address after validation. > > Signed-off-by: Vipin Varghese > Signed-off-by: Pascal Mazon > --- > > Changes: > - seggrated the function for hex sting validation - Ferruh > - Fixed the logic lookup for MAC address > --- > drivers/net/tap/rte_eth_tap.c | 75 +++++++++++++++++++++++++++++++++---------- > 1 file changed, 58 insertions(+), 17 deletions(-) > > diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c > index 9d39384..5f67d51 100644 > --- a/drivers/net/tap/rte_eth_tap.c > +++ b/drivers/net/tap/rte_eth_tap.c > @@ -48,6 +48,10 @@ > #define ETH_TAP_MAC_ARG "mac" > #define ETH_TAP_MAC_FIXED "fixed" > > +#define ETH_TAP_USR_MAC_FMT "xx:xx:xx:xx:xx:xx" > +#define ETH_TAP_CMP_MAC_FMT "0123456789ABCDEFabcdef" > +#define ETH_TAP_MAC_ARG_FMT ETH_TAP_MAC_FIXED "|" ETH_TAP_USR_MAC_FMT > + > static struct rte_vdev_driver pmd_tap_drv; > > static const char *valid_arguments[] = { > @@ -1335,7 +1339,7 @@ enum ioctl_mode { > > static int > eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, > - char *remote_iface, int fixed_mac_type) > + char *remote_iface, struct ether_addr *mac_addr) > { > int numa_node = rte_socket_id(); > struct rte_eth_dev *dev; > @@ -1397,16 +1401,10 @@ enum ioctl_mode { > pmd->txq[i].fd = -1; > } > > - if (fixed_mac_type) { > - /* fixed mac = 00:64:74:61:70: */ > - static int iface_idx; > - char mac[ETHER_ADDR_LEN] = "\0dtap"; > - > - mac[ETHER_ADDR_LEN - 1] = iface_idx++; > - rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN); > - } else { > + if (is_zero_ether_addr(mac_addr)) > eth_random_addr((uint8_t *)&pmd->eth_addr); > - } > + else > + rte_memcpy(&pmd->eth_addr, mac_addr, sizeof(mac_addr)); > > /* Immediately create the netdevice (this will create the 1st queue). */ > /* rx queue */ > @@ -1567,15 +1565,58 @@ enum ioctl_mode { > return 0; > } > > +static int parse_user_mac(struct ether_addr *user_mac, > + const char *value) > +{ > + unsigned int index = 0; > + char mac_temp[strlen(ETH_TAP_USR_MAC_FMT) + 1], *mac_byte = NULL; > + > + if (user_mac == NULL || value == NULL) > + return 0; > + > + snprintf(mac_temp, sizeof(mac_temp), "%s", value); > + mac_byte = strtok(mac_temp, ":"); > + > + while ((mac_byte != NULL) && > + (strlen(mac_byte) <= 2) && > + (strlen(mac_byte) == strspn(mac_byte, > + ETH_TAP_CMP_MAC_FMT))) { > + user_mac->addr_bytes[index++] = strtoul(mac_byte, NULL, 16); > + mac_byte = strtok(NULL, ":"); > + } > + > + return index; > +} > + > static int > set_mac_type(const char *key __rte_unused, > const char *value, > void *extra_args) > { > - if (value && > - !strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED))) > - *(int *)extra_args = 1; > + struct ether_addr *user_mac = extra_args; > + > + if (!value) > + return 0; > + > + if (!strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED))) { > + static int iface_idx; > + > + /* fixed mac = 00:64:74:61:70: */ > + memcpy((char *)user_mac->addr_bytes, "\0dtap", ETHER_ADDR_LEN); > + user_mac->addr_bytes[ETHER_ADDR_LEN - 1] = iface_idx++ + '0'; > + goto success; > + } > + > + if (parse_user_mac(user_mac, value) != 6) > + goto error; > +success: > + RTE_LOG(DEBUG, PMD, "TAP user MAC param (%s)\n", value); > return 0; > + > +error: > + RTE_LOG(ERR, PMD, "TAP user MAC (%s) is not in format (%s|%s)\n", > + value, ETH_TAP_MAC_FIXED, ETH_TAP_USR_MAC_FMT); > + return -1; > } > > /* Open a TAP interface device. > @@ -1589,7 +1630,7 @@ enum ioctl_mode { > int speed; > char tap_name[RTE_ETH_NAME_MAX_LEN]; > char remote_iface[RTE_ETH_NAME_MAX_LEN]; > - int fixed_mac_type = 0; > + struct ether_addr user_mac; > > name = rte_vdev_device_name(dev); > params = rte_vdev_device_args(dev); > @@ -1626,7 +1667,7 @@ enum ioctl_mode { > ret = rte_kvargs_process(kvlist, > ETH_TAP_MAC_ARG, > &set_mac_type, > - &fixed_mac_type); > + &user_mac); > if (ret == -1) > goto leave; > } > @@ -1637,7 +1678,7 @@ enum ioctl_mode { > RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n", > name, tap_name); > > - ret = eth_dev_tap_create(dev, tap_name, remote_iface, fixed_mac_type); > + ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac); > > leave: > if (ret == -1) { > @@ -1701,5 +1742,5 @@ enum ioctl_mode { > RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap); > RTE_PMD_REGISTER_PARAM_STRING(net_tap, > ETH_TAP_IFACE_ARG "= " > - ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED " " > + ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_ARG_FMT " " > ETH_TAP_REMOTE_ARG "=");