app/eventdev: switch sequence number to dynamic mbuf field
[dpdk.git] / lib / librte_pipeline / rte_swx_pipeline.c
index 8b7ff56..5848078 100644 (file)
@@ -22,7 +22,17 @@ do {                                                                           \
 } while (0)
 
 #define CHECK_NAME(name, err_code)                                             \
-       CHECK((name) && (name)[0], err_code)
+       CHECK((name) &&                                                        \
+             (name)[0] &&                                                     \
+             (strnlen((name), RTE_SWX_NAME_SIZE) < RTE_SWX_NAME_SIZE),        \
+             err_code)
+
+#define CHECK_INSTRUCTION(instr, err_code)                                     \
+       CHECK((instr) &&                                                       \
+             (instr)[0] &&                                                    \
+             (strnlen((instr), RTE_SWX_INSTRUCTION_SIZE) <                    \
+              RTE_SWX_INSTRUCTION_SIZE),                                      \
+             err_code)
 
 #ifndef TRACE_LEVEL
 #define TRACE_LEVEL 0
@@ -1635,12 +1645,12 @@ rte_swx_pipeline_extern_type_member_func_register(struct rte_swx_pipeline *p,
 
        CHECK(p, EINVAL);
 
-       CHECK(extern_type_name, EINVAL);
+       CHECK_NAME(extern_type_name, EINVAL);
        type = extern_type_find(p, extern_type_name);
        CHECK(type, EINVAL);
        CHECK(type->n_funcs < RTE_SWX_EXTERN_TYPE_MEMBER_FUNCS_MAX, ENOSPC);
 
-       CHECK(name, EINVAL);
+       CHECK_NAME(name, EINVAL);
        CHECK(!extern_type_member_func_find(type, name), EEXIST);
 
        CHECK(member_func, EINVAL);
@@ -4658,7 +4668,7 @@ instr_jmp_invalid_translate(struct rte_swx_pipeline *p,
 {
        struct header *h;
 
-       CHECK(n_tokens == 2, EINVAL);
+       CHECK(n_tokens == 3, EINVAL);
 
        strcpy(data->jmp_label, tokens[1]);
 
@@ -5280,8 +5290,6 @@ instr_return_exec(struct rte_swx_pipeline *p)
        t->ip = t->ret;
 }
 
-#define RTE_SWX_INSTRUCTION_TOKENS_MAX 16
-
 static int
 instr_translate(struct rte_swx_pipeline *p,
                struct action *action,
@@ -5301,6 +5309,7 @@ instr_translate(struct rte_swx_pipeline *p,
                        break;
 
                CHECK(n_tokens < RTE_SWX_INSTRUCTION_TOKENS_MAX, EINVAL);
+               CHECK_NAME(token, EINVAL);
 
                tokens[n_tokens] = token;
                n_tokens++;
@@ -5647,7 +5656,7 @@ instr_jmp_resolve(struct instruction *instructions,
                                   data->jmp_label);
                CHECK(found, EINVAL);
 
-               instr->jmp.ip = &instr[found - instruction_data];
+               instr->jmp.ip = &instructions[found - instruction_data];
        }
 
        return 0;
@@ -5671,7 +5680,7 @@ instr_verify(struct rte_swx_pipeline *p __rte_unused,
                for (i = 0; i < n_instructions; i++) {
                        type = instr[i].type;
 
-                       if (instr[i].type == INSTR_TX)
+                       if (type == INSTR_TX)
                                break;
                }
                CHECK(i < n_instructions, EINVAL);
@@ -5932,14 +5941,13 @@ instruction_config(struct rte_swx_pipeline *p,
 {
        struct instruction *instr = NULL;
        struct instruction_data *data = NULL;
-       char *string = NULL;
        int err = 0;
        uint32_t i;
 
        CHECK(n_instructions, EINVAL);
        CHECK(instructions, EINVAL);
        for (i = 0; i < n_instructions; i++)
-               CHECK(instructions[i], EINVAL);
+               CHECK_INSTRUCTION(instructions[i], EINVAL);
 
        /* Memory allocation. */
        instr = calloc(n_instructions, sizeof(struct instruction));
@@ -5955,15 +5963,17 @@ instruction_config(struct rte_swx_pipeline *p,
        }
 
        for (i = 0; i < n_instructions; i++) {
-               string = strdup(instructions[i]);
+               char *string = strdup(instructions[i]);
                if (!string) {
                        err = ENOMEM;
                        goto error;
                }
 
                err = instr_translate(p, a, string, &instr[i], &data[i]);
-               if (err)
+               if (err) {
+                       free(string);
                        goto error;
+               }
 
                free(string);
        }
@@ -5982,8 +5992,6 @@ instruction_config(struct rte_swx_pipeline *p,
        if (err)
                goto error;
 
-       free(data);
-
        if (a) {
                a->instructions = instr;
                a->n_instructions = n_instructions;
@@ -5992,10 +6000,10 @@ instruction_config(struct rte_swx_pipeline *p,
                p->n_instructions = n_instructions;
        }
 
+       free(data);
        return 0;
 
 error:
-       free(string);
        free(data);
        free(instr);
        return err;
@@ -6443,7 +6451,7 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
                struct action *a;
                uint32_t action_data_size;
 
-               CHECK(action_name, EINVAL);
+               CHECK_NAME(action_name, EINVAL);
 
                a = action_find(p, action_name);
                CHECK(a, EINVAL);
@@ -6453,7 +6461,7 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
                        action_data_size_max = action_data_size;
        }
 
-       CHECK(params->default_action_name, EINVAL);
+       CHECK_NAME(params->default_action_name, EINVAL);
        for (i = 0; i < p->n_actions; i++)
                if (!strcmp(params->action_names[i],
                            params->default_action_name))
@@ -6464,6 +6472,9 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
              !params->default_action_data, EINVAL);
 
        /* Table type checks. */
+       if (recommended_table_type_name)
+               CHECK_NAME(recommended_table_type_name, EINVAL);
+
        if (params->n_fields) {
                enum rte_swx_table_match_type match_type;