1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef _RTE_IP_FRAG_H_
6 #define _RTE_IP_FRAG_H_
10 * RTE IP Fragmentation and Reassembly
12 * Implementation of IP packet fragmentation and reassembly.
22 #include <rte_config.h>
23 #include <rte_malloc.h>
24 #include <rte_memory.h>
26 #include <rte_byteorder.h>
30 /** death row size (in packets) */
31 #define RTE_IP_FRAG_DEATH_ROW_LEN 32
33 /** death row size in mbufs */
34 #define RTE_IP_FRAG_DEATH_ROW_MBUF_LEN \
35 (RTE_IP_FRAG_DEATH_ROW_LEN * (RTE_LIBRTE_IP_FRAG_MAX_FRAG + 1))
37 /** mbuf death row (packets to be freed) */
38 struct rte_ip_frag_death_row {
39 uint32_t cnt; /**< number of mbufs currently on death row */
40 struct rte_mbuf *row[RTE_IP_FRAG_DEATH_ROW_MBUF_LEN];
41 /**< mbufs to be freed */
45 * Create a new IP fragmentation table.
48 * Number of buckets in the hash table.
49 * @param bucket_entries
50 * Number of entries per bucket (e.g. hash associativity).
51 * Should be power of two.
53 * Maximum number of entries that could be stored in the table.
54 * The value should be less or equal then bucket_num * bucket_entries.
56 * Maximum TTL in cycles for each fragmented packet.
58 * The *socket_id* argument is the socket identifier in the case of
59 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA constraints.
61 * The pointer to the new allocated fragmentation table, on success. NULL on error.
63 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
64 uint32_t bucket_entries, uint32_t max_entries,
65 uint64_t max_cycles, int socket_id);
68 * Free allocated IP fragmentation table.
71 * Fragmentation table to free.
74 rte_ip_frag_table_destroy(struct rte_ip_frag_tbl *tbl);
77 * This function implements the fragmentation of IPv6 packets.
82 * Array storing the output fragments.
84 * Number of fragments.
86 * Size in bytes of the Maximum Transfer Unit (MTU) for the outgoing IPv6
87 * datagrams. This value includes the size of the IPv6 header.
89 * MBUF pool used for allocating direct buffers for the output fragments.
90 * @param pool_indirect
91 * MBUF pool used for allocating indirect buffers for the output fragments.
93 * Upon successful completion - number of output fragments placed
94 * in the pkts_out array.
95 * Otherwise - (-1) * errno.
98 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
99 struct rte_mbuf **pkts_out,
100 uint16_t nb_pkts_out,
102 struct rte_mempool *pool_direct,
103 struct rte_mempool *pool_indirect);
106 * This function implements reassembly of fragmented IPv6 packets.
107 * Incoming mbuf should have its l2_len/l3_len fields setup correctly.
110 * Table where to lookup/add the fragmented packet.
112 * Death row to free buffers to
114 * Incoming mbuf with IPv6 fragment.
116 * Fragment arrival timestamp.
118 * Pointer to the IPv6 header.
120 * Pointer to the IPv6 fragment extension header.
122 * Pointer to mbuf for reassembled packet, or NULL if:
123 * - an error occurred.
124 * - not all fragments of the packet are collected yet.
126 struct rte_mbuf *rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
127 struct rte_ip_frag_death_row *dr,
128 struct rte_mbuf *mb, uint64_t tms, struct rte_ipv6_hdr *ip_hdr,
129 struct rte_ipv6_fragment_ext *frag_hdr);
132 * Return a pointer to the packet's fragment header, if found.
133 * It only looks at the extension header that's right after the fixed IPv6
134 * header, and doesn't follow the whole chain of extension headers.
137 * Pointer to the IPv6 header.
139 * Pointer to the IPv6 fragment extension header, or NULL if it's not
142 static inline struct rte_ipv6_fragment_ext *
143 rte_ipv6_frag_get_ipv6_fragment_header(struct rte_ipv6_hdr *hdr)
145 if (hdr->proto == IPPROTO_FRAGMENT) {
146 return (struct rte_ipv6_fragment_ext *) ++hdr;
153 * IPv4 fragmentation.
155 * This function implements the fragmentation of IPv4 packets.
160 * Array storing the output fragments.
162 * Number of fragments.
164 * Size in bytes of the Maximum Transfer Unit (MTU) for the outgoing IPv4
165 * datagrams. This value includes the size of the IPv4 header.
167 * MBUF pool used for allocating direct buffers for the output fragments.
168 * @param pool_indirect
169 * MBUF pool used for allocating indirect buffers for the output fragments.
171 * Upon successful completion - number of output fragments placed
172 * in the pkts_out array.
173 * Otherwise - (-1) * errno.
175 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
176 struct rte_mbuf **pkts_out,
177 uint16_t nb_pkts_out, uint16_t mtu_size,
178 struct rte_mempool *pool_direct,
179 struct rte_mempool *pool_indirect);
182 * This function implements reassembly of fragmented IPv4 packets.
183 * Incoming mbufs should have its l2_len/l3_len fields setup correctly.
186 * Table where to lookup/add the fragmented packet.
188 * Death row to free buffers to
190 * Incoming mbuf with IPv4 fragment.
192 * Fragment arrival timestamp.
194 * Pointer to the IPV4 header inside the fragment.
196 * Pointer to mbuf for reassembled packet, or NULL if:
197 * - an error occurred.
198 * - not all fragments of the packet are collected yet.
200 struct rte_mbuf * rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
201 struct rte_ip_frag_death_row *dr,
202 struct rte_mbuf *mb, uint64_t tms, struct rte_ipv4_hdr *ip_hdr);
205 * Check if the IPv4 packet is fragmented
208 * IPv4 header of the packet
210 * 1 if fragmented, 0 if not fragmented
213 rte_ipv4_frag_pkt_is_fragmented(const struct rte_ipv4_hdr *hdr)
215 uint16_t flag_offset, ip_flag, ip_ofs;
217 flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
218 ip_ofs = (uint16_t)(flag_offset & RTE_IPV4_HDR_OFFSET_MASK);
219 ip_flag = (uint16_t)(flag_offset & RTE_IPV4_HDR_MF_FLAG);
221 return ip_flag != 0 || ip_ofs != 0;
225 * Free mbufs on a given death row.
228 * Death row to free mbufs in.
230 * How many buffers to prefetch before freeing.
232 void rte_ip_frag_free_death_row(struct rte_ip_frag_death_row *dr,
237 * Dump fragmentation table statistics to file.
240 * File to dump statistics to
242 * Fragmentation table to dump statistics from
245 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
248 * Delete expired fragments
251 * Table to delete expired fragments from
253 * Death row to free buffers to
259 rte_ip_frag_table_del_expired_entries(struct rte_ip_frag_tbl *tbl,
260 struct rte_ip_frag_death_row *dr, uint64_t tms);
262 /**@{@name Obsolete macros, kept here for compatibility reasons.
263 * Will be deprecated/removed in future DPDK releases.
266 #define IP_FRAG_DEATH_ROW_LEN RTE_IP_FRAG_DEATH_ROW_LEN
268 #define IP_FRAG_DEATH_ROW_MBUF_LEN RTE_IP_FRAG_DEATH_ROW_MBUF_LEN
270 #define ipv6_extension_fragment rte_ipv6_fragment_ext
277 #endif /* _RTE_IP_FRAG_H_ */