Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3512445pxb; Mon, 24 Jan 2022 11:06:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgPAmKu2YV4fRKFJw8/ZZNwHF9unFTHGnOlJngwnz8SEAwbS8j2+AQ9PSAbqCUHCpYq5oO X-Received: by 2002:a17:903:2342:b0:14b:449:d517 with SMTP id c2-20020a170903234200b0014b0449d517mr15706415plh.104.1643051210048; Mon, 24 Jan 2022 11:06:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643051210; cv=none; d=google.com; s=arc-20160816; b=Y8c+mlDy5TBBIWuJEvXxP9ayoT1/K5KxGsiKsfXlx5yAjxjpilqZnt9iNkdIEJTw25 cWElpRnVASDL+lYPxJLwf3+Ka0y+bBWRJQB6iR1BBxkJhmEEjXPRa7uPhA1oWWJj8pUK qK2bmWArSaSUiHaVthVG1Ly28VDkaTxbNVtouBUKnOVvm7HBOyuIGS66VMGDXC2msaNB /8YTeThru4kZ5fLk4MQyzt/EvTiQ3lUQTmiaJNwTEbIg4TDFf1Ku0NW7C53t+Rcd01fU yeP7ngqSi0ZmS0gXy9+R43apJvpvYImOsByYlgXajpB5cP3YgoLWwc5plWdLHrK64657 V4WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=b6lPzJay0Edbak75eYKB8oiqvCM5OpeIVy2MHGlZ4ys=; b=wg5khM3+YPUCc2vbqQqme2K6cMIbUI1/keVgrChneKmQIctUWNtFy1p3YjESKD8nPW kYsXvPL57lxQRlSfXMr01h5+27OHH0cX5dM+oGQnMxHacYRN/dRbaRGgQaD2h8QMO5EV goo5Qg3S5blbLvrGuBT5ow8A2/B5B3t5Pl/apMgVlFOjZJBDdcGAmsdfh33wLmI1gqte sOEfUVotdo05PZMQ3yaSXWqY6fEJA017EkcMRqf07XMGu4V05mnw7tyTmZK9dFpGQ9k1 kjigUayZljvmmSeAONmM6neRHAD/JBsWKf8b2kPI86+qLHk64UNR1oUuRGQsvvYul6wK gX9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c20si138703pjv.147.2022.01.24.11.06.35; Mon, 24 Jan 2022 11:06:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238010AbiAXLyf (ORCPT + 99 others); Mon, 24 Jan 2022 06:54:35 -0500 Received: from mail.netfilter.org ([217.70.188.207]:44836 "EHLO mail.netfilter.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiAXLye (ORCPT ); Mon, 24 Jan 2022 06:54:34 -0500 Received: from netfilter.org (unknown [78.30.32.163]) by mail.netfilter.org (Postfix) with ESMTPSA id 955BE60013; Mon, 24 Jan 2022 12:51:32 +0100 (CET) Date: Mon, 24 Jan 2022 12:54:30 +0100 From: Pablo Neira Ayuso To: kai zhang Cc: kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: fix duplicate logs of iptables TRACE target Message-ID: References: <20220124053732.55985-1-zhangkaiheb@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220124053732.55985-1-zhangkaiheb@126.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 >