DPDK patches and discussions
 help / color / mirror / Atom feed
From: Vipin Varghese <vipin.varghese@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, deepak.k.jain@intel.com,
	amol.patel@intel.com, Vipin Varghese <vipin.varghese@intel.com>
Subject: [dpdk-dev] [PATCH v2] net/tap: allow user mac to be passed as args
Date: Thu, 21 Dec 2017 21:31:00 +0530	[thread overview]
Message-ID: <1513872060-4758-1-git-send-email-vipin.varghese@intel.com> (raw)
In-Reply-To: <1512071396-10653-1-git-send-email-vipin.varghese@intel.com>

Added fixes for user TAP user MAC
1) user format to RTE_PMD_REGISTER_PARAM_STRING
2) TAP to the RTE_LOG in absence of dynamic RTE_LOG
3) Boundary case for MAC string added

---------------------------------------------------------------

Other Details:
1) not to extract "string to mac" conversion to its own function
2) set_mac_type does not take any pmd or device name
3) Segault for boundary cases 'mac="01:01:01:01:01:01', not found
4) Added user MAC format string

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
---
 drivers/net/tap/rte_eth_tap.c | 80 ++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 39 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 0c53458..85c12af 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -81,6 +81,11 @@
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)
 
+#define MAC_STRING_NULL (0)
+#define MAC_STRING_FIXED (1)
+#define MAC_STRING_USER (2)
+#define ETH_TAP_USER_MAC_FMT ("xx:xx:xx:xx:xx:xx")
+
 static unsigned char user_mac[ETHER_ADDR_LEN];
 
 static struct rte_vdev_driver pmd_tap_drv;
@@ -1293,17 +1298,18 @@ enum ioctl_mode {
 		pmd->txq[i].fd = -1;
 	}
 
-	if (fixed_mac_type == 1) {
+	if (fixed_mac_type == MAC_STRING_FIXED) {
 		/* fixed mac = 00:64:74:61:70:<iface_idx> */
 		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 */
+	} else if (fixed_mac_type == MAC_STRING_USER) {
+		/* user mac is received */
 		RTE_LOG(INFO, PMD,
-			"Using user MAC (%02x:%02x:%02x:%02x:%02x:%02x)\n",
+			"%s; Using user MAC (%02x:%02x:%02x:%02x:%02x:%02x) argument\n",
+			pmd->name,
 			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);
@@ -1476,53 +1482,49 @@ enum ioctl_mode {
 }
 
 static int
-set_mac_type(const char *key __rte_unused,
-	     const char *value,
-	     void *extra_args)
+set_mac_type(const char *key __rte_unused, const char *value, void *extra_args)
 {
-	char macTemp[20], *macByte = NULL;
+	char mac_temp[20] = {0}, *mac_byte = NULL;
 	unsigned int index = 0;
 
 	if (value) {
+		RTE_LOG(DEBUG, PMD, "TAP user MAC (%s) to set.\n", value);
+
 		if (!strncasecmp(ETH_TAP_MAC_FIXED, value,
 			strlen(ETH_TAP_MAC_FIXED))) {
-			*(int *)extra_args = 1;
+			*(int *)extra_args = MAC_STRING_FIXED;
 		} 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, ":");
+				strncpy(mac_temp, value, 18);
+				mac_temp[19] = "\0";
+				mac_byte = strtok(mac_temp, ":");
+
+				while ((mac_byte != NULL) &&
+					(strspn(mac_byte, "0123456789ABCDEFabcdef")) &&
+					(strspn((mac_byte + 1), "0123456789ABCDEFabcdef")) &&
+					(strlen(mac_byte) == 2)) {
+					user_mac[index] = strtoul(mac_byte, NULL, 16);
+					mac_byte = strtok(NULL, ":");
 					index += 1;
 				}
 
-				if (index != 6) {
-					RTE_LOG(ERR, PMD, " failure in MAC value (%s) at %u\n",
-						macByte, index + 1);
-					return -1;
-				}
+				if (index != 6)
+					goto error;
 
-				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;
-			}
+				*(int *)extra_args = MAC_STRING_USER;
+			} else
+				goto error;
 		}
+		RTE_LOG(DEBUG, PMD, "TAP user MAC (%s) considered\n", value);
 	}
 
 	return 0;
+
+error:
+	RTE_LOG(ERR, PMD, "TAP user MAC (%s) is not in format (%s)\n",
+		value, ETH_TAP_USER_MAC_FMT);
+	return -1;
 }
 
 /* Open a TAP interface device.
@@ -1536,7 +1538,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;
+	int fixed_mac_type = MAC_STRING_NULL;
 
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
@@ -1656,7 +1658,7 @@ enum ioctl_mode {
 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
 RTE_PMD_REGISTER_PARAM_STRING(net_tap,
-			      ETH_TAP_IFACE_ARG "=<string> "
-			      ETH_TAP_SPEED_ARG "=<int> "
-			      ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED " "
-			      ETH_TAP_REMOTE_ARG "=<string>");
+	ETH_TAP_IFACE_ARG "=<string> "
+	ETH_TAP_SPEED_ARG "=<int> "
+	ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED "|" ETH_TAP_USER_MAC_FMT " "
+	ETH_TAP_REMOTE_ARG "=<string>");
-- 
1.9.1

  parent reply	other threads:[~2017-12-21 10:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30 19:49 [dpdk-dev] [PATCH v1] " Vipin Varghese
2017-12-07 20:11 ` Ferruh Yigit
2017-12-08 10:14   ` Pascal Mazon
2017-12-16  2:21   ` Varghese, Vipin
2017-12-21 16:01 ` Vipin Varghese [this message]
2018-01-16 11:32   ` [dpdk-dev] [PATCH v2] " Ferruh Yigit
2018-01-31 18:22 [dpdk-dev] [PATCH] net/tap: allow user MAC " Vipin Varghese
2018-02-05 15:54 ` [dpdk-dev] [PATCH v2] " Pascal Mazon
2018-02-05 15:58   ` Varghese, Vipin
2018-02-05 18:13     ` Varghese, Vipin
2018-02-05 18:42   ` Ferruh Yigit
2018-02-12 14:44 [dpdk-dev] [PATCH v1] " Vipin Varghese
2018-03-12 20:21 ` [dpdk-dev] [PATCH v2] " Vipin Varghese
2018-03-12 15:08   ` Ferruh Yigit
2018-03-12 15:38     ` Varghese, Vipin
2018-03-12 17:33   ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513872060-4758-1-git-send-email-vipin.varghese@intel.com \
    --to=vipin.varghese@intel.com \
    --cc=amol.patel@intel.com \
    --cc=deepak.k.jain@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).