The "rte_flow_item_geneve_opt" structure has field for option length.
This field has 2 different usages which might limit each other:

 1. field to matching with value/mask.
 2. descriptor for data array size.

This patch adds a new field "data_array_size" into
"rte_flow_item_geneve_opt" structure in addition to existing
"option_len" field.

Signed-off-by: Michael Baum <michae...@nvidia.com>
---
 app/test-pmd/cmdline_flow.c                 | 10 ++++++
 doc/guides/prog_guide/rte_flow.rst          | 16 +++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  3 +-
 lib/ethdev/rte_flow.c                       | 36 ++++++++++-----------
 lib/ethdev/rte_flow.h                       |  3 +-
 5 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 60ee9337cf..966a47936a 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -492,6 +492,7 @@ enum index {
        ITEM_GENEVE_OPT_TYPE,
        ITEM_GENEVE_OPT_LENGTH,
        ITEM_GENEVE_OPT_DATA,
+       ITEM_GENEVE_OPT_DATA_ARRAY_SIZE,
        ITEM_INTEGRITY,
        ITEM_INTEGRITY_LEVEL,
        ITEM_INTEGRITY_VALUE,
@@ -2032,6 +2033,7 @@ static const enum index item_geneve_opt[] = {
        ITEM_GENEVE_OPT_TYPE,
        ITEM_GENEVE_OPT_LENGTH,
        ITEM_GENEVE_OPT_DATA,
+       ITEM_GENEVE_OPT_DATA_ARRAY_SIZE,
        ITEM_NEXT,
        ZERO,
 };
@@ -5772,6 +5774,14 @@ static const struct token token_list[] = {
                                (sizeof(struct rte_flow_item_geneve_opt),
                                ITEM_GENEVE_OPT_DATA_SIZE)),
        },
+       [ITEM_GENEVE_OPT_DATA_ARRAY_SIZE] = {
+               .name = "data_size",
+               .help = "GENEVE option data array size",
+               .next = NEXT(item_geneve_opt, NEXT_ENTRY(COMMON_UNSIGNED),
+                            item_param),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_item_geneve_opt,
+                                       data_array_size)),
+       },
        [ITEM_INTEGRITY] = {
                .name = "integrity",
                .help = "match packet integrity",
diff --git a/doc/guides/prog_guide/rte_flow.rst 
b/doc/guides/prog_guide/rte_flow.rst
index dad588763f..cce02fe1d6 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1092,6 +1092,22 @@ Matches a GENEVE header.
 - ``rsvd1``: reserved, normally 0x00.
 - Default ``mask`` matches VNI only.
 
+
+Item: ``GENEVE_OPT``
+^^^^^^^^^^^^^^^^^^^^
+
+Matches a GENEVE TLV option header.
+
+- ``option_class``: option class ID.
+- ``option_type``: option type.
+- ``option_len``: option data length in 4-bytes granularity.
+- ``data``: option data array.
+- ``data_array_size``: option data array size.
+  This field is not matchable, it is descriptor how to read the array.
+  It should be specified in ``mask`` as well.
+- Default ``mask`` matches type only.
+
+
 Item: ``VXLAN-GPE``
 ^^^^^^^^^^^^^^^^^^^
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst 
b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 2fbf9220d8..97623044e9 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3743,7 +3743,8 @@ This section lists supported pattern items and their 
attributes, if any.
   - ``type {unsigned}``: GENEVE option type.
   - ``length {unsigned}``: GENEVE option length in 32-bit words.
   - ``data {hex string}``: GENEVE option data, the length is defined by
-    ``length`` field.
+    ``data_size`` field.
+  - ``data_size {unsigned}``: GENEVE option data size in 32-bit words.
 
 - ``vxlan-gpe``: match VXLAN-GPE header.
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 2803507462..d68359961d 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -81,6 +81,21 @@ rte_flow_item_flex_conv(void *buf, const void *data)
        return src->length;
 }
 
+static size_t
+rte_flow_item_geneve_opt_conv(void *buf, const void *data)
+{
+       const struct rte_flow_item_geneve_opt *src = data;
+       uint16_t byte_size = src->data_array_size << 2;
+
+       if (buf) {
+               struct rte_flow_item_geneve_opt *dst = buf;
+               void *deep_src = (void *)((uintptr_t)(dst + 1));
+
+               dst->data = rte_memcpy(deep_src, src->data, byte_size);
+       }
+       return byte_size;
+}
+
 /** Generate flow_item[] entry. */
 #define MK_FLOW_ITEM(t, s) \
        [RTE_FLOW_ITEM_TYPE_ ## t] = { \
@@ -155,7 +170,8 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] 
= {
        MK_FLOW_ITEM(L2TPV3OIP, sizeof(struct rte_flow_item_l2tpv3oip)),
        MK_FLOW_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
        MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
-       MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)),
+       MK_FLOW_ITEM_FN(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt),
+                       rte_flow_item_geneve_opt_conv),
        MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)),
        MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)),
        MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)),
@@ -622,7 +638,6 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
        switch (item->type) {
                union {
                        const struct rte_flow_item_raw *raw;
-                       const struct rte_flow_item_geneve_opt *geneve_opt;
                } spec;
                union {
                        const struct rte_flow_item_raw *raw;
@@ -632,11 +647,9 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
                } mask;
                union {
                        const struct rte_flow_item_raw *raw;
-                       const struct rte_flow_item_geneve_opt *geneve_opt;
                } src;
                union {
                        struct rte_flow_item_raw *raw;
-                       struct rte_flow_item_geneve_opt *geneve_opt;
                } dst;
                void *deep_src;
                size_t tmp;
@@ -676,21 +689,6 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
                        off += tmp;
                }
                break;
-       case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
-               off = rte_flow_conv_copy(buf, data, size,
-                                        rte_flow_desc_item, item->type);
-               spec.geneve_opt = item->spec;
-               src.geneve_opt = data;
-               dst.geneve_opt = buf;
-               tmp = spec.geneve_opt->option_len << 2;
-               if (size > 0 && src.geneve_opt->data) {
-                       deep_src = (void *)((uintptr_t)(dst.geneve_opt + 1));
-                       dst.geneve_opt->data = rte_memcpy(deep_src,
-                                                         src.geneve_opt->data,
-                                                         tmp);
-               }
-               off += tmp;
-               break;
        default:
                off = rte_flow_conv_copy(buf, data, size,
                                         rte_flow_desc_item, item->type);
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 6e8ab1d4c7..0ccb7562bd 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -1876,7 +1876,8 @@ struct rte_flow_item_geneve_opt {
        rte_be16_t option_class;
        uint8_t option_type;
        uint8_t option_len;
-       uint32_t *data;
+       rte_be32_t *data;
+       uint8_t data_array_size;
 };
 
 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE_OPT. */
-- 
2.25.1

Reply via email to