199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright(c) 2017 Intel Corporation
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #ifndef _GRO_TCP4_H_
699a2dd95SBruce Richardson #define _GRO_TCP4_H_
799a2dd95SBruce Richardson
8*5c55e819SKumara Parameshwaran #include "gro_tcp.h"
999a2dd95SBruce Richardson
1099a2dd95SBruce Richardson #define GRO_TCP4_TBL_MAX_ITEM_NUM (1024UL * 1024UL)
1199a2dd95SBruce Richardson
12*5c55e819SKumara Parameshwaran /* Header fields representing common fields in TCP flow */
1399a2dd95SBruce Richardson struct tcp4_flow_key {
14*5c55e819SKumara Parameshwaran struct cmn_tcp_key cmn_key;
1599a2dd95SBruce Richardson uint32_t ip_src_addr;
1699a2dd95SBruce Richardson uint32_t ip_dst_addr;
1799a2dd95SBruce Richardson };
1899a2dd95SBruce Richardson
1999a2dd95SBruce Richardson struct gro_tcp4_flow {
2099a2dd95SBruce Richardson struct tcp4_flow_key key;
2199a2dd95SBruce Richardson /*
2299a2dd95SBruce Richardson * The index of the first packet in the flow.
2399a2dd95SBruce Richardson * INVALID_ARRAY_INDEX indicates an empty flow.
2499a2dd95SBruce Richardson */
2599a2dd95SBruce Richardson uint32_t start_index;
2699a2dd95SBruce Richardson };
2799a2dd95SBruce Richardson
2899a2dd95SBruce Richardson /*
2999a2dd95SBruce Richardson * TCP/IPv4 reassembly table structure.
3099a2dd95SBruce Richardson */
3199a2dd95SBruce Richardson struct gro_tcp4_tbl {
3299a2dd95SBruce Richardson /* item array */
33*5c55e819SKumara Parameshwaran struct gro_tcp_item *items;
3499a2dd95SBruce Richardson /* flow array */
3599a2dd95SBruce Richardson struct gro_tcp4_flow *flows;
3699a2dd95SBruce Richardson /* current item number */
3799a2dd95SBruce Richardson uint32_t item_num;
3899a2dd95SBruce Richardson /* current flow num */
3999a2dd95SBruce Richardson uint32_t flow_num;
4099a2dd95SBruce Richardson /* item array size */
4199a2dd95SBruce Richardson uint32_t max_item_num;
4299a2dd95SBruce Richardson /* flow array size */
4399a2dd95SBruce Richardson uint32_t max_flow_num;
4499a2dd95SBruce Richardson };
4599a2dd95SBruce Richardson
4699a2dd95SBruce Richardson /**
4799a2dd95SBruce Richardson * This function creates a TCP/IPv4 reassembly table.
4899a2dd95SBruce Richardson *
4999a2dd95SBruce Richardson * @param socket_id
5099a2dd95SBruce Richardson * Socket index for allocating the TCP/IPv4 reassemble table
5199a2dd95SBruce Richardson * @param max_flow_num
5299a2dd95SBruce Richardson * The maximum number of flows in the TCP/IPv4 GRO table
5399a2dd95SBruce Richardson * @param max_item_per_flow
5499a2dd95SBruce Richardson * The maximum number of packets per flow
5599a2dd95SBruce Richardson *
5699a2dd95SBruce Richardson * @return
5799a2dd95SBruce Richardson * - Return the table pointer on success.
5899a2dd95SBruce Richardson * - Return NULL on failure.
5999a2dd95SBruce Richardson */
6099a2dd95SBruce Richardson void *gro_tcp4_tbl_create(uint16_t socket_id,
6199a2dd95SBruce Richardson uint16_t max_flow_num,
6299a2dd95SBruce Richardson uint16_t max_item_per_flow);
6399a2dd95SBruce Richardson
6499a2dd95SBruce Richardson /**
6599a2dd95SBruce Richardson * This function destroys a TCP/IPv4 reassembly table.
6699a2dd95SBruce Richardson *
6799a2dd95SBruce Richardson * @param tbl
6899a2dd95SBruce Richardson * Pointer pointing to the TCP/IPv4 reassembly table.
6999a2dd95SBruce Richardson */
7099a2dd95SBruce Richardson void gro_tcp4_tbl_destroy(void *tbl);
7199a2dd95SBruce Richardson
7299a2dd95SBruce Richardson /**
7399a2dd95SBruce Richardson * This function merges a TCP/IPv4 packet. It doesn't process the packet,
7499a2dd95SBruce Richardson * which has SYN, FIN, RST, PSH, CWR, ECE or URG set, or doesn't have
7599a2dd95SBruce Richardson * payload.
7699a2dd95SBruce Richardson *
7799a2dd95SBruce Richardson * This function doesn't check if the packet has correct checksums and
7899a2dd95SBruce Richardson * doesn't re-calculate checksums for the merged packet. Additionally,
7999a2dd95SBruce Richardson * it assumes the packets are complete (i.e., MF==0 && frag_off==0),
8099a2dd95SBruce Richardson * when IP fragmentation is possible (i.e., DF==0). It returns the
8199a2dd95SBruce Richardson * packet, if the packet has invalid parameters (e.g. SYN bit is set)
8299a2dd95SBruce Richardson * or there is no available space in the table.
8399a2dd95SBruce Richardson *
8499a2dd95SBruce Richardson * @param pkt
8599a2dd95SBruce Richardson * Packet to reassemble
8699a2dd95SBruce Richardson * @param tbl
8799a2dd95SBruce Richardson * Pointer pointing to the TCP/IPv4 reassembly table
8899a2dd95SBruce Richardson * @start_time
8999a2dd95SBruce Richardson * The time when the packet is inserted into the table
9099a2dd95SBruce Richardson *
9199a2dd95SBruce Richardson * @return
9299a2dd95SBruce Richardson * - Return a positive value if the packet is merged.
9399a2dd95SBruce Richardson * - Return zero if the packet isn't merged but stored in the table.
9499a2dd95SBruce Richardson * - Return a negative value for invalid parameters or no available
9599a2dd95SBruce Richardson * space in the table.
9699a2dd95SBruce Richardson */
9799a2dd95SBruce Richardson int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
9899a2dd95SBruce Richardson struct gro_tcp4_tbl *tbl,
9999a2dd95SBruce Richardson uint64_t start_time);
10099a2dd95SBruce Richardson
10199a2dd95SBruce Richardson /**
10299a2dd95SBruce Richardson * This function flushes timeout packets in a TCP/IPv4 reassembly table,
10399a2dd95SBruce Richardson * and without updating checksums.
10499a2dd95SBruce Richardson *
10599a2dd95SBruce Richardson * @param tbl
10699a2dd95SBruce Richardson * TCP/IPv4 reassembly table pointer
10799a2dd95SBruce Richardson * @param flush_timestamp
10899a2dd95SBruce Richardson * Flush packets which are inserted into the table before or at the
10999a2dd95SBruce Richardson * flush_timestamp.
11099a2dd95SBruce Richardson * @param out
11199a2dd95SBruce Richardson * Pointer array used to keep flushed packets
11299a2dd95SBruce Richardson * @param nb_out
11399a2dd95SBruce Richardson * The element number in 'out'. It also determines the maximum number of
11499a2dd95SBruce Richardson * packets that can be flushed finally.
11599a2dd95SBruce Richardson *
11699a2dd95SBruce Richardson * @return
11799a2dd95SBruce Richardson * The number of flushed packets
11899a2dd95SBruce Richardson */
11999a2dd95SBruce Richardson uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
12099a2dd95SBruce Richardson uint64_t flush_timestamp,
12199a2dd95SBruce Richardson struct rte_mbuf **out,
12299a2dd95SBruce Richardson uint16_t nb_out);
12399a2dd95SBruce Richardson
12499a2dd95SBruce Richardson /**
12599a2dd95SBruce Richardson * This function returns the number of the packets in a TCP/IPv4
12699a2dd95SBruce Richardson * reassembly table.
12799a2dd95SBruce Richardson *
12899a2dd95SBruce Richardson * @param tbl
12999a2dd95SBruce Richardson * TCP/IPv4 reassembly table pointer
13099a2dd95SBruce Richardson *
13199a2dd95SBruce Richardson * @return
13299a2dd95SBruce Richardson * The number of packets in the table
13399a2dd95SBruce Richardson */
13499a2dd95SBruce Richardson uint32_t gro_tcp4_tbl_pkt_count(void *tbl);
13599a2dd95SBruce Richardson
13699a2dd95SBruce Richardson /*
13799a2dd95SBruce Richardson * Check if two TCP/IPv4 packets belong to the same flow.
13899a2dd95SBruce Richardson */
13999a2dd95SBruce Richardson static inline int
is_same_tcp4_flow(struct tcp4_flow_key k1,struct tcp4_flow_key k2)14099a2dd95SBruce Richardson is_same_tcp4_flow(struct tcp4_flow_key k1, struct tcp4_flow_key k2)
14199a2dd95SBruce Richardson {
142*5c55e819SKumara Parameshwaran return ((k1.ip_src_addr == k2.ip_src_addr) &&
14399a2dd95SBruce Richardson (k1.ip_dst_addr == k2.ip_dst_addr) &&
144*5c55e819SKumara Parameshwaran is_same_common_tcp_key(&k1.cmn_key, &k2.cmn_key));
14599a2dd95SBruce Richardson }
14699a2dd95SBruce Richardson
14799a2dd95SBruce Richardson #endif
148