2 * Copyright (c) 2016-2017 Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef _STREAM_TABLE_H_
17 #define _STREAM_TABLE_H_
31 uint32_t nb_ent; /* max number of entries in the table. */
32 rte_spinlock_t l; /* lock to protect the hash table */
34 struct stbl_entry *ent;
35 } __rte_cache_aligned;
38 struct shtbl ht[TLE_VNUM];
43 union ipv4_addrs addr;
44 } __attribute__((__packed__));
48 union ipv6_addrs addr;
49 } __attribute__((__packed__));
54 union ipv4_addrs addr4;
55 union ipv6_addrs addr6;
57 } __attribute__((__packed__));
59 extern void stbl_fini(struct stbl *st);
61 extern int stbl_init(struct stbl *st, uint32_t num, int32_t socket);
64 stbl_pkt_fill_key(struct stbl_key *k, const union pkt_info *pi, uint32_t type)
66 static const struct stbl_key zero = {
73 else if (type == TLE_V6)
74 k->addr6 = *pi->addr6;
80 stbl_lock(struct stbl *st, uint32_t type)
82 rte_spinlock_lock(&st->ht[type].l);
86 stbl_unlock(struct stbl *st, uint32_t type)
88 rte_spinlock_unlock(&st->ht[type].l);
91 static inline struct stbl_entry *
92 stbl_add_entry(struct stbl *st, const union pkt_info *pi)
100 stbl_pkt_fill_key(&k, pi, type);
103 rc = rte_hash_add_key(ht->t, &k);
104 if ((uint32_t)rc >= ht->nb_ent)
109 static inline struct stbl_entry *
110 stbl_add_stream(struct stbl *st, const union pkt_info *pi, const void *s)
112 struct stbl_entry *se;
114 se = stbl_add_entry(st, pi);
116 se->data = (void *)(uintptr_t)s;
120 static inline struct stbl_entry *
121 stbl_find_entry(struct stbl *st, const union pkt_info *pi)
129 stbl_pkt_fill_key(&k, pi, type);
132 rc = rte_hash_lookup(ht->t, &k);
133 if ((uint32_t)rc >= ht->nb_ent)
139 stbl_find_data(struct stbl *st, const union pkt_info *pi)
141 struct stbl_entry *ent;
143 ent = stbl_find_entry(st, pi);
144 return (ent == NULL) ? NULL : ent->data;
147 #include "tcp_stream.h"
150 stbl_stream_fill_key(struct stbl_key *k, const struct tle_stream *s,
153 static const struct stbl_key zero = {
159 k->addr4 = s->ipv4.addr;
160 else if (type == TLE_V6)
161 k->addr6 = s->ipv6.addr;
166 static inline struct stbl_entry *
167 stbl_add_stream_lock(struct stbl *st, const struct tle_tcp_stream *s)
171 struct stbl_entry *se;
176 stbl_stream_fill_key(&k, &s->s, type);
180 rc = rte_hash_add_key(ht->t, &k);
181 stbl_unlock(st, type);
183 if ((uint32_t)rc >= ht->nb_ent)
188 se->data = (void *)(uintptr_t)s;
194 stbl_del_stream(struct stbl *st, struct stbl_entry *se,
195 const struct tle_tcp_stream *s, uint32_t lock)
206 stbl_stream_fill_key(&k, &s->s, type);
209 rte_hash_del_key(st->ht[type].t, &k);
211 stbl_unlock(st, type);
218 #endif /* _STREAM_TABLE_H_ */