|
@@ -88,17 +88,40 @@ static const struct nla_policy nft_nat_policy[NFTA_NAT_MAX + 1] = {
|
|
|
[NFTA_NAT_FLAGS] = { .type = NLA_U32 },
|
|
|
};
|
|
|
|
|
|
-static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
|
|
|
- const struct nlattr * const tb[])
|
|
|
+static int nft_nat_validate(const struct nft_ctx *ctx,
|
|
|
+ const struct nft_expr *expr,
|
|
|
+ const struct nft_data **data)
|
|
|
{
|
|
|
struct nft_nat *priv = nft_expr_priv(expr);
|
|
|
- u32 family;
|
|
|
int err;
|
|
|
|
|
|
err = nft_chain_validate_dependency(ctx->chain, NFT_CHAIN_T_NAT);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
|
+ switch (priv->type) {
|
|
|
+ case NFT_NAT_SNAT:
|
|
|
+ err = nft_chain_validate_hooks(ctx->chain,
|
|
|
+ (1 << NF_INET_POST_ROUTING) |
|
|
|
+ (1 << NF_INET_LOCAL_IN));
|
|
|
+ break;
|
|
|
+ case NFT_NAT_DNAT:
|
|
|
+ err = nft_chain_validate_hooks(ctx->chain,
|
|
|
+ (1 << NF_INET_PRE_ROUTING) |
|
|
|
+ (1 << NF_INET_LOCAL_OUT));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
|
|
|
+ const struct nlattr * const tb[])
|
|
|
+{
|
|
|
+ struct nft_nat *priv = nft_expr_priv(expr);
|
|
|
+ u32 family;
|
|
|
+ int err;
|
|
|
+
|
|
|
if (tb[NFTA_NAT_TYPE] == NULL ||
|
|
|
(tb[NFTA_NAT_REG_ADDR_MIN] == NULL &&
|
|
|
tb[NFTA_NAT_REG_PROTO_MIN] == NULL))
|
|
@@ -115,6 +138,10 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
+ err = nft_nat_validate(ctx, expr, NULL);
|
|
|
+ if (err < 0)
|
|
|
+ return err;
|
|
|
+
|
|
|
if (tb[NFTA_NAT_FAMILY] == NULL)
|
|
|
return -EINVAL;
|
|
|
|
|
@@ -219,13 +246,6 @@ nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-static int nft_nat_validate(const struct nft_ctx *ctx,
|
|
|
- const struct nft_expr *expr,
|
|
|
- const struct nft_data **data)
|
|
|
-{
|
|
|
- return nft_chain_validate_dependency(ctx->chain, NFT_CHAIN_T_NAT);
|
|
|
-}
|
|
|
-
|
|
|
static struct nft_expr_type nft_nat_type;
|
|
|
static const struct nft_expr_ops nft_nat_ops = {
|
|
|
.type = &nft_nat_type,
|