lib: use SPDX tag for Intel copyright files
[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 L3 length of a TCP/IPv4 packet. The L3 length
13  * is the sum of ipv4 header, tcp header and L4 payload.
14  */
15 #define TCP4_MAX_L3_LENGTH UINT16_MAX
16
17 /* criteria of mergeing packets */
18 struct tcp4_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_key {
30         struct tcp4_key key;
31         /*
32          * the index of the first packet in the item group.
33          * If the value is INVALID_ARRAY_INDEX, it means
34          * the key is empty.
35          */
36         uint32_t start_index;
37 };
38
39 struct gro_tcp4_item {
40         /*
41          * first segment of the packet. If the value
42          * is NULL, it means the item is empty.
43          */
44         struct rte_mbuf *firstseg;
45         /* last segment of the packet */
46         struct rte_mbuf *lastseg;
47         /*
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
53          * table.
54          */
55         uint64_t start_time;
56         /*
57          * we use next_pkt_idx to chain the packets that
58          * have same key value but can't be merged together.
59          */
60         uint32_t next_pkt_idx;
61         /* the sequence number of the packet */
62         uint32_t sent_seq;
63         /* the IP ID of the packet */
64         uint16_t ip_id;
65         /* the number of merged packets */
66         uint16_t nb_merged;
67 };
68
69 /*
70  * TCP/IPv4 reassembly table structure.
71  */
72 struct gro_tcp4_tbl {
73         /* item array */
74         struct gro_tcp4_item *items;
75         /* key array */
76         struct gro_tcp4_key *keys;
77         /* current item number */
78         uint32_t item_num;
79         /* current key num */
80         uint32_t key_num;
81         /* item array size */
82         uint32_t max_item_num;
83         /* key array size */
84         uint32_t max_key_num;
85 };
86
87 /**
88  * This function creates a TCP/IPv4 reassembly table.
89  *
90  * @param socket_id
91  *  socket index for allocating TCP/IPv4 reassemble table
92  * @param max_flow_num
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.
96  *
97  * @return
98  *  if create successfully, return a pointer which points to the
99  *  created TCP/IPv4 GRO table. Otherwise, return NULL.
100  */
101 void *gro_tcp4_tbl_create(uint16_t socket_id,
102                 uint16_t max_flow_num,
103                 uint16_t max_item_per_flow);
104
105 /**
106  * This function destroys a TCP/IPv4 reassembly table.
107  *
108  * @param tbl
109  *  a pointer points to the TCP/IPv4 reassembly table.
110  */
111 void gro_tcp4_tbl_destroy(void *tbl);
112
113 /**
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.
122  *
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).
127  *
128  * @param pkt
129  *  packet to reassemble.
130  * @param tbl
131  *  a pointer that points to a TCP/IPv4 reassembly table.
132  * @start_time
133  *  the start time that the packet is inserted into the table
134  *
135  * @return
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.
141  */
142 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
143                 struct gro_tcp4_tbl *tbl,
144                 uint64_t start_time);
145
146 /**
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.
151  *
152  * @param tbl
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.
157  * @param out
158  *  pointer array which is used to keep flushed packets.
159  * @param nb_out
160  *  the element number of out. It's also the max number of timeout
161  *  packets that can be flushed finally.
162  *
163  * @return
164  *  the number of packets that are returned.
165  */
166 uint16_t gro_tcp4_tbl_timeout_flush(struct gro_tcp4_tbl *tbl,
167                 uint64_t flush_timestamp,
168                 struct rte_mbuf **out,
169                 uint16_t nb_out);
170
171 /**
172  * This function returns the number of the packets in a TCP/IPv4
173  * reassembly table.
174  *
175  * @param tbl
176  *  pointer points to a TCP/IPv4 reassembly table.
177  *
178  * @return
179  *  the number of packets in the table
180  */
181 uint32_t gro_tcp4_tbl_pkt_count(void *tbl);
182 #endif