Skip to content

Commit ff45901

Browse files
Florian Westphalummakynes
authored andcommitted
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>
1 parent 22d4536 commit ff45901

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎net/ipv4/netfilter/nf_nat_masquerade_ipv4.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,
3737
NF_CT_ASSERT(hooknum == NF_INET_POST_ROUTING);
3838

3939
ct = nf_ct_get(skb, &ctinfo);
40-
nat = nfct_nat(ct);
4140

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

59-
nat->masq_index = out->ifindex;
58+
nat = nf_ct_nat_ext_add(ct);
59+
if (nat)
60+
nat->masq_index = out->ifindex;
6061

6162
/* Transfer from original range. */
6263
memset(&newrange.min_addr, 0, sizeof(newrange.min_addr));

‎net/ipv6/netfilter/nf_nat_masquerade_ipv6.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range *range,
3030
const struct net_device *out)
3131
{
3232
enum ip_conntrack_info ctinfo;
33+
struct nf_conn_nat *nat;
3334
struct in6_addr src;
3435
struct nf_conn *ct;
3536
struct nf_nat_range newrange;
@@ -42,7 +43,9 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range *range,
4243
&ipv6_hdr(skb)->daddr, 0, &src) < 0)
4344
return NF_DROP;
4445

45-
nfct_nat(ct)->masq_index = out->ifindex;
46+
nat = nf_ct_nat_ext_add(ct);
47+
if (nat)
48+
nat->masq_index = out->ifindex;
4649

4750
newrange.flags = range->flags | NF_NAT_RANGE_MAP_IPS;
4851
newrange.min_addr.in6 = src;

0 commit comments

Comments
 (0)