DPDK  18.05.1
rte_ip_frag.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_IP_FRAG_H_
6 #define _RTE_IP_FRAG_H_
7 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 
22 #include <rte_config.h>
23 #include <rte_malloc.h>
24 #include <rte_memory.h>
25 #include <rte_ip.h>
26 #include <rte_byteorder.h>
27 
28 struct rte_mbuf;
29 
30 enum {
34  IP_MAX_FRAG_NUM = RTE_LIBRTE_IP_FRAG_MAX_FRAG,
36 };
37 
39 struct ip_frag {
40  uint16_t ofs;
41  uint16_t len;
42  struct rte_mbuf *mb;
43 };
44 
46 struct ip_frag_key {
47  uint64_t src_dst[4];
48  uint32_t id;
49  uint32_t key_len;
50 };
51 
56 struct ip_frag_pkt {
57  TAILQ_ENTRY(ip_frag_pkt) lru;
58  struct ip_frag_key key;
59  uint64_t start;
60  uint32_t total_size;
61  uint32_t frag_size;
62  uint32_t last_idx;
63  struct ip_frag frags[IP_MAX_FRAG_NUM];
65 
66 #define IP_FRAG_DEATH_ROW_LEN 32
69 struct rte_ip_frag_death_row {
70  uint32_t cnt;
71  struct rte_mbuf *row[IP_FRAG_DEATH_ROW_LEN * (IP_MAX_FRAG_NUM + 1)];
73 };
74 
75 TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
79  uint64_t find_num;
80  uint64_t add_num;
81  uint64_t del_num;
82  uint64_t reuse_num;
83  uint64_t fail_total;
84  uint64_t fail_nospace;
86 
89  uint64_t max_cycles;
90  uint32_t entry_mask;
91  uint32_t max_entries;
92  uint32_t use_entries;
93  uint32_t bucket_entries;
94  uint32_t nb_entries;
95  uint32_t nb_buckets;
96  struct ip_frag_pkt *last;
97  struct ip_pkt_list lru;
99  __extension__ struct ip_frag_pkt pkt[0];
100 };
101 
103 #define RTE_IPV6_EHDR_MF_SHIFT 0
104 #define RTE_IPV6_EHDR_MF_MASK 1
105 #define RTE_IPV6_EHDR_FO_SHIFT 3
106 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
107 
108 #define RTE_IPV6_FRAG_USED_MASK \
109  (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
110 
111 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
112 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
113 
114 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
115  (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
116 
117 struct ipv6_extension_fragment {
118  uint8_t next_header;
119  uint8_t reserved;
120  uint16_t frag_data;
121  uint32_t id;
122 } __attribute__((__packed__));
123 
124 
125 
145 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
146  uint32_t bucket_entries, uint32_t max_entries,
147  uint64_t max_cycles, int socket_id);
148 
155 void
157 
179 int32_t
180 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
181  struct rte_mbuf **pkts_out,
182  uint16_t nb_pkts_out,
183  uint16_t mtu_size,
184  struct rte_mempool *pool_direct,
185  struct rte_mempool *pool_indirect);
186 
209  struct rte_ip_frag_death_row *dr,
210  struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr,
211  struct ipv6_extension_fragment *frag_hdr);
212 
224 static inline struct ipv6_extension_fragment *
226 {
227  if (hdr->proto == IPPROTO_FRAGMENT) {
228  return (struct ipv6_extension_fragment *) ++hdr;
229  }
230  else
231  return NULL;
232 }
233 
257 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
258  struct rte_mbuf **pkts_out,
259  uint16_t nb_pkts_out, uint16_t mtu_size,
260  struct rte_mempool *pool_direct,
261  struct rte_mempool *pool_indirect);
262 
283  struct rte_ip_frag_death_row *dr,
284  struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr);
285 
294 static inline int
296  uint16_t flag_offset, ip_flag, ip_ofs;
297 
298  flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
299  ip_ofs = (uint16_t)(flag_offset & IPV4_HDR_OFFSET_MASK);
300  ip_flag = (uint16_t)(flag_offset & IPV4_HDR_MF_FLAG);
301 
302  return ip_flag != 0 || ip_ofs != 0;
303 }
304 
314  uint32_t prefetch);
315 
316 
325 void
326 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 
332 #endif /* _RTE_IP_FRAG_H_ */