From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id 5A25E1B19A for ; Thu, 5 Oct 2017 11:49:24 +0200 (CEST) Received: by mail-wm0-f46.google.com with SMTP id m72so1092907wmc.0 for ; Thu, 05 Oct 2017 02:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yHXrz04oZ2OpvAscRY36DlTM4Qw/SiU8y1njfYSAPAs=; b=I31klswu+YzZp1h5SYpgyQ7RI+DoiZ0iF1HZrHx05kDO5wW4qbbfQRSC1nBdwCdRNw iAZ46oJ42+WcJXHVq0dhng965eLlds9eWf8FqJjWPYIkEWbNKdwZ9ATsGLRpXr6xtpfX 3pRhAYoYM0bicxrTwEYT+YK4MzHltFV0LtxrrZWo+tGle3sL0DX+WI6IF3gkA9dPN2+l dQRYdYv/LlRnWlK94PRoJUarahMIeKgyKyV48lxKF57xinZvEfKK5h4UDXo2JAKwdwge e45LCMFV7JR39us2XdmYJeh7FcoT/arlUImeEq/nd0hpSxBJp21XcKfXxecubSHpw0v1 QxVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yHXrz04oZ2OpvAscRY36DlTM4Qw/SiU8y1njfYSAPAs=; b=Fv4zU9OOn0Ph/v/a3hUX1IjpydlI8K+M473zeoP+DqfBSrfUoCJfEE+UQtalWwMFKs f3KIbEs9eN/IDBmh5nRDgdFpc/F2+DqpIYlgbXPNVKnfxYhlioX3+mIwur3w9wUYhp2r i7xz4+NWb7PcXxw2uBhuBV4KSd3IpUpp/m0RG5Gb3D/2ETPE58ebNl9x5xaATVFWdRkR kIGBo8ZdHpp0c2kCjRq8MtejCJyOO7cIRKBENHtIjp0JLrbFmX2dBev1n/j+ju0GcbJy 1TMGQnbyGGYytIyG/R6uyHN0nxAF50aiD7xqXeXy9o0X3iDesCoLdIVmDqtbS0Y09Ztl U06A== X-Gm-Message-State: AHPjjUgVzSadskLLOCNrbP7jnSaKcZal/sQ9GnArr4zP/dmlz3ilmcve ucwqhBvzwHpc6+37jxUgGBVB0A== X-Google-Smtp-Source: AOwi7QAQdixJl0UaslX/v1UoPlzDgNcy9BcsWcpBcDOVSJn0onBy/INMUp58Id4D/Qw1NcGI7zaK3w== X-Received: by 10.80.144.131 with SMTP id c3mr32020781eda.120.1507196963937; Thu, 05 Oct 2017 02:49:23 -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 g3sm4277763edi.35.2017.10.05.02.49.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 02:49:23 -0700 (PDT) From: Adrien Mazarguil To: Ferruh Yigit , Gaetan Rivet Cc: dev@dpdk.org Date: Thu, 5 Oct 2017 11:49:04 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 3/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: , X-List-Received-Date: Thu, 05 Oct 2017 09:49:24 -0000 This provides a means for applications to retrieve the name of flow pattern items and actions. Signed-off-by: Adrien Mazarguil --- doc/guides/prog_guide/rte_flow.rst | 1 + lib/librte_ether/rte_flow.c | 62 +++++++++++++++++++++++++++++++++ lib/librte_ether/rte_flow.h | 52 +++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 5026730..a346ba5 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -1715,6 +1715,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_ether/rte_flow.c b/lib/librte_ether/rte_flow.c index 03a4d35..f4fb607 100644 --- a/lib/librte_ether/rte_flow.c +++ b/lib/librte_ether/rte_flow.c @@ -465,6 +465,60 @@ rte_flow_conv_rule(struct rte_flow_conv_rule *dst, "not enough room for alignment padding"); } +/** Internal helper to convert an object type to a string. */ +static int +rte_flow_conv_name(int is_action, + char *dst, + size_t size, + const void *src, + struct rte_flow_error *error) +{ + const struct { + const struct rte_flow_desc_data *data; + size_t num; + } res_data[2] = { + { rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), }, + { rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), }, + }, *const res = &res_data[!!is_action]; + unsigned int obj_type = (uintptr_t)src; + + if (obj_type >= res->num) + return rte_flow_error_set + (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "unknown object type to retrieve name for"); + return snprintf(dst, size, "%s", res->data[obj_type].name); +} + +/** Internal helper to convert an object type to a pointer to its name. */ +static int +rte_flow_conv_name_ptr(int is_action, + const char **dst, + size_t size, + const void *src, + struct rte_flow_error *error) +{ + const struct { + const struct rte_flow_desc_data *data; + size_t num; + } res_data[2] = { + { rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), }, + { rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), }, + }, *const res = &res_data[!!is_action]; + unsigned int obj_type = (uintptr_t)src; + + if (obj_type >= res->num) + return rte_flow_error_set + (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "unknown object type to retrieve name for"); + if (size && size < sizeof(const char **)) + return rte_flow_error_set + (error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "not enough room for object name pointer"); + if (size) + *((const char **)dst) = res->data[obj_type].name; + return sizeof(const char **); +} + /** Helper function to convert flow API objects. */ int rte_flow_conv(enum rte_flow_conv_op op, @@ -497,6 +551,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, dst, size, src, error); + case RTE_FLOW_CONV_OP_ACTION_NAME: + return rte_flow_conv_name(1, dst, size, src, error); + case RTE_FLOW_CONV_OP_ITEM_NAME_PTR: + return rte_flow_conv_name_ptr(0, dst, size, src, error); + case RTE_FLOW_CONV_OP_ACTION_NAME_PTR: + return rte_flow_conv_name_ptr(1, dst, size, src, error); } return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, diff --git a/lib/librte_ether/rte_flow.h b/lib/librte_ether/rte_flow.h index 3d06bdc..01c711e 100644 --- a/lib/librte_ether/rte_flow.h +++ b/lib/librte_ether/rte_flow.h @@ -1180,6 +1180,58 @@ 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()). + * + * - @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()). + * + * - @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.1.4