[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241207173803.90744-6-kerneljasonxing@gmail.com>
Date: Sun, 8 Dec 2024 01:37:57 +0800
From: Jason Xing <kerneljasonxing@...il.com>
To: davem@...emloft.net,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
dsahern@...nel.org,
willemdebruijn.kernel@...il.com,
willemb@...gle.com,
ast@...nel.org,
daniel@...earbox.net,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org
Cc: bpf@...r.kernel.org,
netdev@...r.kernel.org,
Jason Xing <kernelxing@...cent.com>
Subject: [PATCH net-next v4 05/11] net-timestamp: support SCM_TSTAMP_SND for bpf extension
From: Jason Xing <kernelxing@...cent.com>
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@...cent.com>
---
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
Powered by blists - more mailing lists