diff mbox series

[net-next,v2] netfilter: use NF_DROP instead of -NF_DROP

Message ID 20240325123614.10425-1-kerneljasonxing@gmail.com
State New
Headers show
Series [net-next,v2] netfilter: use NF_DROP instead of -NF_DROP | expand

Commit Message

Jason Xing March 25, 2024, 12:36 p.m. UTC
From: Jason Xing <kernelxing@tencent.com>

At the beginning in 2009 one patch [1] introduced collecting drop
counter in nf_conntrack_in() by returning -NF_DROP. Later, another
patch [2] changed the return value of tcp_packet() which now is
renamed to nf_conntrack_tcp_packet() from -NF_DROP to NF_DROP. As
we can see, that -NF_DROP should be corrected.

Similarly, there are other two points where the -NF_DROP is used.

Well, as NF_DROP is equal to 0, inverting NF_DROP makes no sense
as patch [2] said many years ago.

[1]
commit 7d1e04598e5e ("netfilter: nf_conntrack: account packets drop by tcp_packet()")
[2]
commit ec8d540969da ("netfilter: conntrack: fix dropping packet after l4proto->packet()")

Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
v2
Link: https://lore.kernel.org/all/20240325031945.15760-1-kerneljasonxing@gmail.com/
1. squash three patches into one
---
 net/ipv4/netfilter/iptable_filter.c  | 2 +-
 net/ipv6/netfilter/ip6table_filter.c | 2 +-
 net/netfilter/nf_conntrack_core.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

Jason Xing March 29, 2024, 12:33 p.m. UTC | #1
On Mon, Mar 25, 2024 at 8:36 PM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> From: Jason Xing <kernelxing@tencent.com>
>
> At the beginning in 2009 one patch [1] introduced collecting drop
> counter in nf_conntrack_in() by returning -NF_DROP. Later, another
> patch [2] changed the return value of tcp_packet() which now is
> renamed to nf_conntrack_tcp_packet() from -NF_DROP to NF_DROP. As
> we can see, that -NF_DROP should be corrected.
>
> Similarly, there are other two points where the -NF_DROP is used.
>
> Well, as NF_DROP is equal to 0, inverting NF_DROP makes no sense
> as patch [2] said many years ago.
>
> [1]
> commit 7d1e04598e5e ("netfilter: nf_conntrack: account packets drop by tcp_packet()")
> [2]
> commit ec8d540969da ("netfilter: conntrack: fix dropping packet after l4proto->packet()")
>
> Signed-off-by: Jason Xing <kernelxing@tencent.com>

Hello Pablo,

I don't know how it works in the nf area, so I would like to know the
status of this patch and another one (netfilter: conntrack: dccp: try
not to drop skb in conntrack
)? Is there anything I need to change?

Thanks,
Jason




> ---
> v2
> Link: https://lore.kernel.org/all/20240325031945.15760-1-kerneljasonxing@gmail.com/
> 1. squash three patches into one
> ---
>  net/ipv4/netfilter/iptable_filter.c  | 2 +-
>  net/ipv6/netfilter/ip6table_filter.c | 2 +-
>  net/netfilter/nf_conntrack_core.c    | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
> index b9062f4552ac..3ab908b74795 100644
> --- a/net/ipv4/netfilter/iptable_filter.c
> +++ b/net/ipv4/netfilter/iptable_filter.c
> @@ -44,7 +44,7 @@ static int iptable_filter_table_init(struct net *net)
>                 return -ENOMEM;
>         /* Entry 1 is the FORWARD hook */
>         ((struct ipt_standard *)repl->entries)[1].target.verdict =
> -               forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
> +               forward ? -NF_ACCEPT - 1 : NF_DROP - 1;
>
>         err = ipt_register_table(net, &packet_filter, repl, filter_ops);
>         kfree(repl);
> diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
> index df785ebda0ca..e8992693e14a 100644
> --- a/net/ipv6/netfilter/ip6table_filter.c
> +++ b/net/ipv6/netfilter/ip6table_filter.c
> @@ -43,7 +43,7 @@ static int ip6table_filter_table_init(struct net *net)
>                 return -ENOMEM;
>         /* Entry 1 is the FORWARD hook */
>         ((struct ip6t_standard *)repl->entries)[1].target.verdict =
> -               forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
> +               forward ? -NF_ACCEPT - 1 : NF_DROP - 1;
>
>         err = ip6t_register_table(net, &packet_filter, repl, filter_ops);
>         kfree(repl);
> diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
> index c63868666bd9..6102dc09cdd3 100644
> --- a/net/netfilter/nf_conntrack_core.c
> +++ b/net/netfilter/nf_conntrack_core.c
> @@ -2024,7 +2024,7 @@ nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)
>                         goto repeat;
>
>                 NF_CT_STAT_INC_ATOMIC(state->net, invalid);
> -               if (ret == -NF_DROP)
> +               if (ret == NF_DROP)
>                         NF_CT_STAT_INC_ATOMIC(state->net, drop);
>
>                 ret = -ret;
> --
> 2.37.3
>
Pablo Neira Ayuso March 29, 2024, 9:42 p.m. UTC | #2
Hi Jason,

