All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] bpf: add support for SO_PRIORITY in bpf_getsockopt
@ 2017-11-09 23:04 Vlad Dumitrescu
  2017-11-10  0:43 ` Alexei Starovoitov
  0 siblings, 1 reply; 12+ messages in thread
From: Vlad Dumitrescu @ 2017-11-09 23:04 UTC (permalink / raw)
  To: davem, ast, daniel, brakmo; +Cc: netdev, kraigatgoog

From: Vlad Dumitrescu <vladum@google.com>

Allows BPF_PROG_TYPE_SOCK_OPS programs to read sk_priority.

Signed-off-by: Vlad Dumitrescu <vladum@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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-11-13 22:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-09 23:04 [PATCH net-next] bpf: add support for SO_PRIORITY in bpf_getsockopt Vlad Dumitrescu
2017-11-10  0:43 ` Alexei Starovoitov
2017-11-10 17:51   ` Vlad Dumitrescu
2017-11-10 19:17   ` [PATCH net-next] bpf: expose sk_priority through struct bpf_sock_ops Vlad Dumitrescu
2017-11-10 21:07     ` Daniel Borkmann
2017-11-11  4:06       ` Alexei Starovoitov
2017-11-11 20:46         ` Daniel Borkmann
2017-11-11 22:38           ` Alexei Starovoitov
2017-11-13 19:00             ` Vlad Dumitrescu
2017-11-13 20:09               ` Lawrence Brakmo
2017-11-13 20:20                 ` Daniel Borkmann
2017-11-13 22:51                   ` Alexei Starovoitov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.