Blame view
net/netfilter/nft_masq.c
2.69 KB
9ba1f726b netfilter: nf_tab... |
1 |
/* |
cd7275146 netfilter: update... |
2 |
* Copyright (c) 2014 Arturo Borrero Gonzalez <arturo@debian.org> |
9ba1f726b netfilter: nf_tab... |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
* * 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_nat.h> #include <net/netfilter/nft_masq.h> const struct nla_policy nft_masq_policy[NFTA_MASQ_MAX + 1] = { |
8a6bf5da1 netfilter: nft_ma... |
20 21 22 |
[NFTA_MASQ_FLAGS] = { .type = NLA_U32 }, [NFTA_MASQ_REG_PROTO_MIN] = { .type = NLA_U32 }, [NFTA_MASQ_REG_PROTO_MAX] = { .type = NLA_U32 }, |
9ba1f726b netfilter: nf_tab... |
23 24 |
}; EXPORT_SYMBOL_GPL(nft_masq_policy); |
75e8d06d4 netfilter: nf_tab... |
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
int nft_masq_validate(const struct nft_ctx *ctx, const struct nft_expr *expr, const struct nft_data **data) { int err; err = nft_chain_validate_dependency(ctx->chain, NFT_CHAIN_T_NAT); if (err < 0) return err; return nft_chain_validate_hooks(ctx->chain, (1 << NF_INET_POST_ROUTING)); } EXPORT_SYMBOL_GPL(nft_masq_validate); |
9ba1f726b netfilter: nf_tab... |
39 40 41 42 |
int nft_masq_init(const struct nft_ctx *ctx, const struct nft_expr *expr, const struct nlattr * const tb[]) { |
8a6bf5da1 netfilter: nft_ma... |
43 |
u32 plen = FIELD_SIZEOF(struct nf_nat_range, min_addr.all); |
9ba1f726b netfilter: nf_tab... |
44 |
struct nft_masq *priv = nft_expr_priv(expr); |
7210e4e38 netfilter: nf_tab... |
45 |
int err; |
8a6bf5da1 netfilter: nft_ma... |
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
if (tb[NFTA_MASQ_FLAGS]) { priv->flags = ntohl(nla_get_be32(tb[NFTA_MASQ_FLAGS])); if (priv->flags & ~NF_NAT_RANGE_MASK) return -EINVAL; } if (tb[NFTA_MASQ_REG_PROTO_MIN]) { priv->sreg_proto_min = nft_parse_register(tb[NFTA_MASQ_REG_PROTO_MIN]); err = nft_validate_register_load(priv->sreg_proto_min, plen); if (err < 0) return err; if (tb[NFTA_MASQ_REG_PROTO_MAX]) { priv->sreg_proto_max = nft_parse_register(tb[NFTA_MASQ_REG_PROTO_MAX]); err = nft_validate_register_load(priv->sreg_proto_max, plen); if (err < 0) return err; } else { priv->sreg_proto_max = priv->sreg_proto_min; } } |
9ba1f726b netfilter: nf_tab... |
72 |
|
20afd4239 netfilter: nf_tab... |
73 |
return nf_ct_netns_get(ctx->net, ctx->afi->family); |
9ba1f726b netfilter: nf_tab... |
74 75 76 77 78 79 |
} EXPORT_SYMBOL_GPL(nft_masq_init); int nft_masq_dump(struct sk_buff *skb, const struct nft_expr *expr) { const struct nft_masq *priv = nft_expr_priv(expr); |
8a6bf5da1 netfilter: nft_ma... |
80 81 |
if (priv->flags != 0 && nla_put_be32(skb, NFTA_MASQ_FLAGS, htonl(priv->flags))) |
9ba1f726b netfilter: nf_tab... |
82 |
goto nla_put_failure; |
8a6bf5da1 netfilter: nft_ma... |
83 84 85 86 87 88 89 |
if (priv->sreg_proto_min) { if (nft_dump_register(skb, NFTA_MASQ_REG_PROTO_MIN, priv->sreg_proto_min) || nft_dump_register(skb, NFTA_MASQ_REG_PROTO_MAX, priv->sreg_proto_max)) goto nla_put_failure; } |
9ba1f726b netfilter: nf_tab... |
90 91 92 93 94 95 96 97 |
return 0; nla_put_failure: return -1; } EXPORT_SYMBOL_GPL(nft_masq_dump); MODULE_LICENSE("GPL"); |
cd7275146 netfilter: update... |
98 |
MODULE_AUTHOR("Arturo Borrero Gonzalez <arturo@debian.org>"); |