4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _GSO_COMMON_H_
35 #define _GSO_COMMON_H_
43 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
44 || ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
46 #define TCP_HDR_PSH_MASK ((uint8_t)0x08)
47 #define TCP_HDR_FIN_MASK ((uint8_t)0x01)
49 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
50 (PKT_TX_TCP_SEG | PKT_TX_IPV4))
53 * Internal function which updates the TCP header of a packet, following
54 * segmentation. This is required to update the header's 'sent' sequence
55 * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
58 * The packet containing the TCP header.
60 * The offset of the TCP header from the start of the packet.
62 * The sent sequence number.
64 * Indicates whether or not this is a tail segment.
67 update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq,
70 struct tcp_hdr *tcp_hdr;
72 tcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
74 tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
76 tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
81 * Internal function which updates the IPv4 header of a packet, following
82 * segmentation. This is required to update the header's 'total_length' field,
83 * to reflect the reduced length of the now-segmented packet. Furthermore, the
84 * header's 'packet_id' field must be updated to reflect the new ID of the
85 * now-segmented packet.
88 * The packet containing the IPv4 header.
90 * The offset of the IPv4 header from the start of the packet.
92 * The new ID of the packet.
95 update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
97 struct ipv4_hdr *ipv4_hdr;
99 ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
101 ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
102 ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
106 * Internal function which divides the input packet into small segments.
107 * Each of the newly-created segments is organized as a two-segment MBUF,
108 * where the first segment is a standard mbuf, which stores a copy of
109 * packet header, and the second is an indirect mbuf which points to a
110 * section of data in the input packet.
114 * @param pkt_hdr_offset
115 * Packet header offset, measured in bytes.
116 * @param pyld_unit_size
117 * The max payload length of a GSO segment.
119 * MBUF pool used for allocating direct buffers for output segments.
120 * @param indirect_pool
121 * MBUF pool used for allocating indirect buffers for output segments.
123 * Pointer array used to keep the mbuf addresses of output segments. If
124 * the memory space in pkts_out is insufficient, gso_do_segment() fails
125 * and returns -EINVAL.
127 * The max number of items that pkts_out can keep.
130 * - The number of segments created in the event of success.
131 * - Return -ENOMEM if run out of memory in MBUF pools.
132 * - Return -EINVAL for invalid parameters.
134 int gso_do_segment(struct rte_mbuf *pkt,
135 uint16_t pkt_hdr_offset,
136 uint16_t pyld_unit_size,
137 struct rte_mempool *direct_pool,
138 struct rte_mempool *indirect_pool,
139 struct rte_mbuf **pkts_out,
140 uint16_t nb_pkts_out);