Skip to content

Commit

Permalink
actions: Factor out new helper function add_prerequisite().
Browse files Browse the repository at this point in the history
This will acquire new users in upcoming commits.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
  • Loading branch information
blp committed Dec 16, 2015
1 parent e769509 commit 5b84185
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ovn/lib/actions.c
Expand Up @@ -183,6 +183,19 @@ parse_next_action(struct action_context *ctx)
}
}

/* Parses 'prerequisite' as an expression in the context of 'ctx', then adds it
* as a conjunction with the existing 'ctx->prereqs'. */
static void
add_prerequisite(struct action_context *ctx, const char *prerequisite)
{
struct expr *expr;
char *error;

expr = expr_parse_string(prerequisite, ctx->symtab, &error);
ovs_assert(!error);
ctx->prereqs = expr_combine(EXPR_T_AND, ctx->prereqs, expr);
}

static void
emit_ct(struct action_context *ctx, bool recirc_next, bool commit)
{
Expand All @@ -209,12 +222,7 @@ emit_ct(struct action_context *ctx, bool recirc_next, bool commit)
ct->alg = 0;

/* CT only works with IP, so set up a prerequisite. */
struct expr *expr;
char *error;

expr = expr_parse_string("ip", ctx->symtab, &error);
ovs_assert(!error);
ctx->prereqs = expr_combine(EXPR_T_AND, ctx->prereqs, expr);
add_prerequisite(ctx, "ip");
}

static void
Expand Down Expand Up @@ -249,9 +257,7 @@ parse_actions(struct action_context *ctx)
emit_resubmit(ctx, ctx->output_ptable);
} else if (lexer_match_id(ctx->lexer, "ip.ttl")) {
if (lexer_match(ctx->lexer, LEX_T_DECREMENT)) {
struct expr *e = expr_parse_string("ip", ctx->symtab,
&ctx->error);
ctx->prereqs = expr_combine(EXPR_T_AND, ctx->prereqs, e);
add_prerequisite(ctx, "ip");
ofpact_put_DEC_TTL(ctx->ofpacts);
} else {
action_syntax_error(ctx, "expecting `--'");
Expand Down

0 comments on commit 5b84185

Please sign in to comment.