1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vnet/ip/ip.h>
#include <vnet/classify/vnet_classify.h>
#include <vnet/classify/in_out_acl.h>
#include <vnet/l2/l2_output.h>
#include <vnet/l2/l2_input.h>
in_out_acl_main_t in_out_acl_main;
static int
vnet_in_out_acl_ip_feature_enable (vlib_main_t * vnm,
in_out_acl_main_t * am,
u32 sw_if_index,
in_out_acl_table_id_t tid,
int feature_enable, int is_output)
{
if (tid == IN_OUT_ACL_TABLE_L2)
{
if (is_output)
l2output_intf_bitmap_enable (sw_if_index, L2OUTPUT_FEAT_ACL,
feature_enable);
else
l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ACL,
feature_enable);
}
else
{ /* IP[46] */
vnet_feature_config_main_t *fcm;
u8 arc;
if (tid == IN_OUT_ACL_TABLE_IP4)
{
char *arc_name = is_output ? "ip4-output" : "ip4-unicast";
vnet_feature_enable_disable (arc_name,
is_output ? "ip4-outacl" : "ip4-inacl",
sw_if_index, feature_enable, 0, 0);
arc = vnet_get_feature_arc_index (arc_name);
}
else
{
char *arc_name = is_output ? "ip6-output" : "ip6-unicast";
vnet_feature_enable_disable (arc_name,
is_output ? "ip6-outacl" : "ip6-inacl",
sw_if_index, feature_enable, 0, 0);
arc = vnet_get_feature_arc_index (arc_name);
}
fcm = vnet_get_feature_arc_config_main (arc);
am->vnet_config_main[is_output][tid] = &fcm->config_main;
}
return 0;
}
int
vnet_set_in_out_acl_intfc (vlib_main_t * vm, u32 sw_if_index,
u32 ip4_table_index,
u32 ip6_table_index, u32 l2_table_index,
u32 is_add, u32 is_output)
{
in_out_acl_main_t *am = &in_out_acl_main;
vnet_classify_main_t *vcm = am->vnet_classify_main;
u32 acl[IN_OUT_ACL_N_TABLES] = { ip4_table_index, ip6_table_index,
l2_table_index
};
u32 ti;
/* Assume that we've validated sw_if_index in the API layer */
for (ti = 0; ti < IN_OUT_ACL_N_TABLES; ti++)
{
if (acl[ti] == ~0)
continue;
if (pool_is_free_index (vcm->tables, acl[ti]))
return VNET_API_ERROR_NO_SUCH_TABLE;
vec_validate_init_empty
(am->classify_table_index_by_sw_if_index[is_output][ti], sw_if_index,
~0);
/* Reject any DEL operation with wrong sw_if_index */
if (!is_add &&
(acl[ti] !=
am->classify_table_index_by_sw_if_index[is_output][ti]
[sw_if_index]))
{
clib_warning
("Non-existent intf_idx=%d with table_index=%d for delete",
sw_if_index, acl[ti]);
return VNET_API_ERROR_NO_SUCH_TABLE;
}
/* Return ok on ADD operaton if feature is already enabled */
if (is_add &&
am->classify_table_index_by_sw_if_index[is_output][ti][sw_if_index]
!= ~0)
return 0;
vnet_in_out_acl_ip_feature_enable (vm, am, sw_if_index, ti, is_add,
is_output);
if (is_add)
am->classify_table_index_by_sw_if
}
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
Copyright (c) 2005 Eliot Dresselhaus
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef included_vector_sse2_h
#define included_vector_sse2_h
#include <vppinfra/error_bootstrap.h> /* for ASSERT */
#include <x86intrin.h>
/* *INDENT-OFF* */
#define foreach_sse42_vec128i \
_(i,8,16,epi8) _(i,16,8,epi16) _(i,32,4,epi32) _(i,64,2,epi64x)
#define foreach_sse42_vec128u \
_(u,8,16,epi8) _(u,16,8,epi16) _(u,32,4,epi32) _(u,64,2,epi64x)
#define foreach_sse42_vec128f \
_(f,32,4,ps) _(f,64,2,pd)
/* splat, load_unaligned, store_unaligned, is_all_zero, is_equal,
is_all_equal */
#define _(t, s, c, i) \
static_always_inline t##s##x##c \
t##s##x##c##_splat (t##s x) \
{ return (t##s##x##c) _mm_set1_##i (x); } \
\
static_always_inline t##s##x##c \
t##s##x##c##_load_unaligned (void *p) \
{ return (t##s##x##c) _mm_loadu_si128 (p); } \
\
static_always_inline void \
t##s##x##c##_store_unaligned (t##s##x##c v, void *p) \
{ _mm_storeu_si128 ((__m128i *) p, (__m128i) v); } \
\
static_always_inline int \
t##s##x##c##_is_all_zero (t##s##x##c x) \
{ return _mm_testz_si128 ((__m128i) x, (__m128i) x); } \
\
static_always_inline int \
t##s##x##c##_is_equal (t##s##x##c a, t##s##x##c b) \
{ return t##s##x##c##_is_all_zero (a ^ b); } \
\
static_always_inline int \
t##s##x##c##_is_all_equal (t##s##x##c v, t##s x) \
{ return t##s##x##c##_is_equal (v, t##s##x##c##_splat (x)); }; \
foreach_sse42_vec128i foreach_sse42_vec128u
#undef _
/* min, max */
#define _(t, s, c, i) \
static_always_inline t##s##x##c \
t##s##x##c##_min (t##s##x##c a, t##s##x##c b) \
{ return (t##s##x##c) _mm_min_##i ((__m128i) a, (__m128i) b); } \
\
static_always_inline t##s##x##c \
t##s##x##c##_max (t##s##x##c a, t##s##x##c b) \
{ return (t##s##x##c) _mm_max_##i ((__m128i) a, (__m128i) b); } \
_(i,8,16,epi8) _(i,16,8,epi16) _(i,32,4,epi32) _(i,64,2,epi64)
_(u,8,16,epu8) _(u,16,8,epu16) _(u,32,4,epu32) _(u,64,2,epu64)
#undef _
/* *INDENT-ON* */
#define CLIB_VEC128_SPLAT_DEFINED
#define CLIB_HAVE_VEC128_UNALIGNED_LOAD_STORE
/* 128 bit interleaves. */
always_inline u8x16
u8x16_interleave_hi (u8x16 a, u8x16 b)
{
return (u8x16) _mm_unpackhi_epi8 ((__m128i) a, (__m128i) b);
}
always_inline u8x16
u8x16_interleave_lo (u8x16 a, u8x16 b)
{
return (u8x16) _mm_unpacklo_epi8 ((__m128i) a, (__m128i) b);
}
always_inline u16x8
u16x8_interleave_hi (u16x8 a, u16x8 b)
{
return (u16x8) _mm_unpackhi_epi16 ((__m128i) a, (__m128i) b);
}
always_inline u16x8
u16x8_interleave_lo (u16x8 a, u16x8 b)
{
return (u16x8) _mm_unpacklo_epi16 ((__m128i) a, (__m128i) b);
}
always_inline u32x4
u32x4_interleave_hi (u32x4 a, u32x4 b)
{
return (u32x4) _mm_unpackhi_epi32 ((__m128i) a, (__m128i) b);
}
always_inline u32x4
u32x4_interleave_lo (u32x4 a, u32x4 b)
{
return (u32x4) _mm_unpacklo_epi32 ((__m128i) a, (__m128i) b);
}
always_inline u64x2
u64x2_interleave_hi (u64x2 a, u64x2 b)
{
return (u64x2) _mm_unpackhi_epi64 ((__m128i) a, (__m128i) b);
}
always_inline u64x2
u64x2_interleave_lo (u64x2 a, u64x2 b)
{
return (u64x2) _mm_unpacklo_epi64 ((__m128i) a, (__m128i) b);
}
/* 64 bit interleaves. */
always_inline u8x8
u8x8_interleave_hi (u8x8 a, u8x8 b)
{
return (u8x8) _m_punpckhbw ((__m64) a, (__m64) b);
}
always_inline u8x8
u8x8_interleave_lo (u8x8 a, u8x8 b)
{
return (u8x8) _m_punpcklbw ((__m64) a, (__m64) b);
}
always_inline u16x4
u16x4_interleave_hi (u16x4 a, u16x4 b)
{
return (u16x4) _m_punpckhwd ((__m64) a, (__m64) b);
}
always_inline u16x4
u16x4_interleave_lo (u16x4 a, u16x4 b)
{
return (u16x4) _m_punpcklwd ((__m64) a, (__m64) b);
}
always_inline u32x2
u32x2_interleave_hi (u32x2 a, u32x2 b)
{
return (u32x2) _m_punpckhdq ((__m64) a, (__m64) b);
}
always_inline u32x2
u32x2_interleave_lo (u32x2 a, u32x2 b)
{
return (u32x2) _m_punpckldq ((__m64) a, (__m64) b);
}
/* 128 bit packs. */
always_inline u8x16
u16x8_pack (u16x8 lo, u16x8 hi)
{
return (u8x16) _mm_packus_epi16 ((__m128i) lo, (__m128i) hi);
}
always_inline i8x16
i16x8_pack (i16x8 lo, i16x8 hi)
{
return (i8x16) _mm_packs_epi16 ((__m128i) lo, (__m128i) hi);
}
always_inline u16x8
u32x4_pack (u32x4 lo, u32x4 hi)
{
return (u16x8) _mm_packs_epi32 ((__m128i) lo, (__m128i) hi);
}
/* 64 bit packs. */
always_inline u8x8
u16x4_pack (u16x4 lo, u16x4 hi)
{
return (u8x8) _m_packuswb ((__m64) lo, (__m64) hi);
}
always_inline i8x8
i16x4_pack (i16x4 lo, i16x4 hi)
{
return (i8x8) _m_packsswb ((__m64) lo, (__m64) hi);
}
always_inline u16x4
u32x2_pack (u32x2 lo, u32x2 hi)
{
return (u16x4) _m_packssdw ((__m64) lo, (__m64) hi);
}
always_inline i16x4
i32x2_pack (i32x2 lo, i32x2 hi)
{
return (i16x4) _m_packssdw ((__m64) lo, (__m64) hi);
}
#ifndef __ICC
always_inline u64x2
u64x2_read_lo (u64x2 x, u64 * a)
{
return (u64x2) _mm_loadl_pi ((__m128) x, (__m64 *) a);
}
always_inline u64x2
u64x2_read_hi (u64x2 x, u64 * a)
{
return (u64x2) _mm_loadh_pi ((__m128) x, (__m64 *) a);
}
always_inline void
u64x2_write_lo (u64x2 x, u64 * a)
{
_mm_storel_pi ((__m64 *) a, (__m128) x);
}
always_inline void
u64x2_write_hi (u64x2 x, u64 * a)
{
_mm_storeh_pi ((__m64 *) a, (__m128) x);
}
#endif
#define _signed_binop(n,m,f,g) \
/* Unsigned */ \
always_inline u##n##x##m \
u##n##x##m##_##f (u##n##x##m x, u##n##x##m y) \
{ return (u##n##x##m) _mm_##g##n ((__m128i) x, (__m128i) y); } \
\
/* Signed */ \
always_inline i##n##x##m \
i##n##x##m##_##f (i##n##x##m x, i##n##x##m y) \
{ return (i##n##x##m) _mm_##g##n ((__m128i) x, (__m128i) y); }
/* Addition/subtraction with saturation. */
_signed_binop (8, 16, add_saturate, adds_epu)
_signed_binop (16, 8, add_saturate, adds_epu)
_signed_binop (8, 16, sub_saturate, subs_epu)
_signed_binop (16, 8, sub_saturate, subs_epu)
/* Multiplication. */
always_inline i16x8 i16x8_mul_lo (i16x8 x, i16x8 y)
{
return (i16x8) _mm_mullo_epi16 ((__m128i) x, (__m128i) y);
}
always_inline u16x8
u16x8_mul_lo (u16x8 x, u16x8 y)
{
return (u16x8) _mm_mullo_epi16 ((__m128i) x, (__m128i) y);
}
always_inline i16x8
i16x8_mul_hi (i16x8 x, i16x8 y)
{
return (i16x8) _mm_mulhi_epu16 ((__m128i) x, (__m128i) y);
}
always_inline u16x8
u16x8_mul_hi (u16x8 x, u16x8 y
|