vhost: check overflow before mmap
[dpdk.git] / examples / ip_pipeline / pipeline / pipeline_flow_classification_be.c
index c528dfb..097ec34 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2016 Intel Corporation
  */
 
 #include <string.h>
@@ -55,6 +26,7 @@ struct pipeline_flow_classification {
        uint32_t key_offset;
        uint32_t hash_offset;
        uint8_t key_mask[PIPELINE_FC_FLOW_KEY_MAX_SIZE];
+       uint32_t key_mask_present;
        uint32_t flow_id_offset;
 
 } __rte_cache_aligned;
@@ -220,7 +192,7 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
        uint32_t flow_id_offset_present = 0;
 
        uint32_t i;
-       char key_mask_str[PIPELINE_FC_FLOW_KEY_MAX_SIZE * 2];
+       char key_mask_str[PIPELINE_FC_FLOW_KEY_MAX_SIZE * 2 + 1];
 
        p->hash_offset = 0;
 
@@ -302,13 +274,13 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
                                params->name, arg_name);
                        key_mask_present = 1;
 
-                       PIPELINE_ARG_CHECK((mask_str_len <
+                       PIPELINE_ARG_CHECK((mask_str_len <=
                                (PIPELINE_FC_FLOW_KEY_MAX_SIZE * 2)),
                                "Parse error in section \"%s\": entry "
                                "\"%s\" is too long", params->name,
                                arg_name);
 
-                       snprintf(key_mask_str, mask_str_len, "%s",
+                       snprintf(key_mask_str, mask_str_len + 1, "%s",
                                arg_value);
 
                        continue;
@@ -370,11 +342,21 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
                uint32_t key_size = p->key_size;
                int status;
 
+               PIPELINE_ARG_CHECK(((key_size == 8) || (key_size == 16)),
+                       "Parse error in section \"%s\": entry key_mask "
+                       "only allowed for key_size of 8 or 16 bytes",
+                       params->name);
+
                PIPELINE_ARG_CHECK((strlen(key_mask_str) ==
                        (key_size * 2)), "Parse error in section "
                        "\"%s\": key_mask should have exactly %u hex "
                        "digits", params->name, (key_size * 2));
 
+               PIPELINE_ARG_CHECK((hash_offset_present == 0), "Parse "
+                       "error in section \"%s\": entry hash_offset only "
+                       "allowed when key_mask is not present",
+                       params->name);
+
                status = parse_hex_string(key_mask_str, p->key_mask,
                        &p->key_size);
 
@@ -383,6 +365,8 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
                        "key_mask", key_mask_str);
        }
 
+       p->key_mask_present = key_mask_present;
+
        return 0;
 }
 
@@ -462,7 +446,6 @@ static void *pipeline_fc_init(struct pipeline_params *params,
                        .arg_create = pipeline_port_out_params_convert(
                                &params->port_out[i]),
                        .f_action = NULL,
-                       .f_action_bulk = NULL,
                        .arg_ah = NULL,
                };
 
@@ -480,38 +463,16 @@ static void *pipeline_fc_init(struct pipeline_params *params,
        /* Tables */
        p->n_tables = 1;
        {
-               struct rte_table_hash_key8_ext_params
-                       table_hash_key8_params = {
-                       .n_entries = p_fc->n_flows,
-                       .n_entries_ext = p_fc->n_flows,
-                       .signature_offset = p_fc->hash_offset,
-                       .key_offset = p_fc->key_offset,
-                       .f_hash = hash_func[(p_fc->key_size / 8) - 1],
-                       .key_mask = p_fc->key_mask,
-                       .seed = 0,
-               };
-
-               struct rte_table_hash_key16_ext_params
-                       table_hash_key16_params = {
-                       .n_entries = p_fc->n_flows,
-                       .n_entries_ext = p_fc->n_flows,
-                       .signature_offset = p_fc->hash_offset,
-                       .key_offset = p_fc->key_offset,
-                       .f_hash = hash_func[(p_fc->key_size / 8) - 1],
-                       .key_mask = p_fc->key_mask,
-                       .seed = 0,
-               };
-
-               struct rte_table_hash_ext_params
-                       table_hash_params = {
+               struct rte_table_hash_params table_hash_params = {
+                       .name = p->name,
                        .key_size = p_fc->key_size,
+                       .key_offset = p_fc->key_offset,
+                       .key_mask = (p_fc->key_mask_present) ?
+                               p_fc->key_mask : NULL,
                        .n_keys = p_fc->n_flows,
-                       .n_buckets = p_fc->n_flows / 4,
-                       .n_buckets_ext = p_fc->n_flows / 4,
+                       .n_buckets = rte_align32pow2(p_fc->n_flows / 4),
                        .f_hash = hash_func[(p_fc->key_size / 8) - 1],
                        .seed = 0,
-                       .signature_offset = p_fc->hash_offset,
-                       .key_offset = p_fc->key_offset,
                };
 
                struct rte_pipeline_table_params table_params = {
@@ -528,32 +489,19 @@ static void *pipeline_fc_init(struct pipeline_params *params,
 
                switch (p_fc->key_size) {
                case 8:
-                       if (p_fc->hash_offset != 0) {
-                               table_params.ops =
-                                       &rte_table_hash_key8_ext_ops;
-                       } else {
-                               table_params.ops =
-                                       &rte_table_hash_key8_ext_dosig_ops;
-                       }
-                       table_params.arg_create = &table_hash_key8_params;
+                       table_params.ops = &rte_table_hash_key8_ext_ops;
                        break;
 
                case 16:
-                       if (p_fc->hash_offset != 0) {
-                               table_params.ops =
-                                       &rte_table_hash_key16_ext_ops;
-                       } else {
-                               table_params.ops =
-                                       &rte_table_hash_key16_ext_dosig_ops;
-                       }
-                       table_params.arg_create = &table_hash_key16_params;
+                       table_params.ops = &rte_table_hash_key16_ext_ops;
                        break;
 
                default:
                        table_params.ops = &rte_table_hash_ext_ops;
-                       table_params.arg_create = &table_hash_params;
                }
 
+               table_params.arg_create = &table_hash_params;
+
                status = rte_pipeline_table_create(p->p,
                        &table_params,
                        &p->table_id[0]);
@@ -628,27 +576,6 @@ pipeline_fc_free(void *pipeline)
        return 0;
 }
 
-static int
-pipeline_fc_track(void *pipeline,
-       __rte_unused uint32_t port_in,
-       uint32_t *port_out)
-{
-       struct pipeline *p = (struct pipeline *) pipeline;
-
-       /* Check input arguments */
-       if ((p == NULL) ||
-               (port_in >= p->n_ports_in) ||
-               (port_out == NULL))
-               return -1;
-
-       if (p->n_ports_in == 1) {
-               *port_out = 0;
-               return 0;
-       }
-
-       return -1;
-}
-
 static int
 pipeline_fc_timer(void *pipeline)
 {
@@ -793,5 +720,4 @@ struct pipeline_be_ops pipeline_flow_classification_be_ops = {
        .f_free = pipeline_fc_free,
        .f_run = NULL,
        .f_timer = pipeline_fc_timer,
-       .f_track = pipeline_fc_track,
 };