[PATCH v3 1/3] ethdev: add ICMPv6 ID and sequence
Leo Xu
yongquanx at nvidia.com
Sun Feb 5 14:41:52 CET 2023
This patch adds API support for ICMPv6 ID and sequence.
1: Add two new pattern item types for ICMPv6 echo request and reply:
RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST
RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY
2: Add new structures for ICMP packet definitions.
struct rte_icmp_base_hdr; # For basic header of all ICMP/ICMPv6 header
struct rte_icmp_echo_hdr; # For ICMP/ICMPv6 echo header
The existing struct rte_icmp_hdr should not be used in new code. It
should be set to be deprecated in future. The reason for that is,
icmp_ident/icmp_seq_nb are not common fields of ICMP/ICMPv6 packets.
3: Enhance testpmd flow pattern to support ICMPv6 identifier and sequence.
Example of ICMPv6 echo pattern in testpmd command:
pattern eth / ipv6 / icmp6_echo_request / end
pattern eth / ipv6 / icmp6_echo_reply / end
pattern eth / ipv6 / icmp6_echo_request ident is 20 seq is 30 / end
Signed-off-by: Leo Xu <yongquanx at nvidia.com>
Acked-by: Ori Kam <orika at nvidia.com>
---
.mailmap | 1 +
app/test-pmd/cmdline_flow.c | 70 +++++++++++++++++++++
doc/guides/nics/features/default.ini | 2 +
doc/guides/prog_guide/rte_flow.rst | 14 +++++
doc/guides/rel_notes/release_23_03.rst | 5 ++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 10 +++
lib/ethdev/rte_flow.c | 2 +
lib/ethdev/rte_flow.h | 24 +++++++
lib/net/rte_icmp.h | 22 +++++++
9 files changed, 150 insertions(+)
diff --git a/.mailmap b/.mailmap
index 75884b6fe2..310853bd5e 100644
--- a/.mailmap
+++ b/.mailmap
@@ -728,6 +728,7 @@ Lei Gong <arei.gonglei at huawei.com>
Lei Ji <jilei8 at huawei.com>
Lei Yao <lei.a.yao at intel.com>
Leonid Myravjev <myravjev at amicon.ru>
+Leo Xu <yongquanx at nvidia.com>
Leszek Zygo <leszek.zygo at intel.com>
Levend Sayar <levendsayar at gmail.com>
Lev Faerman <lev.faerman at intel.com>
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 88108498e0..97ab742abd 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -360,6 +360,12 @@ enum index {
ITEM_ICMP6,
ITEM_ICMP6_TYPE,
ITEM_ICMP6_CODE,
+ ITEM_ICMP6_ECHO_REQUEST,
+ ITEM_ICMP6_ECHO_REQUEST_ID,
+ ITEM_ICMP6_ECHO_REQUEST_SEQ,
+ ITEM_ICMP6_ECHO_REPLY,
+ ITEM_ICMP6_ECHO_REPLY_ID,
+ ITEM_ICMP6_ECHO_REPLY_SEQ,
ITEM_ICMP6_ND_NS,
ITEM_ICMP6_ND_NS_TARGET_ADDR,
ITEM_ICMP6_ND_NA,
@@ -1327,6 +1333,8 @@ static const enum index next_item[] = {
ITEM_IPV6_EXT,
ITEM_IPV6_FRAG_EXT,
ITEM_ICMP6,
+ ITEM_ICMP6_ECHO_REQUEST,
+ ITEM_ICMP6_ECHO_REPLY,
ITEM_ICMP6_ND_NS,
ITEM_ICMP6_ND_NA,
ITEM_ICMP6_ND_OPT,
@@ -1575,6 +1583,20 @@ static const enum index item_icmp6[] = {
ZERO,
};
+static const enum index item_icmp6_echo_request[] = {
+ ITEM_ICMP6_ECHO_REQUEST_ID,
+ ITEM_ICMP6_ECHO_REQUEST_SEQ,
+ ITEM_NEXT,
+ ZERO,
+};
+
+static const enum index item_icmp6_echo_reply[] = {
+ ITEM_ICMP6_ECHO_REPLY_ID,
+ ITEM_ICMP6_ECHO_REPLY_SEQ,
+ ITEM_NEXT,
+ ZERO,
+};
+
static const enum index item_icmp6_nd_ns[] = {
ITEM_ICMP6_ND_NS_TARGET_ADDR,
ITEM_NEXT,
@@ -4323,6 +4345,54 @@ static const struct token token_list[] = {
.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
code)),
},
+ [ITEM_ICMP6_ECHO_REQUEST] = {
+ .name = "icmp6_echo_request",
+ .help = "match ICMPv6 echo request",
+ .priv = PRIV_ITEM(ICMP6_ECHO_REQUEST,
+ sizeof(struct rte_flow_item_icmp6_echo)),
+ .next = NEXT(item_icmp6_echo_request),
+ .call = parse_vc,
+ },
+ [ITEM_ICMP6_ECHO_REQUEST_ID] = {
+ .name = "ident",
+ .help = "ICMPv6 echo request identifier",
+ .next = NEXT(item_icmp6_echo_request, NEXT_ENTRY(COMMON_UNSIGNED),
+ item_param),
+ .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_echo,
+ hdr.identifier)),
+ },
+ [ITEM_ICMP6_ECHO_REQUEST_SEQ] = {
+ .name = "seq",
+ .help = "ICMPv6 echo request sequence",
+ .next = NEXT(item_icmp6_echo_request, NEXT_ENTRY(COMMON_UNSIGNED),
+ item_param),
+ .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_echo,
+ hdr.sequence)),
+ },
+ [ITEM_ICMP6_ECHO_REPLY] = {
+ .name = "icmp6_echo_reply",
+ .help = "match ICMPv6 echo reply",
+ .priv = PRIV_ITEM(ICMP6_ECHO_REPLY,
+ sizeof(struct rte_flow_item_icmp6_echo)),
+ .next = NEXT(item_icmp6_echo_reply),
+ .call = parse_vc,
+ },
+ [ITEM_ICMP6_ECHO_REPLY_ID] = {
+ .name = "ident",
+ .help = "ICMPv6 echo reply identifier",
+ .next = NEXT(item_icmp6_echo_reply, NEXT_ENTRY(COMMON_UNSIGNED),
+ item_param),
+ .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_echo,
+ hdr.identifier)),
+ },
+ [ITEM_ICMP6_ECHO_REPLY_SEQ] = {
+ .name = "seq",
+ .help = "ICMPv6 echo reply sequence",
+ .next = NEXT(item_icmp6_echo_reply, NEXT_ENTRY(COMMON_UNSIGNED),
+ item_param),
+ .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_echo,
+ hdr.sequence)),
+ },
[ITEM_ICMP6_ND_NS] = {
.name = "icmp6_nd_ns",
.help = "match ICMPv6 neighbor discovery solicitation",
diff --git a/doc/guides/nics/features/default.ini b/doc/guides/nics/features/default.ini
index 510cc6679d..976a020985 100644
--- a/doc/guides/nics/features/default.ini
+++ b/doc/guides/nics/features/default.ini
@@ -105,6 +105,8 @@ gtp_psc =
higig2 =
icmp =
icmp6 =
+icmp6_echo_request =
+icmp6_echo_reply =
icmp6_nd_na =
icmp6_nd_ns =
icmp6_nd_opt =
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 3e6242803d..b910ea51bd 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1165,6 +1165,20 @@ Matches any ICMPv6 header.
- ``checksum``: ICMPv6 checksum.
- Default ``mask`` matches ``type`` and ``code``.
+Item: ``ICMP6_ECHO_REQUEST``
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Matches an ICMPv6 echo request.
+
+- ``hdr``: ICMP6 echo header definition (``rte_icmp.h``).
+
+Item: ``ICMP6_ECHO_REPLY``
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Matches an ICMPv6 echo reply.
+
+- ``hdr``: ICMP6 echo header definition (``rte_icmp.h``).
+
Item: ``ICMP6_ND_NS``
^^^^^^^^^^^^^^^^^^^^^
diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst
index c15f6fbb9f..3f5c7af3b6 100644
--- a/doc/guides/rel_notes/release_23_03.rst
+++ b/doc/guides/rel_notes/release_23_03.rst
@@ -69,6 +69,11 @@ New Features
``rte_event_dev_config::nb_single_link_event_port_queues`` parameter
required for eth_rx, eth_tx, crypto and timer eventdev adapters.
+* **Added rte_flow support for matching ICMPv6 ID and sequence fields.**
+
+ * Added flow items to match ICMPv6 echo request and reply packets.
+ Matching patterns can include ICMP identifier and sequence numbers.
+
Removed Items
-------------
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 0037506a79..f497bba26d 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3622,6 +3622,16 @@ This section lists supported pattern items and their attributes, if any.
- ``type {unsigned}``: ICMPv6 type.
- ``code {unsigned}``: ICMPv6 code.
+- ``icmp6_echo_request``: match ICMPv6 echo request.
+
+ - ``ident {unsigned}``: ICMPv6 echo request identifier.
+ - ``seq {unsigned}``: ICMPv6 echo request sequence number.
+
+- ``icmp6_echo_reply``: match ICMPv6 echo reply.
+
+ - ``ident {unsigned}``: ICMPv6 echo reply identifier.
+ - ``seq {unsigned}``: ICMPv6 echo reply sequence number.
+
- ``icmp6_nd_ns``: match ICMPv6 neighbor discovery solicitation.
- ``target_addr {ipv6 address}``: target address.
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 7d0c24366c..adcd4a61be 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -123,6 +123,8 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = {
MK_FLOW_ITEM(IPV6_EXT, sizeof(struct rte_flow_item_ipv6_ext)),
MK_FLOW_ITEM(IPV6_FRAG_EXT, sizeof(struct rte_flow_item_ipv6_frag_ext)),
MK_FLOW_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
+ MK_FLOW_ITEM(ICMP6_ECHO_REQUEST, sizeof(struct rte_flow_item_icmp6_echo)),
+ MK_FLOW_ITEM(ICMP6_ECHO_REPLY, sizeof(struct rte_flow_item_icmp6_echo)),
MK_FLOW_ITEM(ICMP6_ND_NS, sizeof(struct rte_flow_item_icmp6_nd_ns)),
MK_FLOW_ITEM(ICMP6_ND_NA, sizeof(struct rte_flow_item_icmp6_nd_na)),
MK_FLOW_ITEM(ICMP6_ND_OPT, sizeof(struct rte_flow_item_icmp6_nd_opt)),
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index b60987db4b..3ce6f188a3 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -624,6 +624,20 @@ enum rte_flow_item_type {
* See struct rte_flow_item_meter_color.
*/
RTE_FLOW_ITEM_TYPE_METER_COLOR,
+
+ /**
+ * Matches an ICMPv6 echo request.
+ *
+ * @see struct rte_flow_item_icmp6_echo.
+ */
+ RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST,
+
+ /**
+ * Matches an ICMPv6 echo reply.
+ *
+ * @see struct rte_flow_item_icmp6_echo.
+ */
+ RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY,
};
/**
@@ -1303,6 +1317,16 @@ static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
};
#endif
+/**
+ * RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST
+ * RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY
+ *
+ * Matches an ICMPv6 echo request or reply.
+ */
+struct rte_flow_item_icmp6_echo {
+ struct rte_icmp_echo_hdr hdr;
+};
+
/**
* RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
*
diff --git a/lib/net/rte_icmp.h b/lib/net/rte_icmp.h
index 4429e8e29f..7aaf0fd096 100644
--- a/lib/net/rte_icmp.h
+++ b/lib/net/rte_icmp.h
@@ -37,6 +37,28 @@ struct rte_icmp_hdr {
#define RTE_IP_ICMP_ECHO_REPLY 0
#define RTE_IP_ICMP_ECHO_REQUEST 8
+/**
+ * ICMP base header
+ */
+struct rte_icmp_base_hdr {
+ uint8_t type;
+ uint8_t code;
+ rte_be16_t checksum;
+} __rte_packed;
+
+/**
+ * ICMP echo header
+ */
+struct rte_icmp_echo_hdr {
+ struct rte_icmp_base_hdr base;
+ rte_be16_t identifier;
+ rte_be16_t sequence;
+} __rte_packed;
+
+/* ICMP6 packet types */
+#define RTE_ICMP6_ECHO_REQUEST 128
+#define RTE_ICMP6_ECHO_REPLY 129
+
#ifdef __cplusplus
}
#endif
--
2.27.0
More information about the dev
mailing list