DPDK  17.11.1
rte_ip_frag.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_IP_FRAG_H_
35 #define _RTE_IP_FRAG_H_
36 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include <stdint.h>
49 #include <stdio.h>
50 
51 #include <rte_config.h>
52 #include <rte_malloc.h>
53 #include <rte_memory.h>
54 #include <rte_ip.h>
55 #include <rte_byteorder.h>
56 
57 struct rte_mbuf;
58 
59 enum {
63  IP_MAX_FRAG_NUM = RTE_LIBRTE_IP_FRAG_MAX_FRAG,
65 };
66 
68 struct ip_frag {
69  uint16_t ofs;
70  uint16_t len;
71  struct rte_mbuf *mb;
72 };
73 
75 struct ip_frag_key {
76  uint64_t src_dst[4];
77  uint32_t id;
78  uint32_t key_len;
79 };
80 
85 struct ip_frag_pkt {
86  TAILQ_ENTRY(ip_frag_pkt) lru;
87  struct ip_frag_key key;
88  uint64_t start;
89  uint32_t total_size;
90  uint32_t frag_size;
91  uint32_t last_idx;
92  struct ip_frag frags[IP_MAX_FRAG_NUM];
94 
95 #define IP_FRAG_DEATH_ROW_LEN 32
98 struct rte_ip_frag_death_row {
99  uint32_t cnt;
102 };
103 
104 TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
108  uint64_t find_num;
109  uint64_t add_num;
110  uint64_t del_num;
111  uint64_t reuse_num;
112  uint64_t fail_total;
113  uint64_t fail_nospace;
115 
118  uint64_t max_cycles;
119  uint32_t entry_mask;
120  uint32_t max_entries;
121  uint32_t use_entries;
122  uint32_t bucket_entries;
123  uint32_t nb_entries;
124  uint32_t nb_buckets;
125  struct ip_frag_pkt *last;
126  struct ip_pkt_list lru;
127  struct ip_frag_tbl_stat stat;
128  __extension__ struct ip_frag_pkt pkt[0];
129 };
130 
132 #define RTE_IPV6_EHDR_MF_SHIFT 0
133 #define RTE_IPV6_EHDR_MF_MASK 1
134 #define RTE_IPV6_EHDR_FO_SHIFT 3
135 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
136 
137 #define RTE_IPV6_FRAG_USED_MASK \
138  (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
139 
140 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
141 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
142 
143 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
144  (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
145 
146 struct ipv6_extension_fragment {
147  uint8_t next_header;
148  uint8_t reserved;
149  uint16_t frag_data;
150  uint32_t id;
151 } __attribute__((__packed__));
152 
153 
154 
174 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
175  uint32_t bucket_entries, uint32_t max_entries,
176  uint64_t max_cycles, int socket_id);
177 
184 void
186 
208 int32_t
209 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
210  struct rte_mbuf **pkts_out,
211  uint16_t nb_pkts_out,
212  uint16_t mtu_size,
213  struct rte_mempool *pool_direct,
214  struct rte_mempool *pool_indirect);
215 
238  struct rte_ip_frag_death_row *dr,
239  struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr,
240  struct ipv6_extension_fragment *frag_hdr);
241 
253 static inline struct ipv6_extension_fragment *
255 {
256  if (hdr->proto == IPPROTO_FRAGMENT) {
257  return (struct ipv6_extension_fragment *) ++hdr;
258  }
259  else
260  return NULL;
261 }
262 
286 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
287  struct rte_mbuf **pkts_out,
288  uint16_t nb_pkts_out, uint16_t mtu_size,
289  struct rte_mempool *pool_direct,
290  struct rte_mempool *pool_indirect);
291 
312  struct rte_ip_frag_death_row *dr,
313  struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr);
314 
323 static inline int
325  uint16_t flag_offset, ip_flag, ip_ofs;
326 
327  flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
328  ip_ofs = (uint16_t)(flag_offset & IPV4_HDR_OFFSET_MASK);
329  ip_flag = (uint16_t)(flag_offset & IPV4_HDR_MF_FLAG);
330 
331  return ip_flag != 0 || ip_ofs != 0;
332 }
333 
343  uint32_t prefetch);
344 
345 
354 void
355 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 #endif /* _RTE_IP_FRAG_H_ */
uint32_t entry_mask
Definition: rte_ip_frag.h:119
struct rte_mbuf * rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr)
static struct ipv6_extension_fragment * rte_ipv6_frag_get_ipv6_fragment_header(struct ipv6_hdr *hdr)
Definition: rte_ip_frag.h:254
uint32_t nb_entries
Definition: rte_ip_frag.h:123
uint8_t proto
Definition: rte_ip.h:404
struct rte_mbuf __rte_cache_aligned
void rte_ip_frag_table_destroy(struct rte_ip_frag_tbl *tbl)
uint64_t del_num
Definition: rte_ip_frag.h:110
void rte_ip_frag_free_death_row(struct rte_ip_frag_death_row *dr, uint32_t prefetch)
uint32_t nb_buckets
Definition: rte_ip_frag.h:124
uint64_t fail_nospace
Definition: rte_ip_frag.h:113
uint32_t bucket_entries
Definition: rte_ip_frag.h:122
uint64_t reuse_num
Definition: rte_ip_frag.h:111
uint64_t add_num
Definition: rte_ip_frag.h:109
int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in, struct rte_mbuf **pkts_out, uint16_t nb_pkts_out, uint16_t mtu_size, struct rte_mempool *pool_direct, struct rte_mempool *pool_indirect)
uint32_t max_entries
Definition: rte_ip_frag.h:120
struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries, uint32_t max_entries, uint64_t max_cycles, int socket_id)
uint32_t use_entries
Definition: rte_ip_frag.h:121
uint64_t max_cycles
Definition: rte_ip_frag.h:118
#define IP_FRAG_DEATH_ROW_LEN
Definition: rte_ip_frag.h:95
struct ip_frag_pkt * last
Definition: rte_ip_frag.h:125
int32_t rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in, struct rte_mbuf **pkts_out, uint16_t nb_pkts_out, uint16_t mtu_size, struct rte_mempool *pool_direct, struct rte_mempool *pool_indirect)
uint64_t fail_total
Definition: rte_ip_frag.h:112
static uint16_t rte_be_to_cpu_16(rte_be16_t x)
uint16_t fragment_offset
Definition: rte_ip.h:98
uint64_t find_num
Definition: rte_ip_frag.h:108
static int rte_ipv4_frag_pkt_is_fragmented(const struct ipv4_hdr *hdr)
Definition: rte_ip_frag.h:324
void rte_ip_frag_table_statistics_dump(FILE *f, const struct rte_ip_frag_tbl *tbl)
struct rte_mbuf * rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr, struct ipv6_extension_fragment *frag_hdr)