Skip to content

Commit

Permalink
netfilter: masquerade: attach nat extension if not present
Browse files Browse the repository at this point in the history
Currently the nat extension is always attached as soon as nat module is
loaded.  However, most NAT uses do not need the nat extension anymore.

Prepare to remove the add-nat-by-default by making those places that need
it attach it if its not present yet.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Florian Westphal authored and Pablo Neira Ayuso committed Apr 26, 2017
1 parent 22d4536 commit ff45901
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions net/ipv4/netfilter/nf_nat_masquerade_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,
NF_CT_ASSERT(hooknum == NF_INET_POST_ROUTING);

ct = nf_ct_get(skb, &ctinfo);
nat = nfct_nat(ct);

NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED ||
ctinfo == IP_CT_RELATED_REPLY));
Expand All @@ -56,7 +55,9 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,
return NF_DROP;
}

nat->masq_index = out->ifindex;
nat = nf_ct_nat_ext_add(ct);
if (nat)
nat->masq_index = out->ifindex;

/* Transfer from original range. */
memset(&newrange.min_addr, 0, sizeof(newrange.min_addr));
Expand Down
5 changes: 4 additions & 1 deletion net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range *range,
const struct net_device *out)
{
enum ip_conntrack_info ctinfo;
struct nf_conn_nat *nat;
struct in6_addr src;
struct nf_conn *ct;
struct nf_nat_range newrange;
Expand All @@ -42,7 +43,9 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range *range,
&ipv6_hdr(skb)->daddr, 0, &src) < 0)
return NF_DROP;

nfct_nat(ct)->masq_index = out->ifindex;
nat = nf_ct_nat_ext_add(ct);
if (nat)
nat->masq_index = out->ifindex;

newrange.flags = range->flags | NF_NAT_RANGE_MAP_IPS;
newrange.min_addr.in6 = src;
Expand Down

0 comments on commit ff45901

Please sign in to comment.