DPDK patches and discussions
 help / color / mirror / Atom feed
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: Ferruh Yigit <ferruh.yigit@intel.com>
Cc: dev@dpdk.org, Thomas Monjalon <thomas@monjalon.net>,
	Andrew Rybchenko <arybchenko@solarflare.com>
Subject: [dpdk-dev] [PATCH v3 2/7] ethdev: add flow API item/action name conversion
Date: Fri, 31 Aug 2018 11:01:02 +0200	[thread overview]
Message-ID: <20180831085337.21419-3-adrien.mazarguil@6wind.com> (raw)
In-Reply-To: <20180831085337.21419-1-adrien.mazarguil@6wind.com>

This provides a means for applications to retrieve the name of flow pattern
items and actions.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Cc: Thomas Monjalon <thomas@monjalon.net>
Cc: Ferruh Yigit <ferruh.yigit@intel.com>
Cc: Andrew Rybchenko <arybchenko@solarflare.com>
--
v2 changes:

- Replaced rte_flow_conv_name_ptr() with extra is_ptr argument to
  rte_flow_conv_name() since both functions were almost identical.

- Properly documented internal helper functions.
---
 doc/guides/prog_guide/rte_flow.rst |  1 +
 lib/librte_ethdev/rte_flow.c       | 63 +++++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.h       | 56 +++++++++++++++++++++++++++++
 3 files changed, 120 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 964cf9ceb..1b17f6e01 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2437,6 +2437,7 @@ operations include:
 - Attributes, pattern item or action duplication.
 - Duplication of an entire pattern or list of actions.
 - Duplication of a complete flow rule description.
+- Pattern item or action name retrieval.
 
 Caveats
 -------
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 4fd6cfa76..c3ff7e713 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -11,6 +11,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_branch_prediction.h>
+#include <rte_string_fns.h>
 #include "rte_ethdev.h"
 #include "rte_flow_driver.h"
 #include "rte_flow.h"
@@ -679,6 +680,60 @@ rte_flow_conv_rule(struct rte_flow_conv_rule *dst,
 	return off;
 }
 
