mbuf: remove packet type from offload flags
[dpdk.git] / app / test / packet_burst_generator.c
index e9d059c..a93c3b5 100644 (file)
@@ -59,7 +59,7 @@ copy_buf_to_pkt_segs(void *buf, unsigned len, struct rte_mbuf *pkt,
                seg = seg->next;
        }
        copy_len = seg->data_len - offset;
-       seg_buf = rte_pktmbuf_mtod(seg, char *) + offset;
+       seg_buf = rte_pktmbuf_mtod_offset(seg, char *, offset);
        while (len > copy_len) {
                rte_memcpy(seg_buf, buf, (size_t) copy_len);
                len -= copy_len;
@@ -74,17 +74,17 @@ static inline void
 copy_buf_to_pkt(void *buf, unsigned len, struct rte_mbuf *pkt, unsigned offset)
 {
        if (offset + len <= pkt->data_len) {
-               rte_memcpy(rte_pktmbuf_mtod(pkt, char *) + offset, buf, (size_t) len);
+               rte_memcpy(rte_pktmbuf_mtod_offset(pkt, char *, offset), buf,
+                          (size_t) len);
                return;
        }
        copy_buf_to_pkt_segs(buf, len, pkt, offset);
 }
 
-
 void
 initialize_eth_header(struct ether_hdr *eth_hdr, struct ether_addr *src_mac,
-               struct ether_addr *dst_mac, uint8_t ipv4, uint8_t vlan_enabled,
-               uint16_t van_id)
+               struct ether_addr *dst_mac, uint16_t ether_type,
+               uint8_t vlan_enabled, uint16_t van_id)
 {
        ether_addr_copy(dst_mac, &eth_hdr->d_addr);
        ether_addr_copy(src_mac, &eth_hdr->s_addr);
@@ -95,19 +95,27 @@ initialize_eth_header(struct ether_hdr *eth_hdr, struct ether_addr *src_mac,
 
                eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_VLAN);
 
-               if (ipv4)
-                       vhdr->eth_proto =  rte_cpu_to_be_16(ETHER_TYPE_IPv4);
-               else
-                       vhdr->eth_proto =  rte_cpu_to_be_16(ETHER_TYPE_IPv6);
-
+               vhdr->eth_proto =  rte_cpu_to_be_16(ether_type);
                vhdr->vlan_tci = van_id;
        } else {
-               if (ipv4)
-                       eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
-               else
-                       eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
+               eth_hdr->ether_type = rte_cpu_to_be_16(ether_type);
        }
+}
 
+void
+initialize_arp_header(struct arp_hdr *arp_hdr, struct ether_addr *src_mac,
+               struct ether_addr *dst_mac, uint32_t src_ip, uint32_t dst_ip,
+               uint32_t opcode)
+{
+       arp_hdr->arp_hrd = rte_cpu_to_be_16(ARP_HRD_ETHER);
+       arp_hdr->arp_pro = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
+       arp_hdr->arp_hln = ETHER_ADDR_LEN;
+       arp_hdr->arp_pln = sizeof(uint32_t);
+       arp_hdr->arp_op = rte_cpu_to_be_16(opcode);
+       ether_addr_copy(src_mac, &arp_hdr->arp_data.arp_sha);
+       arp_hdr->arp_data.arp_sip = src_ip;
+       ether_addr_copy(dst_mac, &arp_hdr->arp_data.arp_tha);
+       arp_hdr->arp_data.arp_tip = dst_ip;
 }
 
 uint16_t
@@ -147,7 +155,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr,
                uint32_t dst_addr, uint16_t pkt_data_len)
 {
        uint16_t pkt_len;
-       uint16_t *ptr16;
+       unaligned_uint16_t *ptr16;
        uint32_t ip_cksum;
 
        /*
@@ -168,7 +176,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr,
        /*
         * Compute IP header checksum.
         */
-       ptr16 = (uint16_t *)ip_hdr;
+       ptr16 = (unaligned_uint16_t *)ip_hdr;
        ip_cksum = 0;
        ip_cksum += ptr16[0]; ip_cksum += ptr16[1];
        ip_cksum += ptr16[2]; ip_cksum += ptr16[3];