blob: f0c8124158462db89af03d0ad6dac2a1290cd349 [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>
Ray Kinsella7741afa2020-04-07 07:51:23 +010024#include <vppinfra/crc32.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070025#include <vppinfra/xxhash.h>
26
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +010027extern vlib_node_registration_t ip4_classify_node;
28extern vlib_node_registration_t ip6_classify_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070029
30#define CLASSIFY_TRACE 0
31
Steve Shin25e26dc2016-11-08 10:47:10 -080032/*
33 * Classify table option to process packets
34 * CLASSIFY_FLAG_USE_CURR_DATA:
35 * - classify packets starting from VPP node’s current data pointer
36 */
37#define CLASSIFY_FLAG_USE_CURR_DATA 1
38
39/*
40 * Classify session action
41 * CLASSIFY_ACTION_SET_IP4_FIB_INDEX:
42 * - Classified IP packets will be looked up
43 * from the specified ipv4 fib table
44 * CLASSIFY_ACTION_SET_IP6_FIB_INDEX:
45 * - Classified IP packets will be looked up
46 * from the specified ipv6 fib table
47 */
Neale Ranns13eaf3e2017-05-23 06:10:33 -070048typedef enum vnet_classify_action_t_
49{
50 CLASSIFY_ACTION_SET_IP4_FIB_INDEX = 1,
51 CLASSIFY_ACTION_SET_IP6_FIB_INDEX = 2,
Dave Barach630a8e22017-11-18 06:58:34 -050052 CLASSIFY_ACTION_SET_METADATA = 3,
Neale Ranns13eaf3e2017-05-23 06:10:33 -070053} __attribute__ ((packed)) vnet_classify_action_t;
Steve Shin25e26dc2016-11-08 10:47:10 -080054
Ed Warnickecb9cada2015-12-08 15:45:58 -070055struct _vnet_classify_main;
56typedef struct _vnet_classify_main vnet_classify_main_t;
57
58#define foreach_size_in_u32x4 \
59_(1) \
60_(2) \
61_(3) \
62_(4) \
63_(5)
64
khemendra kumard7bfa0e2017-11-27 15:15:53 +053065/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070066typedef CLIB_PACKED(struct _vnet_classify_entry {
67 /* Graph node next index */
68 u32 next_index;
69
70 /* put into vnet_buffer(b)->l2_classfy.opaque_index */
71 union {
72 struct {
73 u32 opaque_index;
74 /* advance on hit, note it's a signed quantity... */
75 i32 advance;
76 };
77 u64 opaque_count;
78 };
79
80 /* Really only need 1 bit */
Steve Shin25e26dc2016-11-08 10:47:10 -080081 u8 flags;
Ed Warnickecb9cada2015-12-08 15:45:58 -070082#define VNET_CLASSIFY_ENTRY_FREE (1<<0)
83
Neale Ranns13eaf3e2017-05-23 06:10:33 -070084 vnet_classify_action_t action;
Steve Shin25e26dc2016-11-08 10:47:10 -080085 u16 metadata;
86
Ed Warnickecb9cada2015-12-08 15:45:58 -070087 /* Hit counter, last heard time */
88 union {
89 u64 hits;
90 struct _vnet_classify_entry * next_free;
91 };
khemendra kumard7bfa0e2017-11-27 15:15:53 +053092
Ed Warnickecb9cada2015-12-08 15:45:58 -070093 f64 last_heard;
94
95 /* Must be aligned to a 16-octet boundary */
96 u32x4 key[0];
97}) vnet_classify_entry_t;
khemendra kumard7bfa0e2017-11-27 15:15:53 +053098/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070099
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530100static inline int
101vnet_classify_entry_is_free (vnet_classify_entry_t * e)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102{
103 return e->flags & VNET_CLASSIFY_ENTRY_FREE;
104}
105
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530106static inline int
107vnet_classify_entry_is_busy (vnet_classify_entry_t * e)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108{
109 return ((e->flags & VNET_CLASSIFY_ENTRY_FREE) == 0);
110}
111
112/* Need these to con the vector allocator */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530113/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114#define _(size) \
115typedef CLIB_PACKED(struct { \
116 u32 pad0[4]; \
117 u64 pad1[2]; \
118 u32x4 key[size]; \
119}) vnet_classify_entry_##size##_t;
120foreach_size_in_u32x4;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530121/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122#undef _
123
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530124typedef struct
125{
126 union
127 {
128 struct
129 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130 u32 offset;
Dave Barachcada2a02017-05-18 19:16:47 -0400131 u8 linear_search;
132 u8 pad[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133 u8 log2_pages;
134 };
135 u64 as_u64;
136 };
137} vnet_classify_bucket_t;
138
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530139typedef struct
140{
David Johnsond9818dd2018-12-14 14:53:41 -0500141 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142 /* Mask to apply after skipping N vectors */
143 u32x4 *mask;
144 /* Buckets and entries */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530145 vnet_classify_bucket_t *buckets;
146 vnet_classify_entry_t *entries;
147
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148 /* Config parameters */
149 u32 match_n_vectors;
150 u32 skip_n_vectors;
151 u32 nbuckets;
152 u32 log2_nbuckets;
Dave Barachcada2a02017-05-18 19:16:47 -0400153 u32 linear_buckets;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154 int entries_per_page;
155 u32 active_elements;
Steve Shin25e26dc2016-11-08 10:47:10 -0800156 u32 current_data_flag;
157 int current_data_offset;
158 u32 data_offset;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159 /* Index of next table to try */
160 u32 next_table_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530161
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162 /* Miss next index, return if next_table_index = 0 */
163 u32 miss_next_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530164
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165 /* Per-bucket working copies, one per thread */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530166 vnet_classify_entry_t **working_copies;
Dave Barachcada2a02017-05-18 19:16:47 -0400167 int *working_copy_lengths;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168 vnet_classify_bucket_t saved_bucket;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530169
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170 /* Free entry freelists */
171 vnet_classify_entry_t **freelists;
172
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530173 u8 *name;
174
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175 /* Private allocation arena, protected by the writer lock */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530176 void *mheap;
177
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178 /* Writer (only) lock for this table */
jaszha035cdde5c2019-07-11 20:47:24 +0000179 clib_spinlock_t writer_lock;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530180
Ed Warnickecb9cada2015-12-08 15:45:58 -0700181} vnet_classify_table_t;
182
Dave Barachf5667c32019-09-25 11:27:46 -0400183typedef struct
184{
185 int refcnt;
186 u32 *table_indices;
187} vnet_classify_filter_set_t;
188
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530189struct _vnet_classify_main
190{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191 /* Table pool */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530192 vnet_classify_table_t *tables;
193
Dave Barachf39ff742016-03-20 10:14:45 -0400194 /* Registered next-index, opaque unformat fcns */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530195 unformat_function_t **unformat_l2_next_index_fns;
196 unformat_function_t **unformat_ip_next_index_fns;
197 unformat_function_t **unformat_acl_next_index_fns;
198 unformat_function_t **unformat_policer_next_index_fns;
199 unformat_function_t **unformat_opaque_index_fns;
Dave Barachf39ff742016-03-20 10:14:45 -0400200
Dave Barachf5667c32019-09-25 11:27:46 -0400201 /* Pool of filter sets */
202 vnet_classify_filter_set_t *filter_sets;
203
204 /* Per-interface filter set map. [0] is used for pcap */
205 u32 *filter_set_by_sw_if_index;
206
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207 /* convenience variables */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530208 vlib_main_t *vlib_main;
209 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210};
211
Dave Barachf39ff742016-03-20 10:14:45 -0400212extern vnet_classify_main_t vnet_classify_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530214u8 *format_classify_table (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700215
216u64 vnet_classify_hash_packet (vnet_classify_table_t * t, u8 * h);
217
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530218static inline u64
219vnet_classify_hash_packet_inline (vnet_classify_table_t * t, u8 * h)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220{
Pierre Pfistercb656302016-03-16 09:14:28 +0000221 u32x4 *mask;
222
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530223 union
224 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225 u32x4 as_u32x4;
226 u64 as_u64[2];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530227 } xor_sum __attribute__ ((aligned (sizeof (u32x4))));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530229 ASSERT (t);
Pierre Pfistercb656302016-03-16 09:14:28 +0000230 mask = t->mask;
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100231#ifdef CLIB_HAVE_VEC128
Damjan Marion83049332019-09-25 00:25:36 +0200232 u32x4u *data = (u32x4u *) h;
233 xor_sum.as_u32x4 = data[0 + t->skip_n_vectors] & mask[0];
234 switch (t->match_n_vectors)
Pierre Pfistercb656302016-03-16 09:14:28 +0000235 {
Damjan Marion83049332019-09-25 00:25:36 +0200236 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 ();
Pierre Pfistercb656302016-03-16 09:14:28 +0000252 }
Damjan Marion83049332019-09-25 00:25:36 +0200253#else
254 u32 skip_u64 = t->skip_n_vectors * 2;
255 u64 *data64 = (u64 *) h;
256 xor_sum.as_u64[0] = data64[0 + skip_u64] & ((u64 *) mask)[0];
257 xor_sum.as_u64[1] = data64[1 + skip_u64] & ((u64 *) mask)[1];
258 switch (t->match_n_vectors)
259 {
260 case 5:
261 xor_sum.as_u64[0] ^= data64[8 + skip_u64] & ((u64 *) mask)[8];
262 xor_sum.as_u64[1] ^= data64[9 + skip_u64] & ((u64 *) mask)[9];
263 /* FALLTHROUGH */
264 case 4:
265 xor_sum.as_u64[0] ^= data64[6 + skip_u64] & ((u64 *) mask)[6];
266 xor_sum.as_u64[1] ^= data64[7 + skip_u64] & ((u64 *) mask)[7];
267 /* FALLTHROUGH */
268 case 3:
269 xor_sum.as_u64[0] ^= data64[4 + skip_u64] & ((u64 *) mask)[4];
270 xor_sum.as_u64[1] ^= data64[5 + skip_u64] & ((u64 *) mask)[5];
271 /* FALLTHROUGH */
272 case 2:
273 xor_sum.as_u64[0] ^= data64[2 + skip_u64] & ((u64 *) mask)[2];
274 xor_sum.as_u64[1] ^= data64[3 + skip_u64] & ((u64 *) mask)[3];
275 /* FALLTHROUGH */
276 case 1:
277 break;
278
279 default:
280 abort ();
281 }
282#endif /* CLIB_HAVE_VEC128 */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530283
Ray Kinsella7741afa2020-04-07 07:51:23 +0100284#ifdef clib_crc32c_uses_intrinsics
285 return clib_crc32c ((u8 *) & xor_sum, sizeof (xor_sum));
286#else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287 return clib_xxhash (xor_sum.as_u64[0] ^ xor_sum.as_u64[1]);
Ray Kinsella7741afa2020-04-07 07:51:23 +0100288#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700289}
290
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530291static inline void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292vnet_classify_prefetch_bucket (vnet_classify_table_t * t, u64 hash)
293{
294 u32 bucket_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530295
296 ASSERT (is_pow2 (t->nbuckets));
297
Ed Warnickecb9cada2015-12-08 15:45:58 -0700298 bucket_index = hash & (t->nbuckets - 1);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530299
300 CLIB_PREFETCH (&t->buckets[bucket_index], CLIB_CACHE_LINE_BYTES, LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700301}
302
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530303static inline vnet_classify_entry_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700304vnet_classify_get_entry (vnet_classify_table_t * t, uword offset)
305{
Damjan Marion4537c302020-09-28 19:03:37 +0200306 u8 *hp = clib_mem_get_heap_base (t->mheap);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530307 u8 *vp = hp + offset;
308
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309 return (void *) vp;
310}
311
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530312static inline uword
313vnet_classify_get_offset (vnet_classify_table_t * t,
314 vnet_classify_entry_t * v)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700315{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530316 u8 *hp, *vp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317
Damjan Marion4537c302020-09-28 19:03:37 +0200318 hp = (u8 *) clib_mem_get_heap_base (t->mheap);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700319 vp = (u8 *) v;
320
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530321 ASSERT ((vp - hp) < 0x100000000ULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322 return vp - hp;
323}
324
325static inline vnet_classify_entry_t *
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530326vnet_classify_entry_at_index (vnet_classify_table_t * t,
327 vnet_classify_entry_t * e, u32 index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700328{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530329 u8 *eu8;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530331 eu8 = (u8 *) e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332
333 eu8 += index * (sizeof (vnet_classify_entry_t) +
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530334 (t->match_n_vectors * sizeof (u32x4)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700335
336 return (vnet_classify_entry_t *) eu8;
337}
338
339static inline void
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530340vnet_classify_prefetch_entry (vnet_classify_table_t * t, u64 hash)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700341{
342 u32 bucket_index;
343 u32 value_index;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530344 vnet_classify_bucket_t *b;
345 vnet_classify_entry_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700346
347 bucket_index = hash & (t->nbuckets - 1);
348
349 b = &t->buckets[bucket_index];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530350
Ed Warnickecb9cada2015-12-08 15:45:58 -0700351 if (b->offset == 0)
352 return;
353
354 hash >>= t->log2_nbuckets;
355
356 e = vnet_classify_get_entry (t, b->offset);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530357 value_index = hash & ((1 << b->log2_pages) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700358
359 e = vnet_classify_entry_at_index (t, e, value_index);
360
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530361 CLIB_PREFETCH (e, CLIB_CACHE_LINE_BYTES, LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700362}
363
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530364vnet_classify_entry_t *vnet_classify_find_entry (vnet_classify_table_t * t,
365 u8 * h, u64 hash, f64 now);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700366
367static inline vnet_classify_entry_t *
368vnet_classify_find_entry_inline (vnet_classify_table_t * t,
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530369 u8 * h, u64 hash, f64 now)
Dave Barachcada2a02017-05-18 19:16:47 -0400370{
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530371 vnet_classify_entry_t *v;
Pierre Pfistercb656302016-03-16 09:14:28 +0000372 u32x4 *mask, *key;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530373 union
374 {
Pierre Pfistercb656302016-03-16 09:14:28 +0000375 u32x4 as_u32x4;
376 u64 as_u64[2];
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530377 } result __attribute__ ((aligned (sizeof (u32x4))));
378 vnet_classify_bucket_t *b;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700379 u32 value_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380 u32 bucket_index;
Dave Barachcada2a02017-05-18 19:16:47 -0400381 u32 limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382 int i;
383
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530384 bucket_index = hash & (t->nbuckets - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700385 b = &t->buckets[bucket_index];
Pierre Pfistercb656302016-03-16 09:14:28 +0000386 mask = t->mask;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700387
388 if (b->offset == 0)
389 return 0;
390
391 hash >>= t->log2_nbuckets;
392
393 v = vnet_classify_get_entry (t, b->offset);
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530394 value_index = hash & ((1 << b->log2_pages) - 1);
Dave Barachcada2a02017-05-18 19:16:47 -0400395 limit = t->entries_per_page;
396 if (PREDICT_FALSE (b->linear_search))
397 {
398 value_index = 0;
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530399 limit *= (1 << b->log2_pages);
Dave Barachcada2a02017-05-18 19:16:47 -0400400 }
401
Ed Warnickecb9cada2015-12-08 15:45:58 -0700402 v = vnet_classify_entry_at_index (t, v, value_index);
403
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100404#ifdef CLIB_HAVE_VEC128
Damjan Marion83049332019-09-25 00:25:36 +0200405 u32x4u *data = (u32x4u *) h;
406 for (i = 0; i < limit; i++)
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530407 {
Damjan Marion83049332019-09-25 00:25:36 +0200408 key = v->key;
409 result.as_u32x4 = (data[0 + t->skip_n_vectors] & mask[0]) ^ key[0];
410 switch (t->match_n_vectors)
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530411 {
Damjan Marion83049332019-09-25 00:25:36 +0200412 case 5:
413 result.as_u32x4 |= (data[4 + t->skip_n_vectors] & mask[4]) ^ key[4];
414 /* FALLTHROUGH */
415 case 4:
416 result.as_u32x4 |= (data[3 + t->skip_n_vectors] & mask[3]) ^ key[3];
417 /* FALLTHROUGH */
418 case 3:
419 result.as_u32x4 |= (data[2 + t->skip_n_vectors] & mask[2]) ^ key[2];
420 /* FALLTHROUGH */
421 case 2:
422 result.as_u32x4 |= (data[1 + t->skip_n_vectors] & mask[1]) ^ key[1];
423 /* FALLTHROUGH */
424 case 1:
425 break;
426 default:
427 abort ();
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530428 }
Damjan Marion83049332019-09-25 00:25:36 +0200429
430 if (u32x4_zero_byte_mask (result.as_u32x4) == 0xffff)
431 {
432 if (PREDICT_TRUE (now))
433 {
434 v->hits++;
435 v->last_heard = now;
436 }
437 return (v);
438 }
439 v = vnet_classify_entry_at_index (t, v, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700440 }
Damjan Marion83049332019-09-25 00:25:36 +0200441#else
442 u32 skip_u64 = t->skip_n_vectors * 2;
443 u64 *data64 = (u64 *) h;
444 for (i = 0; i < limit; i++)
445 {
446 key = v->key;
447
448 result.as_u64[0] =
449 (data64[0 + skip_u64] & ((u64 *) mask)[0]) ^ ((u64 *) key)[0];
450 result.as_u64[1] =
451 (data64[1 + skip_u64] & ((u64 *) mask)[1]) ^ ((u64 *) key)[1];
452 switch (t->match_n_vectors)
453 {
454 case 5:
455 result.as_u64[0] |=
456 (data64[8 + skip_u64] & ((u64 *) mask)[8]) ^ ((u64 *) key)[8];
457 result.as_u64[1] |=
458 (data64[9 + skip_u64] & ((u64 *) mask)[9]) ^ ((u64 *) key)[9];
459 /* FALLTHROUGH */
460 case 4:
461 result.as_u64[0] |=
462 (data64[6 + skip_u64] & ((u64 *) mask)[6]) ^ ((u64 *) key)[6];
463 result.as_u64[1] |=
464 (data64[7 + skip_u64] & ((u64 *) mask)[7]) ^ ((u64 *) key)[7];
465 /* FALLTHROUGH */
466 case 3:
467 result.as_u64[0] |=
468 (data64[4 + skip_u64] & ((u64 *) mask)[4]) ^ ((u64 *) key)[4];
469 result.as_u64[1] |=
470 (data64[5 + skip_u64] & ((u64 *) mask)[5]) ^ ((u64 *) key)[5];
471 /* FALLTHROUGH */
472 case 2:
473 result.as_u64[0] |=
474 (data64[2 + skip_u64] & ((u64 *) mask)[2]) ^ ((u64 *) key)[2];
475 result.as_u64[1] |=
476 (data64[3 + skip_u64] & ((u64 *) mask)[3]) ^ ((u64 *) key)[3];
477 /* FALLTHROUGH */
478 case 1:
479 break;
480 default:
481 abort ();
482 }
483
484 if (result.as_u64[0] == 0 && result.as_u64[1] == 0)
485 {
486 if (PREDICT_TRUE (now))
487 {
488 v->hits++;
489 v->last_heard = now;
490 }
491 return (v);
492 }
493
494 v = vnet_classify_entry_at_index (t, v, 1);
495 }
Adrian Oanca22ac59b2018-02-23 16:27:41 +0100496#endif /* CLIB_HAVE_VEC128 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700497 return 0;
Dave Barachcada2a02017-05-18 19:16:47 -0400498}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700499
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530500vnet_classify_table_t *vnet_classify_new_table (vnet_classify_main_t * cm,
501 u8 * mask, u32 nbuckets,
502 u32 memory_size,
503 u32 skip_n_vectors,
504 u32 match_n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700505
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530506int vnet_classify_add_del_session (vnet_classify_main_t * cm,
507 u32 table_index,
508 u8 * match,
509 u32 hit_next_index,
510 u32 opaque_index,
511 i32 advance,
512 u8 action, u32 metadata, int is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700513
514int vnet_classify_add_del_table (vnet_classify_main_t * cm,
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530515 u8 * mask,
516 u32 nbuckets,
517 u32 memory_size,
518 u32 skip,
519 u32 match,
520 u32 next_table_index,
521 u32 miss_next_index,
522 u32 * table_index,
523 u8 current_data_flag,
524 i16 current_data_offset,
525 int is_add, int del_chain);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700526
527unformat_function_t unformat_ip4_mask;
528unformat_function_t unformat_ip6_mask;
529unformat_function_t unformat_l3_mask;
530unformat_function_t unformat_l2_mask;
531unformat_function_t unformat_classify_mask;
532unformat_function_t unformat_l2_next_index;
533unformat_function_t unformat_ip_next_index;
534unformat_function_t unformat_ip4_match;
535unformat_function_t unformat_ip6_match;
536unformat_function_t unformat_l3_match;
Dave Barach4a3f69c2017-02-22 12:44:56 -0500537unformat_function_t unformat_l4_match;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538unformat_function_t unformat_vlan_tag;
539unformat_function_t unformat_l2_match;
540unformat_function_t unformat_classify_match;
541
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530542void vnet_classify_register_unformat_ip_next_index_fn
543 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400544
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530545void vnet_classify_register_unformat_l2_next_index_fn
546 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400547
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530548void vnet_classify_register_unformat_acl_next_index_fn
549 (unformat_function_t * fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400550
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530551void vnet_classify_register_unformat_policer_next_index_fn
552 (unformat_function_t * fn);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700553
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530554void vnet_classify_register_unformat_opaque_index_fn (unformat_function_t *
555 fn);
Dave Barachf39ff742016-03-20 10:14:45 -0400556
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557#endif /* __included_vnet_classify_h__ */
khemendra kumard7bfa0e2017-11-27 15:15:53 +0530558
559/*
560 * fd.io coding-style-patch-verification: ON
561 *
562 * Local Variables:
563 * eval: (c-set-style "gnu")
564 * End:
565 */