xref: /dpdk/lib/ip_frag/ip_reassembly.h (revision 060ef29d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2021 Intel Corporation
3  */
4 
5 #ifndef _IP_REASSEMBLY_H_
6 #define _IP_REASSEMBLY_H_
7 
8 /*
9  * IP Fragmentation and Reassembly
10  * Implementation of IP packet fragmentation and reassembly.
11  */
12 
13 #include <rte_ip_frag.h>
14 
15 enum {
16 	IP_LAST_FRAG_IDX,    /* index of last fragment */
17 	IP_FIRST_FRAG_IDX,   /* index of first fragment */
18 	IP_MIN_FRAG_NUM,     /* minimum number of fragments */
19 	IP_MAX_FRAG_NUM = RTE_LIBRTE_IP_FRAG_MAX_FRAG,
20 	/* maximum number of fragments per packet */
21 };
22 
23 /* fragmented mbuf */
24 struct ip_frag {
25 	uint16_t ofs;        /* offset into the packet */
26 	uint16_t len;        /* length of fragment */
27 	struct rte_mbuf *mb; /* fragment mbuf */
28 };
29 
30 /*
31  * key: <src addr, dst_addr, id> to uniquely identify fragmented datagram.
32  */
33 struct ip_frag_key {
34 	uint64_t src_dst[4];
35 	/* src and dst address, only first 8 bytes used for IPv4 */
36 	RTE_STD_C11
37 	union {
38 		uint64_t id_key_len; /* combined for easy fetch */
39 		__extension__
40 		struct {
41 			uint32_t id;      /* packet id */
42 			uint32_t key_len; /* src/dst key length */
43 		};
44 	};
45 };
46 
47 /*
48  * Fragmented packet to reassemble.
49  * First two entries in the frags[] array are for the last and first fragments.
50  */
51 struct ip_frag_pkt {
52 	RTE_TAILQ_ENTRY(ip_frag_pkt) lru;      /* LRU list */
53 	struct ip_frag_key key;                /* fragmentation key */
54 	uint64_t start;                        /* creation timestamp */
55 	uint32_t total_size;                   /* expected reassembled size */
56 	uint32_t frag_size;                    /* size of fragments received */
57 	uint32_t last_idx;                     /* index of next entry to fill */
58 	struct ip_frag frags[IP_MAX_FRAG_NUM]; /* fragments */
59 } __rte_cache_aligned;
60 
61  /* fragments tailq */
62 RTE_TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
63 
64 /* fragmentation table statistics */
65 struct ip_frag_tbl_stat {
66 	uint64_t find_num;     /* total # of find/insert attempts. */
67 	uint64_t add_num;      /* # of add ops. */
68 	uint64_t del_num;      /* # of del ops. */
69 	uint64_t reuse_num;    /* # of reuse (del/add) ops. */
70 	uint64_t fail_total;   /* total # of add failures. */
71 	uint64_t fail_nospace; /* # of 'no space' add failures. */
72 } __rte_cache_aligned;
73 
74 /* fragmentation table */
75 struct rte_ip_frag_tbl {
76 	uint64_t max_cycles;     /* ttl for table entries. */
77 	uint32_t entry_mask;     /* hash value mask. */
78 	uint32_t max_entries;    /* max entries allowed. */
79 	uint32_t use_entries;    /* entries in use. */
80 	uint32_t bucket_entries; /* hash associativity. */
81 	uint32_t nb_entries;     /* total size of the table. */
82 	uint32_t nb_buckets;     /* num of associativity lines. */
83 	struct ip_frag_pkt *last;     /* last used entry. */
84 	struct ip_pkt_list lru;       /* LRU list for table entries. */
85 	struct ip_frag_tbl_stat stat; /* statistics counters. */
86 	__extension__ struct ip_frag_pkt pkt[0]; /* hash table. */
87 };
88 
89 #endif /* _IP_REASSEMBLY_H_ */
90