app/testpmd: fix valid ports prints
[dpdk.git] / app / test-pmd / config.c
index 617d3cb..b07376a 100644 (file)
@@ -121,15 +121,11 @@ nic_stats_display(portid_t port_id)
        struct rte_eth_stats stats;
        struct rte_port *port = &ports[port_id];
        uint8_t i;
-       portid_t pid;
 
        static const char *nic_stats_border = "########################";
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
-               printf("Valid port range is [0");
-               RTE_ETH_FOREACH_DEV(pid)
-                       printf(", %d", pid);
-               printf("]\n");
+               print_valid_ports();
                return;
        }
        rte_eth_stats_get(port_id, &stats);
@@ -203,13 +199,8 @@ nic_stats_display(portid_t port_id)
 void
 nic_stats_clear(portid_t port_id)
 {
-       portid_t pid;
-
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
-               printf("Valid port range is [0");
-               RTE_ETH_FOREACH_DEV(pid)
-                       printf(", %d", pid);
-               printf("]\n");
+               print_valid_ports();
                return;
        }
        rte_eth_stats_reset(port_id);
@@ -286,15 +277,11 @@ nic_stats_mapping_display(portid_t port_id)
 {
        struct rte_port *port = &ports[port_id];
        uint16_t i;
-       portid_t pid;
 
        static const char *nic_stats_mapping_border = "########################";
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
-               printf("Valid port range is [0");
-               RTE_ETH_FOREACH_DEV(pid)
-                       printf(", %d", pid);
-               printf("]\n");
+               print_valid_ports();
                return;
        }
 
@@ -405,15 +392,11 @@ port_infos_display(portid_t port_id)
        int vlan_offload;
        struct rte_mempool * mp;
        static const char *info_border = "*********************";
-       portid_t pid;
        uint16_t mtu;
        char name[RTE_ETH_NAME_MAX_LEN];
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
-               printf("Valid port range is [0");
-               RTE_ETH_FOREACH_DEV(pid)
-                       printf(", %d", pid);
-               printf("]\n");
+               print_valid_ports();
                return;
        }
        port = &ports[port_id];
@@ -774,6 +757,17 @@ port_id_is_invalid(portid_t port_id, enum print_warning warning)
        return 1;
 }
 
+void print_valid_ports(void)
+{
+       portid_t pid;
+
+       printf("The valid ports array is [");
+       RTE_ETH_FOREACH_DEV(pid) {
+               printf(" %d", pid);
+       }
+       printf(" ]\n");
+}
+
 static int
 vlan_id_is_invalid(uint16_t vlan_id)
 {
@@ -1077,7 +1071,8 @@ flow_item_spec_copy(void *buf, const struct rte_flow_item *item,
                dst.raw = buf;
                off = RTE_ALIGN_CEIL(sizeof(struct rte_flow_item_raw),
                                     sizeof(*src.raw->pattern));
-               size = off + src.raw->length * sizeof(*src.raw->pattern);
+               size = off + ((const struct rte_flow_item_raw *)item->spec)->
+                       length * sizeof(*src.raw->pattern);
                if (dst.raw) {
                        memcpy(dst.raw, src.raw, sizeof(*src.raw));
                        dst.raw->pattern = memcpy((uint8_t *)dst.raw + off,
@@ -1114,7 +1109,7 @@ static const struct {
        MK_FLOW_ACTION(FLAG, 0),
        MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
        MK_FLOW_ACTION(DROP, 0),
-       MK_FLOW_ACTION(COUNT, 0),
+       MK_FLOW_ACTION(COUNT, sizeof(struct rte_flow_action_count)),
        MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)),
        MK_FLOW_ACTION(PF, 0),
        MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
@@ -1467,7 +1462,7 @@ port_flow_flush(portid_t port_id)
 /** Query a flow rule. */
 int
 port_flow_query(portid_t port_id, uint32_t rule,
-               enum rte_flow_action_type action)
+               const struct rte_flow_action *action)
 {
        struct rte_flow_error error;
        struct rte_port *port;
@@ -1488,16 +1483,17 @@ port_flow_query(portid_t port_id, uint32_t rule,
                printf("Flow rule #%u not found\n", rule);
                return -ENOENT;
        }
-       if ((unsigned int)action >= RTE_DIM(flow_action) ||
-           !flow_action[action].name)
+       if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
+           !flow_action[action->type].name)
                name = "unknown";
        else
-               name = flow_action[action].name;
-       switch (action) {
+               name = flow_action[action->type].name;
+       switch (action->type) {
        case RTE_FLOW_ACTION_TYPE_COUNT:
                break;
        default:
-               printf("Cannot query action type %d (%s)\n", action, name);
+               printf("Cannot query action type %d (%s)\n",
+                       action->type, name);
                return -ENOTSUP;
        }
        /* Poisoning to make sure PMDs update it in case of error. */
@@ -1505,7 +1501,7 @@ port_flow_query(portid_t port_id, uint32_t rule,
        memset(&query, 0, sizeof(query));
        if (rte_flow_query(port_id, pf->flow, action, &query, &error))
                return port_flow_complain(&error);
-       switch (action) {
+       switch (action->type) {
        case RTE_FLOW_ACTION_TYPE_COUNT:
                printf("%s:\n"
                       " hits_set: %u\n"
@@ -1520,7 +1516,7 @@ port_flow_query(portid_t port_id, uint32_t rule,
                break;
        default:
                printf("Cannot display result for action type %d (%s)\n",
-                      action, name);
+                      action->type, name);
                break;
        }
        return 0;