Support SCM_TSTAMP_SND case. Then we will get the software timestamp when the driver is about to send the skb. Later, I will support the hardware timestamp. Signed-off-by: Jason Xing <kerneljasonxing@xxxxxxxxx> --- include/linux/skbuff.h | 2 +- include/uapi/linux/bpf.h | 4 ++++ net/core/skbuff.c | 10 ++++++++-- tools/include/uapi/linux/bpf.h | 4 ++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 35c2e864dd4b..de8d3bd311f5 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -4569,7 +4569,7 @@ void skb_tstamp_tx(struct sk_buff *orig_skb, static inline void skb_tx_timestamp(struct sk_buff *skb) { skb_clone_tx_timestamp(skb); - if (skb_shinfo(skb)->tx_flags & SKBTX_SW_TSTAMP) + if (skb_shinfo(skb)->tx_flags & (SKBTX_SW_TSTAMP | SKBTX_BPF)) __skb_tstamp_tx(skb, NULL, NULL, skb->sk, true, SCM_TSTAMP_SND); } diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 30d2c078966b..6a1083bcf779 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7036,6 +7036,10 @@ enum { * dev layer when SK_BPF_CB_TX_TIMESTAMPING * feature is on. */ + BPF_SOCK_OPS_TS_SW_OPT_CB, /* Called when skb is about to send + * to the nic 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 diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d19d577b996f..288eb9869827 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5564,7 +5564,8 @@ static bool skb_enable_app_tstamp(struct sk_buff *skb, int tstype, bool sw) return false; } -static void skb_tstamp_tx_bpf(struct sk_buff *skb, struct sock *sk, int tstype) +static void skb_tstamp_tx_bpf(struct sk_buff *skb, struct sock *sk, + int tstype, bool sw) { int op; @@ -5575,6 +5576,11 @@ static void skb_tstamp_tx_bpf(struct sk_buff *skb, struct sock *sk, int tstype) case SCM_TSTAMP_SCHED: op = BPF_SOCK_OPS_TS_SCHED_OPT_CB; break; + case SCM_TSTAMP_SND: + if (!sw) + return; + op = BPF_SOCK_OPS_TS_SW_OPT_CB; + break; default: return; } @@ -5596,7 +5602,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, /* bpf extension feature entry */ if (skb_shinfo(orig_skb)->tx_flags & SKBTX_BPF) - skb_tstamp_tx_bpf(orig_skb, sk, tstype); + skb_tstamp_tx_bpf(orig_skb, sk, tstype, sw); /* application feature entry */ if (!skb_enable_app_tstamp(orig_skb, tstype, sw)) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index eed91b7296b7..9bd1c7c77b17 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -7029,6 +7029,10 @@ enum { * dev layer when SK_BPF_CB_TX_TIMESTAMPING * feature is on. */ + BPF_SOCK_OPS_TS_SW_OPT_CB, /* Called when skb is about to send + * to the nic 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 -- 2.43.5