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