All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nf-next v2 6/6] netfilter: nfnetlink_log: only add timestamp on the input path
Date: Wed, 18 Nov 2026 12:57:32 +0100	[thread overview]
Message-ID: <20261118115732.9529-7-fw@strlen.de> (raw)
In-Reply-To: <20261118115732.9529-1-fw@strlen.de>

The timestamp attribute should only be emitted while the packet is on
the input path, like the hardware header attributes.  On output hooks
skb->tstamp can hold the SO_TXTIME transmit time, a delivery deadline
rather than the time the packet was observed.

The old check compared the raw hooknum against NF_INET_FORWARD, which is
meaningless for families with their own hook numbering: it was too
liberal for NFPROTO_ARP and NFPROTO_NETDEV.  Use nfulnl_pre_egress()
instead, so those no longer emit a timestamp at their output hooks.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 v2: adapt to changes in earlier patches, no changes per se.

 net/netfilter/nfnetlink_log.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 5645297b4b3b..697ca7fb1dba 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -548,6 +548,22 @@ static int nfulnl_put_hwheader(struct sk_buff *nlskb, const struct sk_buff *skb,
 	return nla_put(nlskb, NFULA_HWHEADER, len, hwhdrp);
 }
 
+/* The timestamp is the time the packet was observed at the hook.
+ * Only called while the packet is on the input path: on output
+ * hooks skb->tstamp can hold the SO_TXTIME transmit time, which
+ * is a delivery deadline, not an observation time.
+ */
+static int nfulnl_put_timestamp(struct sk_buff *nlskb, const struct sk_buff *skb)
+{
+	struct timespec64 kts = ktime_to_timespec64(skb_tstamp_cond(skb, true));
+	struct nfulnl_msg_packet_timestamp ts = {
+		.sec = cpu_to_be64(kts.tv_sec),
+		.usec = cpu_to_be64(kts.tv_nsec / NSEC_PER_USEC),
+	};
+
+	return nla_put(nlskb, NFULA_TIMESTAMP, sizeof(ts), &ts);
+}
+
 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
 static int nflog_put_master_ifindex(struct sk_buff *nlskb, int attr,
 				    const struct net_device *dev)
@@ -685,15 +701,8 @@ __build_packet_message(struct nfnl_log_net *log,
 		if (indev && skb_mac_header_was_set(skb) &&
 		    nfulnl_put_hwheader(inst->skb, skb, indev))
 			goto nla_put_failure;
-	}
-
-	if (hooknum <= NF_INET_FORWARD) {
-		struct timespec64 kts = ktime_to_timespec64(skb_tstamp_cond(skb, true));
-		struct nfulnl_msg_packet_timestamp ts;
-		ts.sec = cpu_to_be64(kts.tv_sec);
-		ts.usec = cpu_to_be64(kts.tv_nsec / NSEC_PER_USEC);
 
-		if (nla_put(inst->skb, NFULA_TIMESTAMP, sizeof(ts), &ts))
+		if (nfulnl_put_timestamp(inst->skb, skb))
 			goto nla_put_failure;
 	}
 
-- 
2.56.1


      parent reply	other threads:[~2026-11-18 11:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 11:57 [PATCH nf-next v2 0/6] netfilter: logging cleanups Florian Westphal
2026-11-18 11:57 ` [PATCH nf-next v2 1/6] netfilter: nf_log: remove dead ARPHRD_SIT handling from MAC/HW header logging Florian Westphal
2026-11-18 11:57 ` [PATCH nf-next v2 2/6] netfilter: nf_log_syslog: fix MAC header dump to use real header length Florian Westphal
2026-11-18 11:57 ` [PATCH nf-next v2 3/6] netfilter: nfnetlink_log: fix up dev_parse_header usage Florian Westphal
2026-11-18 11:57 ` [PATCH nf-next v2 4/6] netfilter: nfnetlink_log: use real mac header length for hwheader Florian Westphal
2026-11-18 11:57 ` [PATCH nf-next v2 5/6] netfilter: nfnetlink: don't log hwaddr/hwheader on output hooks Florian Westphal
2026-11-18 11:57 ` Florian Westphal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118115732.9529-7-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.