+/**
+ * Retrieve the name of a pattern item/action type.
+ *
+ * @param is_action
+ *   Nonzero when @p src represents an action type instead of a pattern item
+ *   type.
+ * @param is_ptr
+ *   Nonzero to write string address instead of contents into @p dst.
+ * @param[out] dst
+ *   Destination buffer. Can be NULL if @p size is zero.
+ * @param size
+ *   Size of @p dst in bytes.
+ * @param[in] src
+ *   Depending on @p is_action, source pattern item or action type cast as a
+ *   pointer.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *
+ * @return
+ *   A positive value representing the number of bytes needed to store the
+ *   name or its address regardless of @p size on success (@p buf contents
+ *   are truncated to @p size if not large enough), a negative errno value
+ *   otherwise and rte_errno is set.
+ */
+static int
+rte_flow_conv_name(int is_action,
+		   int is_ptr,
+		   char *dst,
+		   const size_t size,
+		   const void *src,
+		   struct rte_flow_error *error)
+{
+	struct desc_info {
+		const struct rte_flow_desc_data *data;
+		size_t num;
+	};
+	static const struct desc_info info_rep[2] = {
+		{ rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), },
+		{ rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), },
+	};
+	const struct desc_info *const info = &info_rep[!!is_action];
+	unsigned int type = (uintptr_t)src;
+
+	if (type >= info->num)
+		return rte_flow_error_set
+			(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+			 "unknown object type to retrieve the name of");
+	if (!is_ptr)
+		return strlcpy(dst, info->data[type].name, size);
+	if (size >= sizeof(const char **))
+		*((const char **)dst) = info->data[type].name;
+	return sizeof(const char **);
+}
+
 /** Helper function to convert flow API objects. */
 int
 rte_flow_conv(enum rte_flow_conv_op op,
@@ -708,6 +763,14 @@ rte_flow_conv(enum rte_flow_conv_op op,
 		return rte_flow_conv_actions(dst, size, src, 0, error);
 	case RTE_FLOW_CONV_OP_RULE:
 		return rte_flow_conv_rule(dst, size, src, error);
+	case RTE_FLOW_CONV_OP_ITEM_NAME:
+		return rte_flow_conv_name(0, 0, dst, size, src, error);
+	case RTE_FLOW_CONV_OP_ACTION_NAME:
+		return rte_flow_conv_name(1, 0, dst, size, src, error);
+	case RTE_FLOW_CONV_OP_ITEM_NAME_PTR:
+		return rte_flow_conv_name(0, 1, dst, size, src, error);
+	case RTE_FLOW_CONV_OP_ACTION_NAME_PTR:
+		return rte_flow_conv_name(1, 1, dst, size, src, error);
 	}
 	return rte_flow_error_set
 		(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 1288e76ae..052ceefb6 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -2043,6 +2043,62 @@ enum rte_flow_conv_op {
 	 *   @code struct rte_flow_conv_rule * @endcode
 	 */
 	RTE_FLOW_CONV_OP_RULE,
+
+	/**
+	 * Convert item type to its name string.
+	 *
+	 * Writes a NUL-terminated string to @p dst. Like snprintf(), the
+	 * returned value excludes the terminator which is always written
+	 * nonetheless.
+	 *
+	 * - @p src type:
+	 *   @code (const void *)enum rte_flow_item_type @endcode
+	 * - @p dst type:
+	 *   @code char * @endcode
+	 **/
+	RTE_FLOW_CONV_OP_ITEM_NAME,
+
+	/**
+	 * Convert action type to its name string.
+	 *
+	 * Writes a NUL-terminated string to @p dst. Like snprintf(), the
+	 * returned value excludes the terminator which is always written
+	 * nonetheless.
+	 *
+	 * - @p src type:
+	 *   @code (const void *)enum rte_flow_action_type @endcode
+	 * - @p dst type:
+	 *   @code char * @endcode
+	 **/
+	RTE_FLOW_CONV_OP_ACTION_NAME,
+
+	/**
+	 * Convert item type to pointer to item name.
+	 *
+	 * Retrieves item name pointer from its type. The string itself is
+	 * not copied; instead, a unique pointer to an internal static
+	 * constant storage is written to @p dst.
+	 *
+	 * - @p src type:
+	 *   @code (const void *)enum rte_flow_item_type @endcode
+	 * - @p dst type:
+	 *   @code const char ** @endcode
+	 */
+	RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
+
+	/**
+	 * Convert action type to pointer to action name.
+	 *
+	 * Retrieves action name pointer from its type. The string itself is
+	 * not copied; instead, a unique pointer to an internal static
+	 * constant storage is written to @p dst.
+	 *
+	 * - @p src type:
+	 *   @code (const void *)enum rte_flow_action_type @endcode
+	 * - @p dst type:
+	 *   @code const char ** @endcode
+	 */
+	RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
 };
 
 /**
-- 
2.11.0

  parent reply	other threads:[~2018-08-31  9:01 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-05  9:49 [dpdk-dev] [PATCH v1 0/7] Flow API helpers enhancements Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 1/7] ethdev: expose flow API error helper Adrien Mazarguil
2017-10-11  9:23   ` Thomas Monjalon
2017-10-11 11:56     ` Adrien Mazarguil
2017-10-11 19:05       ` Aaron Conole
2017-10-12 13:37         ` Neil Horman
2017-10-12 14:02         ` Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 2/7] ethdev: replace flow API object copy function Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 3/7] ethdev: add flow API item/action name conversion Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 4/7] app/testpmd: rely on flow API conversion function Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 5/7] ethdev: enhance flow API item/action descriptions Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 6/7] ethdev: generate flow API conversion header Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 7/7] ethdev: update " Adrien Mazarguil
2017-10-06  1:13 ` [dpdk-dev] [PATCH v1 0/7] Flow API helpers enhancements Ferruh Yigit
2017-10-06  8:05   ` Adrien Mazarguil
2017-10-10 18:05     ` Ferruh Yigit
2017-10-11  9:57       ` Adrien Mazarguil
2017-10-11 18:07         ` Ferruh Yigit
2017-10-12 12:53           ` Adrien Mazarguil
2017-10-12 16:37             ` Ferruh Yigit
2017-10-13 10:42               ` Adrien Mazarguil
2018-08-03 13:36 ` [dpdk-dev] [PATCH v2 0/7] ethdev: add flow API object converter Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 1/7] " Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 2/7] ethdev: add flow API item/action name conversion Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 3/7] app/testpmd: rely on flow API conversion function Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 4/7] net/failsafe: switch to flow API object " Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 5/7] net/bonding: " Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 6/7] ethdev: deprecate rte_flow_copy function Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 7/7] ethdev: add missing item/actions to flow object converter Adrien Mazarguil
2018-08-03 14:06   ` [dpdk-dev] [PATCH v2 0/7] ethdev: add flow API " Thomas Monjalon
2018-08-23 13:48   ` Ferruh Yigit
2018-08-27 15:14     ` Adrien Mazarguil
2018-08-24 10:58   ` Ferruh Yigit
2018-08-27 14:12     ` Adrien Mazarguil
2018-08-31  9:00   ` [dpdk-dev] [PATCH v3 " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 1/7] " Adrien Mazarguil
2018-08-31  9:01     ` Adrien Mazarguil [this message]
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 3/7] app/testpmd: rely on flow API conversion function Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 4/7] net/failsafe: switch to flow API object " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 5/7] net/bonding: " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 6/7] ethdev: add missing items/actions to flow object converter Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 7/7] ethdev: deprecate rte_flow_copy function Adrien Mazarguil
2018-10-04 14:21       ` Ferruh Yigit
2018-08-31 11:32     ` [dpdk-dev] [PATCH v3 0/7] ethdev: add flow API object converter Nélio Laranjeiro
2018-10-03 20:31       ` Thomas Monjalon
2018-10-04 14:25         ` 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=20180831085337.21419-3-adrien.mazarguil@6wind.com \
    --to=adrien.mazarguil@6wind.com \
    --cc=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=thomas@monjalon.net \
    /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).