From: Vipin Varghese <vipin.varghese@intel.com>
To: dev@dpdk.org, ferruh.yigit@intel.com, pascal.mazon@6wind.com
Cc: Vipin Varghese <vipin.varghese@intel.com>
Subject: [dpdk-dev] [PATCH v3] net/tap: allow user MAC to be passed as args
Date: Tue, 13 Mar 2018 03:23:52 +0530 [thread overview]
Message-ID: <1520891632-11092-1-git-send-email-vipin.varghese@intel.com> (raw)
In-Reply-To: <1520886094-28319-1-git-send-email-vipin.varghese@intel.com>
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 <vipin.varghese@intel.com>
Acked-by: Pascal Mazon <pascal.mazon@6wind.com>
---
Changed in V3:
- change the default init for user_mac - Ferruh
Changes in V2:
- updated the auto variable for user_mac - Ferruh
- added documentation update - Vipin
---
doc/guides/nics/tap.rst | 6 ++++
drivers/net/tap/rte_eth_tap.c | 75 +++++++++++++++++++++++++++++++++----------
2 files changed, 64 insertions(+), 17 deletions(-)
diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst
index ea61be3..76eb0bd 100644
--- a/doc/guides/nics/tap.rst
+++ b/doc/guides/nics/tap.rst
@@ -37,6 +37,12 @@ for each interface string containing ``mac=fixed``. The MAC address is formatted
as 00:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
actual MAC address: ``00:64:74:61:70:[00-FF]``.
+ --vdev=net_tap0,mac="00:64:74:61:70:11"
+
+The MAC address will have a user value passed as string. The MAC address is in
+format with delimeter ``:``. The string is byte converted to hex and you get
+the actual MAC address: ``00:64:74:61:70:11``.
+
It is possible to specify a remote netdevice to capture packets from by adding
``remote=foo1``, for example::
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index f09db0e..3e4f7a8 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[] = {
@@ -1337,7 +1341,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;
@@ -1399,16 +1403,10 @@ enum ioctl_mode {
pmd->txq[i].fd = -1;
}
- if (fixed_mac_type) {
- /* 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 (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 */
@@ -1569,15 +1567,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:<iface_idx> */
+ 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.
@@ -1591,7 +1632,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 = { .addr_bytes = {0} };
name = rte_vdev_device_name(dev);
params = rte_vdev_device_args(dev);
@@ -1628,7 +1669,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;
}
@@ -1639,7 +1680,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) {
@@ -1703,5 +1744,5 @@ enum ioctl_mode {
RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
RTE_PMD_REGISTER_PARAM_STRING(net_tap,
ETH_TAP_IFACE_ARG "=<string> "
- ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED " "
+ ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_ARG_FMT " "
ETH_TAP_REMOTE_ARG "=<string>");
--
1.9.1
next prev parent reply other threads:[~2018-03-12 16:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-31 18:22 [dpdk-dev] [PATCH] " Vipin Varghese
2018-02-02 9:16 ` Pascal Mazon
2018-02-02 9:49 ` Varghese, Vipin
2018-02-05 8:23 ` Varghese, Vipin
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-02-22 11:52 ` Pascal Mazon
2018-03-06 16:41 ` Ferruh Yigit
2018-03-07 9:44 ` Varghese, Vipin
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
2018-03-12 21:53 ` Vipin Varghese [this message]
2018-03-12 17:45 ` [dpdk-dev] [PATCH v3] " Ferruh Yigit
2018-03-16 14:22 ` Ferruh Yigit
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=1520891632-11092-1-git-send-email-vipin.varghese@intel.com \
--to=vipin.varghese@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=pascal.mazon@6wind.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).