[PATCH nft 1/5] src: expr: add and use expr_name helper

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

 



Currently callers use expr->ops->name, but follouwp patch will remove the
ops pointer from struct expr.  So add this helper and use it everywhere.

Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 include/expression.h      |  2 ++
 src/evaluate.c            | 22 +++++++++++-----------
 src/expression.c          |  9 +++++++--
 src/json.c                |  3 +--
 src/mergesort.c           |  2 +-
 src/netlink.c             |  2 +-
 src/netlink_delinearize.c |  8 ++++----
 src/netlink_linearize.c   |  2 +-
 src/segtree.c             |  2 +-
 9 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/include/expression.h b/include/expression.h
index f018c958d2dc..8a4cf5b10b8c 100644
--- a/include/expression.h
+++ b/include/expression.h
@@ -406,6 +406,8 @@ extern struct expr *symbol_expr_alloc(const struct location *loc,
 				      enum symbol_types type, struct scope *scope,
 				      const char *identifier);
 
+const char *expr_name(const struct expr *e);
+
 static inline void symbol_expr_set_type(struct expr *expr,
 					const struct datatype *dtype)
 {
diff --git a/src/evaluate.c b/src/evaluate.c
index 0bda431d5a16..be788daab06d 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -449,7 +449,7 @@ static void expr_evaluate_bits(struct eval_ctx *ctx, struct expr **exprp)
 					  &extra_len);
 		break;
 	default:
-		BUG("Unknown expression %s\n", expr->ops->name);
+		BUG("Unknown expression %s\n", expr_name(expr));
 	}
 
 	masklen = len + shift;
@@ -1097,7 +1097,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
 		return expr_binary_error(ctx->msgs, left, op,
 					 "Binary operation (%s) is undefined "
 					 "for %s expressions",
-					 sym, left->ops->name);
+					 sym, expr_name(left));
 
 	if (!expr_is_constant(right))
 		return expr_binary_error(ctx->msgs, right, op,
@@ -1108,7 +1108,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
 		return expr_binary_error(ctx->msgs, left, op,
 					 "Binary operation (%s) is undefined "
 					 "for %s expressions",
-					 sym, right->ops->name);
+					 sym, expr_name(right));
 
 	/* The grammar guarantees this */
 	assert(expr_basetype(left) == expr_basetype(right));
@@ -1349,7 +1349,7 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
 		break;
 	default:
 		BUG("invalid mapping expression %s\n",
-		    map->mappings->ops->name);
+		    expr_name(map->mappings));
 	}
 
 	if (!datatype_equal(map->map->dtype, map->mappings->set->key->dtype))
@@ -1698,7 +1698,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 				return -1;
 			break;
 		default:
-			BUG("invalid expression type %s\n", right->ops->name);
+			BUG("invalid expression type %s\n", expr_name(right));
 		}
 		break;
 	case OP_LT:
@@ -1711,7 +1711,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 					"Relational expression (%s) is undefined "
 				        "for %s expressions",
 					expr_op_symbols[rel->op],
-					left->ops->name);
+					expr_name(left));
 		default:
 			break;
 		}
@@ -1721,7 +1721,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 					"Relational expression (%s) is undefined "
 				        "for %s expressions",
 					expr_op_symbols[rel->op],
-					right->ops->name);
+					expr_name(right));
 
 		if (byteorder_conversion(ctx, &rel->left, BYTEORDER_BIG_ENDIAN) < 0)
 			return -1;
@@ -1817,7 +1817,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
 	if (ctx->nft->debug_mask & NFT_DEBUG_EVALUATION) {
 		struct error_record *erec;
 		erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location,
-				   "Evaluate %s", (*expr)->ops->name);
+				   "Evaluate %s", expr_name(*expr));
 		erec_print(&ctx->nft->output, erec, ctx->nft->debug_mask);
 		expr_print(*expr, &ctx->nft->output);
 		nft_print(&ctx->nft->output, "\n\n");
@@ -1880,7 +1880,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
 	case EXPR_XFRM:
 		return expr_evaluate_xfrm(ctx, expr);
 	default:
-		BUG("unknown expression type %s\n", (*expr)->ops->name);
+		BUG("unknown expression type %s\n", expr_name(*expr));
 	}
 }
 
@@ -1946,7 +1946,7 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
 	case EXPR_MAP:
 		break;
 	default:
-		BUG("invalid verdict expression %s\n", stmt->expr->ops->name);
+		BUG("invalid verdict expression %s\n", expr_name(stmt->expr));
 	}
 	return 0;
 }
@@ -2896,7 +2896,7 @@ static int stmt_evaluate_objref_map(struct eval_ctx *ctx, struct stmt *stmt)
 		break;
 	default:
 		BUG("invalid mapping expression %s\n",
-		    map->mappings->ops->name);
+		    expr_name(map->mappings));
 	}
 
 	if (!datatype_equal(map->map->dtype, map->mappings->set->key->dtype))
