DPDK  19.02.0
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];
50  union {
51  uint64_t id_key_len;
52  __extension__
53  struct {
54  uint32_t id;
55  uint32_t key_len;
56  };
57  };
58 };
59 
64 struct ip_frag_pkt {
65  TAILQ_ENTRY(ip_frag_pkt) lru;
66  struct ip_frag_key key;
67  uint64_t start;
68  uint32_t total_size;
69  uint32_t frag_size;
70  uint32_t last_idx;
71  struct ip_frag frags[IP_MAX_FRAG_NUM];
73 
74 #define IP_FRAG_DEATH_ROW_LEN 32
76 /* death row size in mbufs */
77 #define IP_FRAG_DEATH_ROW_MBUF_LEN (IP_FRAG_DEATH_ROW_LEN * (IP_MAX_FRAG_NUM + 1))
78 
81  uint32_t cnt;
82  struct rte_mbuf *row[IP_FRAG_DEATH_ROW_MBUF_LEN];
84 };
85 
86 TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
90  uint64_t find_num;
91  uint64_t add_num;
92  uint64_t del_num;
93  uint64_t reuse_num;
94  uint64_t fail_total;
95  uint64_t fail_nospace;
97 
100  uint64_t max_cycles;
101  uint32_t entry_mask;
102  uint32_t max_entries;
103  uint32_t use_entries;
104  uint32_t bucket_entries;
105  uint32_t nb_entries;
106  uint32_t nb_buckets;
107  struct ip_frag_pkt *last;
108  struct ip_pkt_list lru;
109  struct ip_frag_tbl_stat stat;
110  __extension__ struct ip_frag_pkt pkt[0];
111 };
112 
114 #define RTE_IPV6_EHDR_MF_SHIFT 0
115 #define RTE_IPV6_EHDR_MF_MASK 1
116 #define RTE_IPV6_EHDR_FO_SHIFT 3
117 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
118 #define RTE_IPV6_EHDR_FO_ALIGN (1 << RTE_IPV6_EHDR_FO_SHIFT)
119 
120 #define RTE_IPV6_FRAG_USED_MASK \
121  (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
122 
123 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
124 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
125 
126 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
127  (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
128 
129 struct ipv6_extension_fragment {
130  uint8_t next_header;
131  uint8_t reserved;
132  uint16_t frag_data;
133  uint32_t id;
134 } __attribute__((__packed__));
135 
136 
137 
157 struct rte_ip_frag_tbl * rte_ip_frag_table_create(uint32_t bucket_num,
158  uint32_t bucket_entries, uint32_t max_entries,
159  uint64_t max_cycles, int socket_id);
160 
167 void
169 
191 int32_t
192 rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
193  struct rte_mbuf **pkts_out,
194  uint16_t nb_pkts_out,
195  uint16_t mtu_size,
196  struct rte_mempool *pool_direct,
197  struct rte_mempool *pool_indirect);
198 
221  struct rte_ip_frag_death_row *dr,
222  struct rte_mbuf *mb, uint64_t tms, struct ipv6_hdr *ip_hdr,
223  struct ipv6_extension_fragment *frag_hdr);
224 
236 static inline struct ipv6_extension_fragment *
238 {
239  if (hdr->proto == IPPROTO_FRAGMENT) {
240  return (struct ipv6_extension_fragment *) ++hdr;
241  }
242  else
243  return NULL;
244 }
245 
269 int32_t rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in,
270  struct rte_mbuf **pkts_out,
271  uint16_t nb_pkts_out, uint16_t mtu_size,
272  struct rte_mempool *pool_direct,
273  struct rte_mempool *pool_indirect);
274 
295  struct rte_ip_frag_death_row *dr,
296  struct rte_mbuf *mb, uint64_t tms, struct ipv4_hdr *ip_hdr);
297 
306 static inline int
308  uint16_t flag_offset, ip_flag, ip_ofs;
309 
310  flag_offset = rte_be_to_cpu_16(hdr->fragment_offset);
311  ip_ofs = (uint16_t)(flag_offset & IPV4_HDR_OFFSET_MASK);
312  ip_flag = (uint16_t)(flag_offset & IPV4_HDR_MF_FLAG);
313 
314  return ip_flag != 0 || ip_ofs != 0;
315 }
316 
326  uint32_t prefetch);
327 
328 
337 void
338 rte_ip_frag_table_statistics_dump(FILE * f, const struct rte_ip_frag_tbl *tbl);
339 
350 void __rte_experimental
352  struct rte_ip_frag_death_row *dr, uint64_t tms);
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* _RTE_IP_FRAG_H_ */