Skip to contentSkip to conversation

openvswitch: support asymmetric conntrack

PATCH In review Aaron Conole 6 participants 17 messages Nov 8, 2019 – Nov 28, 2019

Subsystems (4)
lore
Share & tools
lore

Aaron Conole

author maintainer
#0 lore raw

PATCH 1/2 openvswitch: support asymmetric conntrack

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes 05752523e565 ("openvswitch: Interface with NAT.")
---
 net/openvswitch/conntrack.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/openvswitch/conntrack.c +11 -0
index 05249eb45082..283e8f9a5fd2 100644
@@ -903,6 +903,17 @@ static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
 	}
 	err = ovs_ct_nat_execute(skb, ct, ctinfo, &info->range, maniptype);
 
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ovs_ct_nat_execute(skb, ct, ctinfo, &info->range,
+					 maniptype);
+	}
+
 	/* Mark NAT done if successful and update the flow key. */
 	if (err == NF_ACCEPT)
 		ovs_nat_update_key(key, skb, maniptype);
Signature · 1 line
2.21.0
author maintainer
#1 lore raw

PATCH 2/2 act_ct: support asymmetric conntrack

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +12 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}
+	return err;
 #else
 	return NF_ACCEPT;
 #endif
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 38 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +5 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 376

Quoted 10 lines
net/sched/act_ct.c +7 -0
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}
+	return err;
 #else
 	return NF_ACCEPT;
 #endif

+paul

#3 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 43 lines · Roi Dayan
Quoted 41 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
  net/sched/act_ct.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +9 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
  			  bool commit)
  {
  #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
  	enum nf_nat_manip_type maniptype;
 
  	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
  		return NF_ACCEPT;
  	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
Quoted 8 lines

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 376

Quoted 7 lines
net/sched/act_ct.c +3 -0
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}
+	return err;
  #else
  	return NF_ACCEPT;
  #endif

+paul

Hi Aaron,

I think I understand the issue and this looks good,

Can you describe the scenario to reproduce this?

Thanks,

Paul.

author maintainer
#4 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 53 lines · Paul Blakey
Quoted 43 lines · Roi Dayan
Quoted 41 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
  net/sched/act_ct.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +9 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
  			  bool commit)
  {
  #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
  	enum nf_nat_manip_type maniptype;
 
  	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
  		return NF_ACCEPT;
  	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
Quoted 8 lines

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 376

Quoted 7 lines
net/sched/act_ct.c +3 -0
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}
+	return err;
  #else
  	return NF_ACCEPT;
  #endif

+paul

Quoted 5 lines

Hi Aaron,

I think I understand the issue and this looks good,

Can you describe the scenario to reproduce this?

It reproduces with OpenShift 3.10, which makes forward direction packets between namespaces pump through a tun device that applies NAT rules to rewrite the dest. Limit the namespace number of ephemeral sockets using by editing net.ipv4.ip_local_port_range in the client namespace, and connect to the server namespace. That's the mechanism for OvS. But for TC I guess there wouldn't be anything convenient avaiable.

I'll try to script up something that doesn't use openshift.

Quoted 4 lines

Thanks,

Paul.

#5 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

In reply to Aaron Conole
Quoted 33 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 372

Quoted 10 lines
net/sched/act_ct.c +10 -0
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}

I keep thinking about this and I'm not entirely convinced that this shouldn't be simpler. More like:

if (DNAT)
DNAT
if (SNAT)
SNAT

So it always does DNAT before SNAT, similarly to what iptables would do on PRE/POSTROUTING chains.

Quoted 7 lines
net/sched/act_ct.c +1 -0
+	return err;
 #else
 	return NF_ACCEPT;
 #endif
Signature · 1 line
2.21.0
author maintainer
#6 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 48 lines · Marcelo Ricardo Leitner
Quoted 33 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 372

Quoted 10 lines
net/sched/act_ct.c +10 -0
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}

I keep thinking about this and I'm not entirely convinced that this shouldn't be simpler. More like:

Quoted 7 lines

if (DNAT)
DNAT
if (SNAT)
SNAT

