app: fix whitespace
[dpdk.git] / app / test-pmd / icmpecho.c
index c25a54b..e249e71 100644 (file)
@@ -88,7 +88,7 @@ arp_op_name(uint16_t arp_op)
 }
 
 static const char *
-ip_proto_name(uint8_t ip_proto)
+ip_proto_name(uint16_t ip_proto)
 {
        static const char * ip_proto_names[] = {
                "IP6HOPOPTS", /**< IP6 hop-by-hop options */
@@ -295,6 +295,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
        uint16_t vlan_id;
        uint16_t arp_op;
        uint16_t arp_pro;
+       uint32_t cksum;
        uint8_t  i;
        int l2_len;
 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
@@ -371,18 +372,14 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                                continue;
                        }
                        if (verbose_level > 0) {
-                               memcpy(&eth_addr,
-                                      arp_h->arp_data.arp_ip.arp_sha, 6);
+                               ether_addr_copy(&arp_h->arp_data.arp_sha, &eth_addr);
                                ether_addr_dump("        sha=", &eth_addr);
-                               memcpy(&ip_addr,
-                                      arp_h->arp_data.arp_ip.arp_sip, 4);
+                               ip_addr = arp_h->arp_data.arp_sip;
                                ipv4_addr_dump(" sip=", ip_addr);
                                printf("\n");
-                               memcpy(&eth_addr,
-                                      arp_h->arp_data.arp_ip.arp_tha, 6);
+                               ether_addr_copy(&arp_h->arp_data.arp_tha, &eth_addr);
                                ether_addr_dump("        tha=", &eth_addr);
-                               memcpy(&ip_addr,
-                                      arp_h->arp_data.arp_ip.arp_tip, 4);
+                               ip_addr = arp_h->arp_data.arp_tip;
                                ipv4_addr_dump(" tip=", ip_addr);
                                printf("\n");
                        }
@@ -402,17 +399,14 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                                        &eth_h->s_addr);
 
                        arp_h->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY);
-                       memcpy(&eth_addr, arp_h->arp_data.arp_ip.arp_tha, 6);
-                       memcpy(arp_h->arp_data.arp_ip.arp_tha,
-                              arp_h->arp_data.arp_ip.arp_sha, 6);
-                       memcpy(arp_h->arp_data.arp_ip.arp_sha,
-                              &eth_h->s_addr, 6);
+                       ether_addr_copy(&arp_h->arp_data.arp_tha, &eth_addr);
+                       ether_addr_copy(&arp_h->arp_data.arp_sha, &arp_h->arp_data.arp_tha);
+                       ether_addr_copy(&eth_h->s_addr, &arp_h->arp_data.arp_sha);
 
                        /* Swap IP addresses in ARP payload */
-                       memcpy(&ip_addr, arp_h->arp_data.arp_ip.arp_sip, 4);
-                       memcpy(arp_h->arp_data.arp_ip.arp_sip,
-                              arp_h->arp_data.arp_ip.arp_tip, 4);
-                       memcpy(arp_h->arp_data.arp_ip.arp_tip, &ip_addr, 4);
+                       ip_addr = arp_h->arp_data.arp_sip;
+                       arp_h->arp_data.arp_sip = arp_h->arp_data.arp_tip;
+                       arp_h->arp_data.arp_tip = ip_addr;
                        pkts_burst[nb_replies++] = pkt;
                        continue;
                }
@@ -452,7 +446,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                 * - switch IPv4 source and destinations addresses,
                 * - set IP_ICMP_ECHO_REPLY in ICMP header.
                 * No need to re-compute the IP header checksum.
-                * Reset ICMP checksum.
+                * ICMP checksum is computed by assuming it is valid in the
+                * echo request and not verified.
                 */
                ether_addr_copy(&eth_h->s_addr, &eth_addr);
                ether_addr_copy(&eth_h->d_addr, &eth_h->s_addr);
@@ -461,7 +456,12 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                ip_h->src_addr = ip_h->dst_addr;
                ip_h->dst_addr = ip_addr;
                icmp_h->icmp_type = IP_ICMP_ECHO_REPLY;
-               icmp_h->icmp_cksum = 0;
+               cksum = ~icmp_h->icmp_cksum & 0xffff;
+               cksum += ~htons(IP_ICMP_ECHO_REQUEST << 8) & 0xffff;
+               cksum += htons(IP_ICMP_ECHO_REPLY << 8);
+               cksum = (cksum & 0xffff) + (cksum >> 16);
+               cksum = (cksum & 0xffff) + (cksum >> 16);
+               icmp_h->icmp_cksum = ~cksum;
                pkts_burst[nb_replies++] = pkt;
        }