xref: /dpdk/lib/ip_frag/ip_reassembly.h (revision 3401a4afbb54a1b897551847a3e16c36afdf707a)
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 	union {
37 		uint64_t id_key_len; /* combined for easy fetch */
38 		__extension__
39 		struct {
40 			uint32_t id;      /* packet id */
41 			uint32_t key_len; /* src/dst key length */
42 		};
43 	};
44 };
45 
46 /*
47  * Fragmented packet to reassemble.
48  * First two entries in the frags[] array are for the last and first fragments.
49  */
50 struct __rte_cache_aligned ip_frag_pkt {
51 	RTE_TAILQ_ENTRY(ip_frag_pkt) lru;      /* LRU list */
52 	struct ip_frag_key key;                /* fragmentation key */
53 	uint64_t start;                        /* creation timestamp */
54 	uint32_t total_size;                   /* expected reassembled size */
55 	uint32_t frag_size;                    /* size of fragments received */
56 	uint32_t last_idx;                     /* index of next entry to fill */
57 	struct ip_frag frags[IP_MAX_FRAG_NUM]; /* fragments */
58 };
59 
60  /* fragments tailq */
61 RTE_TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
62 
63 /* fragmentation table statistics */
64 struct __rte_cache_aligned ip_frag_tbl_stat {
65 	uint64_t find_num;     /* total # of find/insert attempts. */
66 	uint64_t add_num;      /* # of add ops. */
67 	uint64_t del_num;      /* # of del ops. */
68 	uint64_t reuse_num;    /* # of reuse (del/add) ops. */
69 	uint64_t fail_total;   /* total # of add failures. */
70 	uint64_t fail_nospace; /* # of 'no space' add failures. */
71 };
72 
73 /* fragmentation table */
74 struct rte_ip_frag_tbl {
75 	uint64_t max_cycles;     /* ttl for table entries. */
76 	uint32_t entry_mask;     /* hash value mask. */
77 	uint32_t max_entries;    /* max entries allowed. */
78 	uint32_t use_entries;    /* entries in use. */
79 	uint32_t bucket_entries; /* hash associativity. */
80 	uint32_t nb_entries;     /* total size of the table. */
81 	uint32_t nb_buckets;     /* num of associativity lines. */
82 	struct ip_frag_pkt *last;     /* last used entry. */
83 	struct ip_pkt_list lru;       /* LRU list for table entries. */
84 	struct ip_frag_tbl_stat stat; /* statistics counters. */
85 	struct ip_frag_pkt pkt[]; /* hash table. */
86 };
87 
88 #endif /* _IP_REASSEMBLY_H_ */
89