1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
8 #define INVALID_ARRAY_INDEX 0xffffffffUL
9 #define GRO_TCP4_TBL_MAX_ITEM_NUM (1024UL * 1024UL)
12 * The max length of a IPv4 packet, which includes the length of the L3
13 * header, the L4 header and the data payload.
15 #define MAX_IPV4_PKT_LENGTH UINT16_MAX
17 /* Header fields representing a TCP/IPv4 flow */
18 struct tcp4_flow_key {
19 struct ether_addr eth_saddr;
20 struct ether_addr eth_daddr;
29 struct gro_tcp4_flow {
30 struct tcp4_flow_key key;
32 * The index of the first packet in the flow.
33 * INVALID_ARRAY_INDEX indicates an empty flow.
38 struct gro_tcp4_item {
40 * The first MBUF segment of the packet. If the value
41 * is NULL, it means the item is empty.
43 struct rte_mbuf *firstseg;
44 /* The last MBUF segment of the packet */
45 struct rte_mbuf *lastseg;
47 * The time when the first packet is inserted into the table.
48 * This value won't be updated, even if the packet is merged
53 * next_pkt_idx is used to chain the packets that
54 * are in the same flow but can't be merged together
55 * (e.g. caused by packet reordering).
57 uint32_t next_pkt_idx;
58 /* TCP sequence number of the packet */
60 /* IPv4 ID of the packet */
62 /* the number of merged packets */
67 * TCP/IPv4 reassembly table structure.
71 struct gro_tcp4_item *items;
73 struct gro_tcp4_flow *flows;
74 /* current item number */
76 /* current flow num */
79 uint32_t max_item_num;
81 uint32_t max_flow_num;
85 * This function creates a TCP/IPv4 reassembly table.
88 * Socket index for allocating the TCP/IPv4 reassemble table
90 * The maximum number of flows in the TCP/IPv4 GRO table
91 * @param max_item_per_flow
92 * The maximum number of packets per flow
95 * - Return the table pointer on success.
96 * - Return NULL on failure.
98 void *gro_tcp4_tbl_create(uint16_t socket_id,
99 uint16_t max_flow_num,
100 uint16_t max_item_per_flow);
103 * This function destroys a TCP/IPv4 reassembly table.
106 * Pointer pointing to the TCP/IPv4 reassembly table.
108 void gro_tcp4_tbl_destroy(void *tbl);
111 * This function merges a TCP/IPv4 packet. It doesn't process the packet,
112 * which has SYN, FIN, RST, PSH, CWR, ECE or URG set, or doesn't have
115 * This function doesn't check if the packet has correct checksums and
116 * doesn't re-calculate checksums for the merged packet. Additionally,
117 * it assumes the packets are complete (i.e., MF==0 && frag_off==0),
118 * when IP fragmentation is possible (i.e., DF==0). It returns the
119 * packet, if the packet has invalid parameters (e.g. SYN bit is set)
120 * or there is no available space in the table.
123 * Packet to reassemble
125 * Pointer pointing to the TCP/IPv4 reassembly table
127 * The time when the packet is inserted into the table
130 * - Return a positive value if the packet is merged.
131 * - Return zero if the packet isn't merged but stored in the table.
132 * - Return a negative value for invalid parameters or no available
133 * space in the table.
135 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
136 struct gro_tcp4_tbl *tbl,
137 uint64_t start_time);
140 * This function flushes timeout packets in a TCP/IPv4 reassembly table,
141 * and without updating checksums.
144 * TCP/IPv4 reassembly table pointer
145 * @param flush_timestamp
146 * Flush packets which are inserted into the table before or at the
149 * Pointer array used to keep flushed packets
151 * The element number in 'out'. It also determines the maximum number of
152 * packets that can be flushed finally.
155 * The number of flushed packets
157 uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
158 uint64_t flush_timestamp,
159 struct rte_mbuf **out,
163 * This function returns the number of the packets in a TCP/IPv4
167 * TCP/IPv4 reassembly table pointer
170 * The number of packets in the table
172 uint32_t gro_tcp4_tbl_pkt_count(void *tbl);