]> www.infradead.org Git - users/hch/misc.git/commitdiff
net-timestamp: Prepare for isolating two modes of SO_TIMESTAMPING
authorJason Xing <kerneljasonxing@gmail.com>
Thu, 20 Feb 2025 07:29:33 +0000 (15:29 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 20 Feb 2025 22:29:15 +0000 (14:29 -0800)
No functional changes here. Only add test to see if the orig_skb
matches the usage of application SO_TIMESTAMPING.

In this series, bpf timestamping and previous socket timestamping
are implemented in the same function __skb_tstamp_tx(). To test
the socket enables socket timestamping feature, this function
skb_tstamp_tx_report_so_timestamping() is added.

In the next patch, another check for bpf timestamping feature
will be introduced just like the above report function, namely,
skb_tstamp_tx_report_bpf_timestamping(). Then users will be able
to know the socket enables either or both of features.

Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250220072940.99994-6-kerneljasonxing@gmail.com
net/core/skbuff.c

index a441613a1e6c1765f7fc2e40f982b81f8f8fdb96..341a3290e898217a73e51e55c8afe826fd8e87d2 100644 (file)
@@ -5539,6 +5539,23 @@ err:
 }
 EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);
 
+static bool skb_tstamp_tx_report_so_timestamping(struct sk_buff *skb,
+                                                struct skb_shared_hwtstamps *hwtstamps,
+                                                int tstype)
+{
+       switch (tstype) {
+       case SCM_TSTAMP_SCHED:
+               return skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP;
+       case SCM_TSTAMP_SND:
+               return skb_shinfo(skb)->tx_flags & (hwtstamps ? SKBTX_HW_TSTAMP :
+                                                   SKBTX_SW_TSTAMP);
+       case SCM_TSTAMP_ACK:
+               return TCP_SKB_CB(skb)->txstamp_ack;
+       }
+
+       return false;
+}
+
 void __skb_tstamp_tx(struct sk_buff *orig_skb,
                     const struct sk_buff *ack_skb,
                     struct skb_shared_hwtstamps *hwtstamps,
@@ -5551,6 +5568,9 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
        if (!sk)
                return;
 
+       if (!skb_tstamp_tx_report_so_timestamping(orig_skb, hwtstamps, tstype))
+               return;
+
        tsflags = READ_ONCE(sk->sk_tsflags);
        if (!hwtstamps && !(tsflags & SOF_TIMESTAMPING_OPT_TX_SWHW) &&
            skb_shinfo(orig_skb)->tx_flags & SKBTX_IN_PROGRESS)