blob: c08cedf6b0322c550718814e23a6667e924598dc [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15#ifndef __included_vnet_classify_h__
16#define __included_vnet_classify_h__
17
Ed Warnickecb9cada2015-12-08 15:45:58 -070018#include <vnet/vnet.h>
khemendra kumard7bfa0e2017-11-27 15:15:53 +053019#include <vnet/api_errno.h> /* for API error numbers */
Ed Warnickecb9cada2015-12-08 15:45:58 -070020
21#include <vppinfra/error.h>
22#include <vppinfra/hash.h>
23#include <vppinfra/cache.h>
24#include <vppinfra/xxhash.h>
25
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +010026extern vlib_node_registration_t ip4_classify_node;
27extern vlib_node_registration_t ip6_classify_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070028
29#define CLASSIFY_TRACE 0
30
Steve Shin25e26dc2016-11-08 10:47:10 -080031/*
32 * Classify table option to process packets
33 * CLASSIFY_FLAG_USE_CURR_DATA:
34 * - classify packets starting from VPP node’s current data pointer
35 */
36#define CLASSIFY_FLAG_USE_CURR_DATA 1
37
38/*
39 * Classify session action
40 * CLASSIFY_ACTION_SET_IP4_FIB_INDEX:
41 * - Classified IP packets will be looked up
42 * from the specified ipv4 fib table
43 * CLASSIFY_ACTION_SET_IP6_FIB_INDEX:
44 * - Classified IP packets will be looked up
45 * from the specified ipv6 fib table
46 */
Neale Ranns13eaf3e2017-05-23 06:10:33 -070047typedef enum vnet_classify_action_t_
48{
49 CLASSIFY_ACTION_SET_IP4_FIB_INDEX = 1,
50 CLASSIFY_ACTION_SET_IP6_FIB_INDEX = 2,
Dave Barach630a8e22017-11-18 06:58:34 -050051 CLASSIFY_ACTION_SET_METADATA = 3,
Neale Ranns13eaf3e2017-05-23 06:10:33 -070052} __attribute__ ((packed)) vnet_classify_action_t;
Steve Shin25e26dc2016-11-08 10:47:10 -080053
Ed Warnickecb9cada2015-12-08 15:45:58 -070054struct _vnet_classify_main;
55typedef struct _vnet_classify_main vnet_classify_main_t;
56
57#define foreach_size_in_u32x4 \
58_(1) \
59_(2) \
60_(3) \
61_(4) \
62_(5)
63
khemendra kumard7bfa0e2017-11-27 15:15:53 +053064/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070065typedef CLIB_PACKED(struct _vnet_classify_entry {
66 /* Graph node next index */
67 u32 next_index;
68
69 /* put into vnet_buffer(b)->l2_classfy.opaque_index */
70 union {
71 struct {
72 u32 opaque_index;
73 /* advance on hit, note it's a signed quantity... */
74 i32 advance;
75 };
76 u64 opaque_count;
77 };
78
79 /* Really only need 1 bit */
Steve Shin25e26dc2016-11-08 10:47:10 -080080 u8 flags;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081#define VNET_CLASSIFY_ENTRY_FREE (1<<0)
82
Neale Ranns13eaf3e2017-05-23 06:10:33 -070083 vnet_classify_action_t action;
Steve Shin25e26dc2016-11-08 10:47:10 -080084 u16 metadata;
85
Ed Warnickecb9cada2015-12-08 15:45:58 -070086 /* Hit counter, last heard time */
87 union {
88 u64 hits;
89 struct _vnet_classify_entry * next_free;
90 };
khemendra kumard7bfa0e2017-11-27 15:15:53 +053091
Ed Warnickecb9cada2015-12-08 15:45:58 -070092 f64 last_heard;
93
94 /* Must be aligned to a 16-octet boundary */
95 u32x4 key[0];
96}) vnet_classify_entry_t;
khemendra kumard7bfa0e2017-11-27 15:15:53 +053097/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
khemendra kumard7bfa0e2017-11-27 15:15:53 +053099static inline int
100vnet_classify_entry_is_free (vnet_classify_entry_t * e)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101{
102 return e->flags & VNET_CLASSIFY_ENTRY_FREE;
103}
104
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530105static inline int
106vnet_classify_entry_is_busy (vnet_classify_entry_t * e)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107{
108 return ((e->flags & VNET_CLASSIFY_ENTRY_FREE) == 0);
109}
110
111/* Need these to con the vector allocator */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530112/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113#define _(size) \
114typedef CLIB_PACKED(struct { \
115 u32 pad0[4]; \
116 u64 pad1[2]; \
117 u32x4 key[size]; \
118}) vnet_classify_entry_##size##_t;
119foreach_size_in_u32x4;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530120/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121#undef _
122
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530123typedef struct
124{
125 union
126 {
127 struct
128 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129 u32 offset;
Dave Barachcada2a02017-05-18 19:16:47 -0400130 u8 linear_search;
131 u8 pad[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132 u8 log2_pages;
133 };
134 u64 as_u64;
135 };
136} vnet_classify_bucket_t;
137
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530138typedef struct
139{
David Johnsond9818dd2018-12-14 14:53:41 -0500140 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 /* Mask to apply after skipping N vectors */
142 u32x4 *mask;
143 /* Buckets and entries */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530144 vnet_classify_bucket_t *buckets;
145 vnet_classify_entry_t *entries;
146
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147 /* Config parameters */
148 u32 match_n_vectors;
149 u32 skip_n_vectors;
150 u32 nbuckets;
151 u32 log2_nbuckets;
Dave Barachcada2a02017-05-18 19:16:47 -0400152 u32 linear_buckets;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153 int entries_per_page;
154 u32 active_elements;
Steve Shin25e26dc2016-11-08 10:47:10 -0800155 u32 current_data_flag;
156 int current_data_offset;
157 u32 data_offset;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 /* Index of next table to try */
159 u32 next_table_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530160
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161 /* Miss next index, return if next_table_index = 0 */
162 u32 miss_next_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530163
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164 /* Per-bucket working copies, one per thread */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530165 vnet_classify_entry_t **working_copies;
Dave Barachcada2a02017-05-18 19:16:47 -0400166 int *working_copy_lengths;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167 vnet_classify_bucket_t saved_bucket;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530168
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169 /* Free entry freelists */
170 vnet_classify_entry_t **freelists;
171
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530172 u8 *name;
173
Ed Warnickecb9cada2015-12-08 15:45:58 -0700174 /* Private allocation arena, protected by the writer lock */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530175 void *mheap;
176
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177 /* Writer (only) lock for this table */
jaszha035cdde5c2019-07-11 20:47:24 +0000178 clib_spinlock_t writer_lock;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530179
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180} vnet_classify_table_t;
181
Dave Barachf5667c32019-09-25 11:27:46 -0400182typedef struct
183{
184 int refcnt;
185 u32 *table_indices;
186} vnet_classify_filter_set_t;
187
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530188struct _vnet_classify_main
189{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700190 /* Table pool */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530191 vnet_classify_table_t *tables;
192
Dave Barachf39ff742016-03-20 10:14:45 -0400193 /* Registered next-index, opaque unformat fcns */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530194 unformat_function_t **unformat_l2_next_index_fns;
195 unformat_function_t **unformat_ip_next_index_fns;
196 unformat_function_t **unformat_acl_next_index_fns;
197 unformat_function_t **unformat_policer_next_index_fns;
198 unformat_function_t **unformat_opaque_index_fns;
Dave Barachf39ff742016-03-20 10:14:45 -0400199
Dave Barachf5667c32019-09-25 11:27:46 -0400200 /* Pool of filter sets */
201 vnet_classify_filter_set_t *filter_sets;
202
203 /* Per-interface filter set map. [0] is used for pcap */
204 u32 *filter_set_by_sw_if_index;
205
Ed Warnickecb9cada2015-12-08 15:45:58 -0700206 /* convenience variables */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530207 vlib_main_t *vlib_main;
208 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700209};
210
Dave Barachf39ff742016-03-20 10:14:45 -0400211extern vnet_classify_main_t vnet_classify_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530213u8 *format_classify_table (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214
215u64 vnet_classify_hash_packet (vnet_classify_table_t * t, u8 * h);
216
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530217static inline u64
218vnet_classify_hash_packet_inline (vnet_classify_table_t * t, u8 * h)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700219{
Pierre Pfistercb656302016-03-16 09:14:28 +0000220 u32x4 *mask;
221
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530222 union
223 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700224 u32x4 as_u32x4;
225 u64 as_u64[2];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530226 } xor_sum __attribute__ ((aligned (sizeof (u32x4))));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700227
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530228 ASSERT (t);
Pierre Pfistercb656302016-03-16 09:14:28 +0000229 mask = t->mask;
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100230#ifdef CLIB_HAVE_VEC128
Damjan Marion83049332019-09-25 00:25:36 +0200231 u32x4u *data = (u32x4u *) h;
232 xor_sum.as_u32x4 = data[0 + t->skip_n_vectors] & mask[0];
233 switch (t->match_n_vectors)
Pierre Pfistercb656302016-03-16 09:14:28 +0000234 {
Damjan Marion83049332019-09-25 00:25:36 +0200235 case 5:
236 xor_sum.as_u32x4 ^= data[4 + t->skip_n_vectors] & mask[4];
237 /* FALLTHROUGH */
238 case 4:
239 xor_sum.as_u32x4 ^= data[3 + t->skip_n_vectors] & mask[3];
240 /* FALLTHROUGH */
241 case 3:
242 xor_sum.as_u32x4 ^= data[2 + t->skip_n_vectors] & mask[2];
243 /* FALLTHROUGH */
244 case 2:
245 xor_sum.as_u32x4 ^= data[1 + t->skip_n_vectors] & mask[1];
246 /* FALLTHROUGH */
247 case 1:
248 break;
249 default:
250 abort ();
Pierre Pfistercb656302016-03-16 09:14:28 +0000251 }
Damjan Marion83049332019-09-25 00:25:36 +0200252#else
253 u32 skip_u64 = t->skip_n_vectors * 2;
254 u64 *data64 = (u64 *) h;
255 xor_sum.as_u64[0] = data64[0 + skip_u64] & ((u64 *) mask)[0];
256 xor_sum.as_u64[1] = data64[1 + skip_u64] & ((u64 *) mask)[1];
257 switch (t->match_n_vectors)
258 {
259 case 5:
260 xor_sum.as_u64[0] ^= data64[8 + skip_u64] & ((u64 *) mask)[8];
261 xor_sum.as_u64[1] ^= data64[9 + skip_u64] & ((u64 *) mask)[9];
262 /* FALLTHROUGH */
263 case 4:
264 xor_sum.as_u64[0] ^= data64[6 + skip_u64] & ((u64 *) mask)[6];
265 xor_sum.as_u64[1] ^= data64[7 + skip_u64] & ((u64 *) mask)[7];
266 /* FALLTHROUGH */
267 case 3:
268 xor_sum.as_u64[0] ^= data64[4 + skip_u64] & ((u64 *) mask)[4];
269 xor_sum.as_u64[1] ^= data64[5 + skip_u64] & ((u64 *) mask)[5];
270 /* FALLTHROUGH */
271 case 2:
272 xor_sum.as_u64[0] ^= data64[2 + skip_u64] & ((u64 *) mask)[2];
273 xor_sum.as_u64[1] ^= data64[3 + skip_u64] & ((u64 *) mask)[3];
274 /* FALLTHROUGH */
275 case 1:
276 break;
277
278 default:
279 abort ();
280 }
281#endif /* CLIB_HAVE_VEC128 */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530282
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283 return clib_xxhash (xor_sum.as_u64[0] ^ xor_sum.as_u64[1]);
284}
285
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530286static inline void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287vnet_classify_prefetch_bucket (vnet_classify_table_t * t, u64 hash)
288{
289 u32 bucket_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530290
291 ASSERT (is_pow2 (t->nbuckets));
292
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293 bucket_index = hash & (t->nbuckets - 1);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530294
295 CLIB_PREFETCH (&t->buckets[bucket_index], CLIB_CACHE_LINE_BYTES, LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700296}
297
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530298static inline vnet_classify_entry_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700299vnet_classify_get_entry (vnet_classify_table_t * t, uword offset)
300{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530301 u8 *hp = t->mheap;
302 u8 *vp = hp + offset;
303
Ed Warnickecb9cada2015-12-08 15:45:58 -0700304 return (void *) vp;
305}
306
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530307static inline uword
308vnet_classify_get_offset (vnet_classify_table_t * t,
309 vnet_classify_entry_t * v)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530311 u8 *hp, *vp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700312
313 hp = (u8 *) t->mheap;
314 vp = (u8 *) v;
315
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530316 ASSERT ((vp - hp) < 0x100000000ULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317 return vp - hp;
318}
319
320static inline vnet_classify_entry_t *
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530321vnet_classify_entry_at_index (vnet_classify_table_t * t,
322 vnet_classify_entry_t * e, u32 index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700323{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530324 u8 *eu8;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700325
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530326 eu8 = (u8 *) e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700327
328 eu8 += index * (sizeof (vnet_classify_entry_t) +
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530329 (t->match_n_vectors * sizeof (u32x4)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330
331 return (vnet_classify_entry_t *) eu8;
332}
333
334static inline void
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530335vnet_classify_prefetch_entry (vnet_classify_table_t * t, u64 hash)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700336{
337 u32 bucket_index;
338 u32 value_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530339 vnet_classify_bucket_t *b;
340 vnet_classify_entry_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700341
342 bucket_index = hash & (t->nbuckets - 1);
343
344 b = &t->buckets[bucket_index];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530345
Ed Warnickecb9cada2015-12-08 15:45:58 -0700346 if (b->offset == 0)
347 return;
348
349 hash >>= t->log2_nbuckets;
350
351 e = vnet_classify_get_entry (t, b->offset);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530352 value_index = hash & ((1 << b->log2_pages) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700353
354 e = vnet_classify_entry_at_index (t, e, value_index);
355
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530356 CLIB_PREFETCH (e, CLIB_CACHE_LINE_BYTES, LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357}
358
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530359vnet_classify_entry_t *vnet_classify_find_entry (vnet_classify_table_t * t,
360 u8 * h, u64 hash, f64 now);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700361
362static inline vnet_classify_entry_t *
363vnet_classify_find_entry_inline (vnet_classify_table_t * t,
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530364 u8 * h, u64 hash, f64 now)
Dave Barachcada2a02017-05-18 19:16:47 -0400365{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530366 vnet_classify_entry_t *v;
Pierre Pfistercb656302016-03-16 09:14:28 +0000367 u32x4 *mask, *key;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530368 union
369 {
Pierre Pfistercb656302016-03-16 09:14:28 +0000370 u32x4 as_u32x4;
371 u64 as_u64[2];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530372 } result __attribute__ ((aligned (sizeof (u32x4))));
373 vnet_classify_bucket_t *b;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374 u32 value_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700375 u32 bucket_index;
Dave Barachcada2a02017-05-18 19:16:47 -0400376 u32 limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700377 int i;
378
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530379 bucket_index = hash & (t->nbuckets - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380 b = &t->buckets[bucket_index];
Pierre Pfistercb656302016-03-16 09:14:28 +0000381 mask = t->mask;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382
383 if (b->offset == 0)
384 return 0;
385
386 hash >>= t->log2_nbuckets;
387
388 v = vnet_classify_get_entry (t, b->offset);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530389 value_index = hash & ((1 << b->log2_pages) - 1);
Dave Barachcada2a02017-05-18 19:16:47 -0400390 limit = t->entries_per_page;
391 if (PREDICT_FALSE (b->linear_search))
392 {
393 value_index = 0;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530394 limit *= (1 << b->log2_pages);
Dave Barachcada2a02017-05-18 19:16:47 -0400395 }
396
Ed Warnickecb9cada2015-12-08 15:45:58 -0700397 v = vnet_classify_entry_at_index (t, v, value_index);
398
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100399#ifdef CLIB_HAVE_VEC128
Damjan Marion83049332019-09-25 00:25:36 +0200400 u32x4u *data = (u32x4u *) h;
401 for (i = 0; i < limit; i++)
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530402 {
Damjan Marion83049332019-09-25 00:25:36 +0200403 key = v->key;
404 result.as_u32x4 = (data[0 + t->skip_n_vectors] & mask[0]) ^ key[0];
405 switch (t->match_n_vectors)
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530406 {
Damjan Marion83049332019-09-25 00:25:36 +0200407 case 5:
408 result.as_u32x4 |= (data[4 + t->skip_n_vectors] & mask[4]) ^ key[4];
409 /* FALLTHROUGH */
410 case 4:
411 result.as_u32x4 |= (data[3 + t->skip_n_vectors] & mask[3]) ^ key[3];
412 /* FALLTHROUGH */
413 case 3:
414 result.as_u32x4 |= (data[2 + t->skip_n_vectors] & mask[2]) ^ key[2];
415 /* FALLTHROUGH */
416 case 2:
417 result.as_u32x4 |= (data[1 + t->skip_n_vectors] & mask[1]) ^ key[1];
418 /* FALLTHROUGH */
419 case 1:
420 break;
421 default:
422 abort ();
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530423 }
Damjan Marion83049332019-09-25 00:25:36 +0200424
425 if (u32x4_zero_byte_mask (result.as_u32x4) == 0xffff)
426 {
427 if (PREDICT_TRUE (now))
428 {
429 v->hits++;
430 v->last_heard = now;
431 }
432 return (v);
433 }
434 v = vnet_classify_entry_at_index (t, v, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700435 }
Damjan Marion83049332019-09-25 00:25:36 +0200436#else
437 u32 skip_u64 = t->skip_n_vectors * 2;
438 u64 *data64 = (u64 *) h;
439 for (i = 0; i < limit; i++)
440 {
441 key = v->key;
442
443 result.as_u64[0] =
444 (data64[0 + skip_u64] & ((u64 *) mask)[0]) ^ ((u64 *) key)[0];
445 result.as_u64[1] =
446 (data64[1 + skip_u64] & ((u64 *) mask)[1]) ^ ((u64 *) key)[1];
447 switch (t->match_n_vectors)
448 {
449 case 5:
450 result.as_u64[0] |=
451 (data64[8 + skip_u64] & ((u64 *) mask)[8]) ^ ((u64 *) key)[8];
452 result.as_u64[1] |=
453 (data64[9 + skip_u64] & ((u64 *) mask)[9]) ^ ((u64 *) key)[9];
454 /* FALLTHROUGH */
455 case 4:
456 result.as_u64[0] |=
457 (data64[6 + skip_u64] & ((u64 *) mask)[6]) ^ ((u64 *) key)[6];
458 result.as_u64[1] |=
459 (data64[7 + skip_u64] & ((u64 *) mask)[7]) ^ ((u64 *) key)[7];
460 /* FALLTHROUGH */
461 case 3:
462 result.as_u64[0] |=
463 (data64[4 + skip_u64] & ((u64 *) mask)[4]) ^ ((u64 *) key)[4];
464 result.as_u64[1] |=
465 (data64[5 + skip_u64] & ((u64 *) mask)[5]) ^ ((u64 *) key)[5];
466 /* FALLTHROUGH */
467 case 2:
468 result.as_u64[0] |=
469 (data64[2 + skip_u64] & ((u64 *) mask)[2]) ^ ((u64 *) key)[2];
470 result.as_u64[1] |=
471 (data64[3 + skip_u64] & ((u64 *) mask)[3]) ^ ((u64 *) key)[3];
472 /* FALLTHROUGH */
473 case 1:
474 break;
475 default:
476 abort ();
477 }
478
479 if (result.as_u64[0] == 0 && result.as_u64[1] == 0)
480 {
481 if (PREDICT_TRUE (now))
482 {
483 v->hits++;
484 v->last_heard = now;
485 }
486 return (v);
487 }
488
489 v = vnet_classify_entry_at_index (t, v, 1);
490 }
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100491#endif /* CLIB_HAVE_VEC128 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492 return 0;
Dave Barachcada2a02017-05-18 19:16:47 -0400493}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700494
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530495vnet_classify_table_t *vnet_classify_new_table (vnet_classify_main_t * cm,
496 u8 * mask, u32 nbuckets,
497 u32 memory_size,
498 u32 skip_n_vectors,
499 u32 match_n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700500
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530501int vnet_classify_add_del_session (vnet_classify_main_t * cm,
502 u32 table_index,
503 u8 * match,
504 u32 hit_next_index,
505 u32 opaque_index,
506 i32 advance,
507 u8 action, u32 metadata, int is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700508
509int vnet_classify_add_del_table (vnet_classify_main_t * cm,
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530510 u8 * mask,
511 u32 nbuckets,
512 u32 memory_size,
513 u32 skip,
514 u32 match,
515 u32 next_table_index,
516 u32 miss_next_index,
517 u32 * table_index,
518 u8 current_data_flag,
519 i16 current_data_offset,
520 int is_add, int del_chain);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521
522unformat_function_t unformat_ip4_mask;
523unformat_function_t unformat_ip6_mask;
524unformat_function_t unformat_l3_mask;
525unformat_function_t unformat_l2_mask;
526unformat_function_t unformat_classify_mask;
527unformat_function_t unformat_l2_next_index;
528unformat_function_t unformat_ip_next_index;
529unformat_function_t unformat_ip4_match;
530unformat_function_t unformat_ip6_match;
531unformat_function_t unformat_l3_match;
Dave Barach4a3f69c2017-02-22 12:44:56 -0500532unformat_function_t unformat_l4_match;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700533unformat_function_t unformat_vlan_tag;
534unformat_function_t unformat_l2_match;
535unformat_function_t unformat_classify_match;
536
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530537void vnet_classify_register_unformat_ip_next_index_fn
538 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400539
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530540void vnet_classify_register_unformat_l2_next_index_fn
541 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400542
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530543void vnet_classify_register_unformat_acl_next_index_fn
544 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400545
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530546void vnet_classify_register_unformat_policer_next_index_fn
547 (unformat_function_t * fn);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700548
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530549void vnet_classify_register_unformat_opaque_index_fn (unformat_function_t *
550 fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400551
Ed Warnickecb9cada2015-12-08 15:45:58 -0700552#endif /* __included_vnet_classify_h__ */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530553
554/*
555 * fd.io coding-style-patch-verification: ON
556 *
557 * Local Variables:
558 * eval: (c-set-style "gnu")
559 * End:
560 */