4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #define INVALID_ARRAY_INDEX 0xffffffffUL
37 #define GRO_TCP4_TBL_MAX_ITEM_NUM (1024UL * 1024UL)
40 * the max L3 length of a TCP/IPv4 packet. The L3 length
41 * is the sum of ipv4 header, tcp header and L4 payload.
43 #define TCP4_MAX_L3_LENGTH UINT16_MAX
45 /* criteria of mergeing packets */
47 struct ether_addr eth_saddr;
48 struct ether_addr eth_daddr;
60 * the index of the first packet in the item group.
61 * If the value is INVALID_ARRAY_INDEX, it means
67 struct gro_tcp4_item {
69 * first segment of the packet. If the value
70 * is NULL, it means the item is empty.
72 struct rte_mbuf *firstseg;
73 /* last segment of the packet */
74 struct rte_mbuf *lastseg;
76 * the time when the first packet is inserted
77 * into the table. If a packet in the table is
78 * merged with an incoming packet, this value
79 * won't be updated. We set this value only
80 * when the first packet is inserted into the
85 * we use next_pkt_idx to chain the packets that
86 * have same key value but can't be merged together.
88 uint32_t next_pkt_idx;
89 /* the sequence number of the packet */
91 /* the IP ID of the packet */
93 /* the number of merged packets */
98 * TCP/IPv4 reassembly table structure.
100 struct gro_tcp4_tbl {
102 struct gro_tcp4_item *items;
104 struct gro_tcp4_key *keys;
105 /* current item number */
107 /* current key num */
109 /* item array size */
110 uint32_t max_item_num;
112 uint32_t max_key_num;
116 * This function creates a TCP/IPv4 reassembly table.
119 * socket index for allocating TCP/IPv4 reassemblt table
120 * @param max_flow_num
121 * the maximum number of flows in the TCP/IPv4 GRO table
122 * @param max_item_per_flow
123 * the maximum packet number per flow.
126 * if create successfully, return a pointer which points to the
127 * created TCP/IPv4 GRO table. Otherwise, return NULL.
129 void *gro_tcp4_tbl_create(uint16_t socket_id,
130 uint16_t max_flow_num,
131 uint16_t max_item_per_flow);
134 * This function destroys a TCP/IPv4 reassembly table.
137 * a pointer points to the TCP/IPv4 reassembly table.
139 void gro_tcp4_tbl_destroy(void *tbl);
142 * This function searches for a packet in the TCP/IPv4 reassembly table
143 * to merge with the inputted one. To merge two packets is to chain them
144 * together and update packet headers. Packets, whose SYN, FIN, RST, PSH
145 * CWR, ECE or URG bit is set, are returned immediately. Packets which
146 * only have packet headers (i.e. without data) are also returned
147 * immediately. Otherwise, the packet is either merged, or inserted into
148 * the table. Besides, if there is no available space to insert the
149 * packet, this function returns immediately too.
151 * This function assumes the inputted packet is with correct IPv4 and
152 * TCP checksums. And if two packets are merged, it won't re-calculate
153 * IPv4 and TCP checksums. Besides, if the inputted packet is IP
154 * fragmented, it assumes the packet is complete (with TCP header).
157 * packet to reassemble.
159 * a pointer that points to a TCP/IPv4 reassembly table.
161 * the start time that the packet is inserted into the table
164 * if the packet doesn't have data, or SYN, FIN, RST, PSH, CWR, ECE
165 * or URG bit is set, or there is no available space in the table to
166 * insert a new item or a new key, return a negative value. If the
167 * packet is merged successfully, return an positive value. If the
168 * packet is inserted into the table, return 0.
170 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
171 struct gro_tcp4_tbl *tbl,
172 uint64_t start_time);
175 * This function flushes timeout packets in a TCP/IPv4 reassembly table
176 * to applications, and without updating checksums for merged packets.
177 * The max number of flushed timeout packets is the element number of
178 * the array which is used to keep flushed packets.
181 * a pointer that points to a TCP GRO table.
182 * @param flush_timestamp
183 * this function flushes packets which are inserted into the table
184 * before or at the flush_timestamp.
186 * pointer array which is used to keep flushed packets.
188 * the element number of out. It's also the max number of timeout
189 * packets that can be flushed finally.
192 * the number of packets that are returned.
194 uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
195 uint64_t flush_timestamp,
196 struct rte_mbuf **out,
200 * This function returns the number of the packets in a TCP/IPv4
204 * pointer points to a TCP/IPv4 reassembly table.
207 * the number of packets in the table
209 uint32_t gro_tcp4_tbl_pkt_count(void *tbl);