So it always does DNAT before SNAT, similarly to what iptables would do on PRE/POSTROUTING chains.

I can rewrite the whole function, but I wanted to start with the smaller fix that worked. I also think it needs more testing then (since it's something of a rewrite of the function).

I guess it's not too important - do you think it gives any readability to do it this way? If so, I can respin the patch changing it like you describe.

Quoted 7 lines
Quoted 7 lines
net/sched/act_ct.c +1 -0
+	return err;
 #else
 	return NF_ACCEPT;
 #endif
Signature · 1 line
2.21.0
#7 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 58 lines · Aaron Conole
Quoted 48 lines · Marcelo Ricardo Leitner
Quoted 33 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 372

Quoted 10 lines
net/sched/act_ct.c +10 -0
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}

I keep thinking about this and I'm not entirely convinced that this shouldn't be simpler. More like:

Quoted 7 lines

if (DNAT)
DNAT
if (SNAT)
SNAT

So it always does DNAT before SNAT, similarly to what iptables would do on PRE/POSTROUTING chains.

Quoted 7 lines

I can rewrite the whole function, but I wanted to start with the smaller fix that worked. I also think it needs more testing then (since it's something of a rewrite of the function).

I guess it's not too important - do you think it gives any readability to do it this way? If so, I can respin the patch changing it like you describe.

I didn't mean a rewrite, but just to never handle SNAT before DNAT. So the fix here would be like:

- return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+ err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+ if (err == NF_ACCEPT && maniptype == NF_NAT_MANIP_DST &&
+ ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+ maniptype = NF_NAT_MANIP_SRC;
+ err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+ }
+ return err;

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
net/sched/act_ct.c +1 -0
+	return err;
 #else
 	return NF_ACCEPT;
 #endif
Signature · 1 line
2.21.0
author maintainer
#8 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 70 lines · Marcelo Ricardo Leitner
Quoted 58 lines · Aaron Conole
Quoted 48 lines · Marcelo Ricardo Leitner
Quoted 33 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 372

Quoted 10 lines
net/sched/act_ct.c +10 -0
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}

I keep thinking about this and I'm not entirely convinced that this shouldn't be simpler. More like:

Quoted 7 lines

if (DNAT)
DNAT
if (SNAT)
SNAT

So it always does DNAT before SNAT, similarly to what iptables would do on PRE/POSTROUTING chains.

Quoted 7 lines

I can rewrite the whole function, but I wanted to start with the smaller fix that worked. I also think it needs more testing then (since it's something of a rewrite of the function).

I guess it's not too important - do you think it gives any readability to do it this way? If so, I can respin the patch changing it like you describe.

I didn't mean a rewrite, but just to never handle SNAT before DNAT. So the fix here would be like:

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 373

Quoted 8 lines
net/sched/act_ct.c +7 -1
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT && maniptype == NF_NAT_MANIP_DST &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		maniptype = NF_NAT_MANIP_SRC;
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}
+	return err;

But the maniptype of the first call could be NAT_MANIP_SRC. In fact, that's what I see if the packet is reply direction && !related.

So, we need the block to invert the manipulation type. Otherwise, we miss the DNAT manipulation.

So I don't think I can use that block.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
net/sched/act_ct.c +1 -0
+	return err;
 #else
 	return NF_ACCEPT;
 #endif
Signature · 1 line
2.21.0
#9 lore raw

Re: [PATCH net 2/2] act_ct: support asymmetric conntrack

Quoted 72 lines · Aaron Conole
Quoted 70 lines · Marcelo Ricardo Leitner
Quoted 58 lines · Aaron Conole
Quoted 48 lines · Marcelo Ricardo Leitner
Quoted 33 lines · Aaron Conole

