gro: cleanup
[dpdk.git] / lib / librte_gro / gro_tcp4.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _GRO_TCP4_H_
6 #define _GRO_TCP4_H_
7
8 #define INVALID_ARRAY_INDEX 0xffffffffUL
9 #define GRO_TCP4_TBL_MAX_ITEM_NUM (1024UL * 1024UL)
10
11 /*
12  * The max length of a IPv4 packet, which includes the length of the L3
13  * header, the L4 header and the data payload.
14  */
15 #define MAX_IPV4_PKT_LENGTH UINT16_MAX
16
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;
21         uint32_t ip_src_addr;
22         uint32_t ip_dst_addr;
23
24         uint32_t recv_ack;
25         uint16_t src_port;
26         uint16_t dst_port;
27 };
28
29 struct gro_tcp4_flow {
30         struct tcp4_flow_key key;
31         /*
32          * The index of the first packet in the flow.
33          * INVALID_ARRAY_INDEX indicates an empty flow.
34          */
35         uint32_t start_index;
36 };
37
38 struct gro_tcp4_item {
39         /*
40          * The first MBUF segment of the packet. If the value
41          * is NULL, it means the item is empty.
42          */
43         struct rte_mbuf *firstseg;
44         /* The last MBUF segment of the packet */
45         struct rte_mbuf *lastseg;
46         /*
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
49          * with other packets.
50          */
51         uint64_t start_time;
52         /*
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).
56          */
57         uint32_t next_pkt_idx;
58         /* TCP sequence number of the packet */
59         uint32_t sent_seq;
60         /* IPv4 ID of the packet */
61         uint16_t ip_id;
62         /* the number of merged packets */
63         uint16_t nb_merged;
64 };
65
66 /*
67  * TCP/IPv4 reassembly table structure.
68  */
69 struct gro_tcp4_tbl {
70         /* item array */
71         struct gro_tcp4_item *items;
72         /* flow array */
73         struct gro_tcp4_flow *flows;
74         /* current item number */
75         uint32_t item_num;
76         /* current flow num */
77         uint32_t flow_num;
78         /* item array size */
79         uint32_t max_item_num;
80         /* flow array size */
81         uint32_t max_flow_num;
82 };
83
84 /**
85  * This function creates a TCP/IPv4 reassembly table.
86  *
87  * @param socket_id
88  *  Socket index for allocating the TCP/IPv4 reassemble table
89  * @param max_flow_num
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
93  *
94  * @return
95  *  - Return the table pointer on success.
96  *  - Return NULL on failure.
97  */
98 void *gro_tcp4_tbl_create(uint16_t socket_id,
99                 uint16_t max_flow_num,
100                 uint16_t max_item_per_flow);
101
102 /**
103  * This function destroys a TCP/IPv4 reassembly table.
104  *
105  * @param tbl
106  *  Pointer pointing to the TCP/IPv4 reassembly table.
107  */
108 void gro_tcp4_tbl_destroy(void *tbl);
109
110 /**
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
113  * payload.
114  *
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.
121  *
122  * @param pkt
123  *  Packet to reassemble
124  * @param tbl
125  *  Pointer pointing to the TCP/IPv4 reassembly table
126  * @start_time
127  *  The time when the packet is inserted into the table
128  *
129  * @return
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.
134  */
135 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
136                 struct gro_tcp4_tbl *tbl,
137                 uint64_t start_time);
138
139 /**
140  * This function flushes timeout packets in a TCP/IPv4 reassembly table,
141  * and without updating checksums.
142  *
143  * @param tbl
144  *  TCP/IPv4 reassembly table pointer
145  * @param flush_timestamp
146  *  Flush packets which are inserted into the table before or at the
147  *  flush_timestamp.
148  * @param out
149  *  Pointer array used to keep flushed packets
150  * @param nb_out
151  *  The element number in 'out'. It also determines the maximum number of
152  *  packets that can be flushed finally.
153  *
154  * @return
155  *  The number of flushed packets
156  */
157 uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
158                 uint64_t flush_timestamp,
159                 struct rte_mbuf **out,
160                 uint16_t nb_out);
161
162 /**
163  * This function returns the number of the packets in a TCP/IPv4
164  * reassembly table.
165  *
166  * @param tbl
167  *  TCP/IPv4 reassembly table pointer
168  *
169  * @return
170  *  The number of packets in the table
171  */
172 uint32_t gro_tcp4_tbl_pkt_count(void *tbl);
173 #endif