From: Jason Xing <kernelxing@xxxxxxxxxxx> Support SCM_TSTAMP_SND case. Then we will get the timestamp when the driver is about to send the skb. Signed-off-by: Jason Xing <kernelxing@xxxxxxxxxxx> --- include/uapi/linux/bpf.h | 5 +++++ net/core/skbuff.c | 13 ++++++++++--- tools/include/uapi/linux/bpf.h | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 72f93c6e45c1..a6d761f07f67 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7027,6 +7027,11 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_SW_OPT_CB, /* Called when skb is about to send + * to the nic when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect diff --git a/net/core/skbuff.c b/net/core/skbuff.c index fd4f06b88a2e..73b15d6277f7 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5550,6 +5550,9 @@ static void __skb_tstamp_tx_bpf(struct sock *sk, struct sk_buff *skb, int tstype case SCM_TSTAMP_SCHED: op = BPF_SOCK_OPS_TS_SCHED_OPT_CB; break; + case SCM_TSTAMP_SND: + op = BPF_SOCK_OPS_TS_SW_OPT_CB; + break; default: return; } @@ -5624,7 +5627,8 @@ static bool skb_tstamp_is_set(const struct sk_buff *skb, int tstype, bool bpf_mo return true; return false; case SCM_TSTAMP_SND: - if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_SW_TSTAMP)) + flag = bpf_mode ? SKBTX_BPF : SKBTX_SW_TSTAMP; + if (unlikely(skb_shinfo(skb)->tx_flags & flag)) return true; return false; case SCM_TSTAMP_ACK: @@ -5651,8 +5655,11 @@ EXPORT_SYMBOL_GPL(__skb_tstamp_tx); void skb_tstamp_tx(struct sk_buff *orig_skb, struct skb_shared_hwtstamps *hwtstamps) { - return skb_tstamp_tx_output(orig_skb, NULL, hwtstamps, orig_skb->sk, - SCM_TSTAMP_SND); + int tstype = SCM_TSTAMP_SND; + + skb_tstamp_tx_output(orig_skb, NULL, hwtstamps, orig_skb->sk, tstype); + if (unlikely(skb_tstamp_is_set(orig_skb, tstype, true))) + __skb_tstamp_tx_bpf(orig_skb->sk, orig_skb, tstype); } EXPORT_SYMBOL_GPL(skb_tstamp_tx); diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 891217ab6d2d..73fc0a95c9ca 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -7020,6 +7020,11 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_SW_OPT_CB, /* Called when skb is about to send + * to the nic when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect -- 2.37.3