From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sclab-apps-2.localdomain (sc-fw1.tilera.com [12.218.212.162]) by dpdk.org (Postfix) with ESMTP id 300FCC8F4 for ; Wed, 29 Apr 2015 18:16:07 +0200 (CEST) X-CheckPoint: {554103C6-F-A3D4DA0C-C0000002} Received: by sclab-apps-2.localdomain (Postfix, from userid 1318) id 0BF95220848; Wed, 29 Apr 2015 09:15:55 -0700 (PDT) From: Cyril Chemparathy To: dev@dpdk.org Date: Wed, 29 Apr 2015 09:15:34 -0700 Message-Id: <1430324134-25654-11-git-send-email-cchemparathy@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1430324134-25654-1-git-send-email-cchemparathy@ezchip.com> References: <1430324134-25654-1-git-send-email-cchemparathy@ezchip.com> Subject: [dpdk-dev] [PATCH 10/10] librte_mbuf: Apply mtod-offset.cocci transform X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2015 16:16:16 -0000 This patch simply applies the transform previously committed in scripts/cocci/mtod-offset.cocci. No other modifications have been made here. This patch applies on commit 9f0bf3f4a3eabd7ab5af13b4ed793c36e7615b35. This patch may need to be regenerated by rerunning scripts/cocci.sh instead of simply merging in the change. Signed-off-by: Cyril Chemparathy --- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c | 21 ++++++---- app/test-pmd/txonly.c | 4 +- app/test/packet_burst_generator.c | 5 ++- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 ++- examples/l3fwd-acl/main.c | 20 ++++----- examples/l3fwd-power/main.c | 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c | 71 ++++++++++++++------------------ examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c | 4 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 3 +- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +-- lib/librte_pmd_mlx4/mlx4.c | 9 ++-- lib/librte_port/rte_port_ras.c | 3 +- lib/librte_vhost/vhost_rxtx.c | 4 +- 17 files changed, 88 insertions(+), 94 deletions(-) diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c index 84237c1..dfbb185 100644 --- a/app/test-pmd/ieee1588fwd.c +++ b/app/test-pmd/ieee1588fwd.c @@ -573,8 +573,8 @@ ieee1588_packet_fwd(struct fwd_stream *fs) * Check that the received PTP packet is a PTP V2 packet of type * PTP_SYNC_MESSAGE. */ - ptp_hdr = (struct ptpv2_msg *) (rte_pktmbuf_mtod(mb, char *) + - sizeof(struct ether_hdr)); + ptp_hdr = rte_pktmbuf_mtod_offset(mb, struct ptpv2_msg *, + sizeof(struct ether_hdr)); if (ptp_hdr->version != 0x02) { printf("Port %u Received PTP V2 Ethernet frame with wrong PTP" " protocol version 0x%x (should be 0x02)\n", diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index ac56090..b8e35ab 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -175,22 +175,25 @@ pkt_burst_receive(struct fwd_stream *fs) /* Do not support ipv4 option field */ if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) { l3_len = sizeof(struct ipv4_hdr); - ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv4_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv4_hdr *, + l2_len); l4_proto = ipv4_hdr->next_proto_id; } else { l3_len = sizeof(struct ipv6_hdr); - ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv6_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv6_hdr *, + l2_len); l4_proto = ipv6_hdr->proto; } if (l4_proto == IPPROTO_UDP) { - udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len); + udp_hdr = rte_pktmbuf_mtod_offset(mb, + struct udp_hdr *, + l2_len + l3_len); l4_len = sizeof(struct udp_hdr); - vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len - + l4_len); + vxlan_hdr = rte_pktmbuf_mtod_offset(mb, + struct vxlan_hdr *, + l2_len + l3_len + l4_len); printf(" - VXLAN packet: packet type =%d, " "Destination UDP port =%d, VNI = %d", diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 9e66552..f8027f1 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -110,7 +110,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; @@ -125,7 +125,7 @@ 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), + rte_memcpy(rte_pktmbuf_mtod_offset(pkt, char *, offset), buf, (size_t) len); return; } diff --git a/app/test/packet_burst_generator.c b/app/test/packet_burst_generator.c index 06762c6..28d9e25 100644 --- a/app/test/packet_burst_generator.c +++ b/app/test/packet_burst_generator.c @@ -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,7 +74,8 @@ 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); diff --git a/examples/dpdk_qat/crypto.c b/examples/dpdk_qat/crypto.c index 00e0eb5..c03ea78 100644 --- a/examples/dpdk_qat/crypto.c +++ b/examples/dpdk_qat/crypto.c @@ -772,8 +772,8 @@ enum crypto_result crypto_encrypt(struct rte_mbuf *rte_buff, enum cipher_alg c, enum hash_alg h) { CpaCySymDpOpData *opData = - (CpaCySymDpOpData *) (rte_pktmbuf_mtod(rte_buff, char *) - + CRYPTO_OFFSET_TO_OPDATA); + rte_pktmbuf_mtod_offset(rte_buff, CpaCySymDpOpData *, + CRYPTO_OFFSET_TO_OPDATA); uint32_t lcore_id; if (unlikely(c >= NUM_CRYPTO || h >= NUM_HMAC)) @@ -847,8 +847,8 @@ enum crypto_result crypto_decrypt(struct rte_mbuf *rte_buff, enum cipher_alg c, enum hash_alg h) { - CpaCySymDpOpData *opData = (void*) (rte_pktmbuf_mtod(rte_buff, char *) - + CRYPTO_OFFSET_TO_OPDATA); + CpaCySymDpOpData *opData = rte_pktmbuf_mtod_offset(rte_buff, void *, + CRYPTO_OFFSET_TO_OPDATA); uint32_t lcore_id; if (unlikely(c >= NUM_CRYPTO || h >= NUM_HMAC)) diff --git a/examples/dpdk_qat/main.c b/examples/dpdk_qat/main.c index 053be91..7c2f628 100644 --- a/examples/dpdk_qat/main.c +++ b/examples/dpdk_qat/main.c @@ -326,8 +326,9 @@ main_loop(__attribute__((unused)) void *dummy) continue; /* Send packet to either QAT encrypt, QAT decrypt or NIC TX */ if (pkt_from_nic_rx) { - struct ipv4_hdr *ip = (struct ipv4_hdr *) (rte_pktmbuf_mtod(pkt, unsigned char *) + - sizeof(struct ether_hdr)); + struct ipv4_hdr *ip = rte_pktmbuf_mtod_offset(pkt, + struct ipv4_hdr *, + sizeof(struct ether_hdr)); if (ip->src_addr & rte_cpu_to_be_32(ACTION_ENCRYPT)) { if (CRYPTO_RESULT_FAIL == crypto_encrypt(pkt, (enum cipher_alg)((ip->src_addr >> 16) & 0xFF), diff --git a/examples/l3fwd-acl/main.c b/examples/l3fwd-acl/main.c index 1a04004..3944843 100644 --- a/examples/l3fwd-acl/main.c +++ b/examples/l3fwd-acl/main.c @@ -218,9 +218,9 @@ send_single_packet(struct rte_mbuf *m, uint8_t port); #define OFF_IPV42PROTO (offsetof(struct ipv4_hdr, next_proto_id)) #define OFF_IPV62PROTO (offsetof(struct ipv6_hdr, proto)) #define MBUF_IPV4_2PROTO(m) \ - (rte_pktmbuf_mtod((m), uint8_t *) + OFF_ETHHEAD + OFF_IPV42PROTO) + rte_pktmbuf_mtod_offset((m), uint8_t *, OFF_ETHHEAD + OFF_IPV42PROTO) #define MBUF_IPV6_2PROTO(m) \ - (rte_pktmbuf_mtod((m), uint8_t *) + OFF_ETHHEAD + OFF_IPV62PROTO) + rte_pktmbuf_mtod_offset((m), uint8_t *, OFF_ETHHEAD + OFF_IPV62PROTO) #define GET_CB_FIELD(in, fd, base, lim, dlm) do { \ unsigned long val; \ @@ -566,9 +566,9 @@ dump_acl4_rule(struct rte_mbuf *m, uint32_t sig) { uint32_t offset = sig & ~ACL_DENY_SIGNATURE; unsigned char a, b, c, d; - struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *) - (rte_pktmbuf_mtod(m, unsigned char *) + - sizeof(struct ether_hdr)); + struct ipv4_hdr *ipv4_hdr = rte_pktmbuf_mtod_offset(m, + struct ipv4_hdr *, + sizeof(struct ether_hdr)); uint32_t_to_char(rte_bswap32(ipv4_hdr->src_addr), &a, &b, &c, &d); printf("Packet Src:%hhu.%hhu.%hhu.%hhu ", a, b, c, d); @@ -590,9 +590,9 @@ dump_acl6_rule(struct rte_mbuf *m, uint32_t sig) { unsigned i; uint32_t offset = sig & ~ACL_DENY_SIGNATURE; - struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *) - (rte_pktmbuf_mtod(m, unsigned char *) + - sizeof(struct ether_hdr)); + struct ipv6_hdr *ipv6_hdr = rte_pktmbuf_mtod_offset(m, + struct ipv6_hdr *, + sizeof(struct ether_hdr)); printf("Packet Src"); for (i = 0; i < RTE_DIM(ipv6_hdr->src_addr); i += sizeof(uint16_t)) @@ -651,8 +651,8 @@ prepare_one_packet(struct rte_mbuf **pkts_in, struct acl_search_t *acl, if (type == PKT_RX_IPV4_HDR) { - ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, - unsigned char *) + sizeof(struct ether_hdr)); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct ipv4_hdr *, + sizeof(struct ether_hdr)); /* Check to make sure the packet is valid (RFC1812) */ if (is_valid_ipv4_pkt(ipv4_hdr, pkt->pkt_len) >= 0) { diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index bb0b66f..b0748cf 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -640,8 +640,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, if (m->ol_flags & PKT_RX_IPV4_HDR) { /* Handle IPv4 headers.*/ ipv4_hdr = - (struct ipv4_hdr *)(rte_pktmbuf_mtod(m, unsigned char*) - + sizeof(struct ether_hdr)); + rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, + sizeof(struct ether_hdr)); #ifdef DO_RFC_1812_CHECKS /* Check to make sure the packet is valid (RFC1812) */ @@ -679,8 +679,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, struct ipv6_hdr *ipv6_hdr; ipv6_hdr = - (struct ipv6_hdr *)(rte_pktmbuf_mtod(m, unsigned char*) - + sizeof(struct ether_hdr)); + rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *, + sizeof(struct ether_hdr)); dst_port = get_ipv6_dst_port(ipv6_hdr, portid, qconf->ipv6_lookup_struct); diff --git a/examples/l3fwd-vf/main.c b/examples/l3fwd-vf/main.c index f007bc1..32ff4d5 100644 --- a/examples/l3fwd-vf/main.c +++ b/examples/l3fwd-vf/main.c @@ -461,8 +461,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, lookup_struct_t * l3fwd eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *); - ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + - sizeof(struct ether_hdr)); + ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, + sizeof(struct ether_hdr)); #ifdef DO_RFC_1812_CHECKS /* Check to make sure the packet is valid (RFC1812) */ diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 7871038..2d06d95 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -752,14 +752,14 @@ simple_ipv4_fwd_4pkts(struct rte_mbuf* m[4], uint8_t portid, struct lcore_conf * eth_hdr[3] = rte_pktmbuf_mtod(m[3], struct ether_hdr *); /* Handle IPv4 headers.*/ - ipv4_hdr[0] = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m[0], unsigned char *) + - sizeof(struct ether_hdr)); - ipv4_hdr[1] = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m[1], unsigned char *) + - sizeof(struct ether_hdr)); - ipv4_hdr[2] = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m[2], unsigned char *) + - sizeof(struct ether_hdr)); - ipv4_hdr[3] = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m[3], unsigned char *) + - sizeof(struct ether_hdr)); + ipv4_hdr[0] = rte_pktmbuf_mtod_offset(m[0], struct ipv4_hdr *, + sizeof(struct ether_hdr)); + ipv4_hdr[1] = rte_pktmbuf_mtod_offset(m[1], struct ipv4_hdr *, + sizeof(struct ether_hdr)); + ipv4_hdr[2] = rte_pktmbuf_mtod_offset(m[2], struct ipv4_hdr *, + sizeof(struct ether_hdr)); + ipv4_hdr[3] = rte_pktmbuf_mtod_offset(m[3], struct ipv4_hdr *, + sizeof(struct ether_hdr)); #ifdef DO_RFC_1812_CHECKS /* Check to make sure the packet is valid (RFC1812) */ @@ -795,14 +795,10 @@ simple_ipv4_fwd_4pkts(struct rte_mbuf* m[4], uint8_t portid, struct lcore_conf * } #endif // End of #ifdef DO_RFC_1812_CHECKS - data[0] = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m[0], unsigned char *) + - sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); - data[1] = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m[1], unsigned char *) + - sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); - data[2] = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m[2], unsigned char *) + - sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); - data[3] = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m[3], unsigned char *) + - sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); + data[0] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[0], __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); + data[1] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[1], __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); + data[2] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[2], __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); + data[3] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[3], __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv4_hdr, time_to_live))); key[0].xmm = _mm_and_si128(data[0], mask0); key[1].xmm = _mm_and_si128(data[1], mask0); @@ -863,14 +859,9 @@ simple_ipv4_fwd_4pkts(struct rte_mbuf* m[4], uint8_t portid, struct lcore_conf * static inline void get_ipv6_5tuple(struct rte_mbuf* m0, __m128i mask0, __m128i mask1, union ipv6_5tuple_host * key) { - __m128i tmpdata0 = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m0, unsigned char *) - + sizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len))); - __m128i tmpdata1 = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m0, unsigned char *) - + sizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len) - + sizeof(__m128i))); - __m128i tmpdata2 = _mm_loadu_si128((__m128i*)(rte_pktmbuf_mtod(m0, unsigned char *) - + sizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len) - + sizeof(__m128i) + sizeof(__m128i))); + __m128i tmpdata0 = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m0, __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len))); + __m128i tmpdata1 = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m0, __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len) + sizeof(__m128i))); + __m128i tmpdata2 = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m0, __m128i *, sizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len) + sizeof(__m128i) + sizeof(__m128i))); key->xmm[0] = _mm_and_si128(tmpdata0, mask0); key->xmm[1] = tmpdata1; key->xmm[2] = _mm_and_si128(tmpdata2, mask1); @@ -893,14 +884,14 @@ simple_ipv6_fwd_4pkts(struct rte_mbuf* m[4], uint8_t portid, struct lcore_conf * eth_hdr[3] = rte_pktmbuf_mtod(m[3], struct ether_hdr *); /* Handle IPv6 headers.*/ - ipv6_hdr[0] = (struct ipv6_hdr *)(rte_pktmbuf_mtod(m[0], unsigned char *) + - sizeof(struct ether_hdr)); - ipv6_hdr[1] = (struct ipv6_hdr *)(rte_pktmbuf_mtod(m[1], unsigned char *) + - sizeof(struct ether_hdr)); - ipv6_hdr[2] = (struct ipv6_hdr *)(rte_pktmbuf_mtod(m[2], unsigned char *) + - sizeof(struct ether_hdr)); - ipv6_hdr[3] = (struct ipv6_hdr *)(rte_pktmbuf_mtod(m[3], unsigned char *) + - sizeof(struct ether_hdr)); + ipv6_hdr[0] = rte_pktmbuf_mtod_offset(m[0], struct ipv6_hdr *, + sizeof(struct ether_hdr)); + ipv6_hdr[1] = rte_pktmbuf_mtod_offset(m[1], struct ipv6_hdr *, + sizeof(struct ether_hdr)); + ipv6_hdr[2] = rte_pktmbuf_mtod_offset(m[2], struct ipv6_hdr *, + sizeof(struct ether_hdr)); + ipv6_hdr[3] = rte_pktmbuf_mtod_offset(m[3], struct ipv6_hdr *, + sizeof(struct ether_hdr)); get_ipv6_5tuple(m[0], mask1, mask2, &key[0]); get_ipv6_5tuple(m[1], mask1, mask2, &key[1]); @@ -959,8 +950,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, struct lcore_conf *qcon if (m->ol_flags & PKT_RX_IPV4_HDR) { /* Handle IPv4 headers.*/ - ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + - sizeof(struct ether_hdr)); + ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, + sizeof(struct ether_hdr)); #ifdef DO_RFC_1812_CHECKS /* Check to make sure the packet is valid (RFC1812) */ @@ -996,8 +987,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, struct lcore_conf *qcon /* Handle IPv6 headers.*/ struct ipv6_hdr *ipv6_hdr; - ipv6_hdr = (struct ipv6_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + - sizeof(struct ether_hdr)); + ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *, + sizeof(struct ether_hdr)); dst_port = get_ipv6_dst_port(ipv6_hdr, portid, qconf->ipv6_lookup_struct); @@ -1188,10 +1179,10 @@ processx4_step3(struct rte_mbuf *pkt[FWDSTEP], uint16_t dst_port[FWDSTEP]) __m128i ve[FWDSTEP]; __m128i *p[FWDSTEP]; - p[0] = (rte_pktmbuf_mtod(pkt[0], __m128i *)); - p[1] = (rte_pktmbuf_mtod(pkt[1], __m128i *)); - p[2] = (rte_pktmbuf_mtod(pkt[2], __m128i *)); - p[3] = (rte_pktmbuf_mtod(pkt[3], __m128i *)); + p[0] = rte_pktmbuf_mtod(pkt[0], __m128i *); + p[1] = rte_pktmbuf_mtod(pkt[1], __m128i *); + p[2] = rte_pktmbuf_mtod(pkt[2], __m128i *); + p[3] = rte_pktmbuf_mtod(pkt[3], __m128i *); ve[0] = val_eth[dst_port[0]]; te[0] = _mm_load_si128(p[0]); diff --git a/examples/load_balancer/runtime.c b/examples/load_balancer/runtime.c index adec4ba..2b265c2 100644 --- a/examples/load_balancer/runtime.c +++ b/examples/load_balancer/runtime.c @@ -535,7 +535,9 @@ app_lcore_worker( } pkt = lp->mbuf_in.array[j]; - ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, unsigned char *) + sizeof(struct ether_hdr)); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, + struct ipv4_hdr *, + sizeof(struct ether_hdr)); ipv4_dst = rte_be_to_cpu_32(ipv4_hdr->dst_addr); if (unlikely(rte_lpm_lookup(lp->lpm_table, ipv4_dst, &port) != 0)) { diff --git a/examples/vhost_xen/main.c b/examples/vhost_xen/main.c index b672bf3..ad24079 100644 --- a/examples/vhost_xen/main.c +++ b/examples/vhost_xen/main.c @@ -874,8 +874,8 @@ virtio_tx_route(struct virtio_net* dev, struct rte_mbuf *m, struct rte_mempool * vlan_hdr->h_vlan_TCI = htons(vlan_tag); /* Copy the remaining packet contents to the mbuf. */ - rte_memcpy((void *)(rte_pktmbuf_mtod(mbuf, uint8_t *) + VLAN_ETH_HLEN), - (const void *)(rte_pktmbuf_mtod(m, uint8_t *) + ETH_HLEN), + rte_memcpy(rte_pktmbuf_mtod_offset(mbuf, void *, VLAN_ETH_HLEN), + rte_pktmbuf_mtod_offset(m, const void *, ETH_HLEN), (m->data_len - ETH_HLEN)); tx_q->m_table[len] = mbuf; len++; diff --git a/lib/librte_ip_frag/rte_ipv4_reassembly.c b/lib/librte_ip_frag/rte_ipv4_reassembly.c index 279be6c..14bab91 100644 --- a/lib/librte_ip_frag/rte_ipv4_reassembly.c +++ b/lib/librte_ip_frag/rte_ipv4_reassembly.c @@ -85,8 +85,7 @@ ipv4_frag_reassemble(const struct ip_frag_pkt *fp) m->ol_flags |= PKT_TX_IP_CKSUM; /* update ipv4 header for the reassmebled packet */ - ip_hdr = (struct ipv4_hdr*)(rte_pktmbuf_mtod(m, uint8_t *) + - m->l2_len); + ip_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, m->l2_len); ip_hdr->total_length = rte_cpu_to_be_16((uint16_t)(fp->total_size + m->l3_len)); diff --git a/lib/librte_ip_frag/rte_ipv6_reassembly.c b/lib/librte_ip_frag/rte_ipv6_reassembly.c index 71cf721..1f1c172 100644 --- a/lib/librte_ip_frag/rte_ipv6_reassembly.c +++ b/lib/librte_ip_frag/rte_ipv6_reassembly.c @@ -108,8 +108,7 @@ ipv6_frag_reassemble(const struct ip_frag_pkt *fp) m->ol_flags |= PKT_TX_IP_CKSUM; /* update ipv6 header for the reassembled datagram */ - ip_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(m, uint8_t *) + - m->l2_len); + ip_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *, m->l2_len); ip_hdr->payload_len = rte_cpu_to_be_16(payload_len); @@ -124,7 +123,7 @@ ipv6_frag_reassemble(const struct ip_frag_pkt *fp) frag_hdr = (struct ipv6_extension_fragment *) (ip_hdr + 1); ip_hdr->proto = frag_hdr->next_header; - ip_frag_memmove(rte_pktmbuf_mtod(m, char*) + sizeof(*frag_hdr), + ip_frag_memmove(rte_pktmbuf_mtod_offset(m, char *, sizeof(*frag_hdr)), rte_pktmbuf_mtod(m, char*), move_len); rte_pktmbuf_adj(m, sizeof(*frag_hdr)); diff --git a/lib/librte_pmd_mlx4/mlx4.c b/lib/librte_pmd_mlx4/mlx4.c index f915bc1..e6b90ec 100644 --- a/lib/librte_pmd_mlx4/mlx4.c +++ b/lib/librte_pmd_mlx4/mlx4.c @@ -1103,10 +1103,10 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) linearize = 1; } /* Set WR fields. */ - assert(((uintptr_t)rte_pktmbuf_mtod(buf, char *) - + assert((rte_pktmbuf_mtod(buf, uintptr_t) - (uintptr_t)buf) <= 0xffff); WR_ID(wr->wr_id).offset = - ((uintptr_t)rte_pktmbuf_mtod(buf, char *) - + (rte_pktmbuf_mtod(buf, uintptr_t) - (uintptr_t)buf); wr->num_sge = segs; /* Register segments as SGEs. */ @@ -1141,7 +1141,7 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) assert(sge->length == 0); assert(sge->lkey == 0); /* Update SGE. */ - sge->addr = (uintptr_t)rte_pktmbuf_mtod(buf, char *); + sge->addr = rte_pktmbuf_mtod(buf, uintptr_t); if (txq->priv->vf) rte_prefetch0((volatile void *)sge->addr); sge->length = DATA_LEN(buf); @@ -1591,8 +1591,7 @@ rxq_alloc_elts_sp(struct rxq *rxq, unsigned int elts_n, assert(sizeof(sge->addr) >= sizeof(uintptr_t)); if (j == 0) { /* The first SGE keeps its headroom. */ - sge->addr = (uintptr_t)rte_pktmbuf_mtod(buf, - char *); + sge->addr = rte_pktmbuf_mtod(buf, uintptr_t); sge->length = (buf->buf_len - RTE_PKTMBUF_HEADROOM); } else { diff --git a/lib/librte_port/rte_port_ras.c b/lib/librte_port/rte_port_ras.c index b6ab67a..5f60e93 100644 --- a/lib/librte_port/rte_port_ras.c +++ b/lib/librte_port/rte_port_ras.c @@ -136,8 +136,7 @@ static inline void process_one(struct rte_port_ring_writer_ipv4_ras *p, struct rte_mbuf *pkt) { /* Assume there is no ethernet header */ - struct ipv4_hdr *pkt_hdr = (struct ipv4_hdr *) - (rte_pktmbuf_mtod(pkt, unsigned char *)); + struct ipv4_hdr *pkt_hdr = rte_pktmbuf_mtod(pkt, struct ipv4_hdr *); /* Get "Do not fragment" flag and fragment offset */ uint16_t frag_field = rte_be_to_cpu_16(pkt_hdr->fragment_offset); diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index 510ffe8..ef13213 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -272,7 +272,7 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t res_base_idx, while (cpy_len > 0) { /* Copy mbuf data to vring buffer */ rte_memcpy((void *)(uintptr_t)(vb_addr + vb_offset), - (const void *)(rte_pktmbuf_mtod(pkt, char*) + seg_offset), + rte_pktmbuf_mtod_offset(pkt, const void *, seg_offset), cpy_len); PRINT_PACKET(dev, @@ -621,7 +621,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, cur = m; prev = m; while (cpy_len != 0) { - rte_memcpy((void *)(rte_pktmbuf_mtod(cur, char *) + seg_offset), + rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *, seg_offset), (void *)((uintptr_t)(vb_addr + vb_offset)), cpy_len); -- 2.1.2