xref: /dpdk/lib/gro/gro_vxlan_udp4.h (revision 99a2dd955fba6e4cc23b77d590a033650ced9c45)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Inspur Corporation
3  */
4 
5 #ifndef _GRO_VXLAN_UDP4_H_
6 #define _GRO_VXLAN_UDP4_H_
7 
8 #include "gro_udp4.h"
9 
10 #define GRO_VXLAN_UDP4_TBL_MAX_ITEM_NUM (1024UL * 1024UL)
11 
12 /* Header fields representing a VxLAN flow */
13 struct vxlan_udp4_flow_key {
14 	struct udp4_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 	/* Note: It is unnecessary to save outer_src_port here because it can
24 	 * be different for VxLAN UDP fragments from the same flow.
25 	 */
26 	uint16_t outer_dst_port;
27 };
28 
29 struct gro_vxlan_udp4_flow {
30 	struct vxlan_udp4_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_udp4_item {
39 	struct gro_udp4_item inner_item;
40 	/* Note: VXLAN UDP/IPv4 GRO needn't check outer_ip_id because
41 	 * the difference between outer_ip_ids of two received packets
42 	 * isn't always +/-1 in case of OVS DPDK. So no outer_ip_id
43 	 * and outer_is_atomic fields here.
44 	 */
45 };
46 
47 /*
48  * VxLAN (with an outer IPv4 header and an inner UDP/IPv4 packet)
49  * reassembly table structure
50  */
51 struct gro_vxlan_udp4_tbl {
52 	/* item array */
53 	struct gro_vxlan_udp4_item *items;
54 	/* flow array */
55 	struct gro_vxlan_udp4_flow *flows;
56 	/* current item number */
57 	uint32_t item_num;
58 	/* current flow number */
59 	uint32_t flow_num;
60 	/* the maximum item number */
61 	uint32_t max_item_num;
62 	/* the maximum flow number */
63 	uint32_t max_flow_num;
64 };
65 
66 /**
67  * This function creates a VxLAN reassembly table for VxLAN packets
68  * which have an outer IPv4 header and an inner UDP/IPv4 packet.
69  *
70  * @param socket_id
71  *  Socket index for allocating the table
72  * @param max_flow_num
73  *  The maximum number of flows in the table
74  * @param max_item_per_flow
75  *  The maximum number of packets per flow
76  *
77  * @return
78  *  - Return the table pointer on success.
79  *  - Return NULL on failure.
80  */
81 void *gro_vxlan_udp4_tbl_create(uint16_t socket_id,
82 		uint16_t max_flow_num,
83 		uint16_t max_item_per_flow);
84 
85 /**
86  * This function destroys a VxLAN reassembly table.
87  *
88  * @param tbl
89  *  Pointer pointing to the VxLAN reassembly table
90  */
91 void gro_vxlan_udp4_tbl_destroy(void *tbl);
92 
93 /**
94  * This function merges a VxLAN packet which has an outer IPv4 header and
95  * an inner UDP/IPv4 packet. It does not process the packet which does not
96  * have payload.
97  *
98  * This function does not check if the packet has correct checksums and
99  * does not re-calculate checksums for the merged packet. It returns the
100  * packet if there is no available space in the table.
101  *
102  * @param pkt
103  *  Packet to reassemble
104  * @param tbl
105  *  Pointer pointing to the VxLAN reassembly table
106  * @start_time
107  *  The time when the packet is inserted into the table
108  *
109  * @return
110  *  - Return a positive value if the packet is merged.
111  *  - Return zero if the packet isn't merged but stored in the table.
112  *  - Return a negative value for invalid parameters or no available
113  *    space in the table.
114  */
115 int32_t gro_vxlan_udp4_reassemble(struct rte_mbuf *pkt,
116 		struct gro_vxlan_udp4_tbl *tbl,
117 		uint64_t start_time);
118 
119 /**
120  * This function flushes timeout packets in the VxLAN reassembly table,
121  * and without updating checksums.
122  *
123  * @param tbl
124  *  Pointer pointing to a VxLAN GRO table
125  * @param flush_timestamp
126  *  This function flushes packets which are inserted into the table
127  *  before or at the flush_timestamp.
128  * @param out
129  *  Pointer array used to keep flushed packets
130  * @param nb_out
131  *  The element number in 'out'. It also determines the maximum number of
132  *  packets that can be flushed finally.
133  *
134  * @return
135  *  The number of flushed packets
136  */
137 uint16_t gro_vxlan_udp4_tbl_timeout_flush(struct gro_vxlan_udp4_tbl *tbl,
138 		uint64_t flush_timestamp,
139 		struct rte_mbuf **out,
140 		uint16_t nb_out);
141 
142 /**
143  * This function returns the number of the packets in a VxLAN
144  * reassembly table.
145  *
146  * @param tbl
147  *  Pointer pointing to the VxLAN reassembly table
148  *
149  * @return
150  *  The number of packets in the table
151  */
152 uint32_t gro_vxlan_udp4_tbl_pkt_count(void *tbl);
153 #endif
154