Commit d2caa696 authored by Patrick McHardy's avatar Patrick McHardy Committed by Pablo Neira Ayuso

netfilter: nft_meta: split nft_meta_init() into two functions for get/set

For value spanning multiple registers, we need to validate the length
of data loads. In order to add this to nft_meta, we need the length from
key validation. Split the nft_meta_init() function into two functions
for the get and set operations as preparation for that.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@gnumonks.org>
parent e88e514e
...@@ -170,21 +170,15 @@ static const struct nla_policy nft_meta_policy[NFTA_META_MAX + 1] = { ...@@ -170,21 +170,15 @@ static const struct nla_policy nft_meta_policy[NFTA_META_MAX + 1] = {
[NFTA_META_SREG] = { .type = NLA_U32 }, [NFTA_META_SREG] = { .type = NLA_U32 },
}; };
static int nft_meta_init_validate_set(uint32_t key) static int nft_meta_get_init(const struct nft_ctx *ctx,
const struct nft_expr *expr,
const struct nlattr * const tb[])
{ {
switch (key) { struct nft_meta *priv = nft_expr_priv(expr);
case NFT_META_MARK: int err;
case NFT_META_PRIORITY:
case NFT_META_NFTRACE:
return 0;
default:
return -EOPNOTSUPP;
}
}
static int nft_meta_init_validate_get(uint32_t key) priv->key = ntohl(nla_get_be32(tb[NFTA_META_KEY]));
{ switch (priv->key) {
switch (key) {
case NFT_META_LEN: case NFT_META_LEN:
case NFT_META_PROTOCOL: case NFT_META_PROTOCOL:
case NFT_META_NFPROTO: case NFT_META_NFPROTO:
...@@ -205,39 +199,40 @@ static int nft_meta_init_validate_get(uint32_t key) ...@@ -205,39 +199,40 @@ static int nft_meta_init_validate_get(uint32_t key)
#ifdef CONFIG_NETWORK_SECMARK #ifdef CONFIG_NETWORK_SECMARK
case NFT_META_SECMARK: case NFT_META_SECMARK:
#endif #endif
return 0; break;
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
priv->dreg = ntohl(nla_get_be32(tb[NFTA_META_DREG]));
err = nft_validate_output_register(priv->dreg);
if (err < 0)
return err;
err = nft_validate_data_load(ctx, priv->dreg, NULL, NFT_DATA_VALUE);
if (err < 0)
return err;
return 0;
} }
static int nft_meta_init(const struct nft_ctx *ctx, const struct nft_expr *expr, static int nft_meta_set_init(const struct nft_ctx *ctx,
const struct nlattr * const tb[]) const struct nft_expr *expr,
const struct nlattr * const tb[])
{ {
struct nft_meta *priv = nft_expr_priv(expr); struct nft_meta *priv = nft_expr_priv(expr);
int err; int err;
priv->key = ntohl(nla_get_be32(tb[NFTA_META_KEY])); priv->key = ntohl(nla_get_be32(tb[NFTA_META_KEY]));
switch (priv->key) {
if (tb[NFTA_META_DREG]) { case NFT_META_MARK:
err = nft_meta_init_validate_get(priv->key); case NFT_META_PRIORITY:
if (err < 0) case NFT_META_NFTRACE:
return err; break;
default:
priv->dreg = ntohl(nla_get_be32(tb[NFTA_META_DREG])); return -EOPNOTSUPP;
err = nft_validate_output_register(priv->dreg);
if (err < 0)
return err;
return nft_validate_data_load(ctx, priv->dreg, NULL,
NFT_DATA_VALUE);
} }
err = nft_meta_init_validate_set(priv->key);
if (err < 0)
return err;
priv->sreg = ntohl(nla_get_be32(tb[NFTA_META_SREG])); priv->sreg = ntohl(nla_get_be32(tb[NFTA_META_SREG]));
err = nft_validate_input_register(priv->sreg); err = nft_validate_input_register(priv->sreg);
if (err < 0) if (err < 0)
...@@ -282,7 +277,7 @@ static const struct nft_expr_ops nft_meta_get_ops = { ...@@ -282,7 +277,7 @@ static const struct nft_expr_ops nft_meta_get_ops = {
.type = &nft_meta_type, .type = &nft_meta_type,
.size = NFT_EXPR_SIZE(sizeof(struct nft_meta)), .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)),
.eval = nft_meta_get_eval, .eval = nft_meta_get_eval,
.init = nft_meta_init, .init = nft_meta_get_init,
.dump = nft_meta_get_dump, .dump = nft_meta_get_dump,
}; };
...@@ -290,7 +285,7 @@ static const struct nft_expr_ops nft_meta_set_ops = { ...@@ -290,7 +285,7 @@ static const struct nft_expr_ops nft_meta_set_ops = {
.type = &nft_meta_type, .type = &nft_meta_type,
.size = NFT_EXPR_SIZE(sizeof(struct nft_meta)), .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)),
.eval = nft_meta_set_eval, .eval = nft_meta_set_eval,
.init = nft_meta_init, .init = nft_meta_set_init,
.dump = nft_meta_set_dump, .dump = nft_meta_set_dump,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment