Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: masquerade: attach nat extension if not present

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>

authored by

Florian Westphal and committed by
Pablo Neira Ayuso
ff459018 22d4536d

+7 -3
+3 -2
net/ipv4/netfilter/nf_nat_masquerade_ipv4.c
··· 37 37 NF_CT_ASSERT(hooknum == NF_INET_POST_ROUTING); 38 38 39 39 ct = nf_ct_get(skb, &ctinfo); 40 - nat = nfct_nat(ct); 41 40 42 41 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED || 43 42 ctinfo == IP_CT_RELATED_REPLY)); ··· 55 56 return NF_DROP; 56 57 } 57 58 58 - nat->masq_index = out->ifindex; 59 + nat = nf_ct_nat_ext_add(ct); 60 + if (nat) 61 + nat->masq_index = out->ifindex; 59 62 60 63 /* Transfer from original range. */ 61 64 memset(&newrange.min_addr, 0, sizeof(newrange.min_addr));
+4 -1
net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
··· 30 30 const struct net_device *out) 31 31 { 32 32 enum ip_conntrack_info ctinfo; 33 + struct nf_conn_nat *nat; 33 34 struct in6_addr src; 34 35 struct nf_conn *ct; 35 36 struct nf_nat_range newrange; ··· 43 42 &ipv6_hdr(skb)->daddr, 0, &src) < 0) 44 43 return NF_DROP; 45 44 46 - nfct_nat(ct)->masq_index = out->ifindex; 45 + nat = nf_ct_nat_ext_add(ct); 46 + if (nat) 47 + nat->masq_index = out->ifindex; 47 48 48 49 newrange.flags = range->flags | NF_NAT_RANGE_MAP_IPS; 49 50 newrange.min_addr.in6 = src;