diff --git a/src/expression.c b/src/expression.c
index 62a6f890f814..37b106f82b39 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -87,6 +87,11 @@ bool expr_cmp(const struct expr *e1, const struct expr *e2)
 	return e1->ops->cmp(e1, e2);
 }
 
+const char *expr_name(const struct expr *e)
+{
+	return e->ops->name;
+}
+
 void expr_describe(const struct expr *expr, struct output_ctx *octx)
 {
 	const struct datatype *dtype = expr->dtype;
@@ -1106,7 +1111,7 @@ void range_expr_value_low(mpz_t rop, const struct expr *expr)
 	case EXPR_SET_ELEM:
 		return range_expr_value_low(rop, expr->key);
 	default:
-		BUG("invalid range expression type %s\n", expr->ops->name);
+		BUG("invalid range expression type %s\n", expr_name(expr));
 	}
 }
 
@@ -1130,6 +1135,6 @@ void range_expr_value_high(mpz_t rop, const struct expr *expr)
 	case EXPR_SET_ELEM:
 		return range_expr_value_high(rop, expr->key);
 	default:
-		BUG("invalid range expression type %s\n", expr->ops->name);
+		BUG("invalid range expression type %s\n", expr_name(expr));
 	}
 }
diff --git a/src/json.c b/src/json.c
index fc92d4641fcf..2a70e42f7802 100644
--- a/src/json.c
+++ b/src/json.c
@@ -39,8 +39,7 @@ static json_t *expr_print_json(const struct expr *expr, struct output_ctx *octx)
 	if (expr->ops->json)
 		return expr->ops->json(expr, octx);
 
-	printf("warning: expr ops %s have no json callback\n",
-	       expr->ops->name);
+	printf("warning: expr ops %s have no json callback\n", expr_name(expr));
 
 	fp = octx->output_fp;
 	octx->output_fp = fmemopen(buf, 1024, "w");
diff --git a/src/mergesort.c b/src/mergesort.c
index a8353203757d..f2e38bc2e485 100644
--- a/src/mergesort.c
+++ b/src/mergesort.c
@@ -44,7 +44,7 @@ static int expr_msort_cmp(const struct expr *e1, const struct expr *e2)
 	case EXPR_MAPPING:
 		return expr_msort_cmp(e1->left, e2->left);
 	default:
-		BUG("Unknown expression %s\n", e1->ops->name);
+		BUG("Unknown expression %s\n", expr_name(e1));
 	}
 }
 
diff --git a/src/netlink.c b/src/netlink.c
index f67f63907075..dfd563a2e94d 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -239,7 +239,7 @@ void netlink_gen_data(const struct expr *expr, struct nft_data_linearize *data)
 	case EXPR_VERDICT:
 		return netlink_gen_verdict(expr, data);
 	default:
-		BUG("invalid data expression type %s\n", expr->ops->name);
+		BUG("invalid data expression type %s\n", expr_name(expr));
 	}
 }
 
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index db1bf03e5c6a..d492910c2f93 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -1778,7 +1778,7 @@ static void binop_adjust_one(const struct expr *binop, struct expr *value,
 		value->len = left->len;
 		break;
 	default:
-		BUG("unknown expression type %s\n", left->ops->name);
+		BUG("unknown expression type %s\n", expr_name(left));
 		break;
 	}
 }
@@ -1806,7 +1806,7 @@ static void __binop_adjust(const struct expr *binop, struct expr *right,
 				__binop_adjust(binop, i->key->key, shift);
 				break;
 			default:
-				BUG("unknown expression type %s\n", i->key->ops->name);
+				BUG("unknown expression type %s\n", expr_name(i->key));
 			}
 		}
 		break;
@@ -1815,7 +1815,7 @@ static void __binop_adjust(const struct expr *binop, struct expr *right,
 		binop_adjust_one(binop, right->right, shift);
 		break;
 	default:
-		BUG("unknown expression type %s\n", right->ops->name);
+		BUG("unknown expression type %s\n", expr_name(right));
 		break;
 	}
 }
@@ -2142,7 +2142,7 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
 		ct_expr_update_type(&ctx->pctx, expr);
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr->ops->name);
+		BUG("unknown expression type %s\n", expr_name(expr));
 	}
 }
 
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 0c8f5fe42814..9b5fa195fdc0 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -739,7 +739,7 @@ static void netlink_gen_expr(struct netlink_linearize_ctx *ctx,
 	case EXPR_XFRM:
 		return netlink_gen_xfrm(ctx, expr, dreg);
 	default:
-		BUG("unknown expression type %s\n", expr->ops->name);
+		BUG("unknown expression type %s\n", expr_name(expr));
 	}
 }
 
diff --git a/src/segtree.c b/src/segtree.c
index 5685618b3724..5f25c97d8578 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -787,7 +787,7 @@ static struct expr *expr_value(struct expr *expr)
 	case EXPR_SET_ELEM:
 		return expr->key;
 	default:
-		BUG("invalid expression type %s\n", expr->ops->name);
+		BUG("invalid expression type %s\n", expr_name(expr));
 	}
 }
 
-- 
2.19.2




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux