| 453 | } |
| 454 | |
| 455 | static inline struct rte_mbuf * |
| 456 | init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len, bool outer_ipv4) |
| 457 | { |
| 458 | struct rte_mbuf *pkt, *tail; |
| 459 | uint16_t space; |
| 460 | |
| 461 | pkt = rte_pktmbuf_alloc(mp); |
| 462 | if (pkt == NULL) |
| 463 | return NULL; |
| 464 | |
| 465 | if (outer_ipv4) { |
| 466 | rte_memcpy(rte_pktmbuf_append(pkt, RTE_ETHER_HDR_LEN), |
| 467 | &dummy_ipv4_eth_hdr, RTE_ETHER_HDR_LEN); |
| 468 | pkt->l3_len = sizeof(struct rte_ipv4_hdr); |
| 469 | } else { |
| 470 | rte_memcpy(rte_pktmbuf_append(pkt, RTE_ETHER_HDR_LEN), |
| 471 | &dummy_ipv6_eth_hdr, RTE_ETHER_HDR_LEN); |
| 472 | pkt->l3_len = sizeof(struct rte_ipv6_hdr); |
| 473 | } |
| 474 | pkt->l2_len = RTE_ETHER_HDR_LEN; |
| 475 | |
| 476 | space = rte_pktmbuf_tailroom(pkt); |
| 477 | tail = pkt; |
| 478 | /* Error if SG mode is not enabled */ |
| 479 | if (!sg_mode && space < len) { |
| 480 | rte_pktmbuf_free(pkt); |
| 481 | return NULL; |
| 482 | } |
| 483 | /* Extra room for expansion */ |
| 484 | while (space < len) { |
| 485 | tail->next = rte_pktmbuf_alloc(mp); |
| 486 | if (!tail->next) |
| 487 | goto error; |
| 488 | tail = tail->next; |
| 489 | space += rte_pktmbuf_tailroom(tail); |
| 490 | pkt->nb_segs++; |
| 491 | } |
| 492 | |
| 493 | if (pkt->buf_len > len + RTE_ETHER_HDR_LEN) |
| 494 | rte_memcpy(rte_pktmbuf_append(pkt, len), data, len); |
| 495 | else |
| 496 | copy_buf_to_pkt_segs(data, len, pkt, RTE_ETHER_HDR_LEN); |
| 497 | return pkt; |
| 498 | error: |
| 499 | rte_pktmbuf_free(pkt); |
| 500 | return NULL; |
| 501 | } |
| 502 | |
| 503 | static int |
| 504 | init_mempools(unsigned int nb_mbuf) |
no test coverage detected