X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fclassify%2Fclassify_api.c;h=0725a9c0635dcb7fef94e0dcc997e145f1a83ff3;hb=692bfc85f;hp=2cf79f3875d09f72796437a50b9e42900aee22c0;hpb=815d7d5637fbffd20bf81c74fd59dac8e4fe4d94;p=vpp.git diff --git a/src/vnet/classify/classify_api.c b/src/vnet/classify/classify_api.c index 2cf79f3875d..0725a9c0635 100644 --- a/src/vnet/classify/classify_api.c +++ b/src/vnet/classify/classify_api.c @@ -71,8 +71,7 @@ _(skip_n_vectors) \ _(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) @@ -90,6 +89,12 @@ static void vl_api_classify_add_del_table_t_handler 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 */ { @@ -105,6 +110,9 @@ static void vl_api_classify_add_del_table_t_handler 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, @@ -118,9 +126,9 @@ out: 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 { @@ -138,9 +146,10 @@ static void vl_api_classify_add_del_session_t_handler 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); @@ -148,11 +157,27 @@ static void vl_api_classify_add_del_session_t_handler 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); } @@ -189,7 +214,7 @@ send_policer_classify_details (u32 sw_if_index, 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); @@ -205,12 +230,18 @@ vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp) 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 != ~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)) { @@ -371,7 +402,7 @@ send_classify_session_details (vl_api_registration_t * reg, 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); @@ -465,7 +496,7 @@ send_flow_classify_details (u32 sw_if_index, 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); @@ -481,12 +512,18 @@ vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp) 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 != ~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)) { @@ -614,7 +651,7 @@ static void vl_api_output_acl_set_interface_t_handler /* * 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() */