* [PATCH] net/sched: act_ct: add nat mangle action only for NAT-conntrack
@ 2020-05-29 4:07 wenxu
2020-05-29 17:56 ` Marcelo Ricardo Leitner
0 siblings, 1 reply; 4+ messages in thread
From: wenxu @ 2020-05-29 4:07 UTC (permalink / raw)
To: paulb; +Cc: netdev, davem
From: wenxu <wenxu@ucloud.cn>
Currently add nat mangle action with comparing invert and ori tuple.
It is better to check IPS_NAT_MASK flags first to avoid non necessary
memcmp for non-NAT conntrack.
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
net/sched/act_ct.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index c50a86a..d621152 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -198,18 +198,21 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
struct flow_action *action)
{
const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
+ bool nat = ct->status & IPS_NAT_MASK;
struct nf_conntrack_tuple target;
nf_ct_invert_tuple(&target, &ct->tuplehash[!dir].tuple);
switch (tuple->src.l3num) {
case NFPROTO_IPV4:
- tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
- action);
+ if (nat)
+ tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
+ action);
break;
case NFPROTO_IPV6:
- tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
- action);
+ if (nat)
+ tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
+ action);
break;
default:
return -EOPNOTSUPP;
@@ -217,10 +220,14 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
switch (nf_ct_protonum(ct)) {
case IPPROTO_TCP:
- tcf_ct_flow_table_add_action_nat_tcp(tuple, target, action);
+ if (nat)
+ tcf_ct_flow_table_add_action_nat_tcp(tuple, target,
+ action);
break;
case IPPROTO_UDP:
- tcf_ct_flow_table_add_action_nat_udp(tuple, target, action);
+ if (nat)
+ tcf_ct_flow_table_add_action_nat_udp(tuple, target,
+ action);
break;
default:
return -EOPNOTSUPP;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net/sched: act_ct: add nat mangle action only for NAT-conntrack
2020-05-29 4:07 [PATCH] net/sched: act_ct: add nat mangle action only for NAT-conntrack wenxu
@ 2020-05-29 17:56 ` Marcelo Ricardo Leitner
2020-05-30 0:04 ` wenxu
0 siblings, 1 reply; 4+ messages in thread
From: Marcelo Ricardo Leitner @ 2020-05-29 17:56 UTC (permalink / raw)
To: wenxu; +Cc: paulb, netdev, davem
On Fri, May 29, 2020 at 12:07:45PM +0800, wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> Currently add nat mangle action with comparing invert and ori tuple.
> It is better to check IPS_NAT_MASK flags first to avoid non necessary
> memcmp for non-NAT conntrack.
>
> Signed-off-by: wenxu <wenxu@ucloud.cn>
> ---
> net/sched/act_ct.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
> index c50a86a..d621152 100644
> --- a/net/sched/act_ct.c
> +++ b/net/sched/act_ct.c
> @@ -198,18 +198,21 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
> struct flow_action *action)
> {
> const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
> + bool nat = ct->status & IPS_NAT_MASK;
> struct nf_conntrack_tuple target;
[A]
>
> nf_ct_invert_tuple(&target, &ct->tuplehash[!dir].tuple);
>
> switch (tuple->src.l3num) {
> case NFPROTO_IPV4:
> - tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
> - action);
> + if (nat)
Why do the same check multiple times, on all actions? As no other
action is performed if not doing a nat, seems at [A] above, it could
just:
if (!nat)
return 0;
> + tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
> + action);
> break;
> case NFPROTO_IPV6:
> - tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
> - action);
> + if (nat)
> + tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
> + action);
> break;
> default:
> return -EOPNOTSUPP;
> @@ -217,10 +220,14 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
>
> switch (nf_ct_protonum(ct)) {
> case IPPROTO_TCP:
> - tcf_ct_flow_table_add_action_nat_tcp(tuple, target, action);
> + if (nat)
> + tcf_ct_flow_table_add_action_nat_tcp(tuple, target,
> + action);
> break;
> case IPPROTO_UDP:
> - tcf_ct_flow_table_add_action_nat_udp(tuple, target, action);
> + if (nat)
> + tcf_ct_flow_table_add_action_nat_udp(tuple, target,
> + action);
> break;
> default:
> return -EOPNOTSUPP;
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net/sched: act_ct: add nat mangle action only for NAT-conntrack
2020-05-29 17:56 ` Marcelo Ricardo Leitner
@ 2020-05-30 0:04 ` wenxu
2020-05-30 5:58 ` wenxu
0 siblings, 1 reply; 4+ messages in thread
From: wenxu @ 2020-05-30 0:04 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: paulb, netdev, davem
在 2020/5/30 1:56, Marcelo Ricardo Leitner 写道:
> On Fri, May 29, 2020 at 12:07:45PM +0800, wenxu@ucloud.cn wrote:
>> From: wenxu <wenxu@ucloud.cn>
>>
>> Currently add nat mangle action with comparing invert and ori tuple.
>> It is better to check IPS_NAT_MASK flags first to avoid non necessary
>> memcmp for non-NAT conntrack.
>>
>> Signed-off-by: wenxu <wenxu@ucloud.cn>
>> ---
>> net/sched/act_ct.c | 19 +++++++++++++------
>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>
>> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
>> index c50a86a..d621152 100644
>> --- a/net/sched/act_ct.c
>> +++ b/net/sched/act_ct.c
>> @@ -198,18 +198,21 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
>> struct flow_action *action)
>> {
>> const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
>> + bool nat = ct->status & IPS_NAT_MASK;
>> struct nf_conntrack_tuple target;
> [A]
>
>>
>> nf_ct_invert_tuple(&target, &ct->tuplehash[!dir].tuple);
>>
>> switch (tuple->src.l3num) {
>> case NFPROTO_IPV4:
>> - tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
>> - action);
>> + if (nat)
> Why do the same check multiple times, on all actions? As no other
> action is performed if not doing a nat, seems at [A] above, it could
> just:
>
> if (!nat)
> return 0;
This function is not always return 0. It is the same for non-nat conntrack.
If the ether proto is not ipv4 or ipv6 and the ip_proto is not tcp and udp,
this function should return -EOPNOTSUPP. Check the nat for each type
is just to following the rule.
>
>> + tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
>> + action);
>> break;
>> case NFPROTO_IPV6:
>> - tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
>> - action);
>> + if (nat)
>> + tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
>> + action);
>> break;
>> default:
>> return -EOPNOTSUPP;
>> @@ -217,10 +220,14 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
>>
>> switch (nf_ct_protonum(ct)) {
>> case IPPROTO_TCP:
>> - tcf_ct_flow_table_add_action_nat_tcp(tuple, target, action);
>> + if (nat)
>> + tcf_ct_flow_table_add_action_nat_tcp(tuple, target,
>> + action);
>> break;
>> case IPPROTO_UDP:
>> - tcf_ct_flow_table_add_action_nat_udp(tuple, target, action);
>> + if (nat)
>> + tcf_ct_flow_table_add_action_nat_udp(tuple, target,
>> + action);
>> break;
>> default:
>> return -EOPNOTSUPP;
>> --
>> 1.8.3.1
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net/sched: act_ct: add nat mangle action only for NAT-conntrack
2020-05-30 0:04 ` wenxu
@ 2020-05-30 5:58 ` wenxu
0 siblings, 0 replies; 4+ messages in thread
From: wenxu @ 2020-05-30 5:58 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: paulb, netdev, davem
在 2020/5/30 8:04, wenxu 写道:
> 在 2020/5/30 1:56, Marcelo Ricardo Leitner 写道:
>> On Fri, May 29, 2020 at 12:07:45PM +0800, wenxu@ucloud.cn wrote:
>>> From: wenxu <wenxu@ucloud.cn>
>>>
>>> Currently add nat mangle action with comparing invert and ori tuple.
>>> It is better to check IPS_NAT_MASK flags first to avoid non necessary
>>> memcmp for non-NAT conntrack.
>>>
>>> Signed-off-by: wenxu <wenxu@ucloud.cn>
>>> ---
>>> net/sched/act_ct.c | 19 +++++++++++++------
>>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
>>> index c50a86a..d621152 100644
>>> --- a/net/sched/act_ct.c
>>> +++ b/net/sched/act_ct.c
>>> @@ -198,18 +198,21 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
>>> struct flow_action *action)
>>> {
>>> const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
>>> + bool nat = ct->status & IPS_NAT_MASK;
>>> struct nf_conntrack_tuple target;
>> [A]
>>
>>>
>>> nf_ct_invert_tuple(&target, &ct->tuplehash[!dir].tuple);
>>>
>>> switch (tuple->src.l3num) {
>>> case NFPROTO_IPV4:
>>> - tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
>>> - action);
>>> + if (nat)
>> Why do the same check multiple times, on all actions? As no other
>> action is performed if not doing a nat, seems at [A] above, it could
>> just:
>>
>> if (!nat)
>> return 0;
> This function is not always return 0. It is the same for non-nat conntrack.
>
> If the ether proto is not ipv4 or ipv6 and the ip_proto is not tcp and udp,
>
> this function should return -EOPNOTSUPP. Check the nat for each type
>
> is just to following the rule.
Marcelo,
Maybe your are right. This function can any care about the nat conntrack entry and
can totally ignore all the non-nat ones
>
>>> + tcf_ct_flow_table_add_action_nat_ipv4(tuple, target,
>>> + action);
>>> break;
>>> case NFPROTO_IPV6:
>>> - tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
>>> - action);
>>> + if (nat)
>>> + tcf_ct_flow_table_add_action_nat_ipv6(tuple, target,
>>> + action);
>>> break;
>>> default:
>>> return -EOPNOTSUPP;
>>> @@ -217,10 +220,14 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
>>>
>>> switch (nf_ct_protonum(ct)) {
>>> case IPPROTO_TCP:
>>> - tcf_ct_flow_table_add_action_nat_tcp(tuple, target, action);
>>> + if (nat)
>>> + tcf_ct_flow_table_add_action_nat_tcp(tuple, target,
>>> + action);
>>> break;
>>> case IPPROTO_UDP:
>>> - tcf_ct_flow_table_add_action_nat_udp(tuple, target, action);
>>> + if (nat)
>>> + tcf_ct_flow_table_add_action_nat_udp(tuple, target,
>>> + action);
>>> break;
>>> default:
>>> return -EOPNOTSUPP;
>>> --
>>> 1.8.3.1
>>>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-05-30 5:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 4:07 [PATCH] net/sched: act_ct: add nat mangle action only for NAT-conntrack wenxu
2020-05-29 17:56 ` Marcelo Ricardo Leitner
2020-05-30 0:04 ` wenxu
2020-05-30 5:58 ` wenxu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.