The act_ct TC module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The act_ct action doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes b57dc7c13ea9 ("net/sched: Introduce action ct")
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index fcc46025e790..f3232a00970f 100644
@@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 			  bool commit)
 {
 #if IS_ENABLED(CONFIG_NF_NAT)
+	int err;
 	enum nf_nat_manip_type maniptype;
 
 	if (!(ct_action & TCA_CT_ACT_NAT))
@@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 372

Quoted 10 lines
net/sched/act_ct.c +10 -0
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		if (maniptype == NF_NAT_MANIP_SRC)
+			maniptype = NF_NAT_MANIP_DST;
+		else
+			maniptype = NF_NAT_MANIP_SRC;
+
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}

I keep thinking about this and I'm not entirely convinced that this shouldn't be simpler. More like:

Quoted 7 lines

if (DNAT)
DNAT
if (SNAT)
SNAT

So it always does DNAT before SNAT, similarly to what iptables would do on PRE/POSTROUTING chains.

Quoted 7 lines

I can rewrite the whole function, but I wanted to start with the smaller fix that worked. I also think it needs more testing then (since it's something of a rewrite of the function).

I guess it's not too important - do you think it gives any readability to do it this way? If so, I can respin the patch changing it like you describe.

I didn't mean a rewrite, but just to never handle SNAT before DNAT. So the fix here would be like:

Quoted 11 lines

net/sched/act_ct.c static int tcf_ct_act_nat(struct sk_buff *skb, · line 373

Quoted 8 lines
net/sched/act_ct.c +7 -1
-	return ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	if (err == NF_ACCEPT && maniptype == NF_NAT_MANIP_DST &&
+	    ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) {
+		maniptype = NF_NAT_MANIP_SRC;
+		err = ct_nat_execute(skb, ct, ctinfo, range, maniptype);
+	}
+	return err;

But the maniptype of the first call could be NAT_MANIP_SRC. In fact, that's what I see if the packet is reply direction && !related.

Interesting, ok.

Quoted 5 lines

So, we need the block to invert the manipulation type. Otherwise, we miss the DNAT manipulation.

So I don't think I can use that block.

Thanks for digging on it.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
net/sched/act_ct.c +1 -0
+	return err;
 #else
 	return NF_ACCEPT;
 #endif
Signature · 1 line
2.21.0
#10 lore raw
In reply to Aaron Conole
Quoted 7 lines · Aaron Conole

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Quoted 5 lines

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes 05752523e565 ("openvswitch: Interface with NAT.")

The patch looks ok. But I am not able apply it. can you fix the encoding.

author maintainer
#11 lore raw
Quoted 8 lines · Pravin Shelar
Quoted 7 lines · Aaron Conole

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Quoted 7 lines
Quoted 5 lines

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes 05752523e565 ("openvswitch: Interface with NAT.")

The patch looks ok. But I am not able apply it. can you fix the encoding.

Hrrm. I didn't make any special changes (just used git send-email). I will look at spinning a second patch.

author maintainer
#12 lore raw
Quoted 13 lines · Aaron Conole
Quoted 11 lines · Pravin Shelar
Quoted 10 lines · Aaron Conole

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fixes 05752523e565 ("openvswitch: Interface with NAT.")

The patch looks ok. But I am not able apply it. can you fix the encoding.

Hrrm. I didn't make any special changes (just used git send-email). I will look at spinning a second patch.

Pravin,

I tried the following:

10:36:59 aconole@dhcp-25 {(312434617cb1...)} ~/git/linux$ curl http://patchwork.ozlabs.org/patch/1192219/mbox/ > test.patch

    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed

100 4827 100 4827 0 0 8824 0 --:--:-- --:--:-- --:--:-- 8808
10:37:21 aconole@dhcp-25 {(312434617cb1...)} ~/git/linux$ git am test.patch
Applying: openvswitch: support asymmetric conntrack
10:37:24 aconole@dhcp-25 {(f759cc2b7323...)} ~/git/linux$

Can you check your mailer settings? The patchwork mbox worked fine, and I was able to apply from my own mbox as well.

-Aaron

#13 lore raw

Downloading from patchwork is working for me. Its strange other patches in my mailbox does not has this issue.

Thanks.

Quoted 42 lines · Aaron Conole
Quoted 13 lines · Aaron Conole
Quoted 11 lines · Pravin Shelar
Quoted 10 lines · Aaron Conole

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fixes 05752523e565 ("openvswitch: Interface with NAT.")

The patch looks ok. But I am not able apply it. can you fix the encoding.

Hrrm. I didn't make any special changes (just used git send-email). I will look at spinning a second patch.

Pravin,

I tried the following:

10:36:59 aconole@dhcp-25 {(312434617cb1...)} ~/git/linux$ curl http://patchwork.ozlabs.org/patch/1192219/mbox/ > test.patch

    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed

100 4827 100 4827 0 0 8824 0 --:--:-- --:--:-- --:--:-- 8808
10:37:21 aconole@dhcp-25 {(312434617cb1...)} ~/git/linux$ git am test.patch
Applying: openvswitch: support asymmetric conntrack
10:37:24 aconole@dhcp-25 {(f759cc2b7323...)} ~/git/linux$

Can you check your mailer settings? The patchwork mbox worked fine, and I was able to apply from my own mbox as well.

-Aaron

#14 lore raw
In reply to Aaron Conole

Le 08/11/2019 à 22:07, Aaron Conole a écrit :

Quoted 11 lines

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes 05752523e565 ("openvswitch: Interface with NAT.")

In this case, ovs_ct_find_existing() won't be able to find the conntrack, right? Inverting the tuple to find the conntrack doesn't work anymore with double NAT. Am I wrong?

Regards,
Nicolas

author maintainer
#15 lore raw
Quoted 7 lines · Nicolas Dichtel

Le 08/11/2019 à 22:07, Aaron Conole a écrit :

Quoted 6 lines

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Quoted 7 lines
Quoted 5 lines

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes 05752523e565 ("openvswitch: Interface with NAT.")

In this case, ovs_ct_find_existing() won't be able to find the conntrack, right?

vswitchd normally won't allow both actions to get programmed. Even the kernel module won't allow it, so this really will only happen when the connection gets established via the nf_hook path, and then needs to be processed via openvswitch. In those cases, the tuple lookup should be correct, because the nf_nat table should contain the correct tuple data, and the skbuff should have the correct tuples in the packet data to begin with.

Quoted 2 lines

Inverting the tuple to find the conntrack doesn't work anymore with double NAT. Am I wrong?

I think since the packet was double-NAT on the way out (via nf_hook path), then the incoming reply will have the correct NAT tuples and the lookup will happen just fine. Just that during processing, both transformations aren't applied.

Makes sense?

Quoted 2 lines

Regards,
Nicolas

#16 lore raw

Le 18/11/2019 à 22:19, Aaron Conole a écrit :

Quoted 25 lines
Quoted 7 lines · Nicolas Dichtel

Le 08/11/2019 à 22:07, Aaron Conole a écrit :

Quoted 6 lines

The openvswitch module shares a common conntrack and NAT infrastructure exposed via netfilter. It's possible that a packet needs both SNAT and DNAT manipulation, due to e.g. tuple collision. Netfilter can support this because it runs through the NAT table twice - once on ingress and again after egress. The openvswitch module doesn't have such capability.

Quoted 7 lines
Quoted 5 lines

Like netfilter hook infrastructure, we should run through NAT twice to keep the symmetry.

Fixes 05752523e565 ("openvswitch: Interface with NAT.")

In this case, ovs_ct_find_existing() won't be able to find the conntrack, right?

vswitchd normally won't allow both actions to get programmed. Even the kernel module won't allow it, so this really will only happen when the connection gets established via the nf_hook path, and then needs to be processed via openvswitch. In those cases, the tuple lookup should be correct, because the nf_nat table should contain the correct tuple data, and the skbuff should have the correct tuples in the packet data to begin with.

Quoted 7 lines
Quoted 2 lines

Inverting the tuple to find the conntrack doesn't work anymore with double NAT. Am I wrong?

I think since the packet was double-NAT on the way out (via nf_hook path), then the incoming reply will have the correct NAT tuples and the lookup will happen just fine. Just that during processing, both transformations aren't applied.

Ok, I didn't look deeply, thank you for the explanation.

Regards,
Nicolas