All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: fix duplicate logs of iptables TRACE target
@ 2022-01-24  5:34 kai zhang
  2022-01-24  7:21 ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: kai zhang @ 2022-01-24  5:34 UTC (permalink / raw)
  To: pablo, kadlec, fw, davem, yoshfuji, dsahern, kuba,
	netfilter-devel, coreteam, netdev, linux-kernel
  Cc: kai zhang

Below configuration, mangle,filter and security tables have no rule:

There are 5 logs for incoming ssh packet:

kernel: [ 7018.727278] TRACE: raw:PREROUTING:policy:2 IN=enp9s0 ...
kernel: [ 7018.727304] TRACE: mangle:PREROUTING:policy:1 IN=enp9s0 ...
kernel: [ 7018.727327] TRACE: mangle:INPUT:policy:1 IN=enp9s0 ...
kernel: [ 7018.727343] TRACE: filter:INPUT:policy:1 IN=enp9s0 ...
kernel: [ 7018.727359] TRACE: security:INPUT:policy:1 IN=enp9s0 ...

Signed-off-by: kai zhang <zhangkaiheb@126.com>
---
 net/ipv4/netfilter/ip_tables.c  | 4 +++-
 net/ipv6/netfilter/ip6_tables.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 2ed7c58b4..5f0e6096e 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -304,9 +304,11 @@ ipt_do_table(void *priv,
 
 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
 		/* The packet is traced: log it */
-		if (unlikely(skb->nf_trace))
+		if (unlikely(skb->nf_trace)) {
 			trace_packet(state->net, skb, hook, state->in,
 				     state->out, table->name, private, e);
+			nf_reset_trace(skb);
+		}
 #endif
 		/* Standard target? */
 		if (!t->u.kernel.target->target) {
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 2d816277f..ae842a835 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -327,9 +327,11 @@ ip6t_do_table(void *priv, struct sk_buff *skb,
 
 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
 		/* The packet is traced: log it */
-		if (unlikely(skb->nf_trace))
+		if (unlikely(skb->nf_trace)) {
 			trace_packet(state->net, skb, hook, state->in,
 				     state->out, table->name, private, e);
+			nf_reset_trace(skb);
+		}
 #endif
 		/* Standard target? */
 		if (!t->u.kernel.target->target) {
-- 
2.30.2


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

* Re: [PATCH] net: fix duplicate logs of iptables TRACE target
  2022-01-24  5:34 [PATCH] net: fix duplicate logs of iptables TRACE target kai zhang
@ 2022-01-24  7:21 ` Florian Westphal
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2022-01-24  7:21 UTC (permalink / raw)
  To: kai zhang
  Cc: pablo, kadlec, fw, davem, yoshfuji, dsahern, kuba,
	netfilter-devel, coreteam, netdev, linux-kernel

kai zhang <zhangkaiheb@126.com> wrote:
> Below configuration, mangle,filter and security tables have no rule:
> 
> There are 5 logs for incoming ssh packet:
> 
> kernel: [ 7018.727278] TRACE: raw:PREROUTING:policy:2 IN=enp9s0 ...
> kernel: [ 7018.727304] TRACE: mangle:PREROUTING:policy:1 IN=enp9s0 ...
> kernel: [ 7018.727327] TRACE: mangle:INPUT:policy:1 IN=enp9s0 ...
> kernel: [ 7018.727343] TRACE: filter:INPUT:policy:1 IN=enp9s0 ...
> kernel: [ 7018.727359] TRACE: security:INPUT:policy:1 IN=enp9s0 ...

Thats correct and exactly whats supposed to happen.

>  #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
>  		/* The packet is traced: log it */
> -		if (unlikely(skb->nf_trace))
> +		if (unlikely(skb->nf_trace)) {
>  			trace_packet(state->net, skb, hook, state->in,
>  				     state->out, table->name, private, e);
> +			nf_reset_trace(skb);
> +		}

This breaks the long established behavior of TRACE,
we don't want users to have to TRACE tables individually which may also
be hard when nat is involved.

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

* Re: [PATCH] net: fix duplicate logs of iptables TRACE target
  2022-01-24  5:37 kai zhang
@ 2022-01-24 11:54 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2022-01-24 11:54 UTC (permalink / raw)
  To: kai zhang
  Cc: kadlec, fw, davem, yoshfuji, dsahern, kuba, netfilter-devel,
	coreteam, netdev, linux-kernel

On Mon, Jan 24, 2022 at 05:37:32AM +0000, kai zhang wrote:
> Below configuration, mangle,filter and security tables have no rule:

Yes, but there are loaded in your iptables-legacy environment.
In iptables-nft this will not happen.

> # iptables -t raw -I PREROUTING 1 -p tcp --dport 22 -j TRACE
> # sysctl net.netfilter.nf_log.2=nf_log_ipv4
> 
> There are 5 logs for incoming ssh packet:
> 
> kernel: [ 7018.727278] TRACE: raw:PREROUTING:policy:2 IN=enp9s0 ...
> kernel: [ 7018.727304] TRACE: mangle:PREROUTING:policy:1 IN=enp9s0 ...
> kernel: [ 7018.727327] TRACE: mangle:INPUT:policy:1 IN=enp9s0 ...
> kernel: [ 7018.727343] TRACE: filter:INPUT:policy:1 IN=enp9s0 ...
> kernel: [ 7018.727359] TRACE: security:INPUT:policy:1 IN=enp9s0 ...

tracing was not designed to display every registered table/chain even
if it has not rules.

> Signed-off-by: kai zhang <zhangkaiheb@126.com>
> ---
>  net/ipv4/netfilter/ip_tables.c  | 4 +++-
>  net/ipv6/netfilter/ip6_tables.c | 4 +++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
> index 2ed7c58b4..5f0e6096e 100644
> --- a/net/ipv4/netfilter/ip_tables.c
> +++ b/net/ipv4/netfilter/ip_tables.c
> @@ -304,9 +304,11 @@ ipt_do_table(void *priv,
>  
>  #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
>  		/* The packet is traced: log it */
> -		if (unlikely(skb->nf_trace))
> +		if (unlikely(skb->nf_trace)) {
>  			trace_packet(state->net, skb, hook, state->in,
>  				     state->out, table->name, private, e);
> +			nf_reset_trace(skb);
> +		}
>  #endif
>  		/* Standard target? */
>  		if (!t->u.kernel.target->target) {
> diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
> index 2d816277f..ae842a835 100644
> --- a/net/ipv6/netfilter/ip6_tables.c
> +++ b/net/ipv6/netfilter/ip6_tables.c
> @@ -327,9 +327,11 @@ ip6t_do_table(void *priv, struct sk_buff *skb,
>  
>  #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
>  		/* The packet is traced: log it */
> -		if (unlikely(skb->nf_trace))
> +		if (unlikely(skb->nf_trace)) {
>  			trace_packet(state->net, skb, hook, state->in,
>  				     state->out, table->name, private, e);
> +			nf_reset_trace(skb);
> +		}
>  #endif
>  		/* Standard target? */
>  		if (!t->u.kernel.target->target) {
> -- 
> 2.30.2
> 

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

* [PATCH] net: fix duplicate logs of iptables TRACE target
@ 2022-01-24  5:37 kai zhang
  2022-01-24 11:54 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: kai zhang @ 2022-01-24  5:37 UTC (permalink / raw)
  To: pablo, kadlec, fw, davem, yoshfuji, dsahern, kuba,
	netfilter-devel, coreteam, netdev, linux-kernel
  Cc: kai zhang

Below configuration, mangle,filter and security tables have no rule:

# iptables -t raw -I PREROUTING 1 -p tcp --dport 22 -j TRACE
# sysctl net.netfilter.nf_log.2=nf_log_ipv4

There are 5 logs for incoming ssh packet:

kernel: [ 7018.727278] TRACE: raw:PREROUTING:policy:2 IN=enp9s0 ...
kernel: [ 7018.727304] TRACE: mangle:PREROUTING:policy:1 IN=enp9s0 ...
kernel: [ 7018.727327] TRACE: mangle:INPUT:policy:1 IN=enp9s0 ...
kernel: [ 7018.727343] TRACE: filter:INPUT:policy:1 IN=enp9s0 ...
kernel: [ 7018.727359] TRACE: security:INPUT:policy:1 IN=enp9s0 ...

Signed-off-by: kai zhang <zhangkaiheb@126.com>
---
 net/ipv4/netfilter/ip_tables.c  | 4 +++-
 net/ipv6/netfilter/ip6_tables.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 2ed7c58b4..5f0e6096e 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -304,9 +304,11 @@ ipt_do_table(void *priv,
 
 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
 		/* The packet is traced: log it */
-		if (unlikely(skb->nf_trace))
+		if (unlikely(skb->nf_trace)) {
 			trace_packet(state->net, skb, hook, state->in,
 				     state->out, table->name, private, e);
+			nf_reset_trace(skb);
+		}
 #endif
 		/* Standard target? */
 		if (!t->u.kernel.target->target) {
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 2d816277f..ae842a835 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -327,9 +327,11 @@ ip6t_do_table(void *priv, struct sk_buff *skb,
 
 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
 		/* The packet is traced: log it */
-		if (unlikely(skb->nf_trace))
+		if (unlikely(skb->nf_trace)) {
 			trace_packet(state->net, skb, hook, state->in,
 				     state->out, table->name, private, e);
+			nf_reset_trace(skb);
+		}
 #endif
 		/* Standard target? */
 		if (!t->u.kernel.target->target) {
-- 
2.30.2


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

end of thread, other threads:[~2022-01-24 11:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24  5:34 [PATCH] net: fix duplicate logs of iptables TRACE target kai zhang
2022-01-24  7:21 ` Florian Westphal
2022-01-24  5:37 kai zhang
2022-01-24 11:54 ` Pablo Neira Ayuso

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.