[PATCH nft] expression: use common code for expr_ops/expr_ops_by_type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Useless duplication.  Also, this avoids bloating expr_ops_by_type()
when it needs to cope with more expressions.

Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 src/expression.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/expression.c b/src/expression.c
index cb11cda43792..c47b3673d19a 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -1185,9 +1185,9 @@ void range_expr_value_high(mpz_t rop, const struct expr *expr)
 	}
 }
 
-const struct expr_ops *expr_ops(const struct expr *e)
+static const struct expr_ops *__expr_ops_by_type(enum expr_types etype)
 {
-	switch (e->etype) {
+	switch (etype) {
 	case EXPR_INVALID:
 		BUG("Invalid expression ops requested");
 		break;
@@ -1220,26 +1220,18 @@ const struct expr_ops *expr_ops(const struct expr *e)
 	case EXPR_XFRM: return &xfrm_expr_ops;
 	}
 
-	BUG("Unknown expression type %d\n", e->etype);
+	BUG("Unknown expression type %d\n", etype);
 }
 
-const struct expr_ops *expr_ops_by_type(enum expr_types etype)
+const struct expr_ops *expr_ops(const struct expr *e)
 {
-	switch (etype) {
-	case EXPR_PAYLOAD: return &payload_expr_ops;
-	case EXPR_EXTHDR: return &exthdr_expr_ops;
-	case EXPR_META: return &meta_expr_ops;
-	case EXPR_SOCKET: return &socket_expr_ops;
-	case EXPR_OSF: return &osf_expr_ops;
-	case EXPR_CT: return &ct_expr_ops;
-	case EXPR_NUMGEN: return &numgen_expr_ops;
-	case EXPR_HASH: return &hash_expr_ops;
-	case EXPR_RT: return &rt_expr_ops;
-	case EXPR_FIB: return &fib_expr_ops;
-	case EXPR_XFRM: return &xfrm_expr_ops;
-	default:
-		break;
-	}
+	return __expr_ops_by_type(e->etype);
+}
 
-	BUG("Unknown expression type %d\n", etype);
+const struct expr_ops *expr_ops_by_type(uint32_t value)
+{
+	if (value > EXPR_XFRM)
+		return NULL;
+
+	return __expr_ops_by_type(value);
 }
-- 
2.24.1




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux