12 #include <expression.h> 18 static void hash_expr_print(
const struct expr *expr,
struct output_ctx *octx)
20 switch (expr->hash.type) {
22 octx->print(octx->ctx,
"symhash");
24 case NFT_HASH_JENKINS:
26 octx->print(octx->ctx,
"jhash ");
27 expr_print(expr->hash.expr, octx);
30 octx->print(octx->ctx,
" mod %u", expr->hash.mod);
31 if (expr->hash.seed_set)
32 octx->print(octx->ctx,
" seed 0x%x", expr->hash.seed);
33 if (expr->hash.offset)
34 octx->print(octx->ctx,
" offset %u", expr->hash.offset);
37 static bool hash_expr_cmp(
const struct expr *e1,
const struct expr *e2)
39 return (e1->hash.expr ||
40 expr_cmp(e1->hash.expr, e2->hash.expr)) &&
41 e1->hash.mod == e2->hash.mod &&
42 e1->hash.seed_set == e2->hash.seed_set &&
43 e1->hash.seed == e2->hash.seed &&
44 e1->hash.offset == e2->hash.offset &&
45 e1->hash.type == e2->hash.type;
48 static void hash_expr_clone(
struct expr *
new,
const struct expr *expr)
51 new->hash.expr = expr_clone(expr->hash.expr);
52 new->hash.mod = expr->hash.mod;
53 new->hash.seed_set = expr->hash.seed_set;
54 new->hash.seed = expr->hash.seed;
55 new->hash.offset = expr->hash.offset;
56 new->hash.type = expr->hash.type;
59 static const struct expr_ops hash_expr_ops = {
62 .print = hash_expr_print,
64 .clone = hash_expr_clone,
67 struct expr *hash_expr_alloc(
const struct location *loc,
69 bool seed_set, uint32_t seed,
71 enum nft_hash_types type)
75 expr = expr_alloc(loc, &hash_expr_ops, &integer_type,
76 BYTEORDER_HOST_ENDIAN, 4 * BITS_PER_BYTE);
78 expr->hash.seed_set = seed_set;
79 expr->hash.seed = seed;
80 expr->hash.offset = offset;
81 expr->hash.type = type;