On 11/9/22 04:37, Yuan Wang wrote:
The "show config rxhdrs" cmd displays the configured protocol headers
that are used for protocol-based buffer split.
However, it shows inner-ipv6 as inner-ipv4.

This patch fixes that by redefining rx_pkt_hdr_protos to hold
the full ptypes, and the show and set commands therefore
remain symmetrical.

Fixes: 52e2e7edcf48 ("app/testpmd: add protocol-based buffer split")

Signed-off-by: Yuan Wang <yuanx.w...@intel.com>

---
v4:
- redefine rx_pkt_hdr_protos to hold the full ptypes.
- use single switch in get_ptype_str().
v3:
- use RTE_PTYPE_*_MASK as masks.
- refactor to use switch statement.
v2:
- add fixline.

---
  app/test-pmd/cmdline.c |  12 ++--
  app/test-pmd/config.c  | 141 +++++++++++++++++++++--------------------
  app/test-pmd/testpmd.c |   5 +-
  3 files changed, 82 insertions(+), 76 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 3fbcb6ca8f..f7df24f105 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -3443,20 +3443,16 @@ parse_hdrs_list(const char *str, const char *item_name, 
unsigned int max_items,
                                unsigned int *parsed_items)
  {
        unsigned int nb_item;
-       char *cur;
-       char *tmp;
-       unsigned int cur_item, prev_items = 0;
+       char *cur, *tmp;

above line is unrelated changes

+       char *str2;
nb_item = 0;
-       char *str2 = strdup(str);
+       str2 = strdup(str);

I've failed to find where str2 is freed.

        cur = strtok_r(str2, ",", &tmp);
        while (cur != NULL) {
-               cur_item = get_ptype(cur);
-               cur_item &= ~prev_items;
-               parsed_items[nb_item] = cur_item;
+               parsed_items[nb_item] = get_ptype(cur);
                cur = strtok_r(NULL, ",", &tmp);
                nb_item++;
-               prev_items |= cur_item;
        }
        if (nb_item > max_items)
                fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index e8a1b77c2a..755728966b 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -5070,73 +5070,79 @@ show_rx_pkt_segments(void)
static const char *get_ptype_str(uint32_t ptype)
  {
-       if ((ptype & (RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP)) ==
-               (RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP))
-               return "ipv4-tcp";
-       else if ((ptype & (RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP)) ==
-               (RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP))
-               return "ipv4-udp";
-       else if ((ptype & (RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP)) 
==
-               (RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP))
-               return "ipv4-sctp";
-       else if ((ptype & (RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_TCP)) ==
-               (RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_TCP))
-               return "ipv6-tcp";
-       else if ((ptype & (RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_UDP)) ==
-               (RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_UDP))
-               return "ipv6-udp";
-       else if ((ptype & (RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP)) 
==
-               (RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP))
-               return "ipv6-sctp";
-       else if ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP)
-               return "tcp";
-       else if ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP)
-               return "udp";
-       else if ((ptype & RTE_PTYPE_L4_SCTP) == RTE_PTYPE_L4_SCTP)
-               return "sctp";
-       else if ((ptype & RTE_PTYPE_L3_IPV4_EXT_UNKNOWN) == 
RTE_PTYPE_L3_IPV4_EXT_UNKNOWN)
-               return "ipv4";
-       else if ((ptype & RTE_PTYPE_L3_IPV6_EXT_UNKNOWN) == 
RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
-               return "ipv6";
-       else if ((ptype & RTE_PTYPE_L2_ETHER) == RTE_PTYPE_L2_ETHER)
-               return "eth";
-
-       else if ((ptype & (RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_TCP)) ==
-               (RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP))
-               return "inner-ipv4-tcp";
-       else if ((ptype & (RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_UDP)) ==
-               (RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP))
-               return "inner-ipv4-udp";
-       else if ((ptype & (RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_SCTP)) ==
-               (RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP))
-               return "inner-ipv4-sctp";
-       else if ((ptype & (RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_TCP)) ==
-               (RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP))
-               return "inner-ipv6-tcp";
-       else if ((ptype & (RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_UDP)) ==
-               (RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP))
-               return "inner-ipv6-udp";
-       else if ((ptype & (RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_SCTP)) ==
-               (RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP))
-               return "inner-ipv6-sctp";
-       else if ((ptype & RTE_PTYPE_INNER_L4_TCP) == RTE_PTYPE_INNER_L4_TCP)
-               return "inner-tcp";
-       else if ((ptype & RTE_PTYPE_INNER_L4_UDP) == RTE_PTYPE_INNER_L4_UDP)
-               return "inner-udp";
-       else if ((ptype & RTE_PTYPE_INNER_L4_SCTP) == RTE_PTYPE_INNER_L4_SCTP)
-               return "inner-sctp";
-       else if ((ptype & RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN) ==
-               RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN)
-               return "inner-ipv4";
-       else if ((ptype & RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN) ==
-               RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN)
-               return "inner-ipv6";
-       else if ((ptype & RTE_PTYPE_INNER_L2_ETHER) == RTE_PTYPE_INNER_L2_ETHER)
-               return "inner-eth";
-       else if ((ptype & RTE_PTYPE_TUNNEL_GRENAT) == RTE_PTYPE_TUNNEL_GRENAT)
-               return "grenat";
-       else
-               return "unsupported";
+       const char *str;
+
+       switch (ptype) {
+       case RTE_PTYPE_L2_ETHER:
+               str = "eth";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN:
+               str = "ipv4";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN:
+               str = "ipv6";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_L4_TCP:
+               str = "ipv4-tcp";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_L4_UDP:
+               str = "ipv4-udp";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_L4_SCTP:
+               str = "ipv4-sctp";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_L4_TCP:
+               str = "ipv6-tcp";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_L4_UDP:
+               str = "ipv6-udp";
+               break;
+       case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_L4_SCTP:
+               str = "ipv6-sctp";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT:
+               str = "grenat";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER:
+               str = "inner-eth";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER
+                       | RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
+               str = "inner-ipv4";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER
+                       | RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
+               str = "inner-ipv6";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
+                       RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_TCP:
+               str = "inner-ipv4-tcp";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
+                       RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_UDP:
+               str = "inner-ipv4-udp";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
+                       RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_SCTP:
+               str = "inner-ipv4-sctp";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
+                       RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_TCP:
+               str = "inner-ipv6-tcp";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
+                       RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_UDP:
+               str = "inner-ipv6-udp";
+               break;
+       case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
+                       RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | 
RTE_PTYPE_INNER_L4_SCTP:
+               str = "inner-ipv6-sctp";
+               break;
+       default:
+               str = "unsupported";
+       }
+
+       return str;
  }
