1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
15 #define IS_FRAGMENTED(frag_off) (((frag_off) & RTE_IPV4_HDR_OFFSET_MASK) != 0 \
16 || ((frag_off) & RTE_IPV4_HDR_MF_FLAG) == RTE_IPV4_HDR_MF_FLAG)
18 #define TCP_HDR_PSH_MASK ((uint8_t)0x08)
19 #define TCP_HDR_FIN_MASK ((uint8_t)0x01)
21 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
22 (PKT_TX_TCP_SEG | PKT_TX_IPV4))
24 #define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
25 PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_MASK)) == \
26 (PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
29 #define IS_IPV4_VXLAN_UDP4(flag) (((flag) & (PKT_TX_UDP_SEG | PKT_TX_IPV4 | \
30 PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_MASK)) == \
31 (PKT_TX_UDP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
34 #define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
35 PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_MASK)) == \
36 (PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
39 #define IS_IPV4_UDP(flag) (((flag) & (PKT_TX_UDP_SEG | PKT_TX_IPV4)) == \
40 (PKT_TX_UDP_SEG | PKT_TX_IPV4))
43 * Internal function which updates the UDP header of a packet, following
44 * segmentation. This is required to update the header's datagram length field.
47 * The packet containing the UDP header.
49 * The offset of the UDP header from the start of the packet.
52 update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
54 struct rte_udp_hdr *udp_hdr;
56 udp_hdr = (struct rte_udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
58 udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
62 * Internal function which updates the TCP header of a packet, following
63 * segmentation. This is required to update the header's 'sent' sequence
64 * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
67 * The packet containing the TCP header.
69 * The offset of the TCP header from the start of the packet.
71 * The sent sequence number.
73 * Indicates whether or not this is a tail segment.
76 update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq,
79 struct rte_tcp_hdr *tcp_hdr;
81 tcp_hdr = (struct rte_tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
83 tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
85 tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
90 * Internal function which updates the IPv4 header of a packet, following
91 * segmentation. This is required to update the header's 'total_length' field,
92 * to reflect the reduced length of the now-segmented packet. Furthermore, the
93 * header's 'packet_id' field must be updated to reflect the new ID of the
94 * now-segmented packet.
97 * The packet containing the IPv4 header.
99 * The offset of the IPv4 header from the start of the packet.
101 * The new ID of the packet.
104 update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
106 struct rte_ipv4_hdr *ipv4_hdr;
108 ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
110 ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
111 ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
115 * Internal function which divides the input packet into small segments.
116 * Each of the newly-created segments is organized as a two-segment MBUF,
117 * where the first segment is a standard mbuf, which stores a copy of
118 * packet header, and the second is an indirect mbuf which points to a
119 * section of data in the input packet.
123 * @param pkt_hdr_offset
124 * Packet header offset, measured in bytes.
125 * @param pyld_unit_size
126 * The max payload length of a GSO segment.
128 * MBUF pool used for allocating direct buffers for output segments.
129 * @param indirect_pool
130 * MBUF pool used for allocating indirect buffers for output segments.
132 * Pointer array used to keep the mbuf addresses of output segments. If
133 * the memory space in pkts_out is insufficient, gso_do_segment() fails
134 * and returns -EINVAL.
136 * The max number of items that pkts_out can keep.
139 * - The number of segments created in the event of success.
140 * - Return -ENOMEM if run out of memory in MBUF pools.
141 * - Return -EINVAL for invalid parameters.
143 int gso_do_segment(struct rte_mbuf *pkt,
144 uint16_t pkt_hdr_offset,
145 uint16_t pyld_unit_size,
146 struct rte_mempool *direct_pool,
147 struct rte_mempool *indirect_pool,
148 struct rte_mbuf **pkts_out,
149 uint16_t nb_pkts_out);