#include <vnet/classify/policer_classify.h>
#include <vnet/classify/flow_classify.h>
#include <vnet/l2/l2_classify.h>
+#include <vnet/ip/ip6.h>
+#include <vnet/ip/ip4.h>
#include <vnet/vnet_msg_enum.h>
_(match_n_vectors) \
_(next_table_index) \
_(miss_next_index) \
-_(current_data_flag) \
-_(current_data_offset)
+_(mask_len)
static void vl_api_classify_add_del_table_t_handler
(vl_api_classify_add_del_table_t * mp)
foreach_classify_add_del_table_field;
#undef _
+ if (mask_len != match_n_vectors * sizeof (u32x4))
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto out;
+ }
+
/* The underlying API fails silently, on purpose, so check here */
if (mp->is_add == 0) /* delete */
{
table_index = ~0;
}
+ u8 current_data_flag = mp->current_data_flag;
+ i16 current_data_offset = clib_net_to_host_i16 (mp->current_data_offset);
+
rv = vnet_classify_add_del_table
(cm, mp->mask, nbuckets, memory_size,
skip_n_vectors, match_n_vectors,
if (rv == 0 && mp->is_add)
{
t = pool_elt_at_index (cm->tables, table_index);
- rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
- rmp->match_n_vectors = ntohl(t->match_n_vectors);
- rmp->new_table_index = ntohl(table_index);
+ rmp->skip_n_vectors = htonl(t->skip_n_vectors);
+ rmp->match_n_vectors = htonl(t->match_n_vectors);
+ rmp->new_table_index = htonl(table_index);
}
else
{
vnet_classify_main_t *cm = &vnet_classify_main;
vl_api_classify_add_del_session_reply_t *rmp;
int rv;
- u32 table_index, hit_next_index, opaque_index, metadata;
+ u32 table_index, hit_next_index, opaque_index, metadata, match_len;
i32 advance;
u8 action;
+ vnet_classify_table_t *t;
table_index = ntohl (mp->table_index);
hit_next_index = ntohl (mp->hit_next_index);
advance = ntohl (mp->advance);
action = mp->action;
metadata = ntohl (mp->metadata);
+ match_len = ntohl (mp->match_len);
+
+ if (pool_is_free_index (cm->tables, table_index))
+ {
+ rv = VNET_API_ERROR_NO_SUCH_TABLE;
+ goto out;
+ }
+
+ t = pool_elt_at_index (cm->tables, table_index);
+
+ if (match_len != (t->skip_n_vectors + t->match_n_vectors) * sizeof (u32x4))
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto out;
+ }
rv = vnet_classify_add_del_session
(cm, table_index, mp->match, hit_next_index, opaque_index,
advance, action, metadata, mp->is_add);
+out:
REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
}
vl_api_policer_classify_details_t *mp;
mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
+ clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
mp->context = context;
mp->sw_if_index = htonl (sw_if_index);
policer_classify_main_t *pcm = &policer_classify_main;
u32 *vec_tbl;
int i;
+ u32 filter_sw_if_index;
reg = vl_api_client_index_to_registration (mp->client_index);
if (!reg)
return;
- vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
+ filter_sw_if_index = ntohl (mp->sw_if_index);
+ if (filter_sw_if_index
+ >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
+ return;
+
+ if (filter_sw_if_index != ~0)
+ vec_tbl =
+ &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
+ else
+ vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
if (vec_len (vec_tbl))
{
u32 count;
/* *INDENT-OFF* */
- pool_foreach (t, cm->tables,
- ({
+ pool_foreach (t, cm->tables)
+ {
vec_add1 (table_ids, ntohl(t - cm->tables));
- }));
+ }
/* *INDENT-ON* */
count = vec_len (table_ids);
vnet_classify_table_t *t;
/* *INDENT-OFF* */
- pool_foreach (t, cm->tables,
- ({
+ pool_foreach (t, cm->tables)
+ {
if (table_id == t - cm->tables)
{
rmp = vl_msg_api_alloc_as_if_client
rmp->retval = 0;
break;
}
- }));
+ }
/* *INDENT-ON* */
if (rmp == 0)
vl_api_classify_session_details_t *rmp;
rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
+ clib_memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
rmp->context = context;
rmp->table_id = ntohl (table_id);
return;
/* *INDENT-OFF* */
- pool_foreach (t, cm->tables,
- ({
+ pool_foreach (t, cm->tables)
+ {
if (table_id == t - cm->tables)
{
vnet_classify_bucket_t * b;
}
break;
}
- }));
+ }
/* *INDENT-ON* */
}
vl_api_flow_classify_details_t *mp;
mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
+ clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
mp->context = context;
mp->sw_if_index = htonl (sw_if_index);
flow_classify_main_t *pcm = &flow_classify_main;
u32 *vec_tbl;
int i;
+ u32 filter_sw_if_index;
reg = vl_api_client_index_to_registration (mp->client_index);
if (!reg)
return;
- vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
+ filter_sw_if_index = ntohl (mp->sw_if_index);
+ if (filter_sw_if_index
+ >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
+ return;
+
+ if (filter_sw_if_index != ~0)
+ vec_tbl =
+ &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
+ else
+ vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
if (vec_len (vec_tbl))
{
/*
* classify_api_hookup
* Add vpe's API message handlers to the table.
- * vlib has alread mapped shared memory and
+ * vlib has already mapped shared memory and
* added the client registration handlers.
* See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
*/
static clib_error_t *
classify_api_hookup (vlib_main_t * vm)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
#define _(N,n) \
vl_msg_api_set_handlers(VL_API_##N, #n, \