DPDK  16.11.11
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];
78  union {
79  uint64_t id_key_len;
80  __extension__
81  struct {
82  uint32_t id;
83  uint32_t key_len;
84  };
85  };
86 };
87 
92 struct ip_frag_pkt {
93  TAILQ_ENTRY(ip_frag_pkt) lru;
94  struct ip_frag_key key;
95  uint64_t start;
96  uint32_t total_size;
97  uint32_t frag_size;
98  uint32_t last_idx;
99  struct ip_frag frags[IP_MAX_FRAG_NUM];
101 
102 #define IP_FRAG_DEATH_ROW_LEN 32
105 struct rte_ip_frag_death_row {
106  uint32_t cnt;
107  struct rte_mbuf *row[IP_FRAG_DEATH_ROW_LEN * (IP_MAX_FRAG_NUM + 1)];
109 };
110 
111 TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
115  uint64_t find_num;
116  uint64_t add_num;
117  uint64_t del_num;
118  uint64_t reuse_num;
119  uint64_t fail_total;
120  uint64_t fail_nospace;
122 
125  uint64_t max_cycles;
126  uint32_t entry_mask;
127  uint32_t max_entries;
128  uint32_t use_entries;
129  uint32_t bucket_entries;
130  uint32_t nb_entries;
131  uint32_t nb_buckets;
132  struct ip_frag_pkt *last;
133  struct ip_pkt_list lru;
135  __extension__ struct ip_frag_pkt pkt[0];
136 };
137 
139 #define RTE_IPV6_EHDR_MF_SHIFT 0
140 #define RTE_IPV6_EHDR_MF_MASK 1
141 #define RTE_IPV6_EHDR_FO_SHIFT 3
142 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
143 
144 #define RTE_IPV6_FRAG_USED_MASK \
145  (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
146 
147 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
148 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
149 
150 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
151  (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
152 
153 struct ipv6_extension_fragment {
154  uint8_t next_header;
155  uint8_t reserved;
156  uint16_t frag_data;
157  uint32_t id;
158 } __attribute__((__packed__));
159 
160 
161 
181 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
182  uint32_t bucket_entries, uint32_t max_entries,
183  uint64_t max_cycles, int socket_id);
184 
191 static inline void
193 {
194  rte_free(tbl);
195 }
196 
218 int32_t
219 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
220  struct rte_mbuf **pkts_out,
221  uint16_t nb_pkts_out,
222  uint16_t mtu_size,
223  struct rte_mempool *pool_direct,
224  struct rte_mempool *pool_indirect);
225 
248  struct rte_ip_frag_death_row *dr,
249  struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr,
250  struct ipv6_extension_fragment *frag_hdr);
251 
263 static inline struct ipv6_extension_fragment *
265 {
266  if (hdr->proto == IPPROTO_FRAGMENT) {
267  return (struct ipv6_extension_fragment *) ++hdr;
268  }
269  else
270  return NULL;
271 }
272 
296 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
297  struct rte_mbuf **pkts_out,
298  uint16_t nb_pkts_out, uint16_t mtu_size,
299  struct rte_mempool *pool_direct,
300  struct rte_mempool *pool_indirect);
301 
322  struct rte_ip_frag_death_row *dr,
323  struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr);
324 
333 static inline int
335  uint16_t flag_offset, ip_flag, ip_ofs;
336 
337  flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
338  ip_ofs = (uint16_t)(flag_offset & IPV4_HDR_OFFSET_MASK);
339  ip_flag = (uint16_t)(flag_offset & IPV4_HDR_MF_FLAG);
340 
341  return ip_flag != 0 || ip_ofs != 0;
342 }
343 
353  uint32_t prefetch);
354 
355 
364 void
365 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
366 
367 #ifdef __cplusplus
368 }
369 #endif
370 
371 #endif /* _RTE_IP_FRAG_H_ */
uint32_t entry_mask
Definition: rte_ip_frag.h:126
static void rte_ip_frag_table_destroy(struct rte_ip_frag_tbl *tbl)
Definition: rte_ip_frag.h:192
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:264
struct ip_frag_tbl_stat stat
Definition: rte_ip_frag.h:134
__extension__ struct ip_frag_pkt pkt[0]
Definition: rte_ip_frag.h:135
uint32_t nb_entries
Definition: rte_ip_frag.h:130
uint8_t proto
Definition: rte_ip.h:404
static uint16_t rte_be_to_cpu_16(uint16_t x)
uint64_t del_num
Definition: rte_ip_frag.h:117
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:131
struct ip_pkt_list lru
Definition: rte_ip_frag.h:133
uint64_t fail_nospace
Definition: rte_ip_frag.h:120
uint32_t bucket_entries
Definition: rte_ip_frag.h:129
uint64_t reuse_num
Definition: rte_ip_frag.h:118
uint64_t add_num
Definition: rte_ip_frag.h:116
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)
void rte_free(void *ptr)
uint32_t max_entries
Definition: rte_ip_frag.h:127
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)
TAILQ_HEAD(rte_driver_list, rte_driver)
uint32_t use_entries
Definition: rte_ip_frag.h:128
uint64_t max_cycles
Definition: rte_ip_frag.h:125
#define RTE_STD_C11
Definition: rte_common.h:64
#define IP_FRAG_DEATH_ROW_LEN
Definition: rte_ip_frag.h:102
#define __rte_cache_aligned
Definition: rte_memory.h:96
struct ip_frag_pkt * last
Definition: rte_ip_frag.h:132
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:119
uint16_t fragment_offset
Definition: rte_ip.h:98
uint64_t find_num
Definition: rte_ip_frag.h:115
static int rte_ipv4_frag_pkt_is_fragmented(const struct ipv4_hdr *hdr)
Definition: rte_ip_frag.h:334
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)