blob: 4fea95d5b72bf05648c30566fdf6e2b2e372f588 [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
18#include <stdarg.h>
19
20#include <vlib/vlib.h>
21#include <vnet/vnet.h>
22#include <vnet/pg/pg.h>
23#include <vnet/ethernet/ethernet.h>
24#include <vnet/ethernet/packet.h>
25#include <vnet/ip/ip_packet.h>
26#include <vnet/ip/ip4_packet.h>
27#include <vnet/ip/ip6_packet.h>
28#include <vlib/cli.h>
khemendra kumard7bfa0e2017-11-27 15:15:53 +053029#include <vnet/api_errno.h> /* for API error numbers */
Ed Warnickecb9cada2015-12-08 15:45:58 -070030
31#include <vppinfra/error.h>
32#include <vppinfra/hash.h>
33#include <vppinfra/cache.h>
34#include <vppinfra/xxhash.h>
35
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +010036extern vlib_node_registration_t ip4_classify_node;
37extern vlib_node_registration_t ip6_classify_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070038
39#define CLASSIFY_TRACE 0
40
Christophe Fontainefef15b42016-04-09 12:38:49 +090041#define U32X4_ALIGNED(p) PREDICT_TRUE((((intptr_t)p) & 0xf) == 0)
Pierre Pfistercb656302016-03-16 09:14:28 +000042
Steve Shin25e26dc2016-11-08 10:47:10 -080043/*
44 * Classify table option to process packets
45 * CLASSIFY_FLAG_USE_CURR_DATA:
46 * - classify packets starting from VPP node’s current data pointer
47 */
48#define CLASSIFY_FLAG_USE_CURR_DATA 1
49
50/*
51 * Classify session action
52 * CLASSIFY_ACTION_SET_IP4_FIB_INDEX:
53 * - Classified IP packets will be looked up
54 * from the specified ipv4 fib table
55 * CLASSIFY_ACTION_SET_IP6_FIB_INDEX:
56 * - Classified IP packets will be looked up
57 * from the specified ipv6 fib table
58 */
Neale Ranns13eaf3e2017-05-23 06:10:33 -070059typedef enum vnet_classify_action_t_
60{
61 CLASSIFY_ACTION_SET_IP4_FIB_INDEX = 1,
62 CLASSIFY_ACTION_SET_IP6_FIB_INDEX = 2,
Dave Barach630a8e22017-11-18 06:58:34 -050063 CLASSIFY_ACTION_SET_METADATA = 3,
Neale Ranns13eaf3e2017-05-23 06:10:33 -070064} __attribute__ ((packed)) vnet_classify_action_t;
Steve Shin25e26dc2016-11-08 10:47:10 -080065
Ed Warnickecb9cada2015-12-08 15:45:58 -070066struct _vnet_classify_main;
67typedef struct _vnet_classify_main vnet_classify_main_t;
68
69#define foreach_size_in_u32x4 \
70_(1) \
71_(2) \
72_(3) \
73_(4) \
74_(5)
75
khemendra kumard7bfa0e2017-11-27 15:15:53 +053076/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070077typedef CLIB_PACKED(struct _vnet_classify_entry {
78 /* Graph node next index */
79 u32 next_index;
80
81 /* put into vnet_buffer(b)->l2_classfy.opaque_index */
82 union {
83 struct {
84 u32 opaque_index;
85 /* advance on hit, note it's a signed quantity... */
86 i32 advance;
87 };
88 u64 opaque_count;
89 };
90
91 /* Really only need 1 bit */
Steve Shin25e26dc2016-11-08 10:47:10 -080092 u8 flags;
Ed Warnickecb9cada2015-12-08 15:45:58 -070093#define VNET_CLASSIFY_ENTRY_FREE (1<<0)
94
Neale Ranns13eaf3e2017-05-23 06:10:33 -070095 vnet_classify_action_t action;
Steve Shin25e26dc2016-11-08 10:47:10 -080096 u16 metadata;
97
Ed Warnickecb9cada2015-12-08 15:45:58 -070098 /* Hit counter, last heard time */
99 union {
100 u64 hits;
101 struct _vnet_classify_entry * next_free;
102 };
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530103
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104 f64 last_heard;
105
106 /* Must be aligned to a 16-octet boundary */
107 u32x4 key[0];
108}) vnet_classify_entry_t;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530109/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530111static inline int
112vnet_classify_entry_is_free (vnet_classify_entry_t * e)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113{
114 return e->flags & VNET_CLASSIFY_ENTRY_FREE;
115}
116
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530117static inline int
118vnet_classify_entry_is_busy (vnet_classify_entry_t * e)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700119{
120 return ((e->flags & VNET_CLASSIFY_ENTRY_FREE) == 0);
121}
122
123/* Need these to con the vector allocator */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530124/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125#define _(size) \
126typedef CLIB_PACKED(struct { \
127 u32 pad0[4]; \
128 u64 pad1[2]; \
129 u32x4 key[size]; \
130}) vnet_classify_entry_##size##_t;
131foreach_size_in_u32x4;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530132/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133#undef _
134
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530135typedef struct
136{
137 union
138 {
139 struct
140 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 u32 offset;
Dave Barachcada2a02017-05-18 19:16:47 -0400142 u8 linear_search;
143 u8 pad[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144 u8 log2_pages;
145 };
146 u64 as_u64;
147 };
148} vnet_classify_bucket_t;
149
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530150typedef struct
151{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152 /* Mask to apply after skipping N vectors */
153 u32x4 *mask;
154 /* Buckets and entries */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530155 vnet_classify_bucket_t *buckets;
156 vnet_classify_entry_t *entries;
157
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 /* Config parameters */
159 u32 match_n_vectors;
160 u32 skip_n_vectors;
161 u32 nbuckets;
162 u32 log2_nbuckets;
Dave Barachcada2a02017-05-18 19:16:47 -0400163 u32 linear_buckets;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164 int entries_per_page;
165 u32 active_elements;
Steve Shin25e26dc2016-11-08 10:47:10 -0800166 u32 current_data_flag;
167 int current_data_offset;
168 u32 data_offset;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169 /* Index of next table to try */
170 u32 next_table_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530171
Ed Warnickecb9cada2015-12-08 15:45:58 -0700172 /* Miss next index, return if next_table_index = 0 */
173 u32 miss_next_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530174
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175 /* Per-bucket working copies, one per thread */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530176 vnet_classify_entry_t **working_copies;
Dave Barachcada2a02017-05-18 19:16:47 -0400177 int *working_copy_lengths;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178 vnet_classify_bucket_t saved_bucket;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530179
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180 /* Free entry freelists */
181 vnet_classify_entry_t **freelists;
182
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530183 u8 *name;
184
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185 /* Private allocation arena, protected by the writer lock */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530186 void *mheap;
187
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188 /* Writer (only) lock for this table */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530189 volatile u32 *writer_lock;
190
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191} vnet_classify_table_t;
192
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530193struct _vnet_classify_main
194{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195 /* Table pool */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530196 vnet_classify_table_t *tables;
197
Dave Barachf39ff742016-03-20 10:14:45 -0400198 /* Registered next-index, opaque unformat fcns */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530199 unformat_function_t **unformat_l2_next_index_fns;
200 unformat_function_t **unformat_ip_next_index_fns;
201 unformat_function_t **unformat_acl_next_index_fns;
202 unformat_function_t **unformat_policer_next_index_fns;
203 unformat_function_t **unformat_opaque_index_fns;
Dave Barachf39ff742016-03-20 10:14:45 -0400204
Ed Warnickecb9cada2015-12-08 15:45:58 -0700205 /* convenience variables */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530206 vlib_main_t *vlib_main;
207 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700208};
209
Dave Barachf39ff742016-03-20 10:14:45 -0400210extern vnet_classify_main_t vnet_classify_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530212u8 *format_classify_table (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213
214u64 vnet_classify_hash_packet (vnet_classify_table_t * t, u8 * h);
215
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530216static inline u64
217vnet_classify_hash_packet_inline (vnet_classify_table_t * t, u8 * h)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700218{
Pierre Pfistercb656302016-03-16 09:14:28 +0000219 u32x4 *mask;
220
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530221 union
222 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700223 u32x4 as_u32x4;
224 u64 as_u64[2];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530225 } xor_sum __attribute__ ((aligned (sizeof (u32x4))));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700226
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530227 ASSERT (t);
Pierre Pfistercb656302016-03-16 09:14:28 +0000228 mask = t->mask;
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100229#ifdef CLIB_HAVE_VEC128
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530230 if (U32X4_ALIGNED (h))
231 { //SSE can't handle unaligned data
232 u32x4 *data = (u32x4 *) h;
233 xor_sum.as_u32x4 = data[0 + t->skip_n_vectors] & mask[0];
234 switch (t->match_n_vectors)
235 {
236 case 5:
237 xor_sum.as_u32x4 ^= data[4 + t->skip_n_vectors] & mask[4];
238 /* FALLTHROUGH */
239 case 4:
240 xor_sum.as_u32x4 ^= data[3 + t->skip_n_vectors] & mask[3];
241 /* FALLTHROUGH */
242 case 3:
243 xor_sum.as_u32x4 ^= data[2 + t->skip_n_vectors] & mask[2];
244 /* FALLTHROUGH */
245 case 2:
246 xor_sum.as_u32x4 ^= data[1 + t->skip_n_vectors] & mask[1];
247 /* FALLTHROUGH */
248 case 1:
249 break;
250 default:
251 abort ();
252 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253 }
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530254 else
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100255#endif /* CLIB_HAVE_VEC128 */
Pierre Pfistercb656302016-03-16 09:14:28 +0000256 {
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530257 u32 skip_u64 = t->skip_n_vectors * 2;
258 u64 *data64 = (u64 *) h;
259 xor_sum.as_u64[0] = data64[0 + skip_u64] & ((u64 *) mask)[0];
260 xor_sum.as_u64[1] = data64[1 + skip_u64] & ((u64 *) mask)[1];
261 switch (t->match_n_vectors)
262 {
263 case 5:
264 xor_sum.as_u64[0] ^= data64[8 + skip_u64] & ((u64 *) mask)[8];
265 xor_sum.as_u64[1] ^= data64[9 + skip_u64] & ((u64 *) mask)[9];
266 /* FALLTHROUGH */
267 case 4:
268 xor_sum.as_u64[0] ^= data64[6 + skip_u64] & ((u64 *) mask)[6];
269 xor_sum.as_u64[1] ^= data64[7 + skip_u64] & ((u64 *) mask)[7];
270 /* FALLTHROUGH */
271 case 3:
272 xor_sum.as_u64[0] ^= data64[4 + skip_u64] & ((u64 *) mask)[4];
273 xor_sum.as_u64[1] ^= data64[5 + skip_u64] & ((u64 *) mask)[5];
274 /* FALLTHROUGH */
275 case 2:
276 xor_sum.as_u64[0] ^= data64[2 + skip_u64] & ((u64 *) mask)[2];
277 xor_sum.as_u64[1] ^= data64[3 + skip_u64] & ((u64 *) mask)[3];
278 /* FALLTHROUGH */
279 case 1:
280 break;
Pierre Pfistercb656302016-03-16 09:14:28 +0000281
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530282 default:
283 abort ();
284 }
Pierre Pfistercb656302016-03-16 09:14:28 +0000285 }
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530286
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287 return clib_xxhash (xor_sum.as_u64[0] ^ xor_sum.as_u64[1]);
288}
289
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530290static inline void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291vnet_classify_prefetch_bucket (vnet_classify_table_t * t, u64 hash)
292{
293 u32 bucket_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530294
295 ASSERT (is_pow2 (t->nbuckets));
296
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297 bucket_index = hash & (t->nbuckets - 1);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530298
299 CLIB_PREFETCH (&t->buckets[bucket_index], CLIB_CACHE_LINE_BYTES, LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300}
301
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530302static inline vnet_classify_entry_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700303vnet_classify_get_entry (vnet_classify_table_t * t, uword offset)
304{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530305 u8 *hp = t->mheap;
306 u8 *vp = hp + offset;
307
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308 return (void *) vp;
309}
310
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530311static inline uword
312vnet_classify_get_offset (vnet_classify_table_t * t,
313 vnet_classify_entry_t * v)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530315 u8 *hp, *vp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700316
317 hp = (u8 *) t->mheap;
318 vp = (u8 *) v;
319
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530320 ASSERT ((vp - hp) < 0x100000000ULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700321 return vp - hp;
322}
323
324static inline vnet_classify_entry_t *
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530325vnet_classify_entry_at_index (vnet_classify_table_t * t,
326 vnet_classify_entry_t * e, u32 index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700327{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530328 u8 *eu8;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530330 eu8 = (u8 *) e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331
332 eu8 += index * (sizeof (vnet_classify_entry_t) +
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530333 (t->match_n_vectors * sizeof (u32x4)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334
335 return (vnet_classify_entry_t *) eu8;
336}
337
338static inline void
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530339vnet_classify_prefetch_entry (vnet_classify_table_t * t, u64 hash)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700340{
341 u32 bucket_index;
342 u32 value_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530343 vnet_classify_bucket_t *b;
344 vnet_classify_entry_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700345
346 bucket_index = hash & (t->nbuckets - 1);
347
348 b = &t->buckets[bucket_index];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530349
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 if (b->offset == 0)
351 return;
352
353 hash >>= t->log2_nbuckets;
354
355 e = vnet_classify_get_entry (t, b->offset);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530356 value_index = hash & ((1 << b->log2_pages) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357
358 e = vnet_classify_entry_at_index (t, e, value_index);
359
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530360 CLIB_PREFETCH (e, CLIB_CACHE_LINE_BYTES, LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700361}
362
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530363vnet_classify_entry_t *vnet_classify_find_entry (vnet_classify_table_t * t,
364 u8 * h, u64 hash, f64 now);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700365
366static inline vnet_classify_entry_t *
367vnet_classify_find_entry_inline (vnet_classify_table_t * t,
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530368 u8 * h, u64 hash, f64 now)
Dave Barachcada2a02017-05-18 19:16:47 -0400369{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530370 vnet_classify_entry_t *v;
Pierre Pfistercb656302016-03-16 09:14:28 +0000371 u32x4 *mask, *key;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530372 union
373 {
Pierre Pfistercb656302016-03-16 09:14:28 +0000374 u32x4 as_u32x4;
375 u64 as_u64[2];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530376 } result __attribute__ ((aligned (sizeof (u32x4))));
377 vnet_classify_bucket_t *b;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700378 u32 value_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700379 u32 bucket_index;
Dave Barachcada2a02017-05-18 19:16:47 -0400380 u32 limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381 int i;
382
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530383 bucket_index = hash & (t->nbuckets - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700384 b = &t->buckets[bucket_index];
Pierre Pfistercb656302016-03-16 09:14:28 +0000385 mask = t->mask;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386
387 if (b->offset == 0)
388 return 0;
389
390 hash >>= t->log2_nbuckets;
391
392 v = vnet_classify_get_entry (t, b->offset);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530393 value_index = hash & ((1 << b->log2_pages) - 1);
Dave Barachcada2a02017-05-18 19:16:47 -0400394 limit = t->entries_per_page;
395 if (PREDICT_FALSE (b->linear_search))
396 {
397 value_index = 0;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530398 limit *= (1 << b->log2_pages);
Dave Barachcada2a02017-05-18 19:16:47 -0400399 }
400
Ed Warnickecb9cada2015-12-08 15:45:58 -0700401 v = vnet_classify_entry_at_index (t, v, value_index);
402
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100403#ifdef CLIB_HAVE_VEC128
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530404 if (U32X4_ALIGNED (h))
405 {
406 u32x4 *data = (u32x4 *) h;
407 for (i = 0; i < limit; i++)
408 {
409 key = v->key;
410 result.as_u32x4 = (data[0 + t->skip_n_vectors] & mask[0]) ^ key[0];
411 switch (t->match_n_vectors)
412 {
413 case 5:
414 result.as_u32x4 |=
415 (data[4 + t->skip_n_vectors] & mask[4]) ^ key[4];
416 /* FALLTHROUGH */
417 case 4:
418 result.as_u32x4 |=
419 (data[3 + t->skip_n_vectors] & mask[3]) ^ key[3];
420 /* FALLTHROUGH */
421 case 3:
422 result.as_u32x4 |=
423 (data[2 + t->skip_n_vectors] & mask[2]) ^ key[2];
424 /* FALLTHROUGH */
425 case 2:
426 result.as_u32x4 |=
427 (data[1 + t->skip_n_vectors] & mask[1]) ^ key[1];
428 /* FALLTHROUGH */
429 case 1:
430 break;
431 default:
432 abort ();
433 }
Pierre Pfistercb656302016-03-16 09:14:28 +0000434
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530435 if (u32x4_zero_byte_mask (result.as_u32x4) == 0xffff)
436 {
437 if (PREDICT_TRUE (now))
438 {
439 v->hits++;
440 v->last_heard = now;
441 }
442 return (v);
443 }
444 v = vnet_classify_entry_at_index (t, v, 1);
445 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700446 }
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530447 else
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100448#endif /* CLIB_HAVE_VEC128 */
Dave Barachcada2a02017-05-18 19:16:47 -0400449 {
450 u32 skip_u64 = t->skip_n_vectors * 2;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530451 u64 *data64 = (u64 *) h;
452 for (i = 0; i < limit; i++)
453 {
454 key = v->key;
Pierre Pfistercb656302016-03-16 09:14:28 +0000455
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530456 result.as_u64[0] =
457 (data64[0 + skip_u64] & ((u64 *) mask)[0]) ^ ((u64 *) key)[0];
458 result.as_u64[1] =
459 (data64[1 + skip_u64] & ((u64 *) mask)[1]) ^ ((u64 *) key)[1];
460 switch (t->match_n_vectors)
461 {
462 case 5:
463 result.as_u64[0] |=
464 (data64[8 + skip_u64] & ((u64 *) mask)[8]) ^ ((u64 *) key)[8];
465 result.as_u64[1] |=
466 (data64[9 + skip_u64] & ((u64 *) mask)[9]) ^ ((u64 *) key)[9];
467 /* FALLTHROUGH */
468 case 4:
469 result.as_u64[0] |=
470 (data64[6 + skip_u64] & ((u64 *) mask)[6]) ^ ((u64 *) key)[6];
471 result.as_u64[1] |=
472 (data64[7 + skip_u64] & ((u64 *) mask)[7]) ^ ((u64 *) key)[7];
473 /* FALLTHROUGH */
474 case 3:
475 result.as_u64[0] |=
476 (data64[4 + skip_u64] & ((u64 *) mask)[4]) ^ ((u64 *) key)[4];
477 result.as_u64[1] |=
478 (data64[5 + skip_u64] & ((u64 *) mask)[5]) ^ ((u64 *) key)[5];
479 /* FALLTHROUGH */
480 case 2:
481 result.as_u64[0] |=
482 (data64[2 + skip_u64] & ((u64 *) mask)[2]) ^ ((u64 *) key)[2];
483 result.as_u64[1] |=
484 (data64[3 + skip_u64] & ((u64 *) mask)[3]) ^ ((u64 *) key)[3];
485 /* FALLTHROUGH */
486 case 1:
487 break;
488 default:
489 abort ();
490 }
Pierre Pfistercb656302016-03-16 09:14:28 +0000491
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530492 if (result.as_u64[0] == 0 && result.as_u64[1] == 0)
493 {
494 if (PREDICT_TRUE (now))
495 {
496 v->hits++;
497 v->last_heard = now;
498 }
499 return (v);
500 }
Pierre Pfistercb656302016-03-16 09:14:28 +0000501
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530502 v = vnet_classify_entry_at_index (t, v, 1);
503 }
Pierre Pfistercb656302016-03-16 09:14:28 +0000504 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700505 return 0;
Dave Barachcada2a02017-05-18 19:16:47 -0400506}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530508vnet_classify_table_t *vnet_classify_new_table (vnet_classify_main_t * cm,
509 u8 * mask, u32 nbuckets,
510 u32 memory_size,
511 u32 skip_n_vectors,
512 u32 match_n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700513
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530514int vnet_classify_add_del_session (vnet_classify_main_t * cm,
515 u32 table_index,
516 u8 * match,
517 u32 hit_next_index,
518 u32 opaque_index,
519 i32 advance,
520 u8 action, u32 metadata, int is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521
522int vnet_classify_add_del_table (vnet_classify_main_t * cm,
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530523 u8 * mask,
524 u32 nbuckets,
525 u32 memory_size,
526 u32 skip,
527 u32 match,
528 u32 next_table_index,
529 u32 miss_next_index,
530 u32 * table_index,
531 u8 current_data_flag,
532 i16 current_data_offset,
533 int is_add, int del_chain);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534
535unformat_function_t unformat_ip4_mask;
536unformat_function_t unformat_ip6_mask;
537unformat_function_t unformat_l3_mask;
538unformat_function_t unformat_l2_mask;
539unformat_function_t unformat_classify_mask;
540unformat_function_t unformat_l2_next_index;
541unformat_function_t unformat_ip_next_index;
542unformat_function_t unformat_ip4_match;
543unformat_function_t unformat_ip6_match;
544unformat_function_t unformat_l3_match;
Dave Barach4a3f69c2017-02-22 12:44:56 -0500545unformat_function_t unformat_l4_match;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700546unformat_function_t unformat_vlan_tag;
547unformat_function_t unformat_l2_match;
548unformat_function_t unformat_classify_match;
549
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530550void vnet_classify_register_unformat_ip_next_index_fn
551 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400552
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530553void vnet_classify_register_unformat_l2_next_index_fn
554 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400555
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530556void vnet_classify_register_unformat_acl_next_index_fn
557 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400558
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530559void vnet_classify_register_unformat_policer_next_index_fn
560 (unformat_function_t * fn);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700561
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530562void vnet_classify_register_unformat_opaque_index_fn (unformat_function_t *
563 fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400564
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565#endif /* __included_vnet_classify_h__ */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530566
567/*
568 * fd.io coding-style-patch-verification: ON
569 *
570 * Local Variables:
571 * eval: (c-set-style "gnu")
572 * End:
573 */