Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net 1/2] openvswitch: support asymmetric conntrack
@ 2019-11-08 21:07 Aaron Conole
  2019-11-08 21:07 ` [PATCH net 2/2] act_ct: " Aaron Conole
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Aaron Conole @ 2019-11-08 21:07 UTC (permalink / raw)
  To: netdev
  Cc: Pravin B Shelar, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, dev, linux-kernel

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.")
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 net/openvswitch/conntrack.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 05249eb45082..283e8f9a5fd2 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -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);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-08 21:07 [PATCH net 1/2] openvswitch: support asymmetric conntrack Aaron Conole
@ 2019-11-08 21:07 ` " Aaron Conole
  2019-11-14 14:22   ` Roi Dayan
  2019-11-14 16:29   ` Marcelo Ricardo Leitner
  2019-11-09 22:15 ` [PATCH net 1/2] openvswitch: " Pravin Shelar
  2019-11-12  8:52 ` Nicolas Dichtel
  2 siblings, 2 replies; 12+ messages in thread
From: Aaron Conole @ 2019-11-08 21:07 UTC (permalink / raw)
  To: netdev
  Cc: Pravin B Shelar, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, dev, linux-kernel

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")

Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 net/sched/act_ct.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index fcc46025e790..f3232a00970f 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -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
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 1/2] openvswitch: support asymmetric conntrack
  2019-11-08 21:07 [PATCH net 1/2] openvswitch: support asymmetric conntrack Aaron Conole
  2019-11-08 21:07 ` [PATCH net 2/2] act_ct: " Aaron Conole
@ 2019-11-09 22:15 ` " Pravin Shelar
  2019-11-18 20:39   ` Aaron Conole
  2019-11-12  8:52 ` Nicolas Dichtel
  2 siblings, 1 reply; 12+ messages in thread
From: Pravin Shelar @ 2019-11-09 22:15 UTC (permalink / raw)
  To: Aaron Conole
  Cc: Linux Kernel Network Developers, David S . Miller,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, ovs dev, linux-kernel

On Fri, Nov 8, 2019 at 1:07 PM Aaron Conole <aconole@redhat.com> wrote:
>
> 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.")
> Signed-off-by: Aaron Conole <aconole@redhat.com>

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 1/2] openvswitch: support asymmetric conntrack
  2019-11-08 21:07 [PATCH net 1/2] openvswitch: support asymmetric conntrack Aaron Conole
  2019-11-08 21:07 ` [PATCH net 2/2] act_ct: " Aaron Conole
  2019-11-09 22:15 ` [PATCH net 1/2] openvswitch: " Pravin Shelar
@ 2019-11-12  8:52 ` Nicolas Dichtel
  2019-11-18 21:19   ` Aaron Conole
  2 siblings, 1 reply; 12+ messages in thread
From: Nicolas Dichtel @ 2019-11-12  8:52 UTC (permalink / raw)
  To: Aaron Conole, netdev
  Cc: Pravin B Shelar, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, dev, linux-kernel

Le 08/11/2019 à 22:07, Aaron Conole a écrit :
> 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.")
> Signed-off-by: Aaron Conole <aconole@redhat.com>
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-08 21:07 ` [PATCH net 2/2] act_ct: " Aaron Conole
@ 2019-11-14 14:22   ` Roi Dayan
  2019-11-14 14:24     ` Paul Blakey
  2019-11-14 16:29   ` Marcelo Ricardo Leitner
  1 sibling, 1 reply; 12+ messages in thread
From: Roi Dayan @ 2019-11-14 14:22 UTC (permalink / raw)
  To: Aaron Conole, netdev
  Cc: Pravin B Shelar, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, dev, linux-kernel, Paul Blakey



On 2019-11-08 11:07 PM, Aaron Conole wrote:
> 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")
> 
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---
>  net/sched/act_ct.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
> index fcc46025e790..f3232a00970f 100644
> --- a/net/sched/act_ct.c
> +++ b/net/sched/act_ct.c
> @@ -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
> 

