]> www.infradead.org Git - users/hch/misc.git/commitdiff
bpf: Add BPF_SOCK_OPS_TSTAMP_ACK_CB callback
authorJason Xing <kerneljasonxing@gmail.com>
Thu, 20 Feb 2025 07:29:37 +0000 (15:29 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 20 Feb 2025 22:29:43 +0000 (14:29 -0800)
Support the ACK case for bpf timestamping.

Add a new sock_ops callback, BPF_SOCK_OPS_TSTAMP_ACK_CB. This
callback will occur at the same timestamping point as the user
space's SCM_TSTAMP_ACK. The BPF program can use it to get the
same SCM_TSTAMP_ACK timestamp without modifying the user-space
application.

This patch extends txstamp_ack to two bits: 1 stands for
SO_TIMESTAMPING mode, 2 bpf extension.

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-10-kerneljasonxing@gmail.com
include/net/tcp.h
include/uapi/linux/bpf.h
net/core/skbuff.c
net/ipv4/tcp.c
tools/include/uapi/linux/bpf.h

index 94ea09faedf45c83bce5bdf751442066546a5622..ae6c95b01012ef5f03e18d6e75ef6f70a9bb1dfc 100644 (file)
@@ -964,10 +964,12 @@ struct tcp_skb_cb {
 
        __u8            sacked;         /* State flags for SACK.        */
        __u8            ip_dsfield;     /* IPv4 tos or IPv6 dsfield     */
-       __u8            txstamp_ack:1,  /* Record TX timestamp for ack? */
+#define TSTAMP_ACK_SK  0x1
+#define TSTAMP_ACK_BPF 0x2
+       __u8            txstamp_ack:2,  /* Record TX timestamp for ack? */
                        eor:1,          /* Is skb MSG_EOR marked? */
                        has_rxtstamp:1, /* SKB has a RX timestamp       */
-                       unused:5;
+                       unused:4;
        __u32           ack_seq;        /* Sequence number ACK'd        */
        union {
                struct {
index 72045c2423963e6c37ca4fce902c71962247bc54..cc10104f34a0a4884b35ef9c2b0b945fbdcecc34 100644 (file)
@@ -7044,6 +7044,11 @@ enum {
                                         * SK_BPF_CB_TX_TIMESTAMPING feature
                                         * is on.
                                         */
+       BPF_SOCK_OPS_TSTAMP_ACK_CB,     /* Called when all the skbs in the
+                                        * same sendmsg call are acked
+                                        * when SK_BPF_CB_TX_TIMESTAMPING
+                                        * feature is on.
+                                        */
 };
 
 /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
index 77b8866f94c5390785d6aeff0d71520fc024c6b7..dd33c12f00ca22a175fd2f7fa828a70f16b0a21f 100644 (file)
@@ -5550,7 +5550,7 @@ static bool skb_tstamp_tx_report_so_timestamping(struct sk_buff *skb,
                return skb_shinfo(skb)->tx_flags & (hwtstamps ? SKBTX_HW_TSTAMP_NOBPF :
                                                    SKBTX_SW_TSTAMP);
        case SCM_TSTAMP_ACK:
-               return TCP_SKB_CB(skb)->txstamp_ack;
+               return TCP_SKB_CB(skb)->txstamp_ack & TSTAMP_ACK_SK;
        }
 
        return false;
@@ -5575,6 +5575,9 @@ static void skb_tstamp_tx_report_bpf_timestamping(struct sk_buff *skb,
                        op = BPF_SOCK_OPS_TSTAMP_SND_SW_CB;
                }
                break;
+       case SCM_TSTAMP_ACK:
+               op = BPF_SOCK_OPS_TSTAMP_ACK_CB;
+               break;
        default:
                return;
        }
index 992d5c9b2487ce7a689253c068ad7b826f6b6fb0..2171e2f045bbfcb46d74095bd88c54275341c379 100644 (file)
@@ -492,7 +492,7 @@ static void tcp_tx_timestamp(struct sock *sk, struct sockcm_cookie *sockc)
 
                sock_tx_timestamp(sk, sockc, &shinfo->tx_flags);
                if (tsflags & SOF_TIMESTAMPING_TX_ACK)
-                       tcb->txstamp_ack = 1;
+                       tcb->txstamp_ack |= TSTAMP_ACK_SK;
                if (tsflags & SOF_TIMESTAMPING_TX_RECORD_MASK)
                        shinfo->tskey = TCP_SKB_CB(skb)->seq + skb->len - 1;
        }
index 72045c2423963e6c37ca4fce902c71962247bc54..cc10104f34a0a4884b35ef9c2b0b945fbdcecc34 100644 (file)
@@ -7044,6 +7044,11 @@ enum {
                                         * SK_BPF_CB_TX_TIMESTAMPING feature
                                         * is on.
                                         */
+       BPF_SOCK_OPS_TSTAMP_ACK_CB,     /* Called when all the skbs in the
+                                        * same sendmsg call are acked
+                                        * when SK_BPF_CB_TX_TIMESTAMPING
+                                        * feature is on.
+                                        */
 };
 
 /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect