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 --- 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