]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Prepare the sock_ops ctx and call bpf prog for TX timestamping
authorJason Xing <kerneljasonxing@gmail.com>
Thu, 20 Feb 2025 07:29:30 +0000 (15:29 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 20 Feb 2025 22:28:54 +0000 (14:28 -0800)
This patch introduces a new bpf_skops_tx_timestamping() function
that prepares the "struct bpf_sock_ops" ctx and then executes the
sockops BPF program.

The subsequent patch will utilize bpf_skops_tx_timestamping() at
the existing TX timestamping kernel callbacks (__sk_tstamp_tx
specifically) to call the sockops BPF program. Later, four callback
points to report information to user space based on this patch will
be introduced.

Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20250220072940.99994-3-kerneljasonxing@gmail.com
include/net/sock.h
net/core/sock.c

index a95eedacae76caaddc02cd3bf96859cc4a197a4f..2f6b55c59c1659da619821cd21244777f1bf0434 100644 (file)
@@ -2924,6 +2924,13 @@ int sock_set_timestamping(struct sock *sk, int optname,
                          struct so_timestamping timestamping);
 
 void sock_enable_timestamps(struct sock *sk);
+#if defined(CONFIG_CGROUP_BPF)
+void bpf_skops_tx_timestamping(struct sock *sk, struct sk_buff *skb, int op);
+#else
+static inline void bpf_skops_tx_timestamping(struct sock *sk, struct sk_buff *skb, int op)
+{
+}
+#endif
 void sock_no_linger(struct sock *sk);
 void sock_set_keepalive(struct sock *sk);
 void sock_set_priority(struct sock *sk, u32 priority);
index a197f0a0b8788590f33ba0dda0528b03dc087497..ba653c6a1229282a1d7b8f65079f25eb802d7e48 100644 (file)
@@ -949,6 +949,20 @@ int sock_set_timestamping(struct sock *sk, int optname,
        return 0;
 }
 
+#if defined(CONFIG_CGROUP_BPF)
+void bpf_skops_tx_timestamping(struct sock *sk, struct sk_buff *skb, int op)
+{
+       struct bpf_sock_ops_kern sock_ops;
+
+       memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));
+       sock_ops.op = op;
+       sock_ops.is_fullsock = 1;
+       sock_ops.sk = sk;
+       bpf_skops_init_skb(&sock_ops, skb, 0);
+       __cgroup_bpf_run_filter_sock_ops(sk, &sock_ops, CGROUP_SOCK_OPS);
+}
+#endif
+
 void sock_set_keepalive(struct sock *sk)
 {
        lock_sock(sk);