summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2019-02-08 17:02:21 +0100
committerFlorian Westphal <fw@strlen.de>2019-02-08 21:22:47 +0100
commit2cc91e6198e7ee8b9d0f8727c67a849fec393cd0 (patch)
tree73735f871ae57a6d95d34898c27491bc84a30e4a /src
parentcc6fef3521c2fdfba4b1daf7be09349e7d807ae1 (diff)
src: expr: add and use internal expr_ops helper
This helper will eventually lookup the correct expr_ops struct, so we can get rid of the expr->ops pointer. Signed-off-by: Florian Westphal <fw@strlen.de> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/expression.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/expression.c b/src/expression.c
index 37b106f8..309a0f13 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -25,6 +25,11 @@
#include <erec.h>
#include <json.h>
+static const struct expr_ops *expr_ops(const struct expr *e)
+{
+ return e->ops;
+}
+
struct expr *expr_alloc(const struct location *loc, const struct expr_ops *ops,
const struct datatype *dtype, enum byteorder byteorder,
unsigned int len)
@@ -60,20 +65,31 @@ struct expr *expr_get(struct expr *expr)
return expr;
}
+static void expr_destroy(struct expr *e)
+{
+ const struct expr_ops *ops = expr_ops(e);
+
+ if (ops && ops->destroy)
+ ops->destroy(e);
+}
+
void expr_free(struct expr *expr)
{
if (expr == NULL)
return;
if (--expr->refcnt > 0)
return;
- if (expr->ops && expr->ops->destroy)
- expr->ops->destroy(expr);
+
+ expr_destroy(expr);
xfree(expr);
}
void expr_print(const struct expr *expr, struct output_ctx *octx)
{
- expr->ops->print(expr, octx);
+ const struct expr_ops *ops = expr_ops(expr);
+
+ if (ops->print)
+ ops->print(expr, octx);
}
bool expr_cmp(const struct expr *e1, const struct expr *e2)
@@ -84,7 +100,7 @@ bool expr_cmp(const struct expr *e1, const struct expr *e2)
if (e1->ops->type != e2->ops->type)
return false;
- return e1->ops->cmp(e1, e2);
+ return expr_ops(e1)->cmp(e1, e2);
}
const char *expr_name(const struct expr *e)
@@ -98,7 +114,7 @@ void expr_describe(const struct expr *expr, struct output_ctx *octx)
const char *delim = "";
nft_print(octx, "%s expression, datatype %s (%s)",
- expr->ops->name, dtype->name, dtype->desc);
+ expr_name(expr), dtype->name, dtype->desc);
if (dtype->basetype != NULL) {
nft_print(octx, " (basetype ");
for (dtype = dtype->basetype; dtype != NULL;
@@ -134,8 +150,10 @@ void expr_describe(const struct expr *expr, struct output_ctx *octx)
void expr_set_type(struct expr *expr, const struct datatype *dtype,
enum byteorder byteorder)
{
- if (expr->ops->set_type)
- expr->ops->set_type(expr, dtype, byteorder);
+ const struct expr_ops *ops = expr_ops(expr);
+
+ if (ops->set_type)
+ ops->set_type(expr, dtype, byteorder);
else {
expr->dtype = dtype;
expr->byteorder = byteorder;
@@ -654,13 +672,15 @@ void relational_expr_pctx_update(struct proto_ctx *ctx,
const struct expr *expr)
{
const struct expr *left = expr->left;
+ const struct expr_ops *ops;
assert(expr->ops->type == EXPR_RELATIONAL);
assert(expr->op == OP_EQ || expr->op == OP_IMPLICIT);
- if (left->ops->pctx_update &&
+ ops = expr_ops(left);
+ if (ops->pctx_update &&
(left->flags & EXPR_F_PROTOCOL))
- left->ops->pctx_update(ctx, expr);
+ ops->pctx_update(ctx, expr);
}
static void range_expr_print(const struct expr *expr, struct output_ctx *octx)