summaryrefslogtreecommitdiffstats
path: root/src/netlink_linearize.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2014-02-17 14:06:44 +0000
committerPatrick McHardy <kaber@trash.net>2014-02-17 17:17:18 +0000
commit0545e0c13b3b7dff4dd53c8a68d8d1066c2829c0 (patch)
treea2047b0a0d7dd68919a7f5c08e99150534457d41 /src/netlink_linearize.c
parent4a11511e936b5d38837137c9d04f047d4dab2c8f (diff)
netlink: fix prefix expression handling
The prefix expression handling is full of bugs: - netlink_gen_data() is used to construct the prefix mask from the full prefix expression. This is both conceptually wrong, the prefix expression is *not* data, and buggy, it only assumes network masks and thus only handles big endian types. - Prefix expression reconstruction doesn't check whether the mask is a valid prefix and reconstructs crap otherwise. It doesn't reconstruct prefixes for anything but network addresses. On top of that its needlessly complicated, using the mpz values directly its a simple matter of finding the sequence of 1's that extend up to the full width. - Unnecessary cloning of expressions where a simple refcount increase would suffice. Rewrite that code properly. Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/netlink_linearize.c')
-rw-r--r--src/netlink_linearize.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index e5fb536b..9d59374c 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -193,9 +193,14 @@ static void netlink_gen_cmp(struct netlink_linearize_ctx *ctx,
netlink_gen_expr(ctx, expr->left, sreg);
if (expr->right->ops->type == EXPR_PREFIX) {
- right = expr->right->prefix;
+ mpz_t mask;
+
+ mpz_init(mask);
+ mpz_prefixmask(mask, expr->right->len, expr->right->prefix_len);
+ netlink_gen_raw_data(mask, expr->right->byteorder,
+ expr->right->len / BITS_PER_BYTE, &nld);
+ mpz_clear(mask);
- netlink_gen_data(expr->right, &nld);
zero.len = nld.len;
nle = alloc_nft_expr("bitwise");
@@ -205,6 +210,8 @@ static void netlink_gen_cmp(struct netlink_linearize_ctx *ctx,
nft_rule_expr_set(nle, NFT_EXPR_BITWISE_MASK, &nld.value, nld.len);
nft_rule_expr_set(nle, NFT_EXPR_BITWISE_XOR, &zero.value, zero.len);
nft_rule_add_expr(ctx->nlr, nle);
+
+ right = expr->right->prefix;
} else {
right = expr->right;
}