From: Vlad Dumitrescu <vla...@google.com>

Allows BPF_PROG_TYPE_SOCK_OPS programs to read sk_priority.

Signed-off-by: Vlad Dumitrescu <vla...@google.com>
---
 net/core/filter.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 1afa17935954..61c791f9f628 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3292,8 +3292,20 @@ BPF_CALL_5(bpf_getsockopt, struct bpf_sock_ops_kern *, 
bpf_sock,
        if (!sk_fullsock(sk))
                goto err_clear;
 
+       if (level == SOL_SOCKET) {
+               if (optlen != sizeof(int))
+                       goto err_clear;
+
+               switch (optname) {
+               case SO_PRIORITY:
+                       *((int *)optval) = sk->sk_priority;
+                       break;
+               default:
+                       goto err_clear;
+               }
 #ifdef CONFIG_INET
-       if (level == SOL_TCP && sk->sk_prot->getsockopt == tcp_getsockopt) {
+       } else if (level == SOL_TCP &&
+                  sk->sk_prot->getsockopt == tcp_getsockopt) {
                if (optname == TCP_CONGESTION) {
                        struct inet_connection_sock *icsk = inet_csk(sk);
 
@@ -3304,11 +3316,11 @@ BPF_CALL_5(bpf_getsockopt, struct bpf_sock_ops_kern *, 
bpf_sock,
                } else {
                        goto err_clear;
                }
+#endif
        } else {
                goto err_clear;
        }
        return 0;
-#endif
 err_clear:
        memset(optval, 0, optlen);
        return -EINVAL;
-- 
2.15.0.448.gf294e3d99a-goog

Reply via email to