4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _IP_FRAG_COMMON_H_
35 #define _IP_FRAG_COMMON_H_
37 #include "rte_ip_frag.h"
40 #ifdef RTE_LIBRTE_IP_FRAG_DEBUG
42 #define IP_FRAG_LOG(lvl, fmt, args...) RTE_LOG(lvl, USER1, fmt, ##args)
44 #define RTE_IP_FRAG_ASSERT(exp) \
46 rte_panic("function %s, line%d\tassert \"" #exp "\" failed\n", \
47 __func__, __LINE__); \
50 #define IP_FRAG_LOG(lvl, fmt, args...) do {} while(0)
51 #define RTE_IP_FRAG_ASSERT(exp) do { } while(0)
52 #endif /* IP_FRAG_DEBUG */
55 #define IP_FRAG_MBUF2DR(dr, mb) ((dr)->row[(dr)->cnt++] = (mb))
57 /* internal functions declarations */
58 struct rte_mbuf * ip_frag_process(struct rte_ip_frag_pkt *fp,
59 struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb,
60 uint16_t ofs, uint16_t len, uint16_t more_frags);
62 struct rte_ip_frag_pkt * ip_frag_find(struct rte_ip_frag_tbl *tbl,
63 struct rte_ip_frag_death_row *dr,
64 const struct ip_frag_key *key, uint64_t tms);
66 struct rte_ip_frag_pkt * ip_frag_lookup(struct rte_ip_frag_tbl *tbl,
67 const struct ip_frag_key *key, uint64_t tms,
68 struct rte_ip_frag_pkt **free, struct rte_ip_frag_pkt **stale);
70 /* these functions need to be declared here as ip_frag_process relies on them */
71 struct rte_mbuf * ipv4_frag_reassemble(const struct rte_ip_frag_pkt *fp);
76 * misc frag key functions
79 /* check if key is empty */
81 ip_frag_key_is_empty(const struct ip_frag_key * key)
83 if (key->src_dst != 0)
90 ip_frag_key_invalidate(struct ip_frag_key * key)
95 /* compare two keys */
97 ip_frag_key_cmp(const struct ip_frag_key * k1, const struct ip_frag_key * k2)
99 return k1->src_dst ^ k2->src_dst;
103 * misc fragment functions
106 /* put fragment on death row */
108 ip_frag_free(struct rte_ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr)
113 for (i = 0; i != fp->last_idx; i++) {
114 if (fp->frags[i].mb != NULL) {
115 dr->row[k++] = fp->frags[i].mb;
116 fp->frags[i].mb = NULL;
124 /* if key is empty, mark key as in use */
126 ip_frag_inuse(struct rte_ip_frag_tbl *tbl, const struct rte_ip_frag_pkt *fp)
128 if (ip_frag_key_is_empty(&fp->key)) {
129 TAILQ_REMOVE(&tbl->lru, fp, lru);
134 /* reset the fragment */
136 ip_frag_reset(struct rte_ip_frag_pkt *fp, uint64_t tms)
138 static const struct ip_frag zero_frag = {
145 fp->total_size = UINT32_MAX;
147 fp->last_idx = IP_MIN_FRAG_NUM;
148 fp->frags[IP_LAST_FRAG_IDX] = zero_frag;
149 fp->frags[IP_FIRST_FRAG_IDX] = zero_frag;
152 /* chain two mbufs */
154 ip_frag_chain(struct rte_mbuf *mn, struct rte_mbuf *mp)
158 /* adjust start of the last fragment data. */
159 rte_pktmbuf_adj(mp, (uint16_t)(mp->pkt.vlan_macip.f.l2_len +
160 mp->pkt.vlan_macip.f.l3_len));
162 /* chain two fragments. */
163 ms = rte_pktmbuf_lastseg(mn);
166 /* accumulate number of segments and total length. */
167 mn->pkt.nb_segs = (uint8_t)(mn->pkt.nb_segs + mp->pkt.nb_segs);
168 mn->pkt.pkt_len += mp->pkt.pkt_len;
170 /* reset pkt_len and nb_segs for chained fragment. */
171 mp->pkt.pkt_len = mp->pkt.data_len;
176 #endif /* _IP_FRAG_COMMON_H_ */