From f686a17eafa0bb5e9b0665c646fac09c9f95c0a5 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sat, 11 Mar 2017 14:31:39 +0100 Subject: fib: Support existence check This allows to check whether a FIB entry exists for a given packet by comparing the expression with a boolean keyword like so: | fib daddr oif exists The implementation requires introduction of a generic expression flag EXPR_F_BOOLEAN which allows relational expression to signal it's LHS that a boolean comparison is being done (indicated by boolean type on RHS). In contrast to exthdr existence checks, fib expression can't know this in beforehand because the LHS syntax is absolutely identical to a non-boolean comparison. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/fib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/fib.c') diff --git a/src/fib.c b/src/fib.c index c65677c8..28ef4b50 100644 --- a/src/fib.c +++ b/src/fib.c @@ -73,7 +73,7 @@ static void __fib_expr_print_f(unsigned int *flags, unsigned int f, const char * static void fib_expr_print(const struct expr *expr) { - unsigned int flags = expr->fib.flags; + unsigned int flags = expr->fib.flags & ~NFTA_FIB_F_PRESENT; printf("fib "); __fib_expr_print_f(&flags, NFTA_FIB_F_SADDR, "saddr"); @@ -130,6 +130,9 @@ struct expr *fib_expr_alloc(const struct location *loc, BUG("Unknown result %d\n", result); } + if (flags & NFTA_FIB_F_PRESENT) + type = &boolean_type; + expr = expr_alloc(loc, &fib_expr_ops, type, BYTEORDER_HOST_ENDIAN, len); -- cgit v1.2.3