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 L3 length of a TCP/IPv4 packet. The L3 length
13 * is the sum of ipv4 header, tcp header and L4 payload.
15 #define TCP4_MAX_L3_LENGTH UINT16_MAX
17 /* criteria of mergeing packets */
19 struct ether_addr eth_saddr;
20 struct ether_addr eth_daddr;
32 * the index of the first packet in the item group.
33 * If the value is INVALID_ARRAY_INDEX, it means
39 struct gro_tcp4_item {
41 * first segment of the packet. If the value
42 * is NULL, it means the item is empty.
44 struct rte_mbuf *firstseg;
45 /* last segment of the packet */
46 struct rte_mbuf *lastseg;
48 * the time when the first packet is inserted
49 * into the table. If a packet in the table is
50 * merged with an incoming packet, this value
51 * won't be updated. We set this value only
52 * when the first packet is inserted into the
57 * we use next_pkt_idx to chain the packets that
58 * have same key value but can't be merged together.
60 uint32_t next_pkt_idx;
61 /* the sequence number of the packet */
63 /* the IP ID of the packet */
65 /* the number of merged packets */
70 * TCP/IPv4 reassembly table structure.
74 struct gro_tcp4_item *items;
76 struct gro_tcp4_key *keys;
77 /* current item number */
82 uint32_t max_item_num;
88 * This function creates a TCP/IPv4 reassembly table.
91 * socket index for allocating TCP/IPv4 reassemble table
93 * the maximum number of flows in the TCP/IPv4 GRO table
94 * @param max_item_per_flow
95 * the maximum packet number per flow.
98 * if create successfully, return a pointer which points to the
99 * created TCP/IPv4 GRO table. Otherwise, return NULL.
101 void *gro_tcp4_tbl_create(uint16_t socket_id,
102 uint16_t max_flow_num,
103 uint16_t max_item_per_flow);
106 * This function destroys a TCP/IPv4 reassembly table.
109 * a pointer points to the TCP/IPv4 reassembly table.
111 void gro_tcp4_tbl_destroy(void *tbl);
114 * This function searches for a packet in the TCP/IPv4 reassembly table
115 * to merge with the inputted one. To merge two packets is to chain them
116 * together and update packet headers. Packets, whose SYN, FIN, RST, PSH
117 * CWR, ECE or URG bit is set, are returned immediately. Packets which
118 * only have packet headers (i.e. without data) are also returned
119 * immediately. Otherwise, the packet is either merged, or inserted into
120 * the table. Besides, if there is no available space to insert the
121 * packet, this function returns immediately too.
123 * This function assumes the inputted packet is with correct IPv4 and
124 * TCP checksums. And if two packets are merged, it won't re-calculate
125 * IPv4 and TCP checksums. Besides, if the inputted packet is IP
126 * fragmented, it assumes the packet is complete (with TCP header).
129 * packet to reassemble.
131 * a pointer that points to a TCP/IPv4 reassembly table.
133 * the start time that the packet is inserted into the table
136 * if the packet doesn't have data, or SYN, FIN, RST, PSH, CWR, ECE
137 * or URG bit is set, or there is no available space in the table to
138 * insert a new item or a new key, return a negative value. If the
139 * packet is merged successfully, return an positive value. If the
140 * packet is inserted into the table, return 0.
142 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
143 struct gro_tcp4_tbl *tbl,
144 uint64_t start_time);
147 * This function flushes timeout packets in a TCP/IPv4 reassembly table
148 * to applications, and without updating checksums for merged packets.
149 * The max number of flushed timeout packets is the element number of
150 * the array which is used to keep flushed packets.
153 * a pointer that points to a TCP GRO table.
154 * @param flush_timestamp
155 * this function flushes packets which are inserted into the table
156 * before or at the flush_timestamp.
158 * pointer array which is used to keep flushed packets.
160 * the element number of out. It's also the max number of timeout
161 * packets that can be flushed finally.
164 * the number of packets that are returned.
166 uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
167 uint64_t flush_timestamp,
168 struct rte_mbuf **out,
172 * This function returns the number of the packets in a TCP/IPv4
176 * pointer points to a TCP/IPv4 reassembly table.
179 * the number of packets in the table
181 uint32_t gro_tcp4_tbl_pkt_count(void *tbl);