void
@@ -5169,6 +5175,7 @@ set_rx_pkt_hdrs(unsigned int *seg_hdrs, unsigned int 
nb_segs)
for (i = 0; i < nb_segs; i++)
                rx_pkt_hdr_protos[i] = (uint32_t)seg_hdrs[i];
+
        /*
         * We calculate the number of hdrs, but payload is not included,
         * so rx_pkt_nb_segs would increase 1.
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 7381dfd9e5..b4a1fb360f 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2654,6 +2654,7 @@ rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
  {
        union rte_eth_rxseg rx_useg[MAX_SEGS_BUFFER_SPLIT] = {};
        unsigned int i, mp_n;
+       uint32_t prev_hdrs = 0;
        int ret;
if (rx_pkt_nb_segs <= 1 ||
@@ -2668,6 +2669,7 @@ rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
        for (i = 0; i < rx_pkt_nb_segs; i++) {
                struct rte_eth_rxseg_split *rx_seg = &rx_useg[i].split;
                struct rte_mempool *mpx;
+

unrelated changes, avoid it

                /*
                 * Use last valid pool for the segments with number
                 * exceeding the pool index.
@@ -2679,7 +2681,8 @@ rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
                                   rx_pkt_seg_offsets[i] : 0;
                rx_seg->mp = mpx ? mpx : mp;
                if (rx_pkt_hdr_protos[i] != 0 && rx_pkt_seg_lengths[i] == 0) {
-                       rx_seg->proto_hdr = rx_pkt_hdr_protos[i];
+                       rx_seg->proto_hdr = rx_pkt_hdr_protos[i] & ~prev_hdrs;
+                       prev_hdrs |= rx_seg->proto_hdr;
                } else {
                        rx_seg->length = rx_pkt_seg_lengths[i] ?
                                        rx_pkt_seg_lengths[i] :

Reply via email to