+paul

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-14 14:22   ` Roi Dayan
@ 2019-11-14 14:24     ` Paul Blakey
  2019-11-18 21:24       ` Aaron Conole
  0 siblings, 1 reply; 12+ messages in thread
From: Paul Blakey @ 2019-11-14 14:24 UTC (permalink / raw)
  To: Roi Dayan, Aaron Conole, netdev
  Cc: Pravin B Shelar, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, dev, linux-kernel

On 11/14/2019 4:22 PM, Roi Dayan wrote:
>
> On 2019-11-08 11:07 PM, Aaron Conole wrote:
>> 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")
>>
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>> ---
>>   net/sched/act_ct.c | 13 ++++++++++++-
>>   1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
>> index fcc46025e790..f3232a00970f 100644
>> --- a/net/sched/act_ct.c
>> +++ b/net/sched/act_ct.c
>> @@ -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
>>
> +paul

Hi Aaron,

I think I understand the issue and this looks good,

Can you describe the scenario to reproduce this?


Thanks,

Paul.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-08 21:07 ` [PATCH net 2/2] act_ct: " Aaron Conole
  2019-11-14 14:22   ` Roi Dayan
@ 2019-11-14 16:29   ` Marcelo Ricardo Leitner
  2019-11-18 21:21     ` Aaron Conole
  1 sibling, 1 reply; 12+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-11-14 16:29 UTC (permalink / raw)
  To: Aaron Conole
  Cc: netdev, Pravin B Shelar, David S . Miller, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, dev, linux-kernel, paulb

On Fri, Nov 08, 2019 at 04:07:14PM -0500, Aaron Conole wrote:
> 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")
> 
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---
>  net/sched/act_ct.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
> index fcc46025e790..f3232a00970f 100644
> --- a/net/sched/act_ct.c
> +++ b/net/sched/act_ct.c
> @@ -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);
> +	}

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.

> +	return err;
>  #else
>  	return NF_ACCEPT;
>  #endif
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 1/2] openvswitch: support asymmetric conntrack
  2019-11-09 22:15 ` [PATCH net 1/2] openvswitch: " Pravin Shelar
@ 2019-11-18 20:39   ` Aaron Conole
  0 siblings, 0 replies; 12+ messages in thread
From: Aaron Conole @ 2019-11-18 20:39 UTC (permalink / raw)
  To: Pravin Shelar
  Cc: Linux Kernel Network Developers, David S . Miller,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, ovs dev, linux-kernel

Pravin Shelar <pshelar@ovn.org> writes:

> On Fri, Nov 8, 2019 at 1:07 PM Aaron Conole <aconole@redhat.com> wrote:
>>
>> 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.")
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>
> 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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 1/2] openvswitch: support asymmetric conntrack
  2019-11-12  8:52 ` Nicolas Dichtel
@ 2019-11-18 21:19   ` Aaron Conole
  0 siblings, 0 replies; 12+ messages in thread
From: Aaron Conole @ 2019-11-18 21:19 UTC (permalink / raw)
  To: Nicolas Dichtel
  Cc: netdev, Pravin B Shelar, David S . Miller, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, dev, linux-kernel

Nicolas Dichtel <nicolas.dichtel@6wind.com> writes:

> Le 08/11/2019 à 22:07, Aaron Conole a écrit :
>> 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.")
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
> 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.

> 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?

> Regards,
> Nicolas


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-14 16:29   ` Marcelo Ricardo Leitner
@ 2019-11-18 21:21     ` Aaron Conole
  2019-11-18 22:40       ` Marcelo Ricardo Leitner
  0 siblings, 1 reply; 12+ messages in thread
From: Aaron Conole @ 2019-11-18 21:21 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner
  Cc: netdev, Pravin B Shelar, David S . Miller, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, dev, linux-kernel, paulb

Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> writes:

