199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #include <stddef.h>
699a2dd95SBruce Richardson
799a2dd95SBruce Richardson #include <rte_jhash.h>
899a2dd95SBruce Richardson #include <rte_hash_crc.h>
999a2dd95SBruce Richardson
1099a2dd95SBruce Richardson #include "ip_frag_common.h"
1199a2dd95SBruce Richardson
1299a2dd95SBruce Richardson #define PRIME_VALUE 0xeaad8405
1399a2dd95SBruce Richardson
1499a2dd95SBruce Richardson #define IP_FRAG_TBL_POS(tbl, sig) \
1599a2dd95SBruce Richardson ((tbl)->pkt + ((sig) & (tbl)->entry_mask))
1699a2dd95SBruce Richardson
1799a2dd95SBruce Richardson static inline void
ip_frag_tbl_add(struct rte_ip_frag_tbl * tbl,struct ip_frag_pkt * fp,const struct ip_frag_key * key,uint64_t tms)1899a2dd95SBruce Richardson ip_frag_tbl_add(struct rte_ip_frag_tbl *tbl, struct ip_frag_pkt *fp,
1999a2dd95SBruce Richardson const struct ip_frag_key *key, uint64_t tms)
2099a2dd95SBruce Richardson {
2199a2dd95SBruce Richardson fp->key = key[0];
2299a2dd95SBruce Richardson ip_frag_reset(fp, tms);
2399a2dd95SBruce Richardson TAILQ_INSERT_TAIL(&tbl->lru, fp, lru);
2499a2dd95SBruce Richardson tbl->use_entries++;
2599a2dd95SBruce Richardson IP_FRAG_TBL_STAT_UPDATE(&tbl->stat, add_num, 1);
2699a2dd95SBruce Richardson }
2799a2dd95SBruce Richardson
2899a2dd95SBruce Richardson static inline void
ip_frag_tbl_reuse(struct rte_ip_frag_tbl * tbl,struct rte_ip_frag_death_row * dr,struct ip_frag_pkt * fp,uint64_t tms)2999a2dd95SBruce Richardson ip_frag_tbl_reuse(struct rte_ip_frag_tbl *tbl, struct rte_ip_frag_death_row *dr,
3099a2dd95SBruce Richardson struct ip_frag_pkt *fp, uint64_t tms)
3199a2dd95SBruce Richardson {
3299a2dd95SBruce Richardson ip_frag_free(fp, dr);
3399a2dd95SBruce Richardson ip_frag_reset(fp, tms);
3499a2dd95SBruce Richardson TAILQ_REMOVE(&tbl->lru, fp, lru);
3599a2dd95SBruce Richardson TAILQ_INSERT_TAIL(&tbl->lru, fp, lru);
3699a2dd95SBruce Richardson IP_FRAG_TBL_STAT_UPDATE(&tbl->stat, reuse_num, 1);
3799a2dd95SBruce Richardson }
3899a2dd95SBruce Richardson
3999a2dd95SBruce Richardson
4099a2dd95SBruce Richardson static inline void
ipv4_frag_hash(const struct ip_frag_key * key,uint32_t * v1,uint32_t * v2)4199a2dd95SBruce Richardson ipv4_frag_hash(const struct ip_frag_key *key, uint32_t *v1, uint32_t *v2)
4299a2dd95SBruce Richardson {
4399a2dd95SBruce Richardson uint32_t v;
4499a2dd95SBruce Richardson const uint32_t *p;
4599a2dd95SBruce Richardson
4699a2dd95SBruce Richardson p = (const uint32_t *)&key->src_dst;
4799a2dd95SBruce Richardson
48*1d69e219SPavan Nikhilesh #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
4999a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[0], PRIME_VALUE);
5099a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[1], v);
5199a2dd95SBruce Richardson v = rte_hash_crc_4byte(key->id, v);
5299a2dd95SBruce Richardson #else
5399a2dd95SBruce Richardson
5499a2dd95SBruce Richardson v = rte_jhash_3words(p[0], p[1], key->id, PRIME_VALUE);
5599a2dd95SBruce Richardson #endif /* RTE_ARCH_X86 */
5699a2dd95SBruce Richardson
5799a2dd95SBruce Richardson *v1 = v;
5899a2dd95SBruce Richardson *v2 = (v << 7) + (v >> 14);
5999a2dd95SBruce Richardson }
6099a2dd95SBruce Richardson
6199a2dd95SBruce Richardson static inline void
ipv6_frag_hash(const struct ip_frag_key * key,uint32_t * v1,uint32_t * v2)6299a2dd95SBruce Richardson ipv6_frag_hash(const struct ip_frag_key *key, uint32_t *v1, uint32_t *v2)
6399a2dd95SBruce Richardson {
6499a2dd95SBruce Richardson uint32_t v;
6599a2dd95SBruce Richardson const uint32_t *p;
6699a2dd95SBruce Richardson
6799a2dd95SBruce Richardson p = (const uint32_t *) &key->src_dst;
6899a2dd95SBruce Richardson
69*1d69e219SPavan Nikhilesh #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
7099a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[0], PRIME_VALUE);
7199a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[1], v);
7299a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[2], v);
7399a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[3], v);
7499a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[4], v);
7599a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[5], v);
7699a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[6], v);
7799a2dd95SBruce Richardson v = rte_hash_crc_4byte(p[7], v);
7899a2dd95SBruce Richardson v = rte_hash_crc_4byte(key->id, v);
7999a2dd95SBruce Richardson #else
8099a2dd95SBruce Richardson
8199a2dd95SBruce Richardson v = rte_jhash_3words(p[0], p[1], p[2], PRIME_VALUE);
8299a2dd95SBruce Richardson v = rte_jhash_3words(p[3], p[4], p[5], v);
8399a2dd95SBruce Richardson v = rte_jhash_3words(p[6], p[7], key->id, v);
8499a2dd95SBruce Richardson #endif /* RTE_ARCH_X86 */
8599a2dd95SBruce Richardson
8699a2dd95SBruce Richardson *v1 = v;
8799a2dd95SBruce Richardson *v2 = (v << 7) + (v >> 14);
8899a2dd95SBruce Richardson }
8999a2dd95SBruce Richardson
9099a2dd95SBruce Richardson struct rte_mbuf *
ip_frag_process(struct ip_frag_pkt * fp,struct rte_ip_frag_death_row * dr,struct rte_mbuf * mb,uint16_t ofs,uint16_t len,uint16_t more_frags)9199a2dd95SBruce Richardson ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
9299a2dd95SBruce Richardson struct rte_mbuf *mb, uint16_t ofs, uint16_t len, uint16_t more_frags)
9399a2dd95SBruce Richardson {
9499a2dd95SBruce Richardson uint32_t idx;
9599a2dd95SBruce Richardson
9699a2dd95SBruce Richardson fp->frag_size += len;
9799a2dd95SBruce Richardson
9899a2dd95SBruce Richardson /* this is the first fragment. */
9999a2dd95SBruce Richardson if (ofs == 0) {
10099a2dd95SBruce Richardson idx = (fp->frags[IP_FIRST_FRAG_IDX].mb == NULL) ?
10199a2dd95SBruce Richardson IP_FIRST_FRAG_IDX : UINT32_MAX;
10299a2dd95SBruce Richardson
10399a2dd95SBruce Richardson /* this is the last fragment. */
10499a2dd95SBruce Richardson } else if (more_frags == 0) {
10599a2dd95SBruce Richardson fp->total_size = ofs + len;
10699a2dd95SBruce Richardson idx = (fp->frags[IP_LAST_FRAG_IDX].mb == NULL) ?
10799a2dd95SBruce Richardson IP_LAST_FRAG_IDX : UINT32_MAX;
10899a2dd95SBruce Richardson
10999a2dd95SBruce Richardson /* this is the intermediate fragment. */
11099a2dd95SBruce Richardson } else if ((idx = fp->last_idx) < RTE_DIM(fp->frags)) {
11199a2dd95SBruce Richardson fp->last_idx++;
11299a2dd95SBruce Richardson }
11399a2dd95SBruce Richardson
11499a2dd95SBruce Richardson /*
11599a2dd95SBruce Richardson * erroneous packet: either exceed max allowed number of fragments,
11699a2dd95SBruce Richardson * or duplicate first/last fragment encountered.
11799a2dd95SBruce Richardson */
11899a2dd95SBruce Richardson if (idx >= RTE_DIM(fp->frags)) {
11999a2dd95SBruce Richardson
12099a2dd95SBruce Richardson /* report an error. */
12199a2dd95SBruce Richardson if (fp->key.key_len == IPV4_KEYLEN)
12299a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d invalid fragmented packet:\n"
12399a2dd95SBruce Richardson "ipv4_frag_pkt: %p, key: <%" PRIx64 ", %#x>, "
12499a2dd95SBruce Richardson "total_size: %u, frag_size: %u, last_idx: %u\n"
12599a2dd95SBruce Richardson "first fragment: ofs: %u, len: %u\n"
12699a2dd95SBruce Richardson "last fragment: ofs: %u, len: %u\n\n",
12799a2dd95SBruce Richardson __func__, __LINE__,
12899a2dd95SBruce Richardson fp, fp->key.src_dst[0], fp->key.id,
12999a2dd95SBruce Richardson fp->total_size, fp->frag_size, fp->last_idx,
13099a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].ofs,
13199a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].len,
13299a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].ofs,
13399a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].len);
13499a2dd95SBruce Richardson else
13599a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d invalid fragmented packet:\n"
13699a2dd95SBruce Richardson "ipv6_frag_pkt: %p, key: <" IPv6_KEY_BYTES_FMT ", %#x>, "
13799a2dd95SBruce Richardson "total_size: %u, frag_size: %u, last_idx: %u\n"
13899a2dd95SBruce Richardson "first fragment: ofs: %u, len: %u\n"
13999a2dd95SBruce Richardson "last fragment: ofs: %u, len: %u\n\n",
14099a2dd95SBruce Richardson __func__, __LINE__,
14199a2dd95SBruce Richardson fp, IPv6_KEY_BYTES(fp->key.src_dst), fp->key.id,
14299a2dd95SBruce Richardson fp->total_size, fp->frag_size, fp->last_idx,
14399a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].ofs,
14499a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].len,
14599a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].ofs,
14699a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].len);
14799a2dd95SBruce Richardson
14899a2dd95SBruce Richardson /* free all fragments, invalidate the entry. */
14999a2dd95SBruce Richardson ip_frag_free(fp, dr);
15099a2dd95SBruce Richardson ip_frag_key_invalidate(&fp->key);
15199a2dd95SBruce Richardson IP_FRAG_MBUF2DR(dr, mb);
15299a2dd95SBruce Richardson
15399a2dd95SBruce Richardson return NULL;
15499a2dd95SBruce Richardson }
15599a2dd95SBruce Richardson
15699a2dd95SBruce Richardson fp->frags[idx].ofs = ofs;
15799a2dd95SBruce Richardson fp->frags[idx].len = len;
15899a2dd95SBruce Richardson fp->frags[idx].mb = mb;
15999a2dd95SBruce Richardson
16099a2dd95SBruce Richardson mb = NULL;
16199a2dd95SBruce Richardson
16299a2dd95SBruce Richardson /* not all fragments are collected yet. */
16399a2dd95SBruce Richardson if (likely (fp->frag_size < fp->total_size)) {
16499a2dd95SBruce Richardson return mb;
16599a2dd95SBruce Richardson
16699a2dd95SBruce Richardson /* if we collected all fragments, then try to reassemble. */
16799a2dd95SBruce Richardson } else if (fp->frag_size == fp->total_size &&
16899a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].mb != NULL) {
16999a2dd95SBruce Richardson if (fp->key.key_len == IPV4_KEYLEN)
17099a2dd95SBruce Richardson mb = ipv4_frag_reassemble(fp);
17199a2dd95SBruce Richardson else
17299a2dd95SBruce Richardson mb = ipv6_frag_reassemble(fp);
17399a2dd95SBruce Richardson }
17499a2dd95SBruce Richardson
17599a2dd95SBruce Richardson /* errorenous set of fragments. */
17699a2dd95SBruce Richardson if (mb == NULL) {
17799a2dd95SBruce Richardson
17899a2dd95SBruce Richardson /* report an error. */
17999a2dd95SBruce Richardson if (fp->key.key_len == IPV4_KEYLEN)
18099a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d invalid fragmented packet:\n"
18199a2dd95SBruce Richardson "ipv4_frag_pkt: %p, key: <%" PRIx64 ", %#x>, "
18299a2dd95SBruce Richardson "total_size: %u, frag_size: %u, last_idx: %u\n"
18399a2dd95SBruce Richardson "first fragment: ofs: %u, len: %u\n"
18499a2dd95SBruce Richardson "last fragment: ofs: %u, len: %u\n\n",
18599a2dd95SBruce Richardson __func__, __LINE__,
18699a2dd95SBruce Richardson fp, fp->key.src_dst[0], fp->key.id,
18799a2dd95SBruce Richardson fp->total_size, fp->frag_size, fp->last_idx,
18899a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].ofs,
18999a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].len,
19099a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].ofs,
19199a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].len);
19299a2dd95SBruce Richardson else
19399a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d invalid fragmented packet:\n"
19499a2dd95SBruce Richardson "ipv6_frag_pkt: %p, key: <" IPv6_KEY_BYTES_FMT ", %#x>, "
19599a2dd95SBruce Richardson "total_size: %u, frag_size: %u, last_idx: %u\n"
19699a2dd95SBruce Richardson "first fragment: ofs: %u, len: %u\n"
19799a2dd95SBruce Richardson "last fragment: ofs: %u, len: %u\n\n",
19899a2dd95SBruce Richardson __func__, __LINE__,
19999a2dd95SBruce Richardson fp, IPv6_KEY_BYTES(fp->key.src_dst), fp->key.id,
20099a2dd95SBruce Richardson fp->total_size, fp->frag_size, fp->last_idx,
20199a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].ofs,
20299a2dd95SBruce Richardson fp->frags[IP_FIRST_FRAG_IDX].len,
20399a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].ofs,
20499a2dd95SBruce Richardson fp->frags[IP_LAST_FRAG_IDX].len);
20599a2dd95SBruce Richardson
20699a2dd95SBruce Richardson /* free associated resources. */
20799a2dd95SBruce Richardson ip_frag_free(fp, dr);
20899a2dd95SBruce Richardson }
20999a2dd95SBruce Richardson
21099a2dd95SBruce Richardson /* we are done with that entry, invalidate it. */
21199a2dd95SBruce Richardson ip_frag_key_invalidate(&fp->key);
21299a2dd95SBruce Richardson return mb;
21399a2dd95SBruce Richardson }
21499a2dd95SBruce Richardson
21599a2dd95SBruce Richardson
21699a2dd95SBruce Richardson /*
21799a2dd95SBruce Richardson * Find an entry in the table for the corresponding fragment.
21899a2dd95SBruce Richardson * If such entry is not present, then allocate a new one.
21999a2dd95SBruce Richardson * If the entry is stale, then free and reuse it.
22099a2dd95SBruce Richardson */
22199a2dd95SBruce Richardson struct ip_frag_pkt *
ip_frag_find(struct rte_ip_frag_tbl * tbl,struct rte_ip_frag_death_row * dr,const struct ip_frag_key * key,uint64_t tms)22299a2dd95SBruce Richardson ip_frag_find(struct rte_ip_frag_tbl *tbl, struct rte_ip_frag_death_row *dr,
22399a2dd95SBruce Richardson const struct ip_frag_key *key, uint64_t tms)
22499a2dd95SBruce Richardson {
22599a2dd95SBruce Richardson struct ip_frag_pkt *pkt, *free, *stale, *lru;
22699a2dd95SBruce Richardson uint64_t max_cycles;
22799a2dd95SBruce Richardson
22899a2dd95SBruce Richardson /*
22999a2dd95SBruce Richardson * Actually the two line below are totally redundant.
23099a2dd95SBruce Richardson * they are here, just to make gcc 4.6 happy.
23199a2dd95SBruce Richardson */
23299a2dd95SBruce Richardson free = NULL;
23399a2dd95SBruce Richardson stale = NULL;
23499a2dd95SBruce Richardson max_cycles = tbl->max_cycles;
23599a2dd95SBruce Richardson
23699a2dd95SBruce Richardson IP_FRAG_TBL_STAT_UPDATE(&tbl->stat, find_num, 1);
23799a2dd95SBruce Richardson
23899a2dd95SBruce Richardson if ((pkt = ip_frag_lookup(tbl, key, tms, &free, &stale)) == NULL) {
23999a2dd95SBruce Richardson
24099a2dd95SBruce Richardson /*timed-out entry, free and invalidate it*/
24199a2dd95SBruce Richardson if (stale != NULL) {
24299a2dd95SBruce Richardson ip_frag_tbl_del(tbl, dr, stale);
24399a2dd95SBruce Richardson free = stale;
24499a2dd95SBruce Richardson
24599a2dd95SBruce Richardson /*
24699a2dd95SBruce Richardson * we found a free entry, check if we can use it.
24799a2dd95SBruce Richardson * If we run out of free entries in the table, then
24899a2dd95SBruce Richardson * check if we have a timed out entry to delete.
24999a2dd95SBruce Richardson */
25099a2dd95SBruce Richardson } else if (free != NULL &&
25199a2dd95SBruce Richardson tbl->max_entries <= tbl->use_entries) {
25299a2dd95SBruce Richardson lru = TAILQ_FIRST(&tbl->lru);
25399a2dd95SBruce Richardson if (max_cycles + lru->start < tms) {
25499a2dd95SBruce Richardson ip_frag_tbl_del(tbl, dr, lru);
25599a2dd95SBruce Richardson } else {
25699a2dd95SBruce Richardson free = NULL;
25799a2dd95SBruce Richardson IP_FRAG_TBL_STAT_UPDATE(&tbl->stat,
25899a2dd95SBruce Richardson fail_nospace, 1);
25999a2dd95SBruce Richardson }
26099a2dd95SBruce Richardson }
26199a2dd95SBruce Richardson
26299a2dd95SBruce Richardson /* found a free entry to reuse. */
26399a2dd95SBruce Richardson if (free != NULL) {
26499a2dd95SBruce Richardson ip_frag_tbl_add(tbl, free, key, tms);
26599a2dd95SBruce Richardson pkt = free;
26699a2dd95SBruce Richardson }
26799a2dd95SBruce Richardson
26899a2dd95SBruce Richardson /*
26999a2dd95SBruce Richardson * we found the flow, but it is already timed out,
27099a2dd95SBruce Richardson * so free associated resources, reposition it in the LRU list,
27199a2dd95SBruce Richardson * and reuse it.
27299a2dd95SBruce Richardson */
27399a2dd95SBruce Richardson } else if (max_cycles + pkt->start < tms) {
27499a2dd95SBruce Richardson ip_frag_tbl_reuse(tbl, dr, pkt, tms);
27599a2dd95SBruce Richardson }
27699a2dd95SBruce Richardson
27799a2dd95SBruce Richardson IP_FRAG_TBL_STAT_UPDATE(&tbl->stat, fail_total, (pkt == NULL));
27899a2dd95SBruce Richardson
27999a2dd95SBruce Richardson tbl->last = pkt;
28099a2dd95SBruce Richardson return pkt;
28199a2dd95SBruce Richardson }
28299a2dd95SBruce Richardson
28399a2dd95SBruce Richardson struct ip_frag_pkt *
ip_frag_lookup(struct rte_ip_frag_tbl * tbl,const struct ip_frag_key * key,uint64_t tms,struct ip_frag_pkt ** free,struct ip_frag_pkt ** stale)28499a2dd95SBruce Richardson ip_frag_lookup(struct rte_ip_frag_tbl *tbl,
28599a2dd95SBruce Richardson const struct ip_frag_key *key, uint64_t tms,
28699a2dd95SBruce Richardson struct ip_frag_pkt **free, struct ip_frag_pkt **stale)
28799a2dd95SBruce Richardson {
28899a2dd95SBruce Richardson struct ip_frag_pkt *p1, *p2;
28999a2dd95SBruce Richardson struct ip_frag_pkt *empty, *old;
29099a2dd95SBruce Richardson uint64_t max_cycles;
29199a2dd95SBruce Richardson uint32_t i, assoc, sig1, sig2;
29299a2dd95SBruce Richardson
29399a2dd95SBruce Richardson empty = NULL;
29499a2dd95SBruce Richardson old = NULL;
29599a2dd95SBruce Richardson
29699a2dd95SBruce Richardson max_cycles = tbl->max_cycles;
29799a2dd95SBruce Richardson assoc = tbl->bucket_entries;
29899a2dd95SBruce Richardson
29999a2dd95SBruce Richardson if (tbl->last != NULL && ip_frag_key_cmp(key, &tbl->last->key) == 0)
30099a2dd95SBruce Richardson return tbl->last;
30199a2dd95SBruce Richardson
30299a2dd95SBruce Richardson /* different hashing methods for IPv4 and IPv6 */
30399a2dd95SBruce Richardson if (key->key_len == IPV4_KEYLEN)
30499a2dd95SBruce Richardson ipv4_frag_hash(key, &sig1, &sig2);
30599a2dd95SBruce Richardson else
30699a2dd95SBruce Richardson ipv6_frag_hash(key, &sig1, &sig2);
30799a2dd95SBruce Richardson
30899a2dd95SBruce Richardson p1 = IP_FRAG_TBL_POS(tbl, sig1);
30999a2dd95SBruce Richardson p2 = IP_FRAG_TBL_POS(tbl, sig2);
31099a2dd95SBruce Richardson
31199a2dd95SBruce Richardson for (i = 0; i != assoc; i++) {
31299a2dd95SBruce Richardson if (p1->key.key_len == IPV4_KEYLEN)
31399a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d:\n"
31499a2dd95SBruce Richardson "tbl: %p, max_entries: %u, use_entries: %u\n"
31599a2dd95SBruce Richardson "ipv4_frag_pkt line0: %p, index: %u from %u\n"
31699a2dd95SBruce Richardson "key: <%" PRIx64 ", %#x>, start: %" PRIu64 "\n",
31799a2dd95SBruce Richardson __func__, __LINE__,
31899a2dd95SBruce Richardson tbl, tbl->max_entries, tbl->use_entries,
31999a2dd95SBruce Richardson p1, i, assoc,
32099a2dd95SBruce Richardson p1[i].key.src_dst[0], p1[i].key.id, p1[i].start);
32199a2dd95SBruce Richardson else
32299a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d:\n"
32399a2dd95SBruce Richardson "tbl: %p, max_entries: %u, use_entries: %u\n"
32499a2dd95SBruce Richardson "ipv6_frag_pkt line0: %p, index: %u from %u\n"
32599a2dd95SBruce Richardson "key: <" IPv6_KEY_BYTES_FMT ", %#x>, start: %" PRIu64 "\n",
32699a2dd95SBruce Richardson __func__, __LINE__,
32799a2dd95SBruce Richardson tbl, tbl->max_entries, tbl->use_entries,
32899a2dd95SBruce Richardson p1, i, assoc,
32999a2dd95SBruce Richardson IPv6_KEY_BYTES(p1[i].key.src_dst), p1[i].key.id, p1[i].start);
33099a2dd95SBruce Richardson
33199a2dd95SBruce Richardson if (ip_frag_key_cmp(key, &p1[i].key) == 0)
33299a2dd95SBruce Richardson return p1 + i;
33399a2dd95SBruce Richardson else if (ip_frag_key_is_empty(&p1[i].key))
33499a2dd95SBruce Richardson empty = (empty == NULL) ? (p1 + i) : empty;
33599a2dd95SBruce Richardson else if (max_cycles + p1[i].start < tms)
33699a2dd95SBruce Richardson old = (old == NULL) ? (p1 + i) : old;
33799a2dd95SBruce Richardson
33899a2dd95SBruce Richardson if (p2->key.key_len == IPV4_KEYLEN)
33999a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d:\n"
34099a2dd95SBruce Richardson "tbl: %p, max_entries: %u, use_entries: %u\n"
34199a2dd95SBruce Richardson "ipv4_frag_pkt line1: %p, index: %u from %u\n"
34299a2dd95SBruce Richardson "key: <%" PRIx64 ", %#x>, start: %" PRIu64 "\n",
34399a2dd95SBruce Richardson __func__, __LINE__,
34499a2dd95SBruce Richardson tbl, tbl->max_entries, tbl->use_entries,
34599a2dd95SBruce Richardson p2, i, assoc,
34699a2dd95SBruce Richardson p2[i].key.src_dst[0], p2[i].key.id, p2[i].start);
34799a2dd95SBruce Richardson else
34899a2dd95SBruce Richardson IP_FRAG_LOG(DEBUG, "%s:%d:\n"
34999a2dd95SBruce Richardson "tbl: %p, max_entries: %u, use_entries: %u\n"
35099a2dd95SBruce Richardson "ipv6_frag_pkt line1: %p, index: %u from %u\n"
35199a2dd95SBruce Richardson "key: <" IPv6_KEY_BYTES_FMT ", %#x>, start: %" PRIu64 "\n",
35299a2dd95SBruce Richardson __func__, __LINE__,
35399a2dd95SBruce Richardson tbl, tbl->max_entries, tbl->use_entries,
35499a2dd95SBruce Richardson p2, i, assoc,
35599a2dd95SBruce Richardson IPv6_KEY_BYTES(p2[i].key.src_dst), p2[i].key.id, p2[i].start);
35699a2dd95SBruce Richardson
35799a2dd95SBruce Richardson if (ip_frag_key_cmp(key, &p2[i].key) == 0)
35899a2dd95SBruce Richardson return p2 + i;
35999a2dd95SBruce Richardson else if (ip_frag_key_is_empty(&p2[i].key))
36099a2dd95SBruce Richardson empty = (empty == NULL) ?( p2 + i) : empty;
36199a2dd95SBruce Richardson else if (max_cycles + p2[i].start < tms)
36299a2dd95SBruce Richardson old = (old == NULL) ? (p2 + i) : old;
36399a2dd95SBruce Richardson }
36499a2dd95SBruce Richardson
36599a2dd95SBruce Richardson *free = empty;
36699a2dd95SBruce Richardson *stale = old;
36799a2dd95SBruce Richardson return NULL;
36899a2dd95SBruce Richardson }
369