* 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",
/* 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",
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;
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;
}
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;
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);
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. */
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 *)
(uintptr_t)sge->addr);
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 {
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))
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))
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),
#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; \
{
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);
{
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))
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) {
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) */
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);
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) */
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) */
}
#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);
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);
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]);
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) */
/* 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);
__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]);
}
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)) {
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++;
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));
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);
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));
process_ipv4(struct rte_port_ring_writer_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);
process_ipv6(struct rte_port_ring_writer_ras *p, struct rte_mbuf *pkt)
{
/* Assume there is no ethernet header */
- struct ipv6_hdr *pkt_hdr = (struct ipv6_hdr *)
- (rte_pktmbuf_mtod(pkt, unsigned char *));
+ struct ipv6_hdr *pkt_hdr = rte_pktmbuf_mtod(pkt, struct ipv6_hdr *);
struct ipv6_extension_fragment *frag_hdr;
frag_hdr = rte_ipv6_frag_get_ipv6_fragment_header(pkt_hdr);
while (total_copied < pkt_len) {
/* Copy mbuf data to buffer */
rte_memcpy((void *)(uintptr_t)(buff_addr + vb_offset),
- (const void *)(rte_pktmbuf_mtod(buff, const char *) + offset),
+ rte_pktmbuf_mtod_offset(buff, const void *, offset),
len_to_cpy);
PRINT_PACKET(dev, (uintptr_t)(buff_addr + vb_offset),
len_to_cpy, 0);
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,
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);