> On Fri, Nov 08, 2019 at 04:07:14PM -0500, Aaron Conole wrote:
>> 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")
>> 
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>> ---
>>  net/sched/act_ct.c | 13 ++++++++++++-
>>  1 file changed, 12 insertions(+), 1 deletion(-)
>> 
>> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
>> index fcc46025e790..f3232a00970f 100644
>> --- a/net/sched/act_ct.c
>> +++ b/net/sched/act_ct.c
>> @@ -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);
>> +	}
>
> 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.

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.

>> +	return err;
>>  #else
>>  	return NF_ACCEPT;
>>  #endif
>> -- 
>> 2.21.0
>> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-14 14:24     ` Paul Blakey
@ 2019-11-18 21:24       ` Aaron Conole
  0 siblings, 0 replies; 12+ messages in thread
From: Aaron Conole @ 2019-11-18 21:24 UTC (permalink / raw)
  To: Paul Blakey
  Cc: Roi Dayan, netdev\,
	Pravin B Shelar, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, dev\, linux-kernel\

Paul Blakey <paulb@mellanox.com> writes:

> On 11/14/2019 4:22 PM, Roi Dayan wrote:
>>
>> On 2019-11-08 11:07 PM, Aaron Conole wrote:
>>> 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")
>>>
>>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>>> ---
>>>   net/sched/act_ct.c | 13 ++++++++++++-
>>>   1 file changed, 12 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
>>> index fcc46025e790..f3232a00970f 100644
>>> --- a/net/sched/act_ct.c
>>> +++ b/net/sched/act_ct.c
>>> @@ -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
>>>
>> +paul
>
> 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.

>
> Thanks,
>
> Paul.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net 2/2] act_ct: support asymmetric conntrack
  2019-11-18 21:21     ` Aaron Conole
@ 2019-11-18 22:40       ` Marcelo Ricardo Leitner
  0 siblings, 0 replies; 12+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-11-18 22:40 UTC (permalink / raw)
  To: Aaron Conole
  Cc: netdev, Pravin B Shelar, David S . Miller, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, dev, linux-kernel, paulb,
	Florian Westphal

On Mon, Nov 18, 2019 at 04:21:39PM -0500, Aaron Conole wrote:
> Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> writes:
> 
> > On Fri, Nov 08, 2019 at 04:07:14PM -0500, Aaron Conole wrote:
> >> 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")
> >> 
> >> Signed-off-by: Aaron Conole <aconole@redhat.com>
> >> ---
> >>  net/sched/act_ct.c | 13 ++++++++++++-
> >>  1 file changed, 12 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
> >> index fcc46025e790..f3232a00970f 100644
> >> --- a/net/sched/act_ct.c
> >> +++ b/net/sched/act_ct.c
> >> @@ -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);
> >> +	}
> >
> > 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.
> 
> 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;

> >> +	return err;
> >>  #else
> >>  	return NF_ACCEPT;
> >>  #endif
> >> -- 
> >> 2.21.0
> >> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, back to index

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 21:07 [PATCH net 1/2] openvswitch: support asymmetric conntrack Aaron Conole
2019-11-08 21:07 ` [PATCH net 2/2] act_ct: " Aaron Conole
2019-11-14 14:22   ` Roi Dayan
2019-11-14 14:24     ` Paul Blakey
2019-11-18 21:24       ` Aaron Conole
2019-11-14 16:29   ` Marcelo Ricardo Leitner
2019-11-18 21:21     ` Aaron Conole
2019-11-18 22:40       ` Marcelo Ricardo Leitner
2019-11-09 22:15 ` [PATCH net 1/2] openvswitch: " Pravin Shelar
2019-11-18 20:39   ` Aaron Conole
2019-11-12  8:52 ` Nicolas Dichtel
2019-11-18 21:19   ` Aaron Conole

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git