test/mbuf: fix access to freed memory
[dpdk.git] / app / test / packet_burst_generator.c
index 9776d58..8ac2457 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
+#include <rte_ip.h>
 
 #include "packet_burst_generator.h"
 
@@ -12,9 +13,6 @@
 
 
 #define IP_DEFTTL  64   /* from RFC 1340. */
-#define IP_VERSION 0x40
-#define IP_HDRLEN  0x05 /* default IP header length == five 32-bits words. */
-#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
 
 static void
 copy_buf_to_pkt_segs(void *buf, unsigned len, struct rte_mbuf *pkt,
@@ -58,8 +56,8 @@ initialize_eth_header(struct rte_ether_hdr *eth_hdr,
                struct rte_ether_addr *dst_mac, uint16_t ether_type,
                uint8_t vlan_enabled, uint16_t van_id)
 {
-       rte_ether_addr_copy(dst_mac, &eth_hdr->d_addr);
-       rte_ether_addr_copy(src_mac, &eth_hdr->s_addr);
+       rte_ether_addr_copy(dst_mac, &eth_hdr->dst_addr);
+       rte_ether_addr_copy(src_mac, &eth_hdr->src_addr);
 
        if (vlan_enabled) {
                struct rte_vlan_hdr *vhdr = (struct rte_vlan_hdr *)(
@@ -119,6 +117,7 @@ initialize_tcp_header(struct rte_tcp_hdr *tcp_hdr, uint16_t src_port,
        memset(tcp_hdr, 0, sizeof(struct rte_tcp_hdr));
        tcp_hdr->src_port = rte_cpu_to_be_16(src_port);
        tcp_hdr->dst_port = rte_cpu_to_be_16(dst_port);
+       tcp_hdr->data_off = (sizeof(struct rte_tcp_hdr) << 2) & 0xF0;
 
        return pkt_len;
 }
@@ -143,8 +142,8 @@ uint16_t
 initialize_ipv6_header(struct rte_ipv6_hdr *ip_hdr, uint8_t *src_addr,
                uint8_t *dst_addr, uint16_t pkt_data_len)
 {
-       ip_hdr->vtc_flow = 0;
-       ip_hdr->payload_len = pkt_data_len;
+       ip_hdr->vtc_flow = rte_cpu_to_be_32(0x60000000); /* Set version to 6. */
+       ip_hdr->payload_len = rte_cpu_to_be_16(pkt_data_len);
        ip_hdr->proto = IPPROTO_UDP;
        ip_hdr->hop_limits = IP_DEFTTL;
 
@@ -167,7 +166,7 @@ initialize_ipv4_header(struct rte_ipv4_hdr *ip_hdr, uint32_t src_addr,
         */
        pkt_len = (uint16_t) (pkt_data_len + sizeof(struct rte_ipv4_hdr));
 
-       ip_hdr->version_ihl   = IP_VHL_DEF;
+       ip_hdr->version_ihl   = RTE_IPV4_VHL_DEF;
        ip_hdr->type_of_service   = 0;
        ip_hdr->fragment_offset = 0;
        ip_hdr->time_to_live   = IP_DEFTTL;
@@ -215,7 +214,7 @@ initialize_ipv4_header_proto(struct rte_ipv4_hdr *ip_hdr, uint32_t src_addr,
         */
        pkt_len = (uint16_t) (pkt_data_len + sizeof(struct rte_ipv4_hdr));
 
-       ip_hdr->version_ihl   = IP_VHL_DEF;
+       ip_hdr->version_ihl   = RTE_IPV4_VHL_DEF;
        ip_hdr->type_of_service   = 0;
        ip_hdr->fragment_offset = 0;
        ip_hdr->time_to_live   = IP_DEFTTL;