X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_ip_frag%2Fip_frag_common.h;h=0fdcc7d0f16e22ebab44936c5ee3d3e6adaab377;hb=d0fe8c48a4780b05f382950c0f8e52471cfe810f;hp=3e588a01d663773941ff2a00f37670131d063dd7;hpb=416707812c03e799719b46993af4a6ddfe14ef6c;p=dpdk.git diff --git a/lib/librte_ip_frag/ip_frag_common.h b/lib/librte_ip_frag/ip_frag_common.h index 3e588a01d6..0fdcc7d0f1 100644 --- a/lib/librte_ip_frag/ip_frag_common.h +++ b/lib/librte_ip_frag/ip_frag_common.h @@ -1,34 +1,5 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation */ #ifndef _IP_FRAG_COMMON_H_ @@ -38,37 +9,44 @@ /* logging macros. */ #ifdef RTE_LIBRTE_IP_FRAG_DEBUG - #define IP_FRAG_LOG(lvl, fmt, args...) RTE_LOG(lvl, USER1, fmt, ##args) - -#define RTE_IP_FRAG_ASSERT(exp) \ -if (!(exp)) { \ - rte_panic("function %s, line%d\tassert \"" #exp "\" failed\n", \ - __func__, __LINE__); \ -} #else #define IP_FRAG_LOG(lvl, fmt, args...) do {} while(0) -#define RTE_IP_FRAG_ASSERT(exp) do { } while(0) #endif /* IP_FRAG_DEBUG */ +#define IPV4_KEYLEN 1 +#define IPV6_KEYLEN 4 + /* helper macros */ #define IP_FRAG_MBUF2DR(dr, mb) ((dr)->row[(dr)->cnt++] = (mb)) +#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 + +#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 */ + /* internal functions declarations */ -struct rte_mbuf * ip_frag_process(struct rte_ip_frag_pkt *fp, +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); -struct rte_ip_frag_pkt * ip_frag_find(struct rte_ip_frag_tbl *tbl, +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); -struct rte_ip_frag_pkt * ip_frag_lookup(struct rte_ip_frag_tbl *tbl, +struct ip_frag_pkt * ip_frag_lookup(struct rte_ip_frag_tbl *tbl, const struct ip_frag_key *key, uint64_t tms, - struct rte_ip_frag_pkt **free, struct rte_ip_frag_pkt **stale); + struct ip_frag_pkt **free, struct ip_frag_pkt **stale); /* these functions need to be declared here as ip_frag_process relies on them */ -struct rte_mbuf * ipv4_frag_reassemble(const struct rte_ip_frag_pkt *fp); +struct rte_mbuf *ipv4_frag_reassemble(struct ip_frag_pkt *fp); +struct rte_mbuf *ipv6_frag_reassemble(struct ip_frag_pkt *fp); @@ -80,8 +58,10 @@ struct rte_mbuf * ipv4_frag_reassemble(const struct rte_ip_frag_pkt *fp); static inline int ip_frag_key_is_empty(const struct ip_frag_key * key) { - if (key->src_dst != 0) - return 0; + uint32_t i; + for (i = 0; i < RTE_MIN(key->key_len, RTE_DIM(key->src_dst)); i++) + if (key->src_dst[i] != 0) + return 0; return 1; } @@ -89,14 +69,20 @@ ip_frag_key_is_empty(const struct ip_frag_key * key) static inline void ip_frag_key_invalidate(struct ip_frag_key * key) { - key->src_dst = 0; + uint32_t i; + for (i = 0; i < key->key_len; i++) + key->src_dst[i] = 0; } /* compare two keys */ static inline int ip_frag_key_cmp(const struct ip_frag_key * k1, const struct ip_frag_key * k2) { - return k1->src_dst ^ k2->src_dst; + uint32_t i, val; + val = k1->id ^ k2->id; + for (i = 0; i < k1->key_len; i++) + val |= k1->src_dst[i] ^ k2->src_dst[i]; + return val; } /* @@ -105,7 +91,7 @@ ip_frag_key_cmp(const struct ip_frag_key * k1, const struct ip_frag_key * k2) /* put fragment on death row */ static inline void -ip_frag_free(struct rte_ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr) +ip_frag_free(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr) { uint32_t i, k; @@ -121,9 +107,29 @@ ip_frag_free(struct rte_ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr) dr->cnt = k; } +/* 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; +} + /* if key is empty, mark key as in use */ static inline void -ip_frag_inuse(struct rte_ip_frag_tbl *tbl, const struct rte_ip_frag_pkt *fp) +ip_frag_inuse(struct rte_ip_frag_tbl *tbl, const struct ip_frag_pkt *fp) { if (ip_frag_key_is_empty(&fp->key)) { TAILQ_REMOVE(&tbl->lru, fp, lru); @@ -133,7 +139,7 @@ ip_frag_inuse(struct rte_ip_frag_tbl *tbl, const struct rte_ip_frag_pkt *fp) /* reset the fragment */ static inline void -ip_frag_reset(struct rte_ip_frag_pkt *fp, uint64_t tms) +ip_frag_reset(struct ip_frag_pkt *fp, uint64_t tms) { static const struct ip_frag zero_frag = { .ofs = 0, @@ -149,28 +155,16 @@ ip_frag_reset(struct rte_ip_frag_pkt *fp, uint64_t tms) fp->frags[IP_FIRST_FRAG_IDX] = zero_frag; } -/* chain two mbufs */ +/* local frag table helper functions */ static inline void -ip_frag_chain(struct rte_mbuf *mn, struct rte_mbuf *mp) +ip_frag_tbl_del(struct rte_ip_frag_tbl *tbl, struct rte_ip_frag_death_row *dr, + struct ip_frag_pkt *fp) { - struct rte_mbuf *ms; - - /* adjust start of the last fragment data. */ - rte_pktmbuf_adj(mp, (uint16_t)(mp->pkt.vlan_macip.f.l2_len + - mp->pkt.vlan_macip.f.l3_len)); - - /* chain two fragments. */ - ms = rte_pktmbuf_lastseg(mn); - ms->pkt.next = mp; - - /* accumulate number of segments and total length. */ - mn->pkt.nb_segs = (uint8_t)(mn->pkt.nb_segs + mp->pkt.nb_segs); - mn->pkt.pkt_len += mp->pkt.pkt_len; - - /* reset pkt_len and nb_segs for chained fragment. */ - mp->pkt.pkt_len = mp->pkt.data_len; - mp->pkt.nb_segs = 1; + 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); } - #endif /* _IP_FRAG_COMMON_H_ */