From patchwork Thu Nov 30 19:49:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Varghese, Vipin" X-Patchwork-Id: 31837 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 315397D4A; Thu, 30 Nov 2017 19:27:13 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 740B23257 for ; Thu, 30 Nov 2017 15:09:11 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Nov 2017 06:09:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.45,341,1508828400"; d="scan'208"; a="1250312217" Received: from unknown (HELO localhost.localdomain) ([10.224.122.203]) by fmsmga002.fm.intel.com with ESMTP; 30 Nov 2017 06:09:08 -0800 From: Vipin Varghese To: dev@dpdk.org Cc: david.hunt@intel.com, deepak.k.jain@intel.com, Vipin Varghese Date: Fri, 1 Dec 2017 01:19:56 +0530 Message-Id: <1512071396-10653-1-git-send-email-vipin.varghese@intel.com> X-Mailer: git-send-email 1.9.1 X-Mailman-Approved-At: Thu, 30 Nov 2017 19:27:12 +0100 Subject: [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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" One of the uses cases from customer site is use TAP PMD to intake user specific MAC address during probe. This allows applications make use of interfaces with desired MAC. Extending MAC argumentinfrastructure for tap PMD; we pass custom MAC address in string format (sample - 11:22:33:44:55:66). Signed-off-by: Vipin Varghese --- drivers/net/tap/rte_eth_tap.c | 56 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 6b27679..0c53458 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -81,6 +81,8 @@ #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0) #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0) +static unsigned char user_mac[ETHER_ADDR_LEN]; + static struct rte_vdev_driver pmd_tap_drv; static const char *valid_arguments[] = { @@ -1291,13 +1293,20 @@ enum ioctl_mode { pmd->txq[i].fd = -1; } - if (fixed_mac_type) { + if (fixed_mac_type == 1) { /* 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 (fixed_mac_type == 2) { + /* user mac is recieved */ + RTE_LOG(INFO, PMD, + "Using user MAC (%02x:%02x:%02x:%02x:%02x:%02x)\n", + user_mac[0], user_mac[1], user_mac[2], + user_mac[3], user_mac[4], user_mac[5]); + rte_memcpy(&pmd->eth_addr, user_mac, ETHER_ADDR_LEN); } else { eth_random_addr((uint8_t *)&pmd->eth_addr); } @@ -1471,9 +1480,48 @@ enum ioctl_mode { const char *value, void *extra_args) { - if (value && - !strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED))) - *(int *)extra_args = 1; + char macTemp[20], *macByte = NULL; + unsigned int index = 0; + + if (value) { + if (!strncasecmp(ETH_TAP_MAC_FIXED, value, + strlen(ETH_TAP_MAC_FIXED))) { + *(int *)extra_args = 1; + } else { + RTE_LOG(INFO, PMD, "User shared MAC param (%s)\n", + value); + + /* desired format aa:bb:cc:dd:ee:ff:11 */ + if (strlen(value) == 17) { + strncpy(macTemp, value, 18); + + macByte = strtok(macTemp, ":"); + while ((macByte != NULL) && + (strspn(macByte, "0123456789ABCDEFabcdef")) && + (strspn((macByte + 1), "0123456789ABCDEFabcdef")) && + (strlen(macByte) == 2)) { + user_mac[index] = strtoul(macByte, NULL, 16); + macByte = strtok(NULL, ":"); + index += 1; + } + + if (index != 6) { + RTE_LOG(ERR, PMD, " failure in MAC value (%s) at %u\n", + macByte, index + 1); + return -1; + } + + RTE_LOG(DEBUG, PMD, " User MAC (%s) considered\n", + value); + *(int *)extra_args = 2; + } else { + RTE_LOG(ERR, PMD, " Mismatch on format for (%s)\n", + value); + return -1; + } + } + } + return 0; }