DPDK  17.05.2
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_malloc.h>
52 #include <rte_memory.h>
53 #include <rte_ip.h>
54 #include <rte_byteorder.h>
55 
56 struct rte_mbuf;
57 
58 enum {
62  IP_MAX_FRAG_NUM = RTE_LIBRTE_IP_FRAG_MAX_FRAG,
64 };
65 
67 struct ip_frag {
68  uint16_t ofs;
69  uint16_t len;
70  struct rte_mbuf *mb;
71 };
72 
74 struct ip_frag_key {
75  uint64_t src_dst[4];
76  uint32_t id;
77  uint32_t key_len;
78 };
79 
84 struct ip_frag_pkt {
85  TAILQ_ENTRY(ip_frag_pkt) lru;
86  struct ip_frag_key key;
87  uint64_t start;
88  uint32_t total_size;
89  uint32_t frag_size;
90  uint32_t last_idx;
91  struct ip_frag frags[IP_MAX_FRAG_NUM];
93 
94 #define IP_FRAG_DEATH_ROW_LEN 32
97 struct rte_ip_frag_death_row {
98  uint32_t cnt;
99  struct rte_mbuf *row[IP_FRAG_DEATH_ROW_LEN * (IP_MAX_FRAG_NUM + 1)];
101 };
102 
103 TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
107  uint64_t find_num;
108  uint64_t add_num;
109  uint64_t del_num;
110  uint64_t reuse_num;
111  uint64_t fail_total;
112  uint64_t fail_nospace;
114 
117  uint64_t max_cycles;
118  uint32_t entry_mask;
119  uint32_t max_entries;
120  uint32_t use_entries;
121  uint32_t bucket_entries;
122  uint32_t nb_entries;
123  uint32_t nb_buckets;
124  struct ip_frag_pkt *last;
125  struct ip_pkt_list lru;
127  __extension__ struct ip_frag_pkt pkt[0];
128 };
129 
131 #define RTE_IPV6_EHDR_MF_SHIFT 0
132 #define RTE_IPV6_EHDR_MF_MASK 1
133 #define RTE_IPV6_EHDR_FO_SHIFT 3
134 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
135 
136 #define RTE_IPV6_FRAG_USED_MASK \
137  (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
138 
139 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
140 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
141 
142 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
143  (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
144 
145 struct ipv6_extension_fragment {
146  uint8_t next_header;
147  uint8_t reserved;
148  uint16_t frag_data;
149  uint32_t id;
150 } __attribute__((__packed__));
151 
152 
153 
173 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
174  uint32_t bucket_entries, uint32_t max_entries,
175  uint64_t max_cycles, int socket_id);
176 
183 static inline void
185 {
186  rte_free(tbl);
187 }
188 
210 int32_t
211 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
212  struct rte_mbuf **pkts_out,
213  uint16_t nb_pkts_out,
214  uint16_t mtu_size,
215  struct rte_mempool *pool_direct,
216  struct rte_mempool *pool_indirect);
217 
240  struct rte_ip_frag_death_row *dr,
241  struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr,
242  struct ipv6_extension_fragment *frag_hdr);
243 
255 static inline struct ipv6_extension_fragment *
257 {
258  if (hdr->proto == IPPROTO_FRAGMENT) {
259  return (struct ipv6_extension_fragment *) ++hdr;
260  }
261  else
262  return NULL;
263 }
264 
288 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
289  struct rte_mbuf **pkts_out,
290  uint16_t nb_pkts_out, uint16_t mtu_size,
291  struct rte_mempool *pool_direct,
292  struct rte_mempool *pool_indirect);
293 
314  struct rte_ip_frag_death_row *dr,
315  struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr);
316 
325 static inline int
327  uint16_t flag_offset, ip_flag, ip_ofs;
328 
329  flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
330  ip_ofs = (uint16_t)(flag_offset & IPV4_HDR_OFFSET_MASK);
331  ip_flag = (uint16_t)(flag_offset & IPV4_HDR_MF_FLAG);
332 
333  return ip_flag != 0 || ip_ofs != 0;
334 }
335 
345  uint32_t prefetch);
346 
347 
356 void
357 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
358 
359 #ifdef __cplusplus
360 }
361 #endif
362 
363 #endif /* _RTE_IP_FRAG_H_ */