diff mbox series

[netfilter] netfilter: nfnetlink_log: always add a timestamp

Message ID 20230725085443.2102634-1-maze@google.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [netfilter] netfilter: nfnetlink_log: always add a timestamp | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1342 this patch: 1342
netdev/cc_maintainers warning 6 maintainers not CCed: kuba@kernel.org coreteam@netfilter.org davem@davemloft.net kadlec@netfilter.org pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch warning WARNING: line length of 88 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Maciej Żenczykowski July 25, 2023, 8:54 a.m. UTC
Compared to all the other work we're already doing to deliver
an skb to userspace this is very cheap - at worse an extra
call to ktime_get_real() - and very useful.

(and indeed it may even be cheaper if we're running from other hooks)

(background: Android occasionally logs packets which
caused wake from sleep/suspend and we'd like to have
timestamps reliably associated with these events)

Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
 net/netfilter/nfnetlink_log.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Florian Westphal July 27, 2023, 1:58 p.m. UTC | #1
Maciej Żenczykowski <maze@google.com> wrote:
> Compared to all the other work we're already doing to deliver
> an skb to userspace this is very cheap - at worse an extra
> call to ktime_get_real() - and very useful.

Reviewed-by: Florian Westphal <fw@strlen.de>
Maciej Żenczykowski Aug. 4, 2023, 7:26 p.m. UTC | #2
On Thu, Jul 27, 2023 at 3:58 PM Florian Westphal <fw@strlen.de> wrote:
>
> Maciej Żenczykowski <maze@google.com> wrote:
> > Compared to all the other work we're already doing to deliver
> > an skb to userspace this is very cheap - at worse an extra
> > call to ktime_get_real() - and very useful.
>
> Reviewed-by: Florian Westphal <fw@strlen.de>

I'm not sure if there's anything else that needs to happen for this to
get merged.
Maybe it fell through the cracks...?  Maybe I didn't add the right CC's...

Thanks,
Maciej
Florian Westphal Aug. 4, 2023, 7:40 p.m. UTC | #3
Maciej Żenczykowski <maze@google.com> wrote:
> On Thu, Jul 27, 2023 at 3:58 PM Florian Westphal <fw@strlen.de> wrote:
> >
> > Maciej Żenczykowski <maze@google.com> wrote:
> > > Compared to all the other work we're already doing to deliver
> > > an skb to userspace this is very cheap - at worse an extra
> > > call to ktime_get_real() - and very useful.
> >
> > Reviewed-by: Florian Westphal <fw@strlen.de>
> 
> I'm not sure if there's anything else that needs to happen for this to
> get merged.

This is fine, it'll be merged for -next.
diff mbox series

Patch

diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index e57eb168ee13..53c9e76473ba 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -470,7 +470,6 @@  __build_packet_message(struct nfnl_log_net *log,
 	sk_buff_data_t old_tail = inst->skb->tail;
 	struct sock *sk;
 	const unsigned char *hwhdrp;
-	ktime_t tstamp;
 
 	nlh = nfnl_msg_put(inst->skb, 0, 0,
 			   nfnl_msg_type(NFNL_SUBSYS_ULOG, NFULNL_MSG_PACKET),
@@ -599,10 +598,9 @@  __build_packet_message(struct nfnl_log_net *log,
 			goto nla_put_failure;
 	}
 
-	tstamp = skb_tstamp_cond(skb, false);
-	if (hooknum <= NF_INET_FORWARD && tstamp) {
+	if (hooknum <= NF_INET_FORWARD) {
+		struct timespec64 kts = ktime_to_timespec64(skb_tstamp_cond(skb, true));
 		struct nfulnl_msg_packet_timestamp ts;
-		struct timespec64 kts = ktime_to_timespec64(tstamp);
 		ts.sec = cpu_to_be64(kts.tv_sec);
 		ts.usec = cpu_to_be64(kts.tv_nsec / NSEC_PER_USEC);