+/*
+ * Instruction.
+ */
+static int
+instruction_config(struct rte_swx_pipeline *p __rte_unused,
+ struct action *a __rte_unused,
+ const char **instructions __rte_unused,
+ uint32_t n_instructions __rte_unused)
+{
+ return 0;
+}
+
+/*
+ * Action.
+ */
+static struct action *
+action_find(struct rte_swx_pipeline *p, const char *name)
+{
+ struct action *elem;
+
+ if (!name)
+ return NULL;
+
+ TAILQ_FOREACH(elem, &p->actions, node)
+ if (strcmp(elem->name, name) == 0)
+ return elem;
+
+ return NULL;
+}
+
+int
+rte_swx_pipeline_action_config(struct rte_swx_pipeline *p,
+ const char *name,
+ const char *args_struct_type_name,
+ const char **instructions,
+ uint32_t n_instructions)
+{
+ struct struct_type *args_struct_type;
+ struct action *a;
+ int err;
+
+ CHECK(p, EINVAL);
+
+ CHECK_NAME(name, EINVAL);
+ CHECK(!action_find(p, name), EEXIST);
+
+ if (args_struct_type_name) {
+ CHECK_NAME(args_struct_type_name, EINVAL);
+ args_struct_type = struct_type_find(p, args_struct_type_name);
+ CHECK(args_struct_type, EINVAL);
+ } else {
+ args_struct_type = NULL;
+ }
+
+ /* Node allocation. */
+ a = calloc(1, sizeof(struct action));
+ CHECK(a, ENOMEM);
+
+ /* Node initialization. */
+ strcpy(a->name, name);
+ a->st = args_struct_type;
+ a->id = p->n_actions;
+
+ /* Instruction translation. */
+ err = instruction_config(p, a, instructions, n_instructions);
+ if (err) {
+ free(a);
+ return err;
+ }
+
+ /* Node add to tailq. */
+ TAILQ_INSERT_TAIL(&p->actions, a, node);
+ p->n_actions++;
+
+ return 0;
+}
+
+static int
+action_build(struct rte_swx_pipeline *p)
+{
+ struct action *action;
+
+ p->action_instructions = calloc(p->n_actions,
+ sizeof(struct instruction *));
+ CHECK(p->action_instructions, ENOMEM);
+
+ TAILQ_FOREACH(action, &p->actions, node)
+ p->action_instructions[action->id] = action->instructions;
+
+ return 0;
+}
+
+static void
+action_build_free(struct rte_swx_pipeline *p)
+{
+ free(p->action_instructions);
+ p->action_instructions = NULL;
+}
+
+static void
+action_free(struct rte_swx_pipeline *p)
+{
+ action_build_free(p);
+
+ for ( ; ; ) {
+ struct action *action;
+
+ action = TAILQ_FIRST(&p->actions);
+ if (!action)
+ break;
+
+ TAILQ_REMOVE(&p->actions, action, node);
+ free(action->instructions);
+ free(action);
+ }
+}
+