xref: /dpdk/lib/gro/gro_vxlan_tcp4.h (revision 5c55e8193b9b608aa38a54741de3303f2bf9193d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 
5 #ifndef _GRO_VXLAN_TCP4_H_
6 #define _GRO_VXLAN_TCP4_H_
7 
8 #include "gro_tcp4.h"
9 
10 #define GRO_VXLAN_TCP4_TBL_MAX_ITEM_NUM (1024UL * 1024UL)
11 
12 /* Header fields representing a VxLAN flow */
13 struct vxlan_tcp4_flow_key {
14 	struct tcp4_flow_key inner_key;
15 	struct rte_vxlan_hdr vxlan_hdr;
16 
17 	struct rte_ether_addr outer_eth_saddr;
18 	struct rte_ether_addr outer_eth_daddr;
19 
20 	uint32_t outer_ip_src_addr;
21 	uint32_t outer_ip_dst_addr;
22 
23 	/* Outer UDP ports */
24 	uint16_t outer_src_port;
25 	uint16_t outer_dst_port;
26 
27 };
28 
29 struct gro_vxlan_tcp4_flow {
30 	struct vxlan_tcp4_flow_key key;
31 	/*
32 	 * The index of the first packet in the flow. INVALID_ARRAY_INDEX
33 	 * indicates an empty flow.
34 	 */
35 	uint32_t start_index;
36 };
37 
38 struct gro_vxlan_tcp4_item {
39 	struct gro_tcp_item inner_item;
40 	/* IPv4 ID in the outer IPv4 header */
41 	uint16_t outer_ip_id;
42 	/* Indicate if outer IPv4 ID can be ignored */
43 	uint8_t outer_is_atomic;
44 };
45 
46 /*
47  * VxLAN (with an outer IPv4 header and an inner TCP/IPv4 packet)
48  * reassembly table structure
49  */
50 struct gro_vxlan_tcp4_tbl {
51 	/* item array */
52 	struct gro_vxlan_tcp4_item *items;
53 	/* flow array */
54 	struct gro_vxlan_tcp4_flow *flows;
55 	/* current item number */
56 	uint32_t item_num;
57 	/* current flow number */
58 	uint32_t flow_num;
59 	/* the maximum item number */
60 	uint32_t max_item_num;
61 	/* the maximum flow number */
62 	uint32_t max_flow_num;
63 };
64 
65 /**
66  * This function creates a VxLAN reassembly table for VxLAN packets
67  * which have an outer IPv4 header and an inner TCP/IPv4 packet.
68  *
69  * @param socket_id
70  *  Socket index for allocating the table
71  * @param max_flow_num
72  *  The maximum number of flows in the table
73  * @param max_item_per_flow
74  *  The maximum number of packets per flow
75  *
76  * @return
77  *  - Return the table pointer on success.
78  *  - Return NULL on failure.
79  */
80 void *gro_vxlan_tcp4_tbl_create(uint16_t socket_id,
81 		uint16_t max_flow_num,
82 		uint16_t max_item_per_flow);
83 
84 /**
85  * This function destroys a VxLAN reassembly table.
86  *
87  * @param tbl
88  *  Pointer pointing to the VxLAN reassembly table
89  */
90 void gro_vxlan_tcp4_tbl_destroy(void *tbl);
91 
92 /**
93  * This function merges a VxLAN packet which has an outer IPv4 header and
94  * an inner TCP/IPv4 packet. It doesn't process the packet, whose TCP
95  * header has SYN, FIN, RST, PSH, CWR, ECE or URG bit set, or which
96  * doesn't have payload.
97  *
98  * This function doesn't check if the packet has correct checksums and
99  * doesn't re-calculate checksums for the merged packet. Additionally,
100  * it assumes the packets are complete (i.e., MF==0 && frag_off==0), when
101  * IP fragmentation is possible (i.e., DF==0). It returns the packet, if
102  * the packet has invalid parameters (e.g. SYN bit is set) or there is no
103  * available space in the table.
104  *
105  * @param pkt
106  *  Packet to reassemble
107  * @param tbl
108  *  Pointer pointing to the VxLAN reassembly table
109  * @start_time
110  *  The time when the packet is inserted into the table
111  *
112  * @return
113  *  - Return a positive value if the packet is merged.
114  *  - Return zero if the packet isn't merged but stored in the table.
115  *  - Return a negative value for invalid parameters or no available
116  *    space in the table.
117  */
118 int32_t gro_vxlan_tcp4_reassemble(struct rte_mbuf *pkt,
119 		struct gro_vxlan_tcp4_tbl *tbl,
120 		uint64_t start_time);
121 
122 /**
123  * This function flushes timeout packets in the VxLAN reassembly table,
124  * and without updating checksums.
125  *
126  * @param tbl
127  *  Pointer pointing to a VxLAN GRO table
128  * @param flush_timestamp
129  *  This function flushes packets which are inserted into the table
130  *  before or at the flush_timestamp.
131  * @param out
132  *  Pointer array used to keep flushed packets
133  * @param nb_out
134  *  The element number in 'out'. It also determines the maximum number of
135  *  packets that can be flushed finally.
136  *
137  * @return
138  *  The number of flushed packets
139  */
140 uint16_t gro_vxlan_tcp4_tbl_timeout_flush(struct gro_vxlan_tcp4_tbl *tbl,
141 		uint64_t flush_timestamp,
142 		struct rte_mbuf **out,
143 		uint16_t nb_out);
144 
145 /**
146  * This function returns the number of the packets in a VxLAN
147  * reassembly table.
148  *
149  * @param tbl
150  *  Pointer pointing to the VxLAN reassembly table
151  *
152  * @return
153  *  The number of packets in the table
154  */
155 uint32_t gro_vxlan_tcp4_tbl_pkt_count(void *tbl);
156 #endif
157