1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #include "gso_common.h"
8 #define IPV4_HDR_MF_BIT (1U << 13)
11 update_ipv4_udp_headers(struct rte_mbuf *pkt, struct rte_mbuf **segs,
14 struct rte_ipv4_hdr *ipv4_hdr;
15 uint16_t frag_offset = 0, is_mf;
16 uint16_t l2_hdrlen = pkt->l2_len, l3_hdrlen = pkt->l3_len;
17 uint16_t tail_idx = nb_segs - 1, length, i;
20 * Update IP header fields for output segments. Specifically,
21 * keep the same IP id, update fragment offset and total
24 for (i = 0; i < nb_segs; i++) {
25 ipv4_hdr = rte_pktmbuf_mtod_offset(segs[i],
26 struct rte_ipv4_hdr *, l2_hdrlen);
27 length = segs[i]->pkt_len - l2_hdrlen;
28 ipv4_hdr->total_length = rte_cpu_to_be_16(length);
30 is_mf = i < tail_idx ? IPV4_HDR_MF_BIT : 0;
31 ipv4_hdr->fragment_offset =
32 rte_cpu_to_be_16(frag_offset | is_mf);
33 frag_offset += ((length - l3_hdrlen) >> 3);
38 gso_udp4_segment(struct rte_mbuf *pkt,
40 struct rte_mempool *direct_pool,
41 struct rte_mempool *indirect_pool,
42 struct rte_mbuf **pkts_out,
45 struct rte_ipv4_hdr *ipv4_hdr;
46 uint16_t pyld_unit_size, hdr_offset;
50 /* Don't process the fragmented packet */
51 ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
53 frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
54 if (unlikely(IS_FRAGMENTED(frag_off))) {
59 * UDP fragmentation is the same as IP fragmentation.
60 * Except the first one, other output packets just have l2
63 hdr_offset = pkt->l2_len + pkt->l3_len;
65 /* Don't process the packet without data. */
66 if (unlikely(hdr_offset + pkt->l4_len >= pkt->pkt_len)) {
70 /* pyld_unit_size must be a multiple of 8 because frag_off
71 * uses 8 bytes as unit.
73 pyld_unit_size = (gso_size - hdr_offset) & ~7U;
75 /* Segment the payload */
76 ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
77 indirect_pool, pkts_out, nb_pkts_out);
79 update_ipv4_udp_headers(pkt, pkts_out, ret);