examples/performance-thread: fix destination port
authorTomasz Kulasek <tomaszx.kulasek@intel.com>
Fri, 29 Apr 2016 16:30:56 +0000 (18:30 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 8 Jun 2016 20:38:52 +0000 (22:38 +0200)
This fixes wrong logic in get_dst_port() on lpm path causing unpredictable
return value when ipv4/ipv6 lookup success (return with no value).

Fixes: dc81ebbacaeb ("lpm: extend IPv4 next hop field")

Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
examples/performance-thread/l3fwd-thread/main.c

index 400daed..4d36093 100644 (file)
@@ -1343,24 +1343,23 @@ get_dst_port(struct rte_mbuf *pkt, uint32_t dst_ipv4, uint8_t portid)
        struct ether_hdr *eth_hdr;
 
        if (RTE_ETH_IS_IPV4_HDR(pkt->packet_type)) {
-               if (rte_lpm_lookup(RTE_PER_LCORE(lcore_conf)->ipv4_lookup_struct,
-                               dst_ipv4, &next_hop_ipv4) != 0) {
-                       next_hop_ipv4 = portid;
-                       return next_hop_ipv4;
-               }
+               return (uint16_t) ((rte_lpm_lookup(
+                               RTE_PER_LCORE(lcore_conf)->ipv4_lookup_struct, dst_ipv4,
+                               &next_hop_ipv4) == 0) ? next_hop_ipv4 : portid);
+
        } else if (RTE_ETH_IS_IPV6_HDR(pkt->packet_type)) {
+
                eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
                ipv6_hdr = (struct ipv6_hdr *)(eth_hdr + 1);
-               if (rte_lpm6_lookup(RTE_PER_LCORE(lcore_conf)->ipv6_lookup_struct,
-                               ipv6_hdr->dst_addr, &next_hop_ipv6) != 0) {
-                       next_hop_ipv6 = portid;
-                       return next_hop_ipv6;
-               }
-       } else {
-               next_hop_ipv4 = portid;
-               return next_hop_ipv4;
+
+               return (uint16_t) ((rte_lpm6_lookup(
+                               RTE_PER_LCORE(lcore_conf)->ipv6_lookup_struct,
+                               ipv6_hdr->dst_addr, &next_hop_ipv6) == 0) ? next_hop_ipv6 :
+                                               portid);
+
        }
 
+       return portid;
 }
 
 static inline void