DPDK  17.11.10
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];
79  union {
80  uint64_t id_key_len;
81  __extension__
82  struct {
83  uint32_t id;
84  uint32_t key_len;
85  };
86  };
87 };
88 
93 struct ip_frag_pkt {
94  TAILQ_ENTRY(ip_frag_pkt) lru;
95  struct ip_frag_key key;
96  uint64_t start;
97  uint32_t total_size;
98  uint32_t frag_size;
99  uint32_t last_idx;
100  struct ip_frag frags[IP_MAX_FRAG_NUM];
102 
103 #define IP_FRAG_DEATH_ROW_LEN 32
106 struct rte_ip_frag_death_row {
107  uint32_t cnt;
108  struct rte_mbuf *row[IP_FRAG_DEATH_ROW_LEN * (IP_MAX_FRAG_NUM + 1)];
110 };
111 
112 TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
116  uint64_t find_num;
117  uint64_t add_num;
118  uint64_t del_num;
119  uint64_t reuse_num;
120  uint64_t fail_total;
121  uint64_t fail_nospace;
123 
126  uint64_t max_cycles;
127  uint32_t entry_mask;
128  uint32_t max_entries;
129  uint32_t use_entries;
130  uint32_t bucket_entries;
131  uint32_t nb_entries;
132  uint32_t nb_buckets;
133  struct ip_frag_pkt *last;
134  struct ip_pkt_list lru;
136  __extension__ struct ip_frag_pkt pkt[0];
137 };
138 
140 #define RTE_IPV6_EHDR_MF_SHIFT 0
141 #define RTE_IPV6_EHDR_MF_MASK 1
142 #define RTE_IPV6_EHDR_FO_SHIFT 3
143 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
144 
145 #define RTE_IPV6_FRAG_USED_MASK \
146  (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
147 
148 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
149 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
150 
151 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
152  (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
153 
154 struct ipv6_extension_fragment {
155  uint8_t next_header;
156  uint8_t reserved;
157  uint16_t frag_data;
158  uint32_t id;
159 } __attribute__((__packed__));
160 
161 
162 
182 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
183  uint32_t bucket_entries, uint32_t max_entries,
184  uint64_t max_cycles, int socket_id);
185 
192 void
194 
216 int32_t
217 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
218  struct rte_mbuf **pkts_out,
219  uint16_t nb_pkts_out,
220  uint16_t mtu_size,
221  struct rte_mempool *pool_direct,
222  struct rte_mempool *pool_indirect);
223 
246  struct rte_ip_frag_death_row *dr,
247  struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr,
248  struct ipv6_extension_fragment *frag_hdr);
249 
261 static inline struct ipv6_extension_fragment *
263 {
264  if (hdr->proto == IPPROTO_FRAGMENT) {
265  return (struct ipv6_extension_fragment *) ++hdr;
266  }
267  else
268  return NULL;
269 }
270 
294 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
295  struct rte_mbuf **pkts_out,
296  uint16_t nb_pkts_out, uint16_t mtu_size,
297  struct rte_mempool *pool_direct,
298  struct rte_mempool *pool_indirect);
299 
320  struct rte_ip_frag_death_row *dr,
321  struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr);
322 
331 static inline int
333  uint16_t flag_offset, ip_flag, ip_ofs;
334 
335  flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
336  ip_ofs = (uint16_t)(flag_offset & IPV4_HDR_OFFSET_MASK);
337  ip_flag = (uint16_t)(flag_offset & IPV4_HDR_MF_FLAG);
338 
339  return ip_flag != 0 || ip_ofs != 0;
340 }
341 
351  uint32_t prefetch);
352 
353 
362 void
363 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
364 
365 #ifdef __cplusplus
366 }
367 #endif
368 
369 #endif /* _RTE_IP_FRAG_H_ */
uint32_t entry_mask
Definition: rte_ip_frag.h:127
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:262
struct ip_frag_tbl_stat stat
Definition: rte_ip_frag.h:135
__extension__ struct ip_frag_pkt pkt[0]
Definition: rte_ip_frag.h:136
uint32_t nb_entries
Definition: rte_ip_frag.h:131
uint8_t proto
Definition: rte_ip.h:408
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:118
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:132
struct ip_pkt_list lru
Definition: rte_ip_frag.h:134
uint64_t fail_nospace
Definition: rte_ip_frag.h:121
uint32_t bucket_entries
Definition: rte_ip_frag.h:130
uint64_t reuse_num
Definition: rte_ip_frag.h:119
uint64_t add_num
Definition: rte_ip_frag.h:117
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:128
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:129
uint64_t max_cycles
Definition: rte_ip_frag.h:126
#define RTE_STD_C11
Definition: rte_common.h:66
#define IP_FRAG_DEATH_ROW_LEN
Definition: rte_ip_frag.h:103
struct ip_frag_pkt * last
Definition: rte_ip_frag.h:133
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:120
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:116
static int rte_ipv4_frag_pkt_is_fragmented(const struct ipv4_hdr *hdr)
Definition: rte_ip_frag.h:332
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)