From patchwork Fri Aug 31 09:01:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 44069 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 60ACF4CB5; Fri, 31 Aug 2018 11:01:23 +0200 (CEST) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by dpdk.org (Postfix) with ESMTP id 108134CAB for ; Fri, 31 Aug 2018 11:01:21 +0200 (CEST) Received: by mail-wm0-f50.google.com with SMTP id j25-v6so2842609wmc.1 for ; Fri, 31 Aug 2018 02:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cg7wPrCBOR0XWnMPnT8WQUETRScquCCH7BEk6idb1tk=; b=cTYTBWYL0pk7Xso0eW0Hzc4nkJ4oipwKPEqniJzDLmaZJaqWxdKkBQqjwnzXYlEIGD kXUTaPlOIPHgNLwVwwHFx9/Um7DmsGcPoYmskwkmg7Y8Ox6Hotc1I8j6sLJizk3G3/I4 AvQnFdZzKNov6hJfnU4PzJVoN5qUDpaVfnLFlLclBdnZtORXqFaDz6i8kZjasCk/WWE4 uuAQiMG8Jn6bCWsFgLIROoBjbeMAjoi8IjPm0VYKLnaz3R+NA7zbLwE3/7RQ7V6pRX1S ARtRADZCGrjgQLUsINtHZFcYY+lFfJofEJIMWdoidkx+YkHIBpqtaZxdeQa3d5oRrJBa cRtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cg7wPrCBOR0XWnMPnT8WQUETRScquCCH7BEk6idb1tk=; b=Eees3gRjm9KGmln9dgVR5EwXutxBT+7r1iKgFZCKVKuhDsETip+zEbuU2WFVuIbfZk +/UdmLKyqHUZTj+wm6ILsAE5/f2S8U0bVAyXP20yvvkQXRdCru/XvfpDwejQ7uuabOT9 2EOcLSNhb6GqYXyzq4FYcIXoxJxseFGk2qEHAAW1my0OFAsUhl+PyIyk13Cp2JCMaHnL L7bprdEd7FpNo01dez2TxkhzLolS/Ze7clCYOvdg1Aha/1e6SWXpbl/uH9peJhNIqybG baP3xS56299EaMRZo6bgTahiaTQuR3cR9gKpQ1aLz/prtboT6K9ktnNcfqDAgJWnFLki d5cw== X-Gm-Message-State: APzg51CzB7hzX6fpQld7IGSFMSeUNpOQnYMp8VrU35X7EVw5V9Wq7q8e Q+AkzJfUN1Lq5W+d47xU5kfysQ== X-Google-Smtp-Source: ANB0VdZor3ngWMpkDs1WG3fvJRUk0FSUQTMNDi9dQScM1Rm4U3za6Tpc8aB4QqU7+YB3T4l5PAvN5w== X-Received: by 2002:a1c:9b91:: with SMTP id d139-v6mr4395888wme.50.1535706079322; Fri, 31 Aug 2018 02:01:19 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id t9-v6sm891994wmf.1.2018.08.31.02.01.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Aug 2018 02:01:18 -0700 (PDT) Date: Fri, 31 Aug 2018 11:01:02 +0200 From: Adrien Mazarguil To: Ferruh Yigit Cc: dev@dpdk.org, Thomas Monjalon , Andrew Rybchenko Message-ID: <20180831085337.21419-3-adrien.mazarguil@6wind.com> References: <20180803132032.29038-1-adrien.mazarguil@6wind.com> <20180831085337.21419-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180831085337.21419-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH v3 2/7] ethdev: add flow API item/action name conversion 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" This provides a means for applications to retrieve the name of flow pattern items and actions. Signed-off-by: Adrien Mazarguil Cc: Thomas Monjalon Cc: Ferruh Yigit Cc: Andrew Rybchenko --- 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 #include #include +#include #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, }; /**