2017-12-19 15:49:03 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2014-05-28 17:32:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _IP_FRAG_COMMON_H_
|
|
|
|
#define _IP_FRAG_COMMON_H_
|
|
|
|
|
2014-05-28 17:32:40 +00:00
|
|
|
#include "rte_ip_frag.h"
|
|
|
|
|
2014-05-28 17:32:41 +00:00
|
|
|
/* logging macros. */
|
|
|
|
#ifdef RTE_LIBRTE_IP_FRAG_DEBUG
|
|
|
|
#define IP_FRAG_LOG(lvl, fmt, args...) RTE_LOG(lvl, USER1, fmt, ##args)
|
|
|
|
#else
|
|
|
|
#define IP_FRAG_LOG(lvl, fmt, args...) do {} while(0)
|
|
|
|
#endif /* IP_FRAG_DEBUG */
|
|
|
|
|
2014-05-28 17:32:46 +00:00
|
|
|
#define IPV4_KEYLEN 1
|
|
|
|
#define IPV6_KEYLEN 4
|
|
|
|
|
2014-05-28 17:32:41 +00:00
|
|
|
/* helper macros */
|
|
|
|
#define IP_FRAG_MBUF2DR(dr, mb) ((dr)->row[(dr)->cnt++] = (mb))
|
|
|
|
|
2014-05-28 17:32:46 +00:00
|
|
|
#define IPv6_KEY_BYTES(key) \
|
|
|
|
(key)[0], (key)[1], (key)[2], (key)[3]
|
|
|
|
#define IPv6_KEY_BYTES_FMT \
|
|
|
|
"%08" PRIx64 "%08" PRIx64 "%08" PRIx64 "%08" PRIx64
|
|
|
|
|
2018-06-04 10:13:02 +00:00
|
|
|
#ifdef RTE_LIBRTE_IP_FRAG_TBL_STAT
|
|
|
|
#define IP_FRAG_TBL_STAT_UPDATE(s, f, v) ((s)->f += (v))
|
|
|
|
#else
|
|
|
|
#define IP_FRAG_TBL_STAT_UPDATE(s, f, v) do {} while (0)
|
|
|
|
#endif /* IP_FRAG_TBL_STAT */
|
|
|
|
|
2014-05-28 17:32:41 +00:00
|
|
|
/* internal functions declarations */
|
2014-06-18 14:50:28 +00:00
|
|
|
struct rte_mbuf * ip_frag_process(struct ip_frag_pkt *fp,
|
2014-05-28 17:32:41 +00:00
|
|
|
struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb,
|
|
|
|
uint16_t ofs, uint16_t len, uint16_t more_frags);
|
|
|
|
|
2014-06-18 14:50:28 +00:00
|
|
|
struct ip_frag_pkt * ip_frag_find(struct rte_ip_frag_tbl *tbl,
|
2014-05-28 17:32:41 +00:00
|
|
|
struct rte_ip_frag_death_row *dr,
|
|
|
|
const struct ip_frag_key *key, uint64_t tms);
|
|
|
|
|
2014-06-18 14:50:28 +00:00
|
|
|
struct ip_frag_pkt * ip_frag_lookup(struct rte_ip_frag_tbl *tbl,
|
2014-05-28 17:32:41 +00:00
|
|
|
const struct ip_frag_key *key, uint64_t tms,
|
2014-06-18 14:50:28 +00:00
|
|
|
struct ip_frag_pkt **free, struct ip_frag_pkt **stale);
|
2014-05-28 17:32:41 +00:00
|
|
|
|
|
|
|
/* these functions need to be declared here as ip_frag_process relies on them */
|
2016-04-21 17:28:01 +00:00
|
|
|
struct rte_mbuf *ipv4_frag_reassemble(struct ip_frag_pkt *fp);
|
|
|
|
struct rte_mbuf *ipv6_frag_reassemble(struct ip_frag_pkt *fp);
|
2014-05-28 17:32:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* misc frag key functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* check if key is empty */
|
|
|
|
static inline int
|
|
|
|
ip_frag_key_is_empty(const struct ip_frag_key * key)
|
|
|
|
{
|
2018-11-05 12:18:58 +00:00
|
|
|
return (key->key_len == 0);
|
2014-05-28 17:32:41 +00:00
|
|
|
}
|
2014-05-28 17:32:38 +00:00
|
|
|
|
2018-11-05 12:18:58 +00:00
|
|
|
/* invalidate the key */
|
2014-05-28 17:32:41 +00:00
|
|
|
static inline void
|
|
|
|
ip_frag_key_invalidate(struct ip_frag_key * key)
|
|
|
|
{
|
2018-11-05 12:18:58 +00:00
|
|
|
key->key_len = 0;
|
2014-05-28 17:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compare two keys */
|
2018-08-02 02:01:03 +00:00
|
|
|
static inline uint64_t
|
2014-05-28 17:32:41 +00:00
|
|
|
ip_frag_key_cmp(const struct ip_frag_key * k1, const struct ip_frag_key * k2)
|
|
|
|
{
|
2018-08-02 02:01:03 +00:00
|
|
|
uint32_t i;
|
|
|
|
uint64_t val;
|
2018-11-05 12:18:58 +00:00
|
|
|
val = k1->id_key_len ^ k2->id_key_len;
|
2014-05-28 17:32:46 +00:00
|
|
|
for (i = 0; i < k1->key_len; i++)
|
|
|
|
val |= k1->src_dst[i] ^ k2->src_dst[i];
|
|
|
|
return val;
|
2014-05-28 17:32:41 +00:00
|
|
|
}
|
2014-05-28 17:32:38 +00:00
|
|
|
|
2014-05-28 17:32:41 +00:00
|
|
|
/*
|
|
|
|
* misc fragment functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* put fragment on death row */
|
|
|
|
static inline void
|
2014-06-18 14:50:28 +00:00
|
|
|
ip_frag_free(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr)
|
2014-05-28 17:32:41 +00:00
|
|
|
{
|
|
|
|
uint32_t i, k;
|
|
|
|
|
|
|
|
k = dr->cnt;
|
|
|
|
for (i = 0; i != fp->last_idx; i++) {
|
|
|
|
if (fp->frags[i].mb != NULL) {
|
|
|
|
dr->row[k++] = fp->frags[i].mb;
|
|
|
|
fp->frags[i].mb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp->last_idx = 0;
|
|
|
|
dr->cnt = k;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:49:01 +00:00
|
|
|
/* delete fragment's mbufs immediately instead of using death row */
|
|
|
|
static inline void
|
|
|
|
ip_frag_free_immediate(struct ip_frag_pkt *fp)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < fp->last_idx; i++) {
|
|
|
|
if (fp->frags[i].mb != NULL) {
|
|
|
|
IP_FRAG_LOG(DEBUG, "%s:%d\n"
|
|
|
|
"mbuf: %p, tms: %" PRIu64", key: <%" PRIx64 ", %#x>\n",
|
|
|
|
__func__, __LINE__, fp->frags[i].mb, fp->start,
|
|
|
|
fp->key.src_dst[0], fp->key.id);
|
|
|
|
rte_pktmbuf_free(fp->frags[i].mb);
|
|
|
|
fp->frags[i].mb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp->last_idx = 0;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:32:41 +00:00
|
|
|
/* if key is empty, mark key as in use */
|
|
|
|
static inline void
|
2014-06-18 14:50:28 +00:00
|
|
|
ip_frag_inuse(struct rte_ip_frag_tbl *tbl, const struct ip_frag_pkt *fp)
|
2014-05-28 17:32:41 +00:00
|
|
|
{
|
|
|
|
if (ip_frag_key_is_empty(&fp->key)) {
|
|
|
|
TAILQ_REMOVE(&tbl->lru, fp, lru);
|
|
|
|
tbl->use_entries--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the fragment */
|
|
|
|
static inline void
|
2014-06-18 14:50:28 +00:00
|
|
|
ip_frag_reset(struct ip_frag_pkt *fp, uint64_t tms)
|
2014-05-28 17:32:41 +00:00
|
|
|
{
|
|
|
|
static const struct ip_frag zero_frag = {
|
|
|
|
.ofs = 0,
|
|
|
|
.len = 0,
|
|
|
|
.mb = NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
fp->start = tms;
|
|
|
|
fp->total_size = UINT32_MAX;
|
|
|
|
fp->frag_size = 0;
|
|
|
|
fp->last_idx = IP_MIN_FRAG_NUM;
|
|
|
|
fp->frags[IP_LAST_FRAG_IDX] = zero_frag;
|
|
|
|
fp->frags[IP_FIRST_FRAG_IDX] = zero_frag;
|
|
|
|
}
|
|
|
|
|
2018-06-04 10:13:02 +00:00
|
|
|
/* local frag table helper functions */
|
|
|
|
static inline void
|
|
|
|
ip_frag_tbl_del(struct rte_ip_frag_tbl *tbl, struct rte_ip_frag_death_row *dr,
|
|
|
|
struct ip_frag_pkt *fp)
|
|
|
|
{
|
|
|
|
ip_frag_free(fp, dr);
|
|
|
|
ip_frag_key_invalidate(&fp->key);
|
|
|
|
TAILQ_REMOVE(&tbl->lru, fp, lru);
|
|
|
|
tbl->use_entries--;
|
|
|
|
IP_FRAG_TBL_STAT_UPDATE(&tbl->stat, del_num, 1);
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:32:41 +00:00
|
|
|
#endif /* _IP_FRAG_COMMON_H_ */
|