On Fri, Mar 29, 2024 at 08:33:32PM +0800, Jason Xing wrote:
> On Mon, Mar 25, 2024 at 8:36 PM Jason Xing <kerneljasonxing@gmail.com> wrote:
> >
> > From: Jason Xing <kernelxing@tencent.com>
> >
> > At the beginning in 2009 one patch [1] introduced collecting drop
> > counter in nf_conntrack_in() by returning -NF_DROP. Later, another
> > patch [2] changed the return value of tcp_packet() which now is
> > renamed to nf_conntrack_tcp_packet() from -NF_DROP to NF_DROP. As
> > we can see, that -NF_DROP should be corrected.
> >
> > Similarly, there are other two points where the -NF_DROP is used.
> >
> > Well, as NF_DROP is equal to 0, inverting NF_DROP makes no sense
> > as patch [2] said many years ago.
> >
> > [1]
> > commit 7d1e04598e5e ("netfilter: nf_conntrack: account packets drop by tcp_packet()")
> > [2]
> > commit ec8d540969da ("netfilter: conntrack: fix dropping packet after l4proto->packet()")
> >
> > Signed-off-by: Jason Xing <kernelxing@tencent.com>
> 
> Hello Pablo,
> 
> I don't know how it works in the nf area, so I would like to know the
> status of this patch and another one (netfilter: conntrack: dccp: try
> not to drop skb in conntrack
> )? Is there anything I need to change?

No action on your side, I will start collecting pending material for
nf-next next week.

Thanks for your patience.
diff mbox series

Patch

diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index b9062f4552ac..3ab908b74795 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -44,7 +44,7 @@  static int iptable_filter_table_init(struct net *net)
 		return -ENOMEM;
 	/* Entry 1 is the FORWARD hook */
 	((struct ipt_standard *)repl->entries)[1].target.verdict =
-		forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
+		forward ? -NF_ACCEPT - 1 : NF_DROP - 1;
 
 	err = ipt_register_table(net, &packet_filter, repl, filter_ops);
 	kfree(repl);
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
index df785ebda0ca..e8992693e14a 100644
--- a/net/ipv6/netfilter/ip6table_filter.c
+++ b/net/ipv6/netfilter/ip6table_filter.c
@@ -43,7 +43,7 @@  static int ip6table_filter_table_init(struct net *net)
 		return -ENOMEM;
 	/* Entry 1 is the FORWARD hook */
 	((struct ip6t_standard *)repl->entries)[1].target.verdict =
-		forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
+		forward ? -NF_ACCEPT - 1 : NF_DROP - 1;
 
 	err = ip6t_register_table(net, &packet_filter, repl, filter_ops);
 	kfree(repl);
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index c63868666bd9..6102dc09cdd3 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2024,7 +2024,7 @@  nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)
 			goto repeat;
 
 		NF_CT_STAT_INC_ATOMIC(state->net, invalid);
-		if (ret == -NF_DROP)
+		if (ret == NF_DROP)
 			NF_CT_STAT_INC_ATOMIC(state->net, drop);
 
 		ret = -ret;