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 */
64 /* Indicate if IPv4 ID can be ignored */
69 * TCP/IPv4 reassembly table structure.
73 struct gro_tcp4_item *items;
75 struct gro_tcp4_flow *flows;
76 /* current item number */
78 /* current flow num */
81 uint32_t max_item_num;
83 uint32_t max_flow_num;
87 * This function creates a TCP/IPv4 reassembly table.
90 * Socket index for allocating the TCP/IPv4 reassemble table
92 * The maximum number of flows in the TCP/IPv4 GRO table
93 * @param max_item_per_flow
94 * The maximum number of packets per flow
97 * - Return the table pointer on success.
98 * - Return NULL on failure.
100 void *gro_tcp4_tbl_create(uint16_t socket_id,
101 uint16_t max_flow_num,
102 uint16_t max_item_per_flow);
105 * This function destroys a TCP/IPv4 reassembly table.
108 * Pointer pointing to the TCP/IPv4 reassembly table.
110 void gro_tcp4_tbl_destroy(void *tbl);
113 * This function merges a TCP/IPv4 packet. It doesn't process the packet,
114 * which has SYN, FIN, RST, PSH, CWR, ECE or URG set, or doesn't have
117 * This function doesn't check if the packet has correct checksums and
118 * doesn't re-calculate checksums for the merged packet. Additionally,
119 * it assumes the packets are complete (i.e., MF==0 && frag_off==0),
120 * when IP fragmentation is possible (i.e., DF==0). It returns the
121 * packet, if the packet has invalid parameters (e.g. SYN bit is set)
122 * or there is no available space in the table.
125 * Packet to reassemble
127 * Pointer pointing to the TCP/IPv4 reassembly table
129 * The time when the packet is inserted into the table
132 * - Return a positive value if the packet is merged.
133 * - Return zero if the packet isn't merged but stored in the table.
134 * - Return a negative value for invalid parameters or no available
135 * space in the table.
137 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
138 struct gro_tcp4_tbl *tbl,
139 uint64_t start_time);
142 * This function flushes timeout packets in a TCP/IPv4 reassembly table,
143 * and without updating checksums.
146 * TCP/IPv4 reassembly table pointer
147 * @param flush_timestamp
148 * Flush packets which are inserted into the table before or at the
151 * Pointer array used to keep flushed packets
153 * The element number in 'out'. It also determines the maximum number of
154 * packets that can be flushed finally.
157 * The number of flushed packets
159 uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
160 uint64_t flush_timestamp,
161 struct rte_mbuf **out,
165 * This function returns the number of the packets in a TCP/IPv4
169 * TCP/IPv4 reassembly table pointer
172 * The number of packets in the table
174 uint32_t gro_tcp4_tbl_pkt_count(void *tbl);