On Thu, Aug 11, 2016 at 09:23:14AM +0200, Laura Garcia Liebana wrote:
> diff --git a/net/netfilter/nft_hash.c b/net/netfilter/nft_hash.c
> new file mode 100644
> index 0000000..eb05527
> --- /dev/null
> +++ b/net/netfilter/nft_hash.c
> @@ -0,0 +1,136 @@
> +/*
> + * Copyright (c) 2016 Laura Garcia <nev...@gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/netlink.h>
> +#include <linux/netfilter.h>
> +#include <linux/netfilter/nf_tables.h>
> +#include <net/netfilter/nf_tables.h>
> +#include <net/netfilter/nf_tables_core.h>
> +#include <linux/jhash.h>
> +
> +struct nft_hash {
> +     enum nft_registers      sreg:8;
> +     enum nft_registers      dreg:8;
> +     u8                      len;
> +     u32                     modulus;
> +     u32                     seed;
> +};
> +
> +static void nft_hash_eval(const struct nft_expr *expr,
> +                       struct nft_regs *regs,
> +                       const struct nft_pktinfo *pkt)
> +{
> +     struct nft_hash *priv = nft_expr_priv(expr);
> +     const void *data = &regs->data[priv->sreg];
> +     u32 h;
> +
> +     h = reciprocal_scale(jhash(data, priv->len, priv->seed), priv->modulus);
> +
> +     regs->data[priv->dreg] = h;
> +}
> +
> +const struct nla_policy nft_hash_policy[NFTA_HASH_MAX + 1] = {
> +     [NFTA_HASH_SREG]                = { .type = NLA_U32 },
> +     [NFTA_HASH_DREG]                = { .type = NLA_U32 },
> +     [NFTA_HASH_LEN]                 = { .type = NLA_U32 },
> +     [NFTA_HASH_MODULUS]             = { .type = NLA_U32 },
> +     [NFTA_HASH_SEED]                = { .type = NLA_U32 },
> +};
> +
> +static int nft_hash_init(const struct nft_ctx *ctx,
> +                      const struct nft_expr *expr,
> +                      const struct nlattr * const tb[])
> +{
> +     struct nft_hash *priv = nft_expr_priv(expr);
> +     u32 len;
> +
> +     if (!tb[NFTA_HASH_SREG] ||
> +         !tb[NFTA_HASH_DREG] ||
> +         !tb[NFTA_HASH_LEN]  ||
> +         !tb[NFTA_HASH_SEED] ||
> +         !tb[NFTA_HASH_MODULUS])
> +             return -EINVAL;
> +
> +     priv->sreg = nft_parse_register(tb[NFTA_HASH_SREG]);
> +     priv->dreg = nft_parse_register(tb[NFTA_HASH_DREG]);
> +
> +     len = ntohl(nla_get_be32(tb[NFTA_HASH_LEN]));
> +     if (len == 0 || len > U8_MAX)
> +             return -ERANGE;
> +
> +     priv->len = len;
> +
> +     priv->modulus = ntohl(nla_get_be32(tb[NFTA_HASH_MODULUS]));
> +     if (priv->modulus <= 1)
> +             return -ERANGE;
> +
> +     priv->seed = ntohl(nla_get_be32(tb[NFTA_HASH_SEED]));
> +
> +     return nft_validate_register_load(priv->sreg, len) &&

>From sreg, we load, good.

> +            nft_validate_register_load(priv->dreg, sizeof(u32));

But to dreg we store. This